module Pretty:Utility functions for pretty-printing. The major features provided by this module aresig..end
fprintf-style interface with support for user-defined printersPretty.doc object that encodes all of the elements to be
printed
along with alignment specifiers and optional and mandatory newlinesPretty.doc to a certain width and emit it as a string, to an
output stream or pass it to a user-defined functiontype doc
Pretty.dprintf function with a printf-like interface.
The Pretty.dprintf method is slightly slower so we do not use it for
large jobs such as the output routines for a compiler. But we use it for
small jobs such as logging and error messages.val nil : docval (++) : doc -> doc -> docval concat : doc -> doc -> docval text : string -> docval num : int -> docval num64 : int64 -> docval real : float -> docval chr : char -> docPretty.text
with a one-character string.val line : doc(text
"\n"). The new line will be indented to the current indentation level,
unless you use Pretty.leftflush right after this.val leftflush : docPretty.line to prevent the indentation. Whatever follows
next will be flushed left. Indentation resumes on the next line.val break : docval align : docval unalign : docval mark : docval unmark : docval indent : int -> doc -> doc((text " ") ++ align ++ doc ++ unalign),
with the specified number of spaces.val markup : doc -> docval seq : sep:doc -> doit:('a -> doc) -> elements:'a list -> docsep is a separator, doit is a function that
converts an element to a document.val docList : ?sep:doc -> ('a -> doc) -> unit -> 'a list -> docunit argument is there
to make this function more easily usable with the Pretty.dprintf
interface. The first argument is a separator, by default a comma.val d_list : string -> (unit -> 'a -> doc) -> unit -> 'a list -> docPretty.dprintf does, and itself works
in the dprintf context. Also accepts
a string as the separator since that's by far the most common.val docArray : ?sep:doc ->
(int -> 'a -> doc) -> unit -> 'a array -> docval docOpt : ('a -> doc) -> unit -> 'a option -> doc'a option with None or Someval d_int32 : int32 -> docval f_int32 : unit -> int32 -> docval d_int64 : int64 -> docval f_int64 : unit -> int64 -> docmodule MakeMapPrinter:functor (Map:sigtypekeytype'atval fold :(key -> 'a -> 'b -> 'b) ->
'a t -> 'b -> 'bend) ->sig..end
module MakeSetPrinter:
val insert : unit -> doc -> docprintf-like interfaceval dprintf : ('a, unit, doc, doc) format4 -> 'adoc objects. The first argument for this function is a format string
argument (of type ('a, unit, doc) format; if you insist on
understanding what that means see the module Printf). The format string
is like that for the printf function in C, except that it understands a
few more formatting controls, all starting with the @ character.
See the gprintf function if you want to pipe the result of dprintf into some other functions.
The following special formatting characters are understood (these do not correspond to arguments of the function):
Pretty.align. Every format string must have matching
Pretty.align and Pretty.unalign. Pretty.unalign.Pretty.line. Just like "\n"Pretty.break.Pretty.mark. Pretty.unmark.Pretty.leftflush
Should be used immediately after @! or "\n".printf % formatting characters the following two
new characters are supported:unit -> doc. This argument is
invoked to produce a documentunit -> 'a -> doc
and the second of type 'a. (The extra unit is do to the
peculiarities of the built-in support for format strings in Ocaml. It
turns out that it is not a major problem.) Here is an example of how
you use this:dprintf "Name=%s, SSN=%7d, Children=@[%a@]\n"
pers.name pers.ssn (docList (chr ',' ++ break) text)
pers.children
The result of dprintf is a Pretty.doc. You can format the document and
emit it using the functions Pretty.fprint and Pretty.sprint.
val gprintf : (doc -> 'a) -> ('b, unit, doc, 'a) format4 -> 'bPretty.dprintf but more general. It also takes a function that is
invoked on the constructed document but before any formatting is done. The
type of the format argument means that 'a is the type of the parameters of
this function, unit is the type of the first argument to %a and %t
formats, doc is the type of the intermediate result, and 'b is the type of
the result of gprintf.val fprint : out_channel -> width:int -> doc -> unitval sprint : width:int -> doc -> stringval fprintf : out_channel -> ('a, unit, doc) format -> 'a
val printf : ('a, unit, doc) format -> 'a
val eprintf : ('a, unit, doc) format -> 'a
val withPrintDepth : int -> (unit -> unit) -> unitval printDepth : int refalign/unalign pairs at which
everything is replaced with ellipsisval printIndent : bool refval fastMode : bool reftrue then optional breaks are taken only when the document
has exceeded the given width. This means that the printout will looked
more ragged but it will be fasterval flushOften : bool refval countNewLines : int refval auto_printer : string -> 'a