feat: allow adjusting anonymous antiquot generation at leading_parser
This commit is contained in:
parent
99464c352e
commit
ffee6676ef
3 changed files with 8 additions and 7 deletions
|
|
@ -96,21 +96,21 @@ are turned into a new anonymous constructor application. For example,
|
|||
| _ => Macro.throwUnsupported
|
||||
|
||||
open Lean.Parser in
|
||||
private def elabParserMacroAux (prec : Syntax) (e : Syntax) : TermElabM Syntax := do
|
||||
private def elabParserMacroAux (prec : Syntax) (e : Syntax) (withAnonymousAntiquot : Bool) : TermElabM Syntax := do
|
||||
let (some declName) ← getDeclName?
|
||||
| throwError "invalid `leading_parser` macro, it must be used in definitions"
|
||||
match extractMacroScopes declName with
|
||||
| { name := Name.str _ s _, .. } =>
|
||||
let kind := quote declName
|
||||
let s := quote s
|
||||
``(withAntiquot (mkAntiquot $s $kind) (leadingNode $kind $prec $e))
|
||||
``(withAntiquot (mkAntiquot $s $kind $(quote withAnonymousAntiquot)) (leadingNode $kind $prec $e))
|
||||
| _ => throwError "invalid `leading_parser` macro, unexpected declaration name"
|
||||
|
||||
@[builtinTermElab «leading_parser»] def elabLeadingParserMacro : TermElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `(leading_parser $e) => elabParserMacroAux (quote Parser.maxPrec) e
|
||||
| `(leading_parser : $prec $e) => elabParserMacroAux prec e
|
||||
| _ => throwUnsupportedSyntax
|
||||
| `(leading_parser $[: $prec?]? $[(withAnonymousAntiquot := $anon?)]? $e) =>
|
||||
elabParserMacroAux (prec?.getD (quote Parser.maxPrec)) e (anon?.all (·.isOfKind ``Parser.Term.trueVal))
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
private def elabTParserMacroAux (prec lhsPrec : Syntax) (e : Syntax) : TermElabM Syntax := do
|
||||
let declName? ← getDeclName?
|
||||
|
|
|
|||
|
|
@ -164,7 +164,8 @@ def basicFun : Parser := nodeWithAntiquot "basicFun" `Lean.Parser.Term.basicFun
|
|||
@[builtinTermParser] def «fun» := leading_parser:maxPrec ppAllowUngrouped >> unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts)
|
||||
|
||||
def optExprPrecedence := optional (atomic ":" >> termParser maxPrec)
|
||||
@[builtinTermParser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> termParser
|
||||
def withAnonymousAntiquot := leading_parser atomic ("(" >> nonReservedSymbol "withAnonymousAntiquot" >> " := ") >> (trueVal <|> falseVal) >> ")" >> ppSpace
|
||||
@[builtinTermParser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> optional withAnonymousAntiquot >> termParser
|
||||
@[builtinTermParser] def «trailing_parser» := leading_parser:leadPrec "trailing_parser " >> optExprPrecedence >> optExprPrecedence >> termParser
|
||||
|
||||
@[builtinTermParser] def borrowed := leading_parser "@& " >> termParser leadPrec
|
||||
|
|
|
|||
2
stage0/src/stdlib_flags.h
generated
2
stage0/src/stdlib_flags.h
generated
|
|
@ -8,7 +8,7 @@ options get_default_options() {
|
|||
// switch to `true` for ABI-breaking changes affecting meta code
|
||||
opts = opts.update({"interpreter", "prefer_native"}, false);
|
||||
// switch to `true` for changing built-in parsers used in quotations
|
||||
opts = opts.update({"internal", "parseQuotWithCurrentStage"}, false);
|
||||
opts = opts.update({"internal", "parseQuotWithCurrentStage"}, true);
|
||||
#endif
|
||||
return opts;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue