- start : String.Pos
- stop : String.Pos
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
.
Instances For
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 endPos => Lean.SourceInfo.original leading pos trailing endPos | info => info
Syntax AST #
- mk: ∀ (info : Lean.SourceInfo) (kind : Lean.SyntaxNodeKind) (args : Array Lean.Syntax), Lean.IsNode (Lean.Syntax.node info kind args)
Instances For
Equations
- Lean.unreachIsNodeMissing h = False.elim (_ : False)
Equations
- Lean.unreachIsNodeAtom h = False.elim (_ : False)
Equations
- Lean.unreachIsNodeIdent h = False.elim (_ : False)
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
- Lean.SyntaxNode.getNumArgs n = Lean.SyntaxNode.withArgs n fun args => Array.size args
Equations
- Lean.SyntaxNode.getArg n i = Lean.SyntaxNode.withArgs n fun args => Array.get! args i
Equations
- Lean.SyntaxNode.getArgs n = Lean.SyntaxNode.withArgs n fun args => args
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Syntax.getAtomVal x = match x with | Lean.Syntax.atom info val => val | x => ""
Equations
- Lean.Syntax.setAtomVal x x = match x, x with | Lean.Syntax.atom info val, v => Lean.Syntax.atom info v | stx, x => 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.
Equations
- Lean.Syntax.getIdAt stx i = Lean.Syntax.getId (Lean.Syntax.getArg stx i)
Equations
- Lean.Syntax.modifyArgs stx fn = match stx with | Lean.Syntax.node i k args => Lean.Syntax.node i k (fn args) | stx => stx
Equations
- Lean.Syntax.modifyArg stx i fn = match stx with | Lean.Syntax.node info k args => Lean.Syntax.node info k (Array.modify args i fn) | stx => stx
Equations
- Lean.Syntax.rewriteBottomUp fn stx = Id.run (Lean.Syntax.rewriteBottomUpM fn stx)
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
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.
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
- Lean.Syntax.topDown stx 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.
Equations
- One or more equations did not get rendered due to their size.
- cur : Lean.Syntax
- parents : Array Lean.Syntax
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.
Instances For
Equations
- Lean.Syntax.Traverser.fromSyntax stx = { cur := stx, parents := #[], idxs := #[] }
Equations
- Lean.Syntax.Traverser.setCur t 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.
Equations
- Lean.Syntax.Traverser.left t = if Array.size t.parents > 0 then Lean.Syntax.Traverser.down (Lean.Syntax.Traverser.up t) (Array.back t.idxs - 1) else t
Advance to the right sibling of the current node, if any.
Equations
- Lean.Syntax.Traverser.right t = if Array.size t.parents > 0 then Lean.Syntax.Traverser.down (Lean.Syntax.Traverser.up t) (Array.back t.idxs + 1) else t
- st : MonadState Lean.Syntax.Traverser m
Monad class that gives read/write access to a Traverser
.
Instances
Equations
- Lean.Syntax.MonadTraverser.getCur = Lean.Syntax.Traverser.cur <$> get
Equations
- Lean.Syntax.MonadTraverser.setCur stx = modify fun t => Lean.Syntax.Traverser.setCur t stx
Equations
- Lean.Syntax.MonadTraverser.goDown idx = modify fun t => Lean.Syntax.Traverser.down t idx
Equations
- Lean.Syntax.MonadTraverser.goUp = modify fun t => Lean.Syntax.Traverser.up t
Equations
- Lean.Syntax.MonadTraverser.goLeft = modify fun t => Lean.Syntax.Traverser.left t
Equations
- Lean.Syntax.MonadTraverser.goRight = modify fun t => Lean.Syntax.Traverser.right t
Equations
- Lean.Syntax.MonadTraverser.getIdx = do let st ← get pure (Option.getD (Array.back? st.idxs) 0)
Equations
Equations
- Lean.mkListNode args = Lean.mkNullNode args
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
- Lean.Syntax.isAntiquot x = match x with | Lean.Syntax.node info (Lean.Name.str pre "antiquot") args => true | x => false
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Syntax.getCanonicalAntiquot stx = if Lean.Syntax.isOfKind stx Lean.choiceKind = true then stx[0] else stx
Equations
- Lean.Syntax.isEscapedAntiquot stx = !Array.isEmpty (Lean.Syntax.getArgs stx[1])
Equations
- Lean.Syntax.unescapeAntiquot stx = if Lean.Syntax.isAntiquot stx = true then Lean.Syntax.setArg stx 1 (Lean.mkNullNode (Array.pop (Lean.Syntax.getArgs stx[1]))) else stx
Equations
- One or more equations did not get rendered due to their size.
Return kind of parser expected at this antiquotation, and whether it is a "pseudo" kind (see mkAntiquot
).
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
- Lean.Syntax.antiquotSpliceKind? x = match x with | Lean.Syntax.node info (Lean.Name.str k "antiquot_scope") args => some k | x => none
Equations
Equations
Equations
- Lean.Syntax.getAntiquotSpliceSuffix stx = if Lean.Syntax.isAntiquotSplice stx = true then stx[5] else stx[1]
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Syntax.antiquotSuffixSplice? x = match x with | Lean.Syntax.node info (Lean.Name.str k "antiquot_suffix_splice") args => some k | x => none
Equations
Equations
- Lean.Syntax.getAntiquotSuffixSpliceInner stx = stx[0]
Equations
- Lean.Syntax.mkAntiquotSuffixSpliceNode kind inner suffix = (Lean.mkNode (kind ++ `antiquot_suffix_splice) #[inner, Lean.mkAtom suffix]).raw
Equations
- Lean.Syntax.isTokenAntiquot stx = Lean.Syntax.isOfKind stx `token_antiquot
Equations
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
- Lean.Syntax.findStack? root 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.