- allOrNone: Std.Format.FlattenBehavior
- fill: Std.Format.FlattenBehavior
Determines how groups should have linebreaks inserted when the text would overfill its remaining space.
allOrNone
will make a linebreak on everyFormat.line
in the group or none of them.[1, 2, 3]
fill
will only make linebreaks on as fewFormat.line
s as possible:[1, 2, 3]
Instances For
Equations
- nil: Lean.Format
The empty format.
- line: Lean.Format
A position where a newline may be inserted if the current group does not fit within the allotted column width.
- text: String → Lean.Format
A node containing a plain string.
- nest: Int → Lean.Format → Lean.Format
nest n f
tells the formatter thatf
is nested inside something with lengthn
so that it is pretty-printed with the correct indentation on a line break. For example, we can define a formatter for listl : List Format
as:let f := join <| l.intersperse <| ", " ++ Format.line group (nest 1 <| "[" ++ f ++ "]")
This will be written all on one line, but if the text is too large, the formatter will put in linebreaks after the commas and indent later lines by 1.
- append: Lean.Format → Lean.Format → Lean.Format
Concatenation of two Formats.
- group: Lean.Format → optParam Std.Format.FlattenBehavior Std.Format.FlattenBehavior.allOrNone → Lean.Format
Creates a new flattening group for the given inner format.
- tag: Nat → Lean.Format → Lean.Format
Used for associating auxiliary information (e.g.
Expr
s) withFormat
objects.
A string with pretty-printing information for rendering in a column-width-aware way.
The pretty-printing algorithm is based on Wadler's paper A Prettier Printer.
Instances For
Equations
- Std.instInhabitedFormat = { default := Lean.Format.nil }
Check whether the given format contains no characters.
Equations
- Std.Format.isEmpty Lean.Format.nil = true
- Std.Format.isEmpty Lean.Format.line = false
- Std.Format.isEmpty (Std.Format.text msg) = (msg == "")
- Std.Format.isEmpty (Lean.Format.nest indent f) = Std.Format.isEmpty f
- Std.Format.isEmpty (Std.Format.append f₁ f₂) = (Std.Format.isEmpty f₁ && Std.Format.isEmpty f₂)
- Std.Format.isEmpty (Lean.Format.group f behavior) = Std.Format.isEmpty f
- Std.Format.isEmpty (Lean.Format.tag a f) = Std.Format.isEmpty f
Alias for a group with FlattenBehavior
set to fill
.
Equations
- Std.Format.appendEx a b = Std.Format.append a b
Equations
Equations
- Std.Format.instAppendFormat = { append := Std.Format.append }
Equations
- Std.Format.instCoeStringFormat = { coe := Std.Format.text }
Equations
- Lean.Format.join xs = List.foldl (fun a a_1 => a ++ a_1) (Std.Format.text "") xs
Equations
- Std.Format.isNil _fun_discr = match _fun_discr with | Lean.Format.nil => true | x => false
Equations
- Std.Format.instInhabitedSpaceResult = { default := { foundLine := default, foundFlattenedHardLine := default, space := default } }
Render the given f : Format
with a line width of w
.
indent
is the starting amount to indent each line by.
Equations
- Std.Format.prettyM f w indent = Std.Format.be w [{ flatten := false, flb := Std.Format.FlattenBehavior.allOrNone, items := [{ f := f, indent := Int.ofNat indent, activeTags := 0 }] }]
Create a format l ++ f ++ r
with a flatten group.
FlattenBehaviour is allOrNone
; for fill
use bracketFill
.
Equations
- Lean.Format.bracket l f r = Lean.Format.group (Lean.Format.nest (Int.ofNat (String.length l)) (Std.Format.text l ++ f ++ Std.Format.text r))
Creates the format "(" ++ f ++ ")"
with a flattening group.
Equations
- Lean.Format.paren f = Lean.Format.bracket "(" f ")"
Creates the format "[" ++ f ++ "]"
with a flattening group.
Equations
- Lean.Format.sbracket f = Lean.Format.bracket "[" f "]"
Same as bracket
except uses the fill
flattening behaviour.
Equations
- Std.Format.bracketFill l f r = Lean.Format.fill (Lean.Format.nest (Int.ofNat (String.length l)) (Std.Format.text l ++ f ++ Std.Format.text r))
Default width of the targeted output pane.
Equations
- Std.Format.defWidth = 120
Nest with the default indentation amount.
Equations
Insert a newline and then f
, all nested by the default indent amount.
Equations
Equations
- One or more equations did not get rendered due to their size.
Pretty-print a Format
object as a string with expected width w
.
Equations
- Lean.Format.pretty f w = let act := Std.Format.prettyM f w 0; (act { out := "", column := 0 }).snd.out
- format : α → Lean.Format
Class for converting a given type α to a Format
object for pretty-printing.
See also Repr
, which also outputs a Format
object.
Instances
Equations
- Std.instToFormatFormat = { format := fun f => f }
Equations
- Std.instToFormatString = { format := fun s => Std.Format.text s }
Intersperse the given list (each item printed with format
) with the given sep
format.
Equations
- Lean.Format.joinSep [] _fun_discr = Lean.Format.nil
- Lean.Format.joinSep [a] _fun_discr = Lean.format a
- Lean.Format.joinSep (a :: as) _fun_discr = Lean.format a ++ _fun_discr ++ Lean.Format.joinSep as _fun_discr
Format each item in items
and prepend prefix pre
.
Equations
- Std.Format.prefixJoin pre [] = Lean.Format.nil
- Std.Format.prefixJoin pre (a :: as) = pre ++ Lean.format a ++ Std.Format.prefixJoin pre as
Format each item in items
and append suffix
.
Equations
- Std.Format.joinSuffix [] _fun_discr = Lean.Format.nil
- Std.Format.joinSuffix (a :: as) _fun_discr = Lean.format a ++ _fun_discr ++ Std.Format.joinSuffix as _fun_discr