forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upstream Std.Util.ExtendedBinders (leanprover#3320)
This is not a complete upstreaming of that file (it also supports `∀ᵉ (x < 2) (y < 3), p x y` as shorthand for `∀ x < 2, ∀ y < 3, p x y`, but I don't think we need this; it is used in Mathlib). Syntaxes still need to be made built-in. --------- Co-authored-by: Leonardo de Moura <[email protected]>
- Loading branch information
1 parent
8b0dd2e
commit 329e006
Showing
54 changed files
with
75,326 additions
and
17,891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ import Init.Conv | |
import Init.Guard | ||
import Init.Simproc | ||
import Init.SizeOfLemmas | ||
import Init.BinderPredicates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/- | ||
Copyright (c) 2021 Microsoft Corporation. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Gabriel Ebner | ||
-/ | ||
prelude | ||
import Init.NotationExtra | ||
|
||
namespace Lean | ||
|
||
/-- | ||
The syntax category of binder predicates contains predicates like `> 0`, `∈ s`, etc. | ||
(`: t` should not be a binder predicate because it would clash with the built-in syntax for ∀/∃.) | ||
-/ | ||
declare_syntax_cat binderPred | ||
|
||
/-- | ||
`satisfies_binder_pred% t pred` expands to a proposition expressing that `t` satisfies `pred`. | ||
-/ | ||
syntax "satisfies_binder_pred% " term:max binderPred : term | ||
|
||
-- Extend ∀ and ∃ to binder predicates. | ||
|
||
/-- | ||
The notation `∃ x < 2, p x` is shorthand for `∃ x, x < 2 ∧ p x`, | ||
and similarly for other binary operators. | ||
-/ | ||
syntax "∃ " binderIdent binderPred ", " term : term | ||
/-- | ||
The notation `∀ x < 2, p x` is shorthand for `∀ x, x < 2 → p x`, | ||
and similarly for other binary operators. | ||
-/ | ||
syntax "∀ " binderIdent binderPred ", " term : term | ||
|
||
macro_rules | ||
| `(∃ $x:ident $pred:binderPred, $p) => | ||
`(∃ $x:ident, satisfies_binder_pred% $x $pred ∧ $p) | ||
| `(∃ _ $pred:binderPred, $p) => | ||
`(∃ x, satisfies_binder_pred% x $pred ∧ $p) | ||
|
||
macro_rules | ||
| `(∀ $x:ident $pred:binderPred, $p) => | ||
`(∀ $x:ident, satisfies_binder_pred% $x $pred → $p) | ||
| `(∀ _ $pred:binderPred, $p) => | ||
`(∀ x, satisfies_binder_pred% x $pred → $p) | ||
|
||
/-- Declare `∃ x > y, ...` as syntax for `∃ x, x > y ∧ ...` -/ | ||
binder_predicate x " > " y:term => `($x > $y) | ||
/-- Declare `∃ x ≥ y, ...` as syntax for `∃ x, x ≥ y ∧ ...` -/ | ||
binder_predicate x " ≥ " y:term => `($x ≥ $y) | ||
/-- Declare `∃ x < y, ...` as syntax for `∃ x, x < y ∧ ...` -/ | ||
binder_predicate x " < " y:term => `($x < $y) | ||
/-- Declare `∃ x ≤ y, ...` as syntax for `∃ x, x ≤ y ∧ ...` -/ | ||
binder_predicate x " ≤ " y:term => `($x ≤ $y) | ||
/-- Declare `∃ x ≠ y, ...` as syntax for `∃ x, x ≠ y ∧ ...` -/ | ||
binder_predicate x " ≠ " y:term => `($x ≠ $y) | ||
|
||
end Lean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/- | ||
Copyright (c) 2021 Microsoft Corporation. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Gabriel Ebner | ||
-/ | ||
import Lean.Parser.Syntax | ||
import Lean.Elab.MacroArgUtil | ||
import Lean.Linter.MissingDocs | ||
|
||
namespace Lean.Elab.Command | ||
|
||
@[builtin_command_elab binderPredicate] def elabBinderPred : CommandElab := fun stx => do | ||
match stx with | ||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind binder_predicate%$tk | ||
$[(name := $name?)]? $[(priority := $prio?)]? $x $args:macroArg* => $rhs) => do | ||
let prio ← liftMacroM do evalOptPrio prio? | ||
let (stxParts, patArgs) := (← args.mapM expandMacroArg).unzip | ||
let name ← match name? with | ||
| some name => pure name.getId | ||
| none => liftMacroM do mkNameFromParserSyntax `binderTerm (mkNullNode stxParts) | ||
let nameTk := name?.getD (mkIdentFrom tk name) | ||
/- The command `syntax [<kind>] ...` adds the current namespace to the syntax node kind. | ||
So, we must include current namespace when we create a pattern for the following | ||
`macro_rules` commands. -/ | ||
let pat : TSyntax `binderPred := ⟨(mkNode ((← getCurrNamespace) ++ name) patArgs).1⟩ | ||
elabCommand <|<- | ||
`($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind syntax%$tk | ||
(name := $nameTk) (priority := $(quote prio)) $[$stxParts]* : binderPred | ||
$[$doc?:docComment]? macro_rules%$tk | ||
| `(satisfies_binder_pred% $$($x):term $pat:binderPred) => $rhs) | ||
| _ => throwUnsupportedSyntax | ||
|
||
open Linter.MissingDocs Parser Term in | ||
/-- Missing docs handler for `binder_predicate` -/ | ||
@[builtin_missing_docs_handler Lean.Parser.Command.binderPredicate] | ||
def checkBinderPredicate : SimpleHandler := fun stx => do | ||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» then | ||
if stx[4].isNone then lint stx[3] "binder predicate" | ||
else lintNamed stx[4][0][3] "binder predicate" | ||
|
||
end Lean.Elab.Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.