Page
Library
Module
Module type
Parameter
Class
Class type
Source
FmtSourceFormat pretty-printer combinators.
Consult naming conventions for your pretty-printers.
References
v0.8.5 - homepage
pf is Format.fprintf.
val kpf :
(Format.formatter -> 'a) ->
Format.formatter ->
('b, Format.formatter, unit, 'a) format4 ->
'bkpf is Format.kfprintf.
strf is Format.asprintf.
Note. When using strf utf_8 and style_renderer are always respectively set to true and `None. See also strf_like.
kstrf is like strf but continuation based.
strf_like ppf is like strf except its utf_8 and style_renderer settings are those of ppf.
with_buffer ~like b is a formatter whose utf_8 and style_renderer settings are copied from those of like (if provided).
stdout is the standard output formatter.
stderr is the standard error formatter.
pr is pf stdout.
epr is pf stderr.
failwith is kstrf failwith, raises Pervasives.Failure with a pretty-printed string argument.
invalid_arg is kstrf invalid_arg, raises Pervasives.Invalid_argument with a pretty-printed string argument.
The type for formatters of values of type 'a.
cut is Format.pp_print_cut.
sp is Format.pp_print_space.
unit fmt formats a unit value with the format fmt.
fmt fmt ppf is pf ppf fmt. If fmt is used with a single non-constant formatting directive, generates a value of type t.
always fmt ppf v formats any value with the constant format fmt.
bool is Format.pp_print_bool.
float_dfrac d rounds the float to the dth decimal fractional digit and formats the result with "%g". Ties are rounded towards positive infinity. The result is only defined for 0 <= d <= 16.
float_dsig d rounds the normalized decimal significand of the float to the dth decimal fractional digit and formats the result with "%g". Ties are rounded towards positive infinity. The result is NaN on infinities and only defined for 0 <= d <= 16.
Warning. The current implementation overflows on large d and floats.
char is Format.pp_print_char.
string is Format.pp_print_string.
exn_backtrace formats an exception backtrace.
These formatters give full control to the client over the formatting process and do not wrap the formatted structures with boxes. Use the Dump module to quickly format values for inspection.
pair ~sep pp_fst pp_snd formats a pair. The first and second projection are formatted using pp_fst and pp_snd and are separated by sep (defaults to cut).
option ~none pp_v formats an optional value. The Some case uses pp_v and None uses none (defaults to nop).
result ~ok ~error formats a result value using ok for the Ok case and error for the Error case.
hashtbl ~sep pp_binding formats the bindings of a hash table. Each binding is formatted with pp_binding and bindings are separated by sep (defaults to cut). If the hash table has multiple bindings for a given key, all bindings are formatted, with the most recent binding first. If the hash table is empty, this is nop.
iter ~sep iter pp_elt formats the iterations of iter over a value using pp_elt. Iterations are separated by sep (defaults to cut).
iter_bindings ~sep iter pp_binding formats the iterations of iter over a value using pp_binding. Iterations are separated by sep (defaults to cut).
using f pp maps values using f and formats them with pp.
box ~indent pp ppf wraps pp in a horizontal or vertical box. Break hints that lead to a new line add indent to the current indentation (defaults to 0).
hbox is like box but is a horizontal box: the line is not split in this box (but may be in sub-boxes).
vbox is like box but is a vertical box: every break hint leads to a new line which adds indent to the current indentation (default to 0).
quote ~mark pp_v ppf is pf "@[<1>@<1>%s%a@<1>%s@]" mark pp_v mark, mark defaults to "\"", it is always counted as spanning as single column (this allows for UTF-8 encoded marks).
Note. These functions only work on US-ASCII strings and/or with newlines ('\n'). If you are dealing with UTF-8 strings or different kinds of line endings you should use the pretty-printers from Uuseg_string.
White space. White space is one of the following US-ASCII characters: space ' ' (0x20), tab '\t' (0x09), newline '\n' (0x0A), vertical tab (0x0B), form feed (0x0C), carriage return '\r' (0x0D).
words formats words by suppressing initial and trailing white space and replacing consecutive white space with a single Format.pp_print_space.
paragraphs formats paragraphs by suppressing initial and trailing spaces and newlines, replacing blank lines (a line made only of white space) by a two Format.pp_force_newline and remaining consecutive white space with a single Format.pp_print_space.
text formats text by respectively replacing spaces and newlines in the string with Format.pp_print_space and Format.pp_force_newline.
lines formats lines by replacing newlines ('\n') in the string with calls to Format.pp_force_newline.
text_loc formats a line-column text range according to GNU conventions.
append pp_v0 pp_v1 ppf (v0, v1) is pp_v0 ppf v0; pp_v1 ppf v1.
byte_size formats a byte size according to its magnitude using SI prefixes up to peta bytes (1015).
bi_byte_size formats a byte size according to its magnitude using binary prefixes up to pebi bytes (215).
Note. Since Format is not UTF-8 aware using UTF-8 output may derail the pretty printing process. Use the pretty-printers from Uuseg_string if you are serious about UTF-8 formatting.
if_utf_8 pp_u pp ppf v is:
pp_u ppf v if utf_8 ppf is true.pp ppf v otherwise.utf_8 ppf is true if UTF-8 output is enabled on ppf. If set_utf_8 hasn't been called on ppf this is true.
set_utf_8 ppf b enables or disables conditional UTF-8 formatting on ppf.
Warning. Using this function replaces any Format.tag functions that may be in place.
The type for styles.
styled_unit s fmt is style s (unit fmt).
The type for style renderers.
`Ansi_tty, renders styles using ANSI escape sequences.`None, styled rendering has no effect.style_renderer ppf is the style renderer used by ppf. If set_style_renderer has never been called on ppf this is `None.
set_style_renderer ppf r sets the style renderer of ppf to r.
Warning. Using this function replaces any Format.tag functions that may be in place.
Given a type ty use:
pp_ty for a pretty printer that provides full control to the client and does not wrap the formatted value in an enclosing box. See these examples.dump_ty for a pretty printer that provides little control over the pretty-printing process, wraps the rendering in an enclosing box and tries as much as possible to respect the OCaml syntax. These pretty-printers should make it easy to inspect and understand values of the given type, they are mainly used for quick printf debugging and/or toplevel interaction. See these examples.If you are in a situation where making a difference between dump_ty and pp_ty doesn't make sense then use pp_ty.
For a type ty that is the main type of the module (the "M.t" convention) drop the suffix, that is simply use M.pp and M.dump.