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]
- allOrNone : FlattenBehavior
- fill : FlattenBehavior
Instances For
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 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 : 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.
Expr
s) withFormat
objects.
Instances For
Check whether the given format contains no characters.
Equations
Instances For
A directive indicating whether a given work group is able to be flattened.
allow
indicates that the group is allowed to be flattened; its argument istrue
if there is sufficient space for it to be flattened (and so it should be), orfalse
if not.disallow
means that this group should not be flattened irrespective of space concerns. This is used at levels of aFormat
outside of any flattening groups. It is necessary to track this so that, after a hard line break, we know whether to try to flatten the next line.
- allow (fits : Bool) : FlattenAllowability
- disallow : FlattenAllowability
Instances For
Whether the given directive indicates that flattening should occur.
Equations
Instances For
Create a format l ++ f ++ r
with a flatten group.
FlattenBehaviour is allOrNone
; for fill
use bracketFill
.
Equations
Instances For
Creates the format "(" ++ f ++ ")"
with a flattening group.
Equations
Instances For
Creates the format "[" ++ f ++ "]"
with a flattening group.
Equations
Instances For
Nest with the default indentation amount.
Equations
Instances For
Insert a newline and then f
, all nested by the default indent amount.
Equations
Instances For
Equations
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 wrapcolumn
characters earlier than usual (this is useful when the output String will be printed starting atcolumn
)