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.
- defaultOptions : Lean.Options
- optionsPerPos : Lean.PrettyPrinter.Delaborator.OptionsPerPos
- currNamespace : Lean.Name
- openDecls : List Lean.OpenDecl
- inPattern : Bool
- subExpr : Lean.SubExpr
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.infos : Std.RBMap Lean.SubExpr.Pos Lean.Elab.Info compareSee
SubExpr.nextExtraPos
.
Equations
- Lean.PrettyPrinter.Delaborator.orElse d₁ d₂ = Lean.catchInternalId Lean.PrettyPrinter.Delaborator.delabFailureId d₁ fun x => d₂ ()
Equations
- Lean.PrettyPrinter.Delaborator.failure = throw (Lean.Exception.internal Lean.PrettyPrinter.Delaborator.delabFailureId)
Equations
- Lean.PrettyPrinter.Delaborator.instAlternativeDelabM = Alternative.mk (fun {α} => Lean.PrettyPrinter.Delaborator.failure) fun {α} => 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 {α} x => x
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.
Evaluate option accessor, using subterm-specific options if set.
Equations
- Lean.PrettyPrinter.Delaborator.getPPOption opt = do let a ← Lean.PrettyPrinter.Delaborator.getOptionsAtCurrPos pure (opt a)
Equations
- Lean.PrettyPrinter.Delaborator.whenPPOption opt d = do let b ← Lean.PrettyPrinter.Delaborator.getPPOption opt if b = true then d else failure
Equations
- Lean.PrettyPrinter.Delaborator.whenNotPPOption opt d = do let b ← Lean.PrettyPrinter.Delaborator.getPPOption opt if b = true then failure else d
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.
Equations
- Lean.PrettyPrinter.Delaborator.annotatePos pos stx = { raw := Lean.Syntax.setInfo (Lean.SourceInfo.synthetic { byteIdx := pos } { byteIdx := pos }) stx.raw }
Equations
- Lean.PrettyPrinter.Delaborator.annotateCurPos stx = do let a ← Lean.PrettyPrinter.Delaborator.SubExpr.getPos pure (Lean.PrettyPrinter.Delaborator.annotatePos a 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.
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.
Equations
- One or more equations did not get rendered due to their size.
"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 Lean.PrettyPrinter.Delaborator.delab match discr with | (stx, snd) => pure stx