fix: ignore antiquotations outside quotations
This commit is contained in:
parent
73cf3533a1
commit
f0960b7f89
4 changed files with 10 additions and 7 deletions
|
|
@ -219,7 +219,9 @@ private def declareSyntaxCatQuotParser (catName : Name) : CommandElabM Unit := d
|
|||
@[termParser] def $(mkIdent name) : Lean.ParserDescr :=
|
||||
Lean.ParserDescr.node $(quote kind) $(quote Lean.Parser.maxPrec)
|
||||
(Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol $(quote quotSymbol))
|
||||
(Lean.ParserDescr.binary `andthen (Lean.ParserDescr.cat $(quote catName) 0) (Lean.ParserDescr.symbol ")"))))
|
||||
(Lean.ParserDescr.binary `andthen
|
||||
(Lean.ParserDescr.unary `incQuotDepth (Lean.ParserDescr.cat $(quote catName) 0))
|
||||
(Lean.ParserDescr.symbol ")"))))
|
||||
elabCommand cmd
|
||||
|
||||
@[builtinCommandElab syntaxCat] def elabDeclareSyntaxCat : CommandElab := fun stx => do
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ builtin_initialize
|
|||
registerAlias "interpolatedStr" interpolatedStr
|
||||
registerAlias "orelse" orelse
|
||||
registerAlias "andthen" andthen
|
||||
registerAlias "incQuotDepth" incQuotDepth
|
||||
|
||||
end Parser
|
||||
|
||||
|
|
|
|||
|
|
@ -1696,7 +1696,7 @@ def antiquotExpr : Parser := identNoAntiquot <|> antiquotNestedExpr
|
|||
|
||||
@[inline] def tokenWithAntiquotFn (p : ParserFn) : ParserFn := fun c s => do
|
||||
let s := p c s
|
||||
if s.hasError then
|
||||
if s.hasError || c.quotDepth == 0 then
|
||||
return s
|
||||
let iniSz := s.stackSize
|
||||
let iniPos := s.pos
|
||||
|
|
@ -1739,7 +1739,9 @@ def mkAntiquot (name : String) (kind : Option SyntaxNodeKind) (anonymous := true
|
|||
checkNoWsBefore "no space before spliced term" >> antiquotExpr >>
|
||||
nameP
|
||||
|
||||
def tryAnti (c : ParserContext) (s : ParserState) : Bool :=
|
||||
def tryAnti (c : ParserContext) (s : ParserState) : Bool := do
|
||||
if c.quotDepth == 0 then
|
||||
return false
|
||||
let (s, stx) := peekToken c s
|
||||
match stx with
|
||||
| Except.ok stx@(Syntax.atom _ sym) => sym == "$"
|
||||
|
|
@ -1768,7 +1770,7 @@ def mkAntiquotSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser :=
|
|||
|
||||
@[inline] def withAntiquotSuffixSpliceFn (kind : SyntaxNodeKind) (p suffix : ParserFn) : ParserFn := fun c s => do
|
||||
let s := p c s
|
||||
if s.hasError || !s.stxStack.back.isAntiquot then
|
||||
if s.hasError || c.quotDepth == 0 || !s.stxStack.back.isAntiquot then
|
||||
return s
|
||||
let iniSz := s.stackSize
|
||||
let iniPos := s.pos
|
||||
|
|
@ -1852,7 +1854,7 @@ def parserOfStack (offset : Nat) (prec : Nat := 0) : Parser :=
|
|||
/-- Run `declName` if possible and inside a quotation, or else `p`. The `ParserInfo` will always be taken from `p`. -/
|
||||
def evalInsideQuot (declName : Name) (p : Parser) : Parser := { p with
|
||||
fn := fun c s =>
|
||||
if c.insideQuot && c.env.contains declName then
|
||||
if c.quotDepth > 0 && !c.suppressInsideQuot && c.env.contains declName then
|
||||
evalParserConst declName c s
|
||||
else
|
||||
p.fn c s }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
weirdmacro.lean:1:6: error: expected no space before ':' or string literal
|
||||
weirdmacro.lean:1:30-1:32: error: elaboration function for 'antiquot' has not been implemented
|
||||
weirdmacro.lean:1:32: error: expected command
|
||||
weirdmacro.lean:3:7-3:11: error: unknown identifier 'term'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue