module Easy_format:sig
..end
Easy_format: indentation made easy.
This module provides a functional, simplified layer over the Format module of the standard library.
Input data must be first modelled as a tree using 3 kinds of nodes:
Atoms represent any text that is guaranteed to be printed as-is. Lists can model any sequence of items such as arrays of data or lists of definitions that are labelled with something like "int main", "let x =" or "x:".
typewrap =
[ `Always_wrap
| `Force_breaks
| `Force_breaks_rec
| `Never_wrap
| `No_breaks
| `Wrap_atoms ]
List wrapping conditions:
`Wrap_atoms
: wrap if the list contains only atoms`Always_wrap
: always wrap when needed`Never_wrap
: never wrap,
i.e. the list is either horizontal or vertical`Force_breaks
: align vertically,
i.e. always break line between list items and
align the left edge of each item.`Force_breaks_rec
: same as `Force_breaks
but turns
any wrappable ancestor node's wrap property (`Wrap_atoms
or `Always_wrap
) into `Force_breaks
.`No_breaks
: align horizontally,
i.e. never break line between list itemstypelabel_break =
[ `Always | `Always_rec | `Auto | `Never ]
When to break the line after a Label
:
Auto
: break after the label if there's not enough roomAlways
: always break after the labelAlways_rec
: always break after the label and force breaks in all parent
lists and labels, similarly to `Force_breaks_rec
for lists.Never
: never break after the labeltypestyle_name =
string
type
style = {
|
tag_open : |
|
tag_close : |
Pair of opening and closing tags that are inserted around text after pretty-printing.
type
atom_param = {
|
atom_style : |
(* | Default: | *) |
val atom : atom_param
type
list_param = {
|
space_after_opening : |
(* | Whether there must be some whitespace
after the opening string.
Default: | *) |
|
space_after_separator : |
(* | Whether there must be some whitespace
after the item separators.
Default: | *) |
|
space_before_separator : |
(* | Whether there must be some whitespace
before the item separators.
Default: | *) |
|
separators_stick_left : |
(* | Whether the separators must
stick to the item on the left.
Default: | *) |
|
space_before_closing : |
(* | Whether there must be some whitespace
before the closing string.
Default: | *) |
|
stick_to_label : |
(* | Whether the opening string should be fused
with the preceding label.
Default: | *) |
|
align_closing : |
(* | Whether the beginning of the
closing string must be aligned
with the beginning of the opening string
(stick_to_label = false) or
with the beginning of the label if any
(stick_to_label = true).
Default: | *) |
|
wrap_body : |
(* | Defines under which conditions the list body
may be wrapped, i.e. allow several lines
and several list items per line.
Default: | *) |
|
indent_body : |
(* | Extra indentation of the list body.
Default: | *) |
|
list_style : |
(* | Default: | *) |
|
opening_style : |
(* | Default: | *) |
|
body_style : |
(* | Default: | *) |
|
separator_style : |
(* | Default: | *) |
|
closing_style : |
(* | Default: | *) |
List-formatting parameters.
Always derive a new set of parameters from an existing record.
See Easy_format.list
.
val list : list_param
Default list-formatting parameters, using the default values described in the type definition above.
In order to make code compatible with future versions of the library,
the record inheritance syntax should be used, e.g.
{ list with align_closing = false }
.
If new record fields are added, the program would still compile
and work as before.
type
label_param = {
|
label_break : |
(* | Whether to break the line after the label.
Introduced in version 1.2.0.
Default: | *) |
|
space_after_label : |
(* | Whether there must be some whitespace after the label.
Default: | *) |
|
indent_after_label : |
(* | Extra indentation before the item that comes after a label.
Default: | *) |
|
label_style : |
(* | Default: | *) |
Label-formatting parameters.
Always derive a new set of parameters from an existing record.
See Easy_format.label
.
val label : label_param
Default label-formatting parameters, using the default values described in the type definition above.
In order to make code compatible with future versions of the library,
the record inheritance syntax should be used, e.g.
{ label with indent_after_label = 0 }
.
If new record fields are added, the program would still compile
and work as before.
type
t =
| |
Atom of |
(* | Plain string normally without line breaks. | *) |
| |
List of |
(* |
| *) |
| |
Label of |
(* |
| *) |
| |
Custom of |
(* | User-defined printing function that allows to use the Format module directly if necessary. It is responsible for leaving the formatter in a clean state. | *) |
The type of the tree to be pretty-printed. Each node contains its own formatting parameters.
Detail of a list node
List ((opening, separator, closing, param), nodes)
:
opening
: opening string such as "{"
"["
"("
"begin"
""
etc.separator
: node separator such as ";"
","
""
"+"
"|"
etc.closing
: closing string such as "}"
"]"
")"
"end"
""
etc.nodes
: elements of the list.typeescape =
[ `Escape of (string -> int -> int -> unit) -> string -> int -> int -> unit
| `Escape_string of string -> string
| `None ]
typestyles =
(style_name * style) list
module Pretty:sig
..end
The regular pretty-printing functions
module Compact:sig
..end
No spacing or newlines other than those in the input data
or those produced by Custom
printing.