chore: enforce notation parameter naming convention
This commit is contained in:
parent
762cebbbfc
commit
09d438ca1d
8 changed files with 14 additions and 14 deletions
|
|
@ -379,10 +379,10 @@ def elabNoKindMacroRulesAux (alts : Array Syntax) : CommandElabM Syntax := do
|
|||
|
||||
@[builtinCommandElab «macro_rules»] def elabMacroRules : CommandElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `(macro_rules $alts:matchAlt*) => elabNoKindMacroRulesAux alts
|
||||
| `(macro_rules [$kind] | $x:ident => $rhs) => `(@[macro $kind] def myMacro : Macro := fun $x:ident => $rhs)
|
||||
| `(macro_rules [$kind] $alts:matchAlt*) => do elabMacroRulesAux ((← getCurrNamespace) ++ kind.getId) alts
|
||||
| _ => throwUnsupportedSyntax
|
||||
| `(macro_rules $alts:matchAlt*) => elabNoKindMacroRulesAux alts
|
||||
| `(macro_rules (kind := $kind) | $x:ident => $rhs) => `(@[macro $kind] def myMacro : Macro := fun $x:ident => $rhs)
|
||||
| `(macro_rules (kind := $kind) $alts:matchAlt*) => do elabMacroRulesAux ((← getCurrNamespace) ++ kind.getId) alts
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.mixfix] def expandMixfix : Macro := fun stx =>
|
||||
withAttrKindGlobal stx fun stx => do
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ def mixfixKind := «prefix» <|> «infix» <|> «infixl» <|> «infixr» <|> «p
|
|||
-- thus should be ignored when we use `checkInsideQuot` to prepare the next stage for a builtin syntax change
|
||||
def identPrec := leading_parser ident >> optPrecedence
|
||||
|
||||
def optKind : Parser := optional ("[" >> ident >> "]")
|
||||
def optKind : Parser := optional ("(" >> nonReservedSymbol "kind" >> ":=" >> ident >> ")")
|
||||
|
||||
def notationItem := ppSpace >> withAntiquot (mkAntiquot "notationItem" `Lean.Parser.Command.notationItem) (strLit <|> identPrec)
|
||||
@[builtinCommandParser] def «notation» := leading_parser Term.attrKind >> "notation" >> optPrecedence >> optNamedName >> optNamedPrio >> many notationItem >> darrow >> termParser
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
macro_rules [numLit]
|
||||
macro_rules (kind := numLit)
|
||||
| `($n:numLit) => `("world")
|
||||
|
||||
#check 2
|
||||
|
|
@ -8,7 +8,7 @@ macro_rules
|
|||
|
||||
#check 2
|
||||
|
||||
macro_rules [numLit]
|
||||
macro_rules (kind := numLit)
|
||||
| n => `("boo")
|
||||
|
||||
#check 2
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
-- New notation that overlaps with existing notation
|
||||
syntax (name := myPair) (priority := high) "(" term "," term ")" : term
|
||||
|
||||
macro_rules[myPair]
|
||||
macro_rules (kind := myPair)
|
||||
| `(($a, $b)) => `([$a, $b])
|
||||
|
||||
#eval (1, 2) -- not ambiguous since myPair parser has higher priority
|
||||
|
|
@ -20,7 +20,7 @@ macro_rules
|
|||
|
||||
syntax (name := mySingleton) "[" term "]" : term
|
||||
|
||||
macro_rules[mySingleton]
|
||||
macro_rules (kind := mySingleton)
|
||||
| `([$a]) => `(2 * $a)
|
||||
|
||||
#check [1] -- ambiguous it can be `mySingleton` or the singleton list
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ syntax (name := mycheck) "#check" sepBy(term, ",") : command
|
|||
|
||||
open Lean
|
||||
|
||||
macro_rules [mycheck]
|
||||
macro_rules (kind := mycheck)
|
||||
| `(#check $es,*) =>
|
||||
let cmds := es.getElems.map $ fun e => Syntax.node `Lean.Parser.Command.check #[mkAtom "#check", e]
|
||||
pure $ mkNullNode cmds
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
syntax:65 (name := myAdd1) term "+++" term:65 : term
|
||||
syntax:65 (name := myAdd2) term "+++" term:65 : term
|
||||
|
||||
macro_rules [myAdd1]
|
||||
macro_rules (kind := myAdd1)
|
||||
| `($a +++ $b) => `(Nat.add $a $b)
|
||||
|
||||
macro_rules [myAdd2]
|
||||
macro_rules (kind := myAdd2)
|
||||
| `($a +++ $b) => `(Append.append $a $b)
|
||||
|
||||
#check (1:Nat) +++ 3
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace Foo
|
|||
|
||||
syntax (name := foo) "bla!" term : term
|
||||
|
||||
macro_rules[foo]
|
||||
macro_rules (kind := foo)
|
||||
| `(bla! $x) => pure x
|
||||
|
||||
#check bla! 10
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ open Lean
|
|||
|
||||
syntax (name := myintro) "intros" sepBy(ident, ",") : tactic
|
||||
|
||||
macro_rules [myintro]
|
||||
macro_rules (kind := myintro)
|
||||
| `(tactic| intros $x,*) => pure $ Syntax.node `Lean.Parser.Tactic.intros #[mkAtom "intros", mkNullNode x]
|
||||
|
||||
theorem tst1 {p q : Prop} : p → q → p :=
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue