A position range inside a string. This type is mostly in combination with syntax trees,
as there might not be a single underlying string in this case that could be used for a Substring
.
- start : String.Pos
- stop : String.Pos
Equations
- String.instInhabitedRange = { default := { start := default, stop := default } }
Equations
- String.instReprRange = { reprPrec := String.reprRange✝ }
Equations
- String.instBEqRange = { beq := String.beqRange✝ }
Equations
- String.instHashableRange = { hash := String.hashRange✝ }
Equations
- Lean.SourceInfo.updateTrailing trailing x = match x with | Lean.SourceInfo.original leading pos trailing_1 endPos => Lean.SourceInfo.original leading pos trailing endPos | info => info
Equations
- Lean.SourceInfo.getRange? canonicalOnly info = do let __do_lift ← info.getPos? canonicalOnly let __do_lift_1 ← info.getTailPos? canonicalOnly pure { start := __do_lift, stop := __do_lift_1 }
Equations
- Lean.instBEqSourceInfo_lean = { beq := Lean.beqSourceInfo✝ }
Syntax AST #
- mk: ∀ (info : Lean.SourceInfo) (kind : Lean.SyntaxNodeKind) (args : Array Lean.Syntax), Lean.IsNode (Lean.Syntax.node info kind args)
Equations
- Lean.unreachIsNodeMissing a = nomatch a
Equations
- Lean.unreachIsNodeAtom a = nomatch a
Equations
- Lean.unreachIsNodeIdent a = nomatch a
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- n.getNumArgs = n.withArgs fun (args : Array Lean.Syntax) => args.size
Equations
- n.getArg i = n.withArgs fun (args : Array Lean.Syntax) => args.get! i
Equations
- n.getArgs = n.withArgs fun (args : Array Lean.Syntax) => args
Equations
- One or more equations did not get rendered due to their size.
Compares syntax structures and position ranges, but not whitespace. We generally assume that if
syntax trees equal in this way generate the same elaboration output, including positions contained
in e.g. diagnostics and the info tree. However, as we have a few request handlers such as goalsAt?
that are sensitive to whitespace information in the info tree, we currently use eqWithInfo
instead
for reuse checks.
Like structRangeEq
but prints trace on failure if trace.Elab.reuse
is activated.
Equations
- One or more equations did not get rendered due to their size.
Full comparison of syntax structures and source infos.
Like eqWithInfo
but prints trace on failure if trace.Elab.reuse
is activated.
Equations
- One or more equations did not get rendered due to their size.
Equations
- x.getAtomVal = match x with | Lean.Syntax.atom info val => val | x => ""
Equations
- x✝.setAtomVal x = match x✝, x with | Lean.Syntax.atom info val, v => Lean.Syntax.atom info v | stx, x => stx
Equations
- stx.ifNode hyes hno = match stx with | Lean.Syntax.node i k args => hyes ⟨Lean.Syntax.node i k args, ⋯⟩ | x => hno ()
Equations
- stx.ifNodeKind kind hyes hno = match stx with | Lean.Syntax.node i k args => if (k == kind) = true then hyes ⟨Lean.Syntax.node i k args, ⋯⟩ else hno () | x => hno ()
Equations
- x.asNode = match x with | Lean.Syntax.node info kind args => ⟨Lean.Syntax.node info kind args, ⋯⟩ | x => ⟨Lean.mkNullNode, Lean.Syntax.asNode.proof_1⟩
Equations
- stx.getIdAt i = (stx.getArg i).getId
Equations
- stx.modifyArgs fn = match stx with | Lean.Syntax.node i k args => Lean.Syntax.node i k (fn args) | stx => stx
Equations
- stx.modifyArg i fn = match stx with | Lean.Syntax.node info k args => Lean.Syntax.node info k (args.modify i fn) | stx => stx
Equations
- Lean.Syntax.rewriteBottomUp fn stx = (Lean.Syntax.rewriteBottomUpM fn stx).run
Set SourceInfo.leading
according to the trailing stop of the preceding token.
The result is a round-tripping syntax tree IF, in the input syntax tree,
- all leading stops, atom contents, and trailing starts are correct
- trailing stops are between the trailing start and the next leading stop.
Remark: after parsing, all SourceInfo.leading
fields are empty.
The Syntax
argument is the output produced by the parser for source
.
This function "fixes" the source.leading
field.
Additionally, we try to choose "nicer" splits between leading and trailing stops according to some heuristics so that e.g. comments are associated to the (intuitively) correct token.
Note that the SourceInfo.trailing
fields must be correct.
The implementation of this Function relies on this property.
Equations
- stx.updateLeading = StateT.run' (Lean.Syntax.replaceM Lean.Syntax.updateLeadingAux stx) 0
Split an ident
into its dot-separated components while preserving source info.
Macro scopes are first erased. For example, `foo.bla.boo._@._hyg.4
↦ [`foo, `bla, `boo]
.
If nFields
is set, we take that many fields from the end and keep the remaining components
as one name. For example, `foo.bla.boo
with (nFields := 1)
↦ [`foo.bla, `boo]
.
Equations
- One or more equations did not get rendered due to their size.
- firstChoiceOnly : Bool
- stx : Lean.Syntax
Instances For
for _ in stx.topDown
iterates through each node and leaf in stx
top-down, left-to-right.
If firstChoiceOnly
is true
, only visit the first argument of each choice node.
Equations
- stx.topDown firstChoiceOnly = { firstChoiceOnly := firstChoiceOnly, stx := stx }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Returns a synthetic Syntax which has the specified String.Range
.
Equations
- Lean.Syntax.ofRange range canonical = Lean.Syntax.atom (Lean.SourceInfo.synthetic range.start range.stop canonical) ""
Represents a cursor into a syntax tree that can be read, written, and advanced down/up/left/right.
Indices are allowed to be out-of-bound, in which case cur
is Syntax.missing
.
If the Traverser
is used linearly, updates are linear in the Syntax
object as well.
- cur : Lean.Syntax
- parents : Array Lean.Syntax
Equations
- Lean.Syntax.Traverser.fromSyntax stx = { cur := stx, parents := #[], idxs := #[] }
Equations
- t.setCur stx = { cur := stx, parents := t.parents, idxs := t.idxs }
Advance to the idx
-th child of the current node.
Equations
- One or more equations did not get rendered due to their size.
Advance to the parent of the current node, if any.
Equations
- One or more equations did not get rendered due to their size.
Advance to the left sibling of the current node, if any.
Advance to the right sibling of the current node, if any.
Monad class that gives read/write access to a Traverser
.
- st : MonadState Lean.Syntax.Traverser m
Equations
- Lean.Syntax.MonadTraverser.getCur = Lean.Syntax.Traverser.cur <$> get
Equations
- Lean.Syntax.MonadTraverser.setCur stx = modify fun (t : Lean.Syntax.Traverser) => t.setCur stx
Equations
- Lean.Syntax.MonadTraverser.goDown idx = modify fun (t : Lean.Syntax.Traverser) => t.down idx
Equations
- Lean.Syntax.MonadTraverser.goUp = modify fun (t : Lean.Syntax.Traverser) => t.up
Equations
- Lean.Syntax.MonadTraverser.goLeft = modify fun (t : Lean.Syntax.Traverser) => t.left
Equations
- Lean.Syntax.MonadTraverser.goRight = modify fun (t : Lean.Syntax.Traverser) => t.right
Equations
- n.getIdAt i = (n.getArg i).getId
Equations
- Lean.mkListNode args = Lean.mkNullNode args
Equations
- x.isQuot = match x with | Lean.Syntax.node info (pre.str "quot") args => true | Lean.Syntax.node info `Lean.Parser.Term.dynamicQuot args => true | x => false
Equations
- x.isAntiquot = match x with | Lean.Syntax.node info (pre.str "antiquot") args => true | x => false
Equations
- stx.isAntiquots = (stx.isAntiquot || stx.isOfKind Lean.choiceKind && decide (stx.getNumArgs > 0) && stx.getArgs.all Lean.Syntax.isAntiquot 0)
Equations
- stx.getCanonicalAntiquot = if stx.isOfKind Lean.choiceKind = true then stx[0] else stx
Equations
- stx.unescapeAntiquot = if stx.isAntiquot = true then stx.setArg 1 (Lean.mkNullNode stx[1].getArgs.pop) else stx
Return kind of parser expected at this antiquotation, and whether it is a "pseudo" kind (see mkAntiquot
).
Equations
- x.antiquotKind? = match x with | Lean.Syntax.node info ((k.str "pseudo").str "antiquot") args => some (k, true) | Lean.Syntax.node info (k.str "antiquot") args => some (k, false) | x => none
Equations
- One or more equations did not get rendered due to their size.
Equations
- x.antiquotSpliceKind? = match x with | Lean.Syntax.node info (k.str "antiquot_scope") args => some k | x => none
Equations
- stx.isAntiquotSplice = stx.antiquotSpliceKind?.isSome
Equations
- stx.getAntiquotSpliceContents = stx[3].getArgs
Equations
- One or more equations did not get rendered due to their size.
Equations
- x.antiquotSuffixSplice? = match x with | Lean.Syntax.node info (k.str "antiquot_suffix_splice") args => some k | x => none
Equations
- stx.isAntiquotSuffixSplice = stx.antiquotSuffixSplice?.isSome
Equations
- stx.getAntiquotSuffixSpliceInner = stx[0]
Equations
- Lean.Syntax.mkAntiquotSuffixSpliceNode kind inner suffix = (Lean.mkNode (kind ++ `antiquot_suffix_splice) #[inner, Lean.mkAtom suffix]).raw
Equations
- stx.isTokenAntiquot = stx.isOfKind `token_antiquot
List of Syntax
nodes in which each succeeding element is the parent of
the current. The associated index is the index of the preceding element in the
list of children of the current element.
Equations
Return stack of syntax nodes satisfying visit
, starting with such a node that also fulfills accept
(default "is leaf"), and ending with the root.
Equations
- root.findStack? visit accept = if visit root = true then Lean.Syntax.findStack?.go visit accept [] root else none
Compare the SyntaxNodeKind
s in pattern
to those of the Syntax
elements in stack
. Return false
if stack
is shorter than pattern
.
Equations
- One or more equations did not get rendered due to their size.