Documentation

Lean.Syntax

structure String.Range :

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
    Equations
    Instances For
      Equations
      Instances For
        Equations
        Instances For
          Equations
          • Lean.SourceInfo.getRange? canonicalOnly info = do let __do_liftinfo.getPos? canonicalOnly let __do_lift_1info.getTailPos? canonicalOnly pure { start := __do_lift, stop := __do_lift_1 }
          Instances For

            Syntax AST #

            Instances For
              Equations
              Instances For
                Equations
                Instances For
                  def Lean.unreachIsNodeAtom {β : Sort u_1} {info : Lean.SourceInfo} {val : String} :
                  Lean.IsNode (Lean.Syntax.atom info val)β
                  Equations
                  Instances For
                    def Lean.unreachIsNodeIdent {β : Sort u_1} {info : Lean.SourceInfo} {rawVal : Substring} {val : Lake.Name} {preresolved : List Lean.Syntax.Preresolved} :
                    Lean.IsNode (Lean.Syntax.ident info rawVal val preresolved)β
                    Equations
                    Instances For
                      @[inline]
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        @[inline]
                        def Lean.SyntaxNode.withArgs {β : Sort u_1} (n : Lean.SyntaxNode) (fn : Array Lean.Syntaxβ) :
                        β
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[inline]
                          Equations
                          Instances For
                            @[inline]
                            Equations
                            Instances For
                              @[inline]
                              Equations
                              Instances For
                                @[inline]
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  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.
                                  Instances For

                                    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.
                                    Instances For
                                      Equations
                                      Instances For
                                        Equations
                                        Instances For
                                          @[inline]
                                          def Lean.Syntax.ifNode {β : Sort u_1} (stx : Lean.Syntax) (hyes : Lean.SyntaxNodeβ) (hno : Unitβ) :
                                          β
                                          Equations
                                          Instances For
                                            @[inline]
                                            def Lean.Syntax.ifNodeKind {β : Sort u_1} (stx : Lean.Syntax) (kind : Lean.SyntaxNodeKind) (hyes : Lean.SyntaxNodeβ) (hno : Unitβ) :
                                            β
                                            Equations
                                            Instances For
                                              Equations
                                              Instances For
                                                Equations
                                                • stx.getIdAt i = (stx.getArg i).getId
                                                Instances For

                                                  Check for a Syntax.ident of the given name anywhere in the tree. This is usually a bad idea since it does not check for shadowing bindings, but in the delaborator we assume that bindings are never shadowed.

                                                  @[inline]
                                                  Equations
                                                  Instances For
                                                    @[inline]
                                                    Equations
                                                    Instances For
                                                      @[specialize #[]]
                                                      partial def Lean.Syntax.replaceM {m : TypeType} [Monad m] (fn : Lean.Syntaxm (Option Lean.Syntax)) :
                                                      @[specialize #[]]

                                                      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
                                                      Instances For

                                                        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.
                                                        Instances For
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            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 }
                                                              Instances For
                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                @[specialize #[]]
                                                                partial def Lean.Syntax.instForInTopDown.loop {m : Type u_1 → Type u_2} :
                                                                {β : Type u_1} → [inst : Monad m] → (Lean.Syntaxβm (ForInStep β))BoolLean.Syntaxβ[inst : Inhabited β] → m (ForInStep β)
                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For
                                                                    Equations
                                                                    • stx.getRange? canonicalOnly = match stx.getPos? canonicalOnly, stx.getTailPos? canonicalOnly with | some start, some stop => some { start := start, stop := stop } | x, x_1 => none
                                                                    Instances For

                                                                      Returns a synthetic Syntax which has the specified String.Range.

                                                                      Equations
                                                                      Instances For

                                                                        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
                                                                          Instances For
                                                                            Equations
                                                                            • t.setCur stx = { cur := stx, parents := t.parents, idxs := t.idxs }
                                                                            Instances For

                                                                              Advance to the idx-th child of the current node.

                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For

                                                                                Advance to the parent of the current node, if any.

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For

                                                                                  Advance to the left sibling of the current node, if any.

                                                                                  Equations
                                                                                  • t.left = if t.parents.size > 0 then t.up.down (t.idxs.back - 1) else t
                                                                                  Instances For

                                                                                    Advance to the right sibling of the current node, if any.

                                                                                    Equations
                                                                                    • t.right = if t.parents.size > 0 then t.up.down (t.idxs.back + 1) else t
                                                                                    Instances For

                                                                                      Monad class that gives read/write access to a Traverser.

                                                                                      Instances
                                                                                        Equations
                                                                                        Instances For
                                                                                          Equations
                                                                                          Instances For
                                                                                            Equations
                                                                                            Instances For
                                                                                              Equations
                                                                                              Instances For
                                                                                                Equations
                                                                                                • Lean.Syntax.MonadTraverser.getIdx = do let stget pure (st.idxs.back?.getD 0)
                                                                                                Instances For
                                                                                                  @[inline]
                                                                                                  Equations
                                                                                                  • n.getIdAt i = (n.getArg i).getId
                                                                                                  Instances For
                                                                                                    Equations
                                                                                                    Instances For
                                                                                                      Equations
                                                                                                      • stx.getQuotContent = let stx := if (stx.getNumArgs == 1) = true then stx[0] else stx; if stx.isOfKind `Lean.Parser.Term.dynamicQuot = true then stx[3] else stx[1]
                                                                                                      Instances For
                                                                                                        Equations
                                                                                                        Instances For
                                                                                                          Equations
                                                                                                          Instances For
                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              def Lean.Syntax.mkAntiquotNode (kind : Lake.Name) (term : Lean.Syntax) (nesting : optParam Nat 0) (name : optParam (Option String) none) (isPseudoKind : optParam Bool false) :
                                                                                                              Equations
                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                              Instances For
                                                                                                                Equations
                                                                                                                • stx.isEscapedAntiquot = !stx[1].getArgs.isEmpty
                                                                                                                Instances For
                                                                                                                  Equations
                                                                                                                  • stx.unescapeAntiquot = if stx.isAntiquot = true then stx.setArg 1 (Lean.mkNullNode stx[1].getArgs.pop) else stx
                                                                                                                  Instances For
                                                                                                                    Equations
                                                                                                                    • stx.getAntiquotTerm = let e := if stx.isAntiquot = true then stx[2] else stx[3]; if e.isIdent = true then e else if e.isAtom = true then (Lean.mkNode `Lean.Parser.Term.hole #[e]).raw else e[1]
                                                                                                                    Instances For

                                                                                                                      Return kind of parser expected at this antiquotation, and whether it is a "pseudo" kind (see mkAntiquot).

                                                                                                                      Equations
                                                                                                                      Instances For
                                                                                                                        Equations
                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                        Instances For
                                                                                                                          Equations
                                                                                                                          • x.antiquotSpliceKind? = match x with | Lean.Syntax.node info (k.str "antiquot_scope") args => some k | x => none
                                                                                                                          Instances For
                                                                                                                            Equations
                                                                                                                            • stx.isAntiquotSplice = stx.antiquotSpliceKind?.isSome
                                                                                                                            Instances For
                                                                                                                              Equations
                                                                                                                              • stx.getAntiquotSpliceContents = stx[3].getArgs
                                                                                                                              Instances For
                                                                                                                                Equations
                                                                                                                                • stx.getAntiquotSpliceSuffix = if stx.isAntiquotSplice = true then stx[5] else stx[1]
                                                                                                                                Instances For
                                                                                                                                  Equations
                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                  Instances For
                                                                                                                                    Equations
                                                                                                                                    • x.antiquotSuffixSplice? = match x with | Lean.Syntax.node info (k.str "antiquot_suffix_splice") args => some k | x => none
                                                                                                                                    Instances For
                                                                                                                                      Equations
                                                                                                                                      • stx.isAntiquotSuffixSplice = stx.antiquotSuffixSplice?.isSome
                                                                                                                                      Instances For
                                                                                                                                        Equations
                                                                                                                                        • stx.getAntiquotSuffixSpliceInner = stx[0]
                                                                                                                                        Instances For
                                                                                                                                          Equations
                                                                                                                                          Instances For
                                                                                                                                            Equations
                                                                                                                                            • stx.isTokenAntiquot = stx.isOfKind `token_antiquot
                                                                                                                                            Instances For
                                                                                                                                              Equations
                                                                                                                                              • stx.isAnyAntiquot = (stx.isAntiquot || stx.isAntiquotSplice || stx.isAntiquotSuffixSplice || stx.isTokenAntiquot)
                                                                                                                                              Instances For
                                                                                                                                                @[reducible, inline]

                                                                                                                                                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
                                                                                                                                                Instances For
                                                                                                                                                  def Lean.Syntax.findStack? (root : Lean.Syntax) (visit : Lean.SyntaxBool) (accept : optParam (Lean.SyntaxBool) fun (stx : Lean.Syntax) => !stx.hasArgs) :

                                                                                                                                                  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
                                                                                                                                                  Instances For
                                                                                                                                                    partial def Lean.Syntax.findStack?.go (visit : Lean.SyntaxBool) (accept : optParam (Lean.SyntaxBool) fun (stx : Lean.Syntax) => !stx.hasArgs) (stack : Lean.Syntax.Stack) (stx : Lean.Syntax) :

                                                                                                                                                    Compare the SyntaxNodeKinds 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.
                                                                                                                                                    Instances For