mirror of
https://github.com/leanprover/lean4.git
synced 2026-04-05 11:44:06 +00:00
Compare commits
2 Commits
sofia/pars
...
parser_wit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4187edf5e7 | ||
|
|
7bc9c12462 |
@@ -174,10 +174,10 @@ structure ParserState where
|
|||||||
|
|
||||||
namespace ParserState
|
namespace ParserState
|
||||||
|
|
||||||
@[inline] def hasError (s : ParserState) : Bool :=
|
def hasError (s : ParserState) : Bool :=
|
||||||
s.errorMsg != none
|
s.errorMsg != none
|
||||||
|
|
||||||
@[inline] def stackSize (s : ParserState) : Nat :=
|
def stackSize (s : ParserState) : Nat :=
|
||||||
s.stxStack.size
|
s.stxStack.size
|
||||||
|
|
||||||
def restore (s : ParserState) (iniStackSz : Nat) (iniPos : String.Pos) : ParserState :=
|
def restore (s : ParserState) (iniStackSz : Nat) (iniPos : String.Pos) : ParserState :=
|
||||||
@@ -336,19 +336,19 @@ def dbgTraceState (label : String) (p : Parser) : Parser where
|
|||||||
fn := dbgTraceStateFn label p.fn
|
fn := dbgTraceStateFn label p.fn
|
||||||
info := p.info
|
info := p.info
|
||||||
|
|
||||||
@[noinline] def epsilonInfo : ParserInfo :=
|
@[noinline]def epsilonInfo : ParserInfo :=
|
||||||
{ firstTokens := FirstTokens.epsilon }
|
{ firstTokens := FirstTokens.epsilon }
|
||||||
|
|
||||||
@[inline] def checkStackTopFn (p : Syntax → Bool) (msg : String) : ParserFn := fun _ s =>
|
def checkStackTopFn (p : Syntax → Bool) (msg : String) : ParserFn := fun _ s =>
|
||||||
if p s.stxStack.back then s
|
if p s.stxStack.back then s
|
||||||
else s.mkUnexpectedError msg
|
else s.mkUnexpectedError msg
|
||||||
|
|
||||||
@[inline] def checkStackTop (p : Syntax → Bool) (msg : String) : Parser := {
|
def checkStackTop (p : Syntax → Bool) (msg : String) : Parser := {
|
||||||
info := epsilonInfo,
|
info := epsilonInfo,
|
||||||
fn := checkStackTopFn p msg
|
fn := checkStackTopFn p msg
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def andthenFn (p q : ParserFn) : ParserFn := fun c s =>
|
def andthenFn (p q : ParserFn) : ParserFn := fun c s =>
|
||||||
let s := p c s
|
let s := p c s
|
||||||
if s.hasError then s else q c s
|
if s.hasError then s else q c s
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ def dbgTraceState (label : String) (p : Parser) : Parser where
|
|||||||
firstTokens := p.firstTokens.seq q.firstTokens
|
firstTokens := p.firstTokens.seq q.firstTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def andthen (p q : Parser) : Parser := {
|
def andthen (p q : Parser) : Parser := {
|
||||||
info := andthenInfo p.info q.info,
|
info := andthenInfo p.info q.info,
|
||||||
fn := andthenFn p.fn q.fn
|
fn := andthenFn p.fn q.fn
|
||||||
}
|
}
|
||||||
@@ -366,12 +366,12 @@ def dbgTraceState (label : String) (p : Parser) : Parser where
|
|||||||
instance : AndThen Parser where
|
instance : AndThen Parser where
|
||||||
andThen a b := andthen a (b ())
|
andThen a b := andthen a (b ())
|
||||||
|
|
||||||
@[inline] def nodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s =>
|
def nodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s =>
|
||||||
let iniSz := s.stackSize
|
let iniSz := s.stackSize
|
||||||
let s := p c s
|
let s := p c s
|
||||||
s.mkNode n iniSz
|
s.mkNode n iniSz
|
||||||
|
|
||||||
@[inline] def trailingNodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s =>
|
def trailingNodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s =>
|
||||||
let iniSz := s.stackSize
|
let iniSz := s.stackSize
|
||||||
let s := p c s
|
let s := p c s
|
||||||
s.mkTrailingNode n iniSz
|
s.mkTrailingNode n iniSz
|
||||||
@@ -382,7 +382,7 @@ instance : AndThen Parser where
|
|||||||
firstTokens := p.firstTokens
|
firstTokens := p.firstTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def node (n : SyntaxNodeKind) (p : Parser) : Parser := {
|
def node (n : SyntaxNodeKind) (p : Parser) : Parser := {
|
||||||
info := nodeInfo n p.info,
|
info := nodeInfo n p.info,
|
||||||
fn := nodeFn n p.fn
|
fn := nodeFn n p.fn
|
||||||
}
|
}
|
||||||
@@ -390,7 +390,7 @@ instance : AndThen Parser where
|
|||||||
def errorFn (msg : String) : ParserFn := fun _ s =>
|
def errorFn (msg : String) : ParserFn := fun _ s =>
|
||||||
s.mkUnexpectedError msg
|
s.mkUnexpectedError msg
|
||||||
|
|
||||||
@[inline] def error (msg : String) : Parser := {
|
def error (msg : String) : Parser := {
|
||||||
info := epsilonInfo,
|
info := epsilonInfo,
|
||||||
fn := errorFn msg
|
fn := errorFn msg
|
||||||
}
|
}
|
||||||
@@ -406,7 +406,7 @@ def errorAtSavedPosFn (msg : String) (delta : Bool) : ParserFn := fun c s =>
|
|||||||
/-- Generate an error at the position saved with the `withPosition` combinator.
|
/-- Generate an error at the position saved with the `withPosition` combinator.
|
||||||
If `delta == true`, then it reports at saved position+1.
|
If `delta == true`, then it reports at saved position+1.
|
||||||
This useful to make sure a parser consumed at least one character. -/
|
This useful to make sure a parser consumed at least one character. -/
|
||||||
@[inline] def errorAtSavedPos (msg : String) (delta : Bool) : Parser := {
|
def errorAtSavedPos (msg : String) (delta : Bool) : Parser := {
|
||||||
fn := errorAtSavedPosFn msg delta
|
fn := errorAtSavedPosFn msg delta
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +415,7 @@ def checkPrecFn (prec : Nat) : ParserFn := fun c s =>
|
|||||||
if c.prec <= prec then s
|
if c.prec <= prec then s
|
||||||
else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term"
|
else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term"
|
||||||
|
|
||||||
@[inline] def checkPrec (prec : Nat) : Parser := {
|
def checkPrec (prec : Nat) : Parser := {
|
||||||
info := epsilonInfo,
|
info := epsilonInfo,
|
||||||
fn := checkPrecFn prec
|
fn := checkPrecFn prec
|
||||||
}
|
}
|
||||||
@@ -425,7 +425,7 @@ def checkLhsPrecFn (prec : Nat) : ParserFn := fun _ s =>
|
|||||||
if s.lhsPrec >= prec then s
|
if s.lhsPrec >= prec then s
|
||||||
else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term"
|
else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term"
|
||||||
|
|
||||||
@[inline] def checkLhsPrec (prec : Nat) : Parser := {
|
def checkLhsPrec (prec : Nat) : Parser := {
|
||||||
info := epsilonInfo,
|
info := epsilonInfo,
|
||||||
fn := checkLhsPrecFn prec
|
fn := checkLhsPrecFn prec
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ def setLhsPrecFn (prec : Nat) : ParserFn := fun _ s =>
|
|||||||
if s.hasError then s
|
if s.hasError then s
|
||||||
else { s with lhsPrec := prec }
|
else { s with lhsPrec := prec }
|
||||||
|
|
||||||
@[inline] def setLhsPrec (prec : Nat) : Parser := {
|
def setLhsPrec (prec : Nat) : Parser := {
|
||||||
info := epsilonInfo,
|
info := epsilonInfo,
|
||||||
fn := setLhsPrecFn prec
|
fn := setLhsPrecFn prec
|
||||||
}
|
}
|
||||||
@@ -442,12 +442,12 @@ def setLhsPrecFn (prec : Nat) : ParserFn := fun _ s =>
|
|||||||
private def addQuotDepthFn (i : Int) (p : ParserFn) : ParserFn := fun c s =>
|
private def addQuotDepthFn (i : Int) (p : ParserFn) : ParserFn := fun c s =>
|
||||||
p { c with quotDepth := c.quotDepth + i |>.toNat } s
|
p { c with quotDepth := c.quotDepth + i |>.toNat } s
|
||||||
|
|
||||||
@[inline] def incQuotDepth (p : Parser) : Parser := {
|
def incQuotDepth (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := addQuotDepthFn 1 p.fn
|
fn := addQuotDepthFn 1 p.fn
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def decQuotDepth (p : Parser) : Parser := {
|
def decQuotDepth (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := addQuotDepthFn (-1) p.fn
|
fn := addQuotDepthFn (-1) p.fn
|
||||||
}
|
}
|
||||||
@@ -455,20 +455,20 @@ private def addQuotDepthFn (i : Int) (p : ParserFn) : ParserFn := fun c s =>
|
|||||||
def suppressInsideQuotFn (p : ParserFn) : ParserFn := fun c s =>
|
def suppressInsideQuotFn (p : ParserFn) : ParserFn := fun c s =>
|
||||||
p { c with suppressInsideQuot := true } s
|
p { c with suppressInsideQuot := true } s
|
||||||
|
|
||||||
@[inline] def suppressInsideQuot (p : Parser) : Parser := {
|
def suppressInsideQuot (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := suppressInsideQuotFn p.fn
|
fn := suppressInsideQuotFn p.fn
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def leadingNode (n : SyntaxNodeKind) (prec : Nat) (p : Parser) : Parser :=
|
def leadingNode (n : SyntaxNodeKind) (prec : Nat) (p : Parser) : Parser :=
|
||||||
checkPrec prec >> node n p >> setLhsPrec prec
|
checkPrec prec >> node n p >> setLhsPrec prec
|
||||||
|
|
||||||
@[inline] def trailingNodeAux (n : SyntaxNodeKind) (p : Parser) : TrailingParser := {
|
def trailingNodeAux (n : SyntaxNodeKind) (p : Parser) : TrailingParser := {
|
||||||
info := nodeInfo n p.info,
|
info := nodeInfo n p.info,
|
||||||
fn := trailingNodeFn n p.fn
|
fn := trailingNodeFn n p.fn
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def trailingNode (n : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parser) : TrailingParser :=
|
def trailingNode (n : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parser) : TrailingParser :=
|
||||||
checkPrec prec >> checkLhsPrec lhsPrec >> trailingNodeAux n p >> setLhsPrec prec
|
checkPrec prec >> checkLhsPrec lhsPrec >> trailingNodeAux n p >> setLhsPrec prec
|
||||||
|
|
||||||
def mergeOrElseErrors (s : ParserState) (error1 : Error) (iniPos : String.Pos) (mergeErrors : Bool) : ParserState :=
|
def mergeOrElseErrors (s : ParserState) (error1 : Error) (iniPos : String.Pos) (mergeErrors : Bool) : ParserState :=
|
||||||
@@ -514,7 +514,7 @@ def orelseFnCore (p q : ParserFn) (antiquotBehavior := OrElseOnAntiquotBehavior.
|
|||||||
s := s.mkNode choiceKind iniSz
|
s := s.mkNode choiceKind iniSz
|
||||||
s
|
s
|
||||||
|
|
||||||
@[inline] def orelseFn (p q : ParserFn) : ParserFn :=
|
def orelseFn (p q : ParserFn) : ParserFn :=
|
||||||
orelseFnCore p q
|
orelseFnCore p q
|
||||||
|
|
||||||
@[noinline] def orelseInfo (p q : ParserInfo) : ParserInfo := {
|
@[noinline] def orelseInfo (p q : ParserInfo) : ParserInfo := {
|
||||||
@@ -529,7 +529,7 @@ def orelseFnCore (p q : ParserFn) (antiquotBehavior := OrElseOnAntiquotBehavior.
|
|||||||
NOTE: In order for the pretty printer to retrace an `orelse`, `p` must be a call to `node` or some other parser
|
NOTE: In order for the pretty printer to retrace an `orelse`, `p` must be a call to `node` or some other parser
|
||||||
producing a single node kind. Nested `orelse` calls are flattened for this, i.e. `(node k1 p1 <|> node k2 p2) <|> ...`
|
producing a single node kind. Nested `orelse` calls are flattened for this, i.e. `(node k1 p1 <|> node k2 p2) <|> ...`
|
||||||
is fine as well. -/
|
is fine as well. -/
|
||||||
@[inline] def orelse (p q : Parser) : Parser := {
|
def orelse (p q : Parser) : Parser := {
|
||||||
info := orelseInfo p.info q.info,
|
info := orelseInfo p.info q.info,
|
||||||
fn := orelseFn p.fn q.fn
|
fn := orelseFn p.fn q.fn
|
||||||
}
|
}
|
||||||
@@ -548,7 +548,7 @@ def atomicFn (p : ParserFn) : ParserFn := fun c s =>
|
|||||||
| ⟨stack, lhsPrec, _, cache, some msg⟩ => ⟨stack, lhsPrec, iniPos, cache, some msg⟩
|
| ⟨stack, lhsPrec, _, cache, some msg⟩ => ⟨stack, lhsPrec, iniPos, cache, some msg⟩
|
||||||
| other => other
|
| other => other
|
||||||
|
|
||||||
@[inline] def atomic (p : Parser) : Parser := {
|
def atomic (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := atomicFn p.fn
|
fn := atomicFn p.fn
|
||||||
}
|
}
|
||||||
@@ -566,7 +566,7 @@ def optionalFn (p : ParserFn) : ParserFn := fun c s =>
|
|||||||
firstTokens := p.firstTokens.toOptional
|
firstTokens := p.firstTokens.toOptional
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def optionalNoAntiquot (p : Parser) : Parser := {
|
def optionalNoAntiquot (p : Parser) : Parser := {
|
||||||
info := optionaInfo p.info,
|
info := optionaInfo p.info,
|
||||||
fn := optionalFn p.fn
|
fn := optionalFn p.fn
|
||||||
}
|
}
|
||||||
@@ -577,7 +577,7 @@ def lookaheadFn (p : ParserFn) : ParserFn := fun c s =>
|
|||||||
let s := p c s
|
let s := p c s
|
||||||
if s.hasError then s else s.restore iniSz iniPos
|
if s.hasError then s else s.restore iniSz iniPos
|
||||||
|
|
||||||
@[inline] def lookahead (p : Parser) : Parser := {
|
def lookahead (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := lookaheadFn p.fn
|
fn := lookaheadFn p.fn
|
||||||
}
|
}
|
||||||
@@ -592,7 +592,7 @@ def notFollowedByFn (p : ParserFn) (msg : String) : ParserFn := fun c s =>
|
|||||||
let s := s.restore iniSz iniPos
|
let s := s.restore iniSz iniPos
|
||||||
s.mkUnexpectedError s!"unexpected {msg}"
|
s.mkUnexpectedError s!"unexpected {msg}"
|
||||||
|
|
||||||
@[inline] def notFollowedBy (p : Parser) (msg : String) : Parser := {
|
def notFollowedBy (p : Parser) (msg : String) : Parser := {
|
||||||
fn := notFollowedByFn p.fn msg
|
fn := notFollowedByFn p.fn msg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,22 +608,22 @@ partial def manyAux (p : ParserFn) : ParserFn := fun c s => Id.run do
|
|||||||
s := s.mkNode nullKind iniSz
|
s := s.mkNode nullKind iniSz
|
||||||
manyAux p c s
|
manyAux p c s
|
||||||
|
|
||||||
@[inline] def manyFn (p : ParserFn) : ParserFn := fun c s =>
|
def manyFn (p : ParserFn) : ParserFn := fun c s =>
|
||||||
let iniSz := s.stackSize
|
let iniSz := s.stackSize
|
||||||
let s := manyAux p c s
|
let s := manyAux p c s
|
||||||
s.mkNode nullKind iniSz
|
s.mkNode nullKind iniSz
|
||||||
|
|
||||||
@[inline] def manyNoAntiquot (p : Parser) : Parser := {
|
def manyNoAntiquot (p : Parser) : Parser := {
|
||||||
info := noFirstTokenInfo p.info,
|
info := noFirstTokenInfo p.info,
|
||||||
fn := manyFn p.fn
|
fn := manyFn p.fn
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def many1Fn (p : ParserFn) : ParserFn := fun c s =>
|
def many1Fn (p : ParserFn) : ParserFn := fun c s =>
|
||||||
let iniSz := s.stackSize
|
let iniSz := s.stackSize
|
||||||
let s := andthenFn p (manyAux p) c s
|
let s := andthenFn p (manyAux p) c s
|
||||||
s.mkNode nullKind iniSz
|
s.mkNode nullKind iniSz
|
||||||
|
|
||||||
@[inline] def many1NoAntiquot (p : Parser) : Parser := {
|
def many1NoAntiquot (p : Parser) : Parser := {
|
||||||
info := p.info,
|
info := p.info,
|
||||||
fn := many1Fn p.fn
|
fn := many1Fn p.fn
|
||||||
}
|
}
|
||||||
@@ -675,12 +675,12 @@ def sepBy1Fn (allowTrailingSep : Bool) (p : ParserFn) (sep : ParserFn) : ParserF
|
|||||||
firstTokens := p.firstTokens
|
firstTokens := p.firstTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def sepByNoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := {
|
def sepByNoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := {
|
||||||
info := sepByInfo p.info sep.info,
|
info := sepByInfo p.info sep.info,
|
||||||
fn := sepByFn allowTrailingSep p.fn sep.fn
|
fn := sepByFn allowTrailingSep p.fn sep.fn
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def sepBy1NoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := {
|
def sepBy1NoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := {
|
||||||
info := sepBy1Info p.info sep.info,
|
info := sepBy1Info p.info sep.info,
|
||||||
fn := sepBy1Fn allowTrailingSep p.fn sep.fn
|
fn := sepBy1Fn allowTrailingSep p.fn sep.fn
|
||||||
}
|
}
|
||||||
@@ -698,12 +698,12 @@ def withResultOfFn (p : ParserFn) (f : Syntax → Syntax) : ParserFn := fun c s
|
|||||||
collectKinds := p.collectKinds
|
collectKinds := p.collectKinds
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def withResultOf (p : Parser) (f : Syntax → Syntax) : Parser := {
|
def withResultOf (p : Parser) (f : Syntax → Syntax) : Parser := {
|
||||||
info := withResultOfInfo p.info,
|
info := withResultOfInfo p.info,
|
||||||
fn := withResultOfFn p.fn f
|
fn := withResultOfFn p.fn f
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def many1Unbox (p : Parser) : Parser :=
|
def many1Unbox (p : Parser) : Parser :=
|
||||||
withResultOf (many1NoAntiquot p) fun stx => if stx.getNumArgs == 1 then stx.getArg 0 else stx
|
withResultOf (many1NoAntiquot p) fun stx => if stx.getNumArgs == 1 then stx.getArg 0 else stx
|
||||||
|
|
||||||
partial def satisfyFn (p : Char → Bool) (errorMsg : String := "unexpected character") : ParserFn := fun c s =>
|
partial def satisfyFn (p : Char → Bool) (errorMsg : String := "unexpected character") : ParserFn := fun c s =>
|
||||||
@@ -721,7 +721,7 @@ partial def takeUntilFn (p : Char → Bool) : ParserFn := fun c s =>
|
|||||||
def takeWhileFn (p : Char → Bool) : ParserFn :=
|
def takeWhileFn (p : Char → Bool) : ParserFn :=
|
||||||
takeUntilFn (fun c => !p c)
|
takeUntilFn (fun c => !p c)
|
||||||
|
|
||||||
@[inline] def takeWhile1Fn (p : Char → Bool) (errorMsg : String) : ParserFn :=
|
def takeWhile1Fn (p : Char → Bool) (errorMsg : String) : ParserFn :=
|
||||||
andthenFn (satisfyFn p errorMsg) (takeWhileFn p)
|
andthenFn (satisfyFn p errorMsg) (takeWhileFn p)
|
||||||
|
|
||||||
partial def finishCommentBlock (nesting : Nat) : ParserFn := fun c s =>
|
partial def finishCommentBlock (nesting : Nat) : ParserFn := fun c s =>
|
||||||
@@ -796,12 +796,12 @@ private def rawAux (startPos : String.Pos) (trailingWs : Bool) : ParserFn := fun
|
|||||||
s.pushSyntax atom
|
s.pushSyntax atom
|
||||||
|
|
||||||
/-- Match an arbitrary Parser and return the consumed String in a `Syntax.atom`. -/
|
/-- Match an arbitrary Parser and return the consumed String in a `Syntax.atom`. -/
|
||||||
@[inline] def rawFn (p : ParserFn) (trailingWs := false) : ParserFn := fun c s =>
|
def rawFn (p : ParserFn) (trailingWs := false) : ParserFn := fun c s =>
|
||||||
let startPos := s.pos
|
let startPos := s.pos
|
||||||
let s := p c s
|
let s := p c s
|
||||||
if s.hasError then s else rawAux startPos trailingWs c s
|
if s.hasError then s else rawAux startPos trailingWs c s
|
||||||
|
|
||||||
@[inline] def chFn (c : Char) (trailingWs := false) : ParserFn :=
|
def chFn (c : Char) (trailingWs := false) : ParserFn :=
|
||||||
rawFn (satisfyFn (fun d => c == d) ("'" ++ toString c ++ "'")) trailingWs
|
rawFn (satisfyFn (fun d => c == d) ("'" ++ toString c ++ "'")) trailingWs
|
||||||
|
|
||||||
def rawCh (c : Char) (trailingWs := false) : Parser :=
|
def rawCh (c : Char) (trailingWs := false) : Parser :=
|
||||||
@@ -1119,7 +1119,7 @@ def rawIdentFn : ParserFn := fun c s =>
|
|||||||
if input.atEnd i then s.mkEOIError
|
if input.atEnd i then s.mkEOIError
|
||||||
else identFnAux i none Name.anonymous c s
|
else identFnAux i none Name.anonymous c s
|
||||||
|
|
||||||
@[inline] def satisfySymbolFn (p : String → Bool) (expected : List String) : ParserFn := fun c s =>
|
def satisfySymbolFn (p : String → Bool) (expected : List String) : ParserFn := fun c s =>
|
||||||
let initStackSz := s.stackSize
|
let initStackSz := s.stackSize
|
||||||
let startPos := s.pos
|
let startPos := s.pos
|
||||||
let s := tokenFn expected c s
|
let s := tokenFn expected c s
|
||||||
@@ -1138,10 +1138,10 @@ def symbolInfo (sym : String) : ParserInfo := {
|
|||||||
firstTokens := FirstTokens.tokens [ sym ]
|
firstTokens := FirstTokens.tokens [ sym ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def symbolFn (sym : String) : ParserFn :=
|
def symbolFn (sym : String) : ParserFn :=
|
||||||
symbolFnAux sym ("'" ++ sym ++ "'")
|
symbolFnAux sym ("'" ++ sym ++ "'")
|
||||||
|
|
||||||
@[inline] def symbolNoAntiquot (sym : String) : Parser :=
|
def symbolNoAntiquot (sym : String) : Parser :=
|
||||||
let sym := sym.trim
|
let sym := sym.trim
|
||||||
{ info := symbolInfo sym,
|
{ info := symbolInfo sym,
|
||||||
fn := symbolFn sym }
|
fn := symbolFn sym }
|
||||||
@@ -1175,7 +1175,7 @@ def nonReservedSymbolFnAux (sym : String) (errorMsg : String) : ParserFn := fun
|
|||||||
s.mkErrorAt errorMsg startPos initStackSz
|
s.mkErrorAt errorMsg startPos initStackSz
|
||||||
| _ => s.mkErrorAt errorMsg startPos initStackSz
|
| _ => s.mkErrorAt errorMsg startPos initStackSz
|
||||||
|
|
||||||
@[inline] def nonReservedSymbolFn (sym : String) : ParserFn :=
|
def nonReservedSymbolFn (sym : String) : ParserFn :=
|
||||||
nonReservedSymbolFnAux sym ("'" ++ sym ++ "'")
|
nonReservedSymbolFnAux sym ("'" ++ sym ++ "'")
|
||||||
|
|
||||||
def nonReservedSymbolInfo (sym : String) (includeIdent : Bool) : ParserInfo := {
|
def nonReservedSymbolInfo (sym : String) (includeIdent : Bool) : ParserInfo := {
|
||||||
@@ -1186,7 +1186,7 @@ def nonReservedSymbolInfo (sym : String) (includeIdent : Bool) : ParserInfo := {
|
|||||||
FirstTokens.tokens [ sym ]
|
FirstTokens.tokens [ sym ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def nonReservedSymbolNoAntiquot (sym : String) (includeIdent := false) : Parser :=
|
def nonReservedSymbolNoAntiquot (sym : String) (includeIdent := false) : Parser :=
|
||||||
let sym := sym.trim
|
let sym := sym.trim
|
||||||
{ info := nonReservedSymbolInfo sym includeIdent,
|
{ info := nonReservedSymbolInfo sym includeIdent,
|
||||||
fn := nonReservedSymbolFn sym }
|
fn := nonReservedSymbolFn sym }
|
||||||
@@ -1251,10 +1251,10 @@ def unicodeSymbolInfo (sym asciiSym : String) : ParserInfo := {
|
|||||||
firstTokens := FirstTokens.tokens [ sym, asciiSym ]
|
firstTokens := FirstTokens.tokens [ sym, asciiSym ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def unicodeSymbolFn (sym asciiSym : String) : ParserFn :=
|
def unicodeSymbolFn (sym asciiSym : String) : ParserFn :=
|
||||||
unicodeSymbolFnAux sym asciiSym ["'" ++ sym ++ "', '" ++ asciiSym ++ "'"]
|
unicodeSymbolFnAux sym asciiSym ["'" ++ sym ++ "', '" ++ asciiSym ++ "'"]
|
||||||
|
|
||||||
@[inline] def unicodeSymbolNoAntiquot (sym asciiSym : String) : Parser :=
|
def unicodeSymbolNoAntiquot (sym asciiSym : String) : Parser :=
|
||||||
let sym := sym.trim
|
let sym := sym.trim
|
||||||
let asciiSym := asciiSym.trim
|
let asciiSym := asciiSym.trim
|
||||||
{ info := unicodeSymbolInfo sym asciiSym,
|
{ info := unicodeSymbolInfo sym asciiSym,
|
||||||
@@ -1270,7 +1270,7 @@ def numLitFn : ParserFn :=
|
|||||||
let s := tokenFn ["numeral"] c s
|
let s := tokenFn ["numeral"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isOfKind numLitKind) then s.mkErrorAt "numeral" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isOfKind numLitKind) then s.mkErrorAt "numeral" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def numLitNoAntiquot : Parser := {
|
def numLitNoAntiquot : Parser := {
|
||||||
fn := numLitFn,
|
fn := numLitFn,
|
||||||
info := mkAtomicInfo "num"
|
info := mkAtomicInfo "num"
|
||||||
}
|
}
|
||||||
@@ -1282,7 +1282,7 @@ def scientificLitFn : ParserFn :=
|
|||||||
let s := tokenFn ["scientific number"] c s
|
let s := tokenFn ["scientific number"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isOfKind scientificLitKind) then s.mkErrorAt "scientific number" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isOfKind scientificLitKind) then s.mkErrorAt "scientific number" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def scientificLitNoAntiquot : Parser := {
|
def scientificLitNoAntiquot : Parser := {
|
||||||
fn := scientificLitFn,
|
fn := scientificLitFn,
|
||||||
info := mkAtomicInfo "scientific"
|
info := mkAtomicInfo "scientific"
|
||||||
}
|
}
|
||||||
@@ -1293,7 +1293,7 @@ def strLitFn : ParserFn := fun c s =>
|
|||||||
let s := tokenFn ["string literal"] c s
|
let s := tokenFn ["string literal"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isOfKind strLitKind) then s.mkErrorAt "string literal" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isOfKind strLitKind) then s.mkErrorAt "string literal" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def strLitNoAntiquot : Parser := {
|
def strLitNoAntiquot : Parser := {
|
||||||
fn := strLitFn,
|
fn := strLitFn,
|
||||||
info := mkAtomicInfo "str"
|
info := mkAtomicInfo "str"
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1304,7 @@ def charLitFn : ParserFn := fun c s =>
|
|||||||
let s := tokenFn ["char literal"] c s
|
let s := tokenFn ["char literal"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isOfKind charLitKind) then s.mkErrorAt "character literal" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isOfKind charLitKind) then s.mkErrorAt "character literal" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def charLitNoAntiquot : Parser := {
|
def charLitNoAntiquot : Parser := {
|
||||||
fn := charLitFn,
|
fn := charLitFn,
|
||||||
info := mkAtomicInfo "char"
|
info := mkAtomicInfo "char"
|
||||||
}
|
}
|
||||||
@@ -1315,7 +1315,7 @@ def nameLitFn : ParserFn := fun c s =>
|
|||||||
let s := tokenFn ["Name literal"] c s
|
let s := tokenFn ["Name literal"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isOfKind nameLitKind) then s.mkErrorAt "Name literal" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isOfKind nameLitKind) then s.mkErrorAt "Name literal" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def nameLitNoAntiquot : Parser := {
|
def nameLitNoAntiquot : Parser := {
|
||||||
fn := nameLitFn,
|
fn := nameLitFn,
|
||||||
info := mkAtomicInfo "name"
|
info := mkAtomicInfo "name"
|
||||||
}
|
}
|
||||||
@@ -1326,12 +1326,12 @@ def identFn : ParserFn := fun c s =>
|
|||||||
let s := tokenFn ["identifier"] c s
|
let s := tokenFn ["identifier"] c s
|
||||||
if !s.hasError && !(s.stxStack.back.isIdent) then s.mkErrorAt "identifier" iniPos initStackSz else s
|
if !s.hasError && !(s.stxStack.back.isIdent) then s.mkErrorAt "identifier" iniPos initStackSz else s
|
||||||
|
|
||||||
@[inline] def identNoAntiquot : Parser := {
|
def identNoAntiquot : Parser := {
|
||||||
fn := identFn,
|
fn := identFn,
|
||||||
info := mkAtomicInfo "ident"
|
info := mkAtomicInfo "ident"
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def rawIdentNoAntiquot : Parser := {
|
def rawIdentNoAntiquot : Parser := {
|
||||||
fn := rawIdentFn
|
fn := rawIdentFn
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1345,7 +1345,7 @@ def identEqFn (id : Name) : ParserFn := fun c s =>
|
|||||||
| Syntax.ident _ _ val _ => if val != id then s.mkErrorAt ("expected identifier '" ++ toString id ++ "'") iniPos initStackSz else s
|
| Syntax.ident _ _ val _ => if val != id then s.mkErrorAt ("expected identifier '" ++ toString id ++ "'") iniPos initStackSz else s
|
||||||
| _ => s.mkErrorAt "identifier" iniPos initStackSz
|
| _ => s.mkErrorAt "identifier" iniPos initStackSz
|
||||||
|
|
||||||
@[inline] def identEq (id : Name) : Parser := {
|
def identEq (id : Name) : Parser := {
|
||||||
fn := identEqFn id,
|
fn := identEqFn id,
|
||||||
info := mkAtomicInfo "ident"
|
info := mkAtomicInfo "ident"
|
||||||
}
|
}
|
||||||
@@ -1467,7 +1467,7 @@ def anyOfFn : List Parser → ParserFn
|
|||||||
| [p], c, s => p.fn c s
|
| [p], c, s => p.fn c s
|
||||||
| p::ps, c, s => orelseFn p.fn (anyOfFn ps) c s
|
| p::ps, c, s => orelseFn p.fn (anyOfFn ps) c s
|
||||||
|
|
||||||
@[inline] def checkColGeFn (errorMsg : String) : ParserFn := fun c s =>
|
def checkColGeFn (errorMsg : String) : ParserFn := fun c s =>
|
||||||
match c.savedPos? with
|
match c.savedPos? with
|
||||||
| none => s
|
| none => s
|
||||||
| some savedPos =>
|
| some savedPos =>
|
||||||
@@ -1476,10 +1476,10 @@ def anyOfFn : List Parser → ParserFn
|
|||||||
if pos.column ≥ savedPos.column then s
|
if pos.column ≥ savedPos.column then s
|
||||||
else s.mkError errorMsg
|
else s.mkError errorMsg
|
||||||
|
|
||||||
@[inline] def checkColGe (errorMsg : String := "checkColGe") : Parser :=
|
def checkColGe (errorMsg : String := "checkColGe") : Parser :=
|
||||||
{ fn := checkColGeFn errorMsg }
|
{ fn := checkColGeFn errorMsg }
|
||||||
|
|
||||||
@[inline] def checkColGtFn (errorMsg : String) : ParserFn := fun c s =>
|
def checkColGtFn (errorMsg : String) : ParserFn := fun c s =>
|
||||||
match c.savedPos? with
|
match c.savedPos? with
|
||||||
| none => s
|
| none => s
|
||||||
| some savedPos =>
|
| some savedPos =>
|
||||||
@@ -1488,10 +1488,10 @@ def anyOfFn : List Parser → ParserFn
|
|||||||
if pos.column > savedPos.column then s
|
if pos.column > savedPos.column then s
|
||||||
else s.mkError errorMsg
|
else s.mkError errorMsg
|
||||||
|
|
||||||
@[inline] def checkColGt (errorMsg : String := "checkColGt") : Parser :=
|
def checkColGt (errorMsg : String := "checkColGt") : Parser :=
|
||||||
{ fn := checkColGtFn errorMsg }
|
{ fn := checkColGtFn errorMsg }
|
||||||
|
|
||||||
@[inline] def checkLineEqFn (errorMsg : String) : ParserFn := fun c s =>
|
def checkLineEqFn (errorMsg : String) : ParserFn := fun c s =>
|
||||||
match c.savedPos? with
|
match c.savedPos? with
|
||||||
| none => s
|
| none => s
|
||||||
| some savedPos =>
|
| some savedPos =>
|
||||||
@@ -1500,16 +1500,16 @@ def anyOfFn : List Parser → ParserFn
|
|||||||
if pos.line == savedPos.line then s
|
if pos.line == savedPos.line then s
|
||||||
else s.mkError errorMsg
|
else s.mkError errorMsg
|
||||||
|
|
||||||
@[inline] def checkLineEq (errorMsg : String := "checkLineEq") : Parser :=
|
def checkLineEq (errorMsg : String := "checkLineEq") : Parser :=
|
||||||
{ fn := checkLineEqFn errorMsg }
|
{ fn := checkLineEqFn errorMsg }
|
||||||
|
|
||||||
@[inline] def withPosition (p : Parser) : Parser := {
|
def withPosition (p : Parser) : Parser := {
|
||||||
info := p.info
|
info := p.info
|
||||||
fn := fun c s =>
|
fn := fun c s =>
|
||||||
p.fn { c with savedPos? := s.pos } s
|
p.fn { c with savedPos? := s.pos } s
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def withPositionAfterLinebreak (p : Parser) : Parser := {
|
def withPositionAfterLinebreak (p : Parser) : Parser := {
|
||||||
info := p.info
|
info := p.info
|
||||||
fn := fun c s =>
|
fn := fun c s =>
|
||||||
let prev := s.stxStack.back
|
let prev := s.stxStack.back
|
||||||
@@ -1517,17 +1517,17 @@ def anyOfFn : List Parser → ParserFn
|
|||||||
p.fn c s
|
p.fn c s
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def withoutPosition (p : Parser) : Parser := {
|
def withoutPosition (p : Parser) : Parser := {
|
||||||
info := p.info
|
info := p.info
|
||||||
fn := fun c s => p.fn { c with savedPos? := none } s
|
fn := fun c s => p.fn { c with savedPos? := none } s
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def withForbidden (tk : Token) (p : Parser) : Parser := {
|
def withForbidden (tk : Token) (p : Parser) : Parser := {
|
||||||
info := p.info
|
info := p.info
|
||||||
fn := fun c s => p.fn { c with forbiddenTk? := tk } s
|
fn := fun c s => p.fn { c with forbiddenTk? := tk } s
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def withoutForbidden (p : Parser) : Parser := {
|
def withoutForbidden (p : Parser) : Parser := {
|
||||||
info := p.info
|
info := p.info
|
||||||
fn := fun c s => p.fn { c with forbiddenTk? := none } s
|
fn := fun c s => p.fn { c with forbiddenTk? := none } s
|
||||||
}
|
}
|
||||||
@@ -1537,7 +1537,7 @@ def eoiFn : ParserFn := fun c s =>
|
|||||||
if c.input.atEnd i then s
|
if c.input.atEnd i then s
|
||||||
else s.mkError "expected end of file"
|
else s.mkError "expected end of file"
|
||||||
|
|
||||||
@[inline] def eoi : Parser :=
|
def eoi : Parser :=
|
||||||
{ fn := eoiFn }
|
{ fn := eoiFn }
|
||||||
|
|
||||||
open Std (RBMap RBMap.empty)
|
open Std (RBMap RBMap.empty)
|
||||||
@@ -1676,7 +1676,7 @@ def categoryParser (catName : Name) (prec : Nat) : Parser := {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Define `termParser` here because we need it for antiquotations
|
-- Define `termParser` here because we need it for antiquotations
|
||||||
@[inline] def termParser (prec : Nat := 0) : Parser :=
|
def termParser (prec : Nat := 0) : Parser :=
|
||||||
categoryParser `term prec
|
categoryParser `term prec
|
||||||
|
|
||||||
-- ==================
|
-- ==================
|
||||||
@@ -1724,7 +1724,7 @@ def tokenAntiquotFn : ParserFn := fun c s => Id.run do
|
|||||||
return s.restore iniSz iniPos
|
return s.restore iniSz iniPos
|
||||||
s.mkNode (`token_antiquot) (iniSz - 1)
|
s.mkNode (`token_antiquot) (iniSz - 1)
|
||||||
|
|
||||||
@[inline] def tokenWithAntiquot (p : Parser) : Parser where
|
def tokenWithAntiquot (p : Parser) : Parser where
|
||||||
fn c s :=
|
fn c s :=
|
||||||
let s := p.fn c s
|
let s := p.fn c s
|
||||||
-- fast check that is false in most cases
|
-- fast check that is false in most cases
|
||||||
@@ -1734,15 +1734,15 @@ def tokenAntiquotFn : ParserFn := fun c s => Id.run do
|
|||||||
s
|
s
|
||||||
info := p.info
|
info := p.info
|
||||||
|
|
||||||
@[inline] def symbol (sym : String) : Parser :=
|
def symbol (sym : String) : Parser :=
|
||||||
tokenWithAntiquot (symbolNoAntiquot sym)
|
tokenWithAntiquot (symbolNoAntiquot sym)
|
||||||
|
|
||||||
instance : Coe String Parser := ⟨fun s => symbol s ⟩
|
instance : Coe String Parser := ⟨fun s => symbol s ⟩
|
||||||
|
|
||||||
@[inline] def nonReservedSymbol (sym : String) (includeIdent := false) : Parser :=
|
def nonReservedSymbol (sym : String) (includeIdent := false) : Parser :=
|
||||||
tokenWithAntiquot (nonReservedSymbolNoAntiquot sym includeIdent)
|
tokenWithAntiquot (nonReservedSymbolNoAntiquot sym includeIdent)
|
||||||
|
|
||||||
@[inline] def unicodeSymbol (sym asciiSym : String) : Parser :=
|
def unicodeSymbol (sym asciiSym : String) : Parser :=
|
||||||
tokenWithAntiquot (unicodeSymbolNoAntiquot sym asciiSym)
|
tokenWithAntiquot (unicodeSymbolNoAntiquot sym asciiSym)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
@@ -1762,7 +1762,7 @@ def mkAntiquot (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPs
|
|||||||
checkNoWsBefore "no space before spliced term" >> antiquotExpr >>
|
checkNoWsBefore "no space before spliced term" >> antiquotExpr >>
|
||||||
nameP
|
nameP
|
||||||
|
|
||||||
@[inline] def withAntiquotFn (antiquotP p : ParserFn) (isCatAntiquot := false) : ParserFn := fun c s =>
|
def withAntiquotFn (antiquotP p : ParserFn) (isCatAntiquot := false) : ParserFn := fun c s =>
|
||||||
-- fast check that is false in most cases
|
-- fast check that is false in most cases
|
||||||
if c.input.get s.pos == '$' then
|
if c.input.get s.pos == '$' then
|
||||||
-- Do not allow antiquotation choice nodes here as `antiquotP` is the strictly more general
|
-- Do not allow antiquotation choice nodes here as `antiquotP` is the strictly more general
|
||||||
@@ -1774,7 +1774,7 @@ def mkAntiquot (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPs
|
|||||||
p c s
|
p c s
|
||||||
|
|
||||||
/-- Optimized version of `mkAntiquot ... <|> p`. -/
|
/-- Optimized version of `mkAntiquot ... <|> p`. -/
|
||||||
@[inline] def withAntiquot (antiquotP p : Parser) : Parser := {
|
def withAntiquot (antiquotP p : Parser) : Parser := {
|
||||||
fn := withAntiquotFn antiquotP.fn p.fn,
|
fn := withAntiquotFn antiquotP.fn p.fn,
|
||||||
info := orelseInfo antiquotP.info p.info
|
info := orelseInfo antiquotP.info p.info
|
||||||
}
|
}
|
||||||
@@ -1800,7 +1800,7 @@ private def withAntiquotSuffixSpliceFn (kind : SyntaxNodeKind) (suffix : ParserF
|
|||||||
s.mkNode (kind ++ `antiquot_suffix_splice) (s.stxStack.size - 2)
|
s.mkNode (kind ++ `antiquot_suffix_splice) (s.stxStack.size - 2)
|
||||||
|
|
||||||
/-- Parse `suffix` after an antiquotation, e.g. `$x,*`, and put both into a new node. -/
|
/-- Parse `suffix` after an antiquotation, e.g. `$x,*`, and put both into a new node. -/
|
||||||
@[inline] def withAntiquotSuffixSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser where
|
def withAntiquotSuffixSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser where
|
||||||
info := andthenInfo p.info suffix.info
|
info := andthenInfo p.info suffix.info
|
||||||
fn c s :=
|
fn c s :=
|
||||||
let s := p.fn c s
|
let s := p.fn c s
|
||||||
@@ -1857,7 +1857,7 @@ def leadingParserAux (kind : Name) (tables : PrattParsingTables) (behavior : Lea
|
|||||||
let s := longestMatchFn none ps c s
|
let s := longestMatchFn none ps c s
|
||||||
mkResult s iniSz
|
mkResult s iniSz
|
||||||
|
|
||||||
@[inline] def leadingParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn :=
|
def leadingParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn :=
|
||||||
withAntiquotFn (isCatAntiquot := true) antiquotParser (leadingParserAux kind tables behavior)
|
withAntiquotFn (isCatAntiquot := true) antiquotParser (leadingParserAux kind tables behavior)
|
||||||
|
|
||||||
def trailingLoopStep (tables : PrattParsingTables) (left : Syntax) (ps : List (Parser × Nat)) : ParserFn := fun c s =>
|
def trailingLoopStep (tables : PrattParsingTables) (left : Syntax) (ps : List (Parser × Nat)) : ParserFn := fun c s =>
|
||||||
@@ -1904,7 +1904,7 @@ partial def trailingLoop (tables : PrattParsingTables) (c : ParserContext) (s :
|
|||||||
`antiquotParser` should be a `mkAntiquot` parser (or always fail) and is tried before all other parsers.
|
`antiquotParser` should be a `mkAntiquot` parser (or always fail) and is tried before all other parsers.
|
||||||
It should not be added to the regular leading parsers because it would heavily
|
It should not be added to the regular leading parsers because it would heavily
|
||||||
overlap with antiquotation parsers nested inside them. -/
|
overlap with antiquotation parsers nested inside them. -/
|
||||||
@[inline] def prattParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn := fun c s =>
|
def prattParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn := fun c s =>
|
||||||
let s := leadingParser kind tables behavior antiquotParser c s
|
let s := leadingParser kind tables behavior antiquotParser c s
|
||||||
if s.hasError then
|
if s.hasError then
|
||||||
s
|
s
|
||||||
@@ -1921,13 +1921,13 @@ def fieldIdxFn : ParserFn := fun c s =>
|
|||||||
else
|
else
|
||||||
s.mkErrorAt "field index" iniPos initStackSz
|
s.mkErrorAt "field index" iniPos initStackSz
|
||||||
|
|
||||||
@[inline] def fieldIdx : Parser :=
|
def fieldIdx : Parser :=
|
||||||
withAntiquot (mkAntiquot "fieldIdx" `fieldIdx) {
|
withAntiquot (mkAntiquot "fieldIdx" `fieldIdx) {
|
||||||
fn := fieldIdxFn,
|
fn := fieldIdxFn,
|
||||||
info := mkAtomicInfo "fieldIdx"
|
info := mkAtomicInfo "fieldIdx"
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline] def skip : Parser := {
|
def skip : Parser := {
|
||||||
fn := fun _ s => s,
|
fn := fun _ s => s,
|
||||||
info := epsilonInfo
|
info := epsilonInfo
|
||||||
}
|
}
|
||||||
@@ -1939,13 +1939,13 @@ namespace Syntax
|
|||||||
section
|
section
|
||||||
variable {β : Type} {m : Type → Type} [Monad m]
|
variable {β : Type} {m : Type → Type} [Monad m]
|
||||||
|
|
||||||
@[inline] def foldArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β :=
|
def foldArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β :=
|
||||||
s.getArgs.foldlM (flip f) b
|
s.getArgs.foldlM (flip f) b
|
||||||
|
|
||||||
@[inline] def foldArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β :=
|
def foldArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β :=
|
||||||
Id.run (s.foldArgsM f b)
|
Id.run (s.foldArgsM f b)
|
||||||
|
|
||||||
@[inline] def forArgsM (s : Syntax) (f : Syntax → m Unit) : m Unit :=
|
def forArgsM (s : Syntax) (f : Syntax → m Unit) : m Unit :=
|
||||||
s.foldArgsM (fun s _ => f s) ()
|
s.foldArgsM (fun s _ => f s) ()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
BIN
stage0/src/Bootstrap.lean
generated
BIN
stage0/src/Bootstrap.lean
generated
Binary file not shown.
BIN
stage0/src/CMakeLists.txt
generated
BIN
stage0/src/CMakeLists.txt
generated
Binary file not shown.
BIN
stage0/src/Init.lean
generated
BIN
stage0/src/Init.lean
generated
Binary file not shown.
BIN
stage0/src/Init/Core.lean
generated
BIN
stage0/src/Init/Core.lean
generated
Binary file not shown.
BIN
stage0/src/Init/Data.lean
generated
BIN
stage0/src/Init/Data.lean
generated
Binary file not shown.
BIN
stage0/src/Init/Data/Channel.lean
generated
Normal file
BIN
stage0/src/Init/Data/Channel.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Init/Data/Queue.lean
generated
Normal file
BIN
stage0/src/Init/Data/Queue.lean
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
stage0/src/Init/Prelude.lean
generated
BIN
stage0/src/Init/Prelude.lean
generated
Binary file not shown.
BIN
stage0/src/Init/System.lean
generated
BIN
stage0/src/Init/System.lean
generated
Binary file not shown.
BIN
stage0/src/Init/System/IO.lean
generated
BIN
stage0/src/Init/System/IO.lean
generated
Binary file not shown.
BIN
stage0/src/Init/System/Mutex.lean
generated
Normal file
BIN
stage0/src/Init/System/Mutex.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Init/System/Promise.lean
generated
Normal file
BIN
stage0/src/Init/System/Promise.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/AlphaEqv.lean
generated
Normal file
BIN
stage0/src/Lean/Compiler/LCNF/AlphaEqv.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Basic.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Basic.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Bind.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Bind.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/CSE.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/CSE.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Check.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Check.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/CompilerM.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/CompilerM.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/InferType.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/InferType.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/LCtx.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/LCtx.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Main.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Main.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/PassManager.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/PassManager.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Passes.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Passes.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/PullFunDecls.lean
generated
Normal file
BIN
stage0/src/Lean/Compiler/LCNF/PullFunDecls.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/PullLetDecls.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/PullLetDecls.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/PullLocalDecls.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/PullLocalDecls.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/ReduceJpArity.lean
generated
Normal file
BIN
stage0/src/Lean/Compiler/LCNF/ReduceJpArity.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Simp.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/Simp.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/Testing.lean
generated
Normal file
BIN
stage0/src/Lean/Compiler/LCNF/Testing.lean
generated
Normal file
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/ToExpr.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/ToExpr.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Compiler/LCNF/ToLCNF.lean
generated
BIN
stage0/src/Lean/Compiler/LCNF/ToLCNF.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Data/RBMap.lean
generated
BIN
stage0/src/Lean/Data/RBMap.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Elab/Deriving/TypeName.lean
generated
BIN
stage0/src/Lean/Elab/Deriving/TypeName.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Meta/CongrTheorems.lean
generated
BIN
stage0/src/Lean/Meta/CongrTheorems.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Meta/Instances.lean
generated
BIN
stage0/src/Lean/Meta/Instances.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Modifiers.lean
generated
BIN
stage0/src/Lean/Modifiers.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Parser/Basic.lean
generated
BIN
stage0/src/Lean/Parser/Basic.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Server/Rpc/Basic.lean
generated
BIN
stage0/src/Lean/Server/Rpc/Basic.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Server/Watchdog.lean
generated
BIN
stage0/src/Lean/Server/Watchdog.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Widget/Basic.lean
generated
BIN
stage0/src/Lean/Widget/Basic.lean
generated
Binary file not shown.
BIN
stage0/src/Lean/Widget/InteractiveDiagnostic.lean
generated
BIN
stage0/src/Lean/Widget/InteractiveDiagnostic.lean
generated
Binary file not shown.
BIN
stage0/src/include/lean/lean.h
generated
BIN
stage0/src/include/lean/lean.h
generated
Binary file not shown.
BIN
stage0/src/initialize/init.cpp
generated
BIN
stage0/src/initialize/init.cpp
generated
Binary file not shown.
BIN
stage0/src/runtime/CMakeLists.txt
generated
BIN
stage0/src/runtime/CMakeLists.txt
generated
Binary file not shown.
BIN
stage0/src/runtime/init_module.cpp
generated
BIN
stage0/src/runtime/init_module.cpp
generated
Binary file not shown.
BIN
stage0/src/runtime/mutex.cpp
generated
Normal file
BIN
stage0/src/runtime/mutex.cpp
generated
Normal file
Binary file not shown.
BIN
stage0/src/runtime/mutex.h
generated
Normal file
BIN
stage0/src/runtime/mutex.h
generated
Normal file
Binary file not shown.
BIN
stage0/src/runtime/object.cpp
generated
BIN
stage0/src/runtime/object.cpp
generated
Binary file not shown.
BIN
stage0/src/stdlib.make.in
generated
BIN
stage0/src/stdlib.make.in
generated
Binary file not shown.
BIN
stage0/stdlib/Bootstrap.c
generated
BIN
stage0/stdlib/Bootstrap.c
generated
Binary file not shown.
BIN
stage0/stdlib/Bootstrap/Dynamic.c
generated
BIN
stage0/stdlib/Bootstrap/Dynamic.c
generated
Binary file not shown.
BIN
stage0/stdlib/Init.c
generated
BIN
stage0/stdlib/Init.c
generated
Binary file not shown.
BIN
stage0/stdlib/Init/Data.c
generated
BIN
stage0/stdlib/Init/Data.c
generated
Binary file not shown.
BIN
stage0/stdlib/Init/Data/Channel.c
generated
Normal file
BIN
stage0/stdlib/Init/Data/Channel.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Init/Data/Queue.c
generated
Normal file
BIN
stage0/stdlib/Init/Data/Queue.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Init/Dynamic.c
generated
Normal file
BIN
stage0/stdlib/Init/Dynamic.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Init/System.c
generated
BIN
stage0/stdlib/Init/System.c
generated
Binary file not shown.
BIN
stage0/stdlib/Init/System/IO.c
generated
BIN
stage0/stdlib/Init/System/IO.c
generated
Binary file not shown.
BIN
stage0/stdlib/Init/System/Mutex.c
generated
Normal file
BIN
stage0/stdlib/Init/System/Mutex.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Init/System/Promise.c
generated
Normal file
BIN
stage0/stdlib/Init/System/Promise.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/AlphaEqv.c
generated
Normal file
BIN
stage0/stdlib/Lean/Compiler/LCNF/AlphaEqv.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Basic.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Basic.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Bind.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Bind.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/CSE.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/CSE.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Check.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Check.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/CompilerM.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/CompilerM.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/InferType.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/InferType.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/LCtx.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/LCtx.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Main.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Main.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/PassManager.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/PassManager.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Passes.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Passes.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullFunDecls.c
generated
Normal file
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullFunDecls.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullLetDecls.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullLetDecls.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullLocalDecls.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/PullLocalDecls.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/ReduceJpArity.c
generated
Normal file
BIN
stage0/stdlib/Lean/Compiler/LCNF/ReduceJpArity.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Simp.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/Simp.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/Testing.c
generated
Normal file
BIN
stage0/stdlib/Lean/Compiler/LCNF/Testing.c
generated
Normal file
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/ToExpr.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/ToExpr.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Compiler/LCNF/ToLCNF.c
generated
BIN
stage0/stdlib/Lean/Compiler/LCNF/ToLCNF.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Data/RBMap.c
generated
BIN
stage0/stdlib/Lean/Data/RBMap.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Elab/BuiltinCommand.c
generated
BIN
stage0/stdlib/Lean/Elab/BuiltinCommand.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Elab/Deriving/TypeName.c
generated
BIN
stage0/stdlib/Lean/Elab/Deriving/TypeName.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Elab/Tactic/BuiltinTactic.c
generated
BIN
stage0/stdlib/Lean/Elab/Tactic/BuiltinTactic.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Meta/Instances.c
generated
BIN
stage0/stdlib/Lean/Meta/Instances.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Modifiers.c
generated
BIN
stage0/stdlib/Lean/Modifiers.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser.c
generated
BIN
stage0/stdlib/Lean/Parser.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Attr.c
generated
BIN
stage0/stdlib/Lean/Parser/Attr.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Basic.c
generated
BIN
stage0/stdlib/Lean/Parser/Basic.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Command.c
generated
BIN
stage0/stdlib/Lean/Parser/Command.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Do.c
generated
BIN
stage0/stdlib/Lean/Parser/Do.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Extension.c
generated
BIN
stage0/stdlib/Lean/Parser/Extension.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Extra.c
generated
BIN
stage0/stdlib/Lean/Parser/Extra.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Level.c
generated
BIN
stage0/stdlib/Lean/Parser/Level.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Module.c
generated
BIN
stage0/stdlib/Lean/Parser/Module.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/StrInterpolation.c
generated
BIN
stage0/stdlib/Lean/Parser/StrInterpolation.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Syntax.c
generated
BIN
stage0/stdlib/Lean/Parser/Syntax.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Tactic.c
generated
BIN
stage0/stdlib/Lean/Parser/Tactic.c
generated
Binary file not shown.
BIN
stage0/stdlib/Lean/Parser/Term.c
generated
BIN
stage0/stdlib/Lean/Parser/Term.c
generated
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user