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.
- optionsPerPos : Lean.PrettyPrinter.Delaborator.OptionsPerPos
- currNamespace : Lake.Name
- openDecls : List Lean.OpenDecl
- inPattern : Bool
- subExpr : Lean.SubExpr
- depth : Nat
Current recursion depth during delaboration. Used by the
pp.deepTerms false
option.
Instances For
- infos : Lean.SubExpr.PosMap Lean.Elab.Info
We attach
Elab.Info
at various locations in theSyntax
output in order to convey its semantics. While the elaborator emitsInfoTree
s, here we have no real text location tree to traverse, so we use a flattened map. See
SubExpr.nextExtraPos
.
Instances For
Equations
Instances For
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.orElse d₁ d₂ = Lean.catchInternalId Lean.PrettyPrinter.Delaborator.delabFailureId d₁ fun (x : Lean.Exception) => d₂ ()
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.failure = throw (Lean.Exception.internal Lean.PrettyPrinter.Delaborator.delabFailureId)
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.instAlternativeDelabM = Alternative.mk (fun {α : Type} => Lean.PrettyPrinter.Delaborator.failure) fun {α : Type} => Lean.PrettyPrinter.Delaborator.orElse
Equations
- Lean.PrettyPrinter.Delaborator.instOrElseDelabM = { orElse := Lean.PrettyPrinter.Delaborator.orElse }
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.PrettyPrinter.Delaborator.instMonadQuotationDelabM = Lean.MonadQuotation.mk (pure default) (pure default) fun {α : Type} (x : Lean.PrettyPrinter.Delaborator.DelabM α) => x
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
- Lean.PrettyPrinter.Delaborator.getPPOption opt = do let __do_lift ← Lean.PrettyPrinter.Delaborator.getOptionsAtCurrPos pure (opt __do_lift)
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.whenPPOption opt d = do let b ← Lean.PrettyPrinter.Delaborator.getPPOption opt if b = true then d else failure
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.whenNotPPOption opt d = do let b ← Lean.PrettyPrinter.Delaborator.getPPOption opt if b = true then failure else d
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
- Lean.PrettyPrinter.Delaborator.annotatePos pos stx = { raw := Lean.Syntax.setInfo (Lean.SourceInfo.synthetic { byteIdx := pos } { byteIdx := pos }) stx.raw }
Instances For
Equations
- Lean.PrettyPrinter.Delaborator.annotateCurPos stx = do let __do_lift ← Lean.PrettyPrinter.Delaborator.SubExpr.getPos pure (Lean.PrettyPrinter.Delaborator.annotatePos __do_lift stx)
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
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
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
Equations
- Lean.PrettyPrinter.Delaborator.addOmissionInfo.mkOmissionInfo stx e = do let __do_lift ← Lean.PrettyPrinter.Delaborator.addTermInfo.mkTermInfo stx e pure { toTermInfo := __do_lift }
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
- Lean.PrettyPrinter.Delaborator.isShallowExpression threshold e = let threshold := min 254 threshold; decide (UInt32.toNat (Lean.Expr.approxDepth e) ≤ threshold)
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
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
Modifies the delaborator so that it annotates the resulting term with the current expression
position and registers TermInfo
to associate the term to the current expression.
Equations
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
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
"Delaborate" the given term into surface-level syntax using the default and given subterm-specific options.
Equations
- Lean.PrettyPrinter.delab e optionsPerPos = do let __discr ← Lean.PrettyPrinter.delabCore e optionsPerPos match __discr with | (stx, snd) => pure stx