Module docstring
{}
{}
Std.Format.FlattenBehavior
inductive
/-- Determines how groups should have linebreaks inserted when the
text would overfill its remaining space.
- `allOrNone` will make a linebreak on every `Format.line` in the group or none of them.
```
[1,
2,
3]
```
- `fill` will only make linebreaks on as few `Format.line`s as possible:
```
[1, 2,
3]
```
-/
inductive Format.FlattenBehavior where
| allOrNone
| fill
deriving Inhabited, BEq
Std.Format.instInhabitedFlattenBehavior
instance
: Inhabited✝ (@Std.Format.FlattenBehavior)
Std.Format.instBEqFlattenBehavior
instance
: BEq✝ (@Std.Format.FlattenBehavior✝)
BEq
Std.Format
inductive
/-- 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_](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf). -/
inductive Format where
/-- The empty format. -/
| nil : Format
/-- A position where a newline may be inserted
if the current group does not fit within the allotted column width. -/
| line : Format
/-- `align` tells the formatter to pad with spaces to the current indent,
or else add a newline if we are already at or past the indent. For example:
```
nest 2 <| "." ++ align ++ "a" ++ line ++ "b"
```
results in:
```
. a
b
```
If `force` is true, then it will pad to the indent even if it is in a flattened group.
-/
| align (force : Bool) : Format
/-- A node containing a plain string. -/
| text : String → Format
/-- `nest n f` tells the formatter that `f` is nested inside something with length `n`
so that it is pretty-printed with the correct indentation on a line break.
For example, we can define a formatter for list `l : 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.
-/
| nest (indent : Int) : Format → Format
/-- Concatenation of two Formats. -/
| append : Format → Format → Format
/-- Creates a new flattening group for the given inner format. -/
| group : Format → (behavior : FlattenBehavior := FlattenBehavior.allOrNone) → Format
/-- Used for associating auxiliary information (e.g. `Expr`s) with `Format` objects. -/
| tag : Nat → Format → Format
deriving Inhabited
Std.instInhabitedFormat
instance
: Inhabited✝ (@Std.Format)
Inhabited
Std.Format.isEmpty
definition
: Format → Bool
Std.Format.fill
definition
(f : Format) : Format
/-- Alias for a group with `FlattenBehavior` set to `fill`. -/
def fill (f : Format) : Format :=
group f (behavior := FlattenBehavior.fill)
Std.Format.instAppend
instance
: Append Format
instance : Append Format := ⟨Format.append⟩
Std.Format.instCoeString
instance
: Coe String Format
Std.Format.join
definition
(xs : List Format) : Format
Std.Format.isNil
definition
: Format → Bool
Std.Format.instInhabitedSpaceResult
instance
: Inhabited✝ (@_private.0.Std.Format.SpaceResult)
Inhabited
Std.Format.MonadPrettyFormat
structure
(m : Type → Type)
/-- A monad in which we can pretty-print `Format` objects. -/
class MonadPrettyFormat (m : Type → Type) where
pushOutput (s : String) : m Unit
pushNewline (indent : Nat) : m Unit
currColumn : m Nat
/-- Start a scope tagged with `n`. -/
startTag : Nat → m Unit
/-- Exit the scope of `n`-many opened tags. -/
endTags : Nat → m Unit
Std.Format.bracket
definition
(l : String) (f : Format) (r : String) : Format
Std.Format.paren
definition
(f : Format) : Format
Std.Format.sbracket
definition
(f : Format) : Format
Std.Format.bracketFill
definition
(l : String) (f : Format) (r : String) : Format
Std.Format.defIndent
definition
/-- Default indentation. -/
def defIndent := 2
Std.Format.defUnicode
definition
def defUnicode := true
Std.Format.defWidth
definition
/-- Default width of the targeted output pane. -/
def defWidth := 120
Std.Format.nestD
definition
(f : Format) : Format
Std.Format.indentD
definition
(f : Format) : Format
/-- Insert a newline and then `f`, all nested by the default indent amount. -/
def indentD (f : Format) : Format :=
nestD (Format.line ++ f)
Std.Format.instMonadPrettyFormatStateMState
instance
: MonadPrettyFormat (StateM State)
instance : MonadPrettyFormat (StateM State) where
-- We avoid a structure instance update, and write these functions using pattern matching because of issue #316
pushOutput s := modify fun ⟨out, col⟩ => ⟨out ++ s, col + s.length⟩
pushNewline indent := modify fun ⟨out, _⟩ => ⟨out ++ "\n".pushn ' ' indent, indent⟩
currColumn := return (← get).column
startTag _ := return ()
endTags _ := return ()
Std.ToFormat
structure
(α : Type u)
Std.instToFormatFormat
instance
: ToFormat Format
Std.instToFormatString
instance
: ToFormat String
instance : ToFormat String where
format s := Format.text s
Std.Format.joinSep
definition
{α : Type u} [ToFormat α] : List α → Format → Format
Std.Format.prefixJoin
definition
{α : Type u} [ToFormat α] (pre : Format) : List α → Format
Std.Format.joinSuffix
definition
{α : Type u} [ToFormat α] : List α → Format → Format