Documentation

Lean.PrettyPrinter.Delaborator.Basic

The delaborator is the first stage of the pretty printer, and the inverse of the elaborator: it turns fully elaborated Expr core terms back into surface-level Syntax, omitting some implicit information again and using higher-level syntax abstractions like notations where possible. The exact behavior can be customized using pretty printer options; activating pp.all should guarantee that the delaborator is injective and that re-elaborating the resulting Syntax round-trips.

Pretty printer options can be given not only for the whole term, but also specific subterms. This is used both when automatically refining pp options until round-trip and when interactively selecting pp options for a subterm (both TBD). The association of options to subterms is done by assigning a unique, synthetic Nat position to each subterm derived from its position in the full term. This position is added to the corresponding Syntax object so that elaboration errors and interactions with the pretty printer output can be traced back to the subterm.

The delaborator is extensible via the [delab] attribute.

Instances For
    • steps : Nat

      The number of delab steps so far. Used by pp.maxSteps to stop delaboration.

    • We attach Elab.Info at various locations in the Syntax output in order to convey its semantics. While the elaborator emits InfoTrees, here we have no real text location tree to traverse, so we use a flattened map.

    • See SubExpr.nextExtraPos.

    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      @[instance 100]
      Equations
      • One or more equations did not get rendered due to their size.
      @[instance 100]
      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.

      Registers a delaborator.

      @[delab k] registers a declaration of type Lean.PrettyPrinter.Delaborator.Delab for the Lean.Expr constructor k. Multiple delaborators for a single constructor are tried in turn until the first success. If the term to be delaborated is an application of a constant c, elaborators for app.c are tried first; this is also done for Expr.consts ("nullary applications") to reduce special casing. If the term is an Expr.mdata with a single key k, mdata.k is tried first.

      @[app_delab c] registers a delaborator for applications with head constant c. Such delaborators also apply to the constant c itself (known as a "nullary application").

      This attribute should be applied to definitions of type Lean.PrettyPrinter.Delaborator.Delab.

      When defining delaborators for constant applications, one should prefer this attribute over @[delab app.c], as @[app_delab c] first performs name resolution on c in the current scope.

      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
          • One or more equations did not get rendered due to their size.
          Instances For

            Evaluate option accessor, using subterm-specific options if set.

            Equations
            Instances For

              Set the given option at the current position and execute x in this context.

              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
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Lean.PrettyPrinter.Delaborator.addFieldInfo (pos : SubExpr.Pos) (projName fieldName : Name) (stx : Syntax) (val : Expr) :
                    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
                        def Lean.PrettyPrinter.Delaborator.addDelabTermInfo (pos : SubExpr.Pos) (stx : Syntax) (e : Expr) (isBinder : Bool := false) (location? : Option DeclarationLocation := none) (docString? : Option String := none) (explicit : Bool := true) :
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Annotates the term with the current expression position and registers TermInfo to associate the term to the current expression.

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

                            Annotates the term with the current expression position and registers TermInfo to associate the term to the current expression, unless the syntax has a synthetic position and associated Info already.

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

                              Modifies the delaborator so that it annotates the resulting term using annotateTermInfo.

                              Equations
                              Instances For
                                def Lean.PrettyPrinter.Delaborator.getUnusedName (suggestion : Name) (body : Expr) (preserveName : Bool := false) :

                                Gets an name based on suggestion that is unused in the local context. Erases macro scopes. If pp.safeShadowing is true, then the name is allowed to shadow a name in the local context if the name does not appear in body.

                                If preserveName is false, then returns the name, possibly with fresh macro scopes added. If suggestion has macro scopes then the result does as well.

                                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

                                    Creates an identifier that is annotated with the term e, using a fresh position using the HoleIterator.

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

                                      Enters the body of the current expression, which must be a lambda or forall. The binding variable is passed to d as Syntax, and it is an identifier that has been annotated with the fvar expression for the variable.

                                      If preserveName is false (the default), gives the binder an unused name. Otherwise, it tries to preserve the textual form of the name, preserving whether it is hygienic.

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

                                          Runs the delaborator act with increased depth. The depth is used when pp.deepTerms is false to determine what is a deep term. See also Lean.PrettyPrinter.Delaborator.Context.depth.

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

                                            Returns true if e is a "shallow" expression. Local variables, constants, and other atomic expressions are always shallow. In general, an expression is considered to be shallow if its depth is at most threshold.

                                            Since the implementation uses Lean.Expr.approxDepth, the threshold is clamped to [0, 254].

                                            Equations
                                            Instances For

                                              Returns true if, at the current depth, we should omit the term and use rather than delaborating it. This function can only return true if pp.deepTerms is set to false. It also contains a heuristic to allow "shallow terms" to be delaborated, even if they appear deep in an expression, which prevents terms such as atomic expressions or OfNat.ofNat literals from being delaborated as .

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

                                                Returns true if the given expression is a proof and should be omitted. This function only returns true if pp.proofs is set to false.

                                                "Shallow" proofs are not omitted. The pp.proofs.threshold option controls the depth threshold for what constitutes a shallow proof. See Lean.PrettyPrinter.Delaborator.isShallowExpression.

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

                                                  Delaborates the current expression as and attaches Elab.OmissionInfo, which influences how the subterm omitted by is delaborated when hovered over.

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

                                                    Registers an unexpander for applications of a given constant.

                                                    @[app_unexpander c] registers a Lean.PrettyPrinter.Unexpander for applications of the constant c. The unexpander is passed the result of pre-pretty printing the application without implicitly passed arguments. If pp.explicit is set to true or pp.notation is set to false, it will not be called at all.

                                                    Unexpanders work as an alternative for delaborators (@[app_delab]) that can be used without special imports. This however also makes them much less capable since they can only transform syntax and don't have access to the expression tree.

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

                                                      "Delaborate" the given term into surface-level syntax using the default and given subterm-specific options.

                                                      Equations
                                                      Instances For