Determines how groups should have linebreaks inserted when the text would overfill its remaining space.
allOrNonewill make a linebreak on everyFormat.linein the group or none of them.[1, 2, 3]fillwill only make linebreaks on as fewFormat.lines as possible:[1, 2, 3]
- allOrNone : FlattenBehavior
- fill : FlattenBehavior
Equations
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.
- nil : Format
The empty format.
- line : Format
A position where a newline may be inserted if the current group does not fit within the allotted column width.
- align (force : Bool) : Format
- text : String → Format
A node containing a plain string.
- nest
(indent : Int)
: Format → Format
nest n ftells the formatter thatfis nested inside something with lengthnso that it is pretty-printed with the correct indentation on a line break. For example, we can define a formatter for listl : List Formatas: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 : Format → Format → Format
Concatenation of two Formats.
- group : Format → (behavior : optParam FlattenBehavior FlattenBehavior.allOrNone) → Format
Creates a new flattening group for the given inner format.
- tag : Nat → Format → Format
Used for associating auxiliary information (e.g.
Exprs) withFormatobjects.
Equations
- Std.instInhabitedFormat = { default := Std.Format.nil }
Check whether the given format contains no characters.
Equations
- Std.Format.nil.isEmpty = true
- Std.Format.line.isEmpty = false
- (Std.Format.align force).isEmpty = true
- (Std.Format.text msg).isEmpty = (msg == "")
- (Std.Format.nest indent f).isEmpty = f.isEmpty
- (f₁.append f₂).isEmpty = (f₁.isEmpty && f₂.isEmpty)
- (f.group behavior).isEmpty = f.isEmpty
- (Std.Format.tag a f).isEmpty = f.isEmpty
Alias for a group with FlattenBehavior set to fill.
Equations
Equations
- Std.Format.instAppend = { append := Std.Format.append }
Equations
- Std.Format.instCoeString = { coe := Std.Format.text }
Equations
- Std.Format.join xs = List.foldl (fun (x1 x2 : Std.Format) => x1 ++ x2) (Std.Format.text "") xs
Render the given f : Format with a line width of w.
indent is the starting amount to indent each line by.
Create a format l ++ f ++ r with a flatten group.
FlattenBehaviour is allOrNone; for fill use bracketFill.
Equations
- Std.Format.bracket l f r = (Std.Format.nest (↑l.length) (Std.Format.text l ++ f ++ Std.Format.text r)).group
Creates the format "(" ++ f ++ ")" with a flattening group.
Equations
- f.paren = Std.Format.bracket "(" f ")"
Creates the format "[" ++ f ++ "]" with a flattening group.
Equations
- f.sbracket = Std.Format.bracket "[" f "]"
Same as bracket except uses the fill flattening behaviour.
Equations
- Std.Format.bracketFill l f r = (Std.Format.nest (↑l.length) (Std.Format.text l ++ f ++ Std.Format.text r)).fill
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
- f.indentD = (Std.Format.line ++ f).nestD
Equations
- One or more equations did not get rendered due to their size.
Renders a Format to a string.
width: the total widthindent: the initial indentation to use for wrapped lines (subsequent wrapping may increase the indentation)column: begin the first line wrapcolumncharacters earlier than usual (this is useful when the output String will be printed starting atcolumn)
Class for converting a given type α to a Format object for pretty-printing.
See also Repr, which also outputs a Format object.
- format : α → Format
Instances
- Aesop.IndexingMode.instToFormat
- Aesop.RegularRule.instToFormat
- Aesop.UnorderedArraySet.instToFormat
- Aesop.instToFormatPINF
- Aesop.instToFormatPINFRaw
- Lean.Elab.FixedParams.instToFormatInfo
- Lean.Elab.Term.StructInst.instToFormatFieldLHS
- Lean.Elab.Term.StructInst.instToFormatFieldView
- Lean.Elab.Term.StructInst.instToFormatStructInstView
- Lean.Elab.WF.GuessLex.instToFormatGuessLexRel
- Lean.Elab.instToFormatAttribute
- Lean.Elab.instToFormatCustomInfo
- Lean.Elab.instToFormatModifiers
- Lean.IR.Borrow.instToFormatParamMap
- Lean.IR.CtorFieldInfo.instToFormat
- Lean.IR.LogEntry.instToFormat
- Lean.IR.UnreachableBranches.Value.instToFormat
- Lean.IR.UnreachableBranches.instToFormatValue
- Lean.IR.instToFormatArg
- Lean.IR.instToFormatCtorInfo
- Lean.IR.instToFormatDecl
- Lean.IR.instToFormatExpr
- Lean.IR.instToFormatFnBody
- Lean.IR.instToFormatIRType
- Lean.IR.instToFormatJoinPointId
- Lean.IR.instToFormatLitVal
- Lean.IR.instToFormatParam
- Lean.IR.instToFormatVarId
- Lean.Json.instToFormat
- Lean.Level.instToFormat
- Lean.Meta.DiscrTree.instToFormat
- Lean.Meta.DiscrTree.instToFormatKey
- Lean.Meta.DiscrTree.instToFormatTrie
- Lean.Meta.Simp.instToFormatSimprocEntry
- Lean.Meta.instToFormatInstanceEntry
- Lean.Meta.instToFormatSimpTheorem
- Lean.Meta.instToFormatUnificationHints
- Lean.Position.instToFormat
- Lean.Syntax.instToFormat
- Lean.Syntax.instToFormatTSyntax
- Lean.instToFormatDataValue
- Lean.instToFormatKVMap
- Lean.instToFormatName_lean
- Lean.instToFormatProdNameDataValue
- Std.instToFormatFormat
- Std.instToFormatString
- instToFormatArray
- instToFormatList
- instToFormatOfToString
- instToFormatOption
- instToFormatPos
- instToFormatProd
Equations
- Std.instToFormatFormat = { format := fun (f : Std.Format) => f }
Equations
- Std.instToFormatString = { format := fun (s : String) => Std.Format.text s }
Intersperse the given list (each item printed with format) with the given sep format.
Equations
- Std.Format.joinSep [] x✝ = Std.Format.nil
- Std.Format.joinSep [a] x✝ = Std.format a
- Std.Format.joinSep (a :: as) x✝ = List.foldl (fun (x1 : Std.Format) (x2 : α) => x1 ++ x✝ ++ Std.format x2) (Std.format a) as
Format each item in items and prepend prefix pre.
Equations
- pre.prefixJoin [] = Std.Format.nil
- pre.prefixJoin (a :: as) = List.foldl (fun (x1 : Std.Format) (x2 : α) => x1 ++ pre ++ Std.format x2) (pre ++ Std.format a) as
Format each item in items and append suffix.
Equations
- Std.Format.joinSuffix [] x✝ = Std.Format.nil
- Std.Format.joinSuffix (a :: as) x✝ = List.foldl (fun (x1 : Std.Format) (x2 : α) => x1 ++ Std.format x2 ++ x✝) (Std.format a ++ x✝) as