Format_docComposable document for the Format formatting engine.
This module introduces a pure and immutable document type which represents a sequence of formatting instructions to be printed by a formatting engine at later point. At the same time, it also provides format string interpreter which produces this document type from format string and their associated printers.
The module is designed to be source compatible with code defining format printers: replacing `Format` by `Format_doc` in your code will convert `Format` printers to `Format_doc` printers.
module Doc : sig ... endDefinitions and immutable API for composing documents
The functions and types below provides source compatibility with format printers and conversion function from Format_doc printers to Format printers. The reverse direction is implemented using an escape hatch in the formatting instruction and should only be used to preserve backward compatibility.
type doc = Doc.ttype t = doctype 'a printer = formatter -> 'a -> unitformatter rdoc creates a formatter that updates the rdoc reference
type 'a format_printer = Stdlib.Format.formatter -> 'a -> unitTranslate a Format_doc printer to a Format one.
val compat : 'a printer -> 'a format_printerval compat1 : ('p1 -> 'a printer) -> 'p1 -> 'a format_printerval compat2 : ('p1 -> 'p2 -> 'a printer) -> 'p1 -> 'p2 -> 'a format_printerval deprecated_printer : (Stdlib.Format.formatter -> unit) -> formatter -> unitIf necessary, embbed a Format printer inside a formatting instruction stream. This breaks every guarantees provided by Format_doc.
val deprecated : 'a format_printer -> 'a printerval deprecated1 : ('p1 -> 'a format_printer) -> 'p1 -> 'a printerdoc_printf and kdoc_printf creates a document directly
Docval doc_printer : 'a printer -> 'a Doc.printerval pp_print_string : string printerval pp_print_substring : pos:int -> len:int -> string printerval pp_print_text : string printerval pp_print_bytes : bytes printerval pp_print_as : formatter -> int -> string -> unitval pp_print_substring_as :
pos:int ->
len:int ->
formatter ->
int ->
string ->
unitval pp_print_char : char printerval pp_print_int : int printerval pp_print_float : float printerval pp_print_bool : bool printerval pp_print_nothing : unit printerval pp_print_seq :
?pp_sep:unit printer ->
'a printer ->
'a Stdlib.Seq.t printerval pp_print_either :
left:'a printer ->
right:'b printer ->
('a, 'b) Stdlib.Either.t printerval pp_open_stag : Stdlib.Format.stag printerval pp_close_stag : unit printerval pp_open_box : int printerval pp_close_box : unit printerval pp_print_space : unit printerval pp_print_cut : unit printerval pp_print_break : formatter -> int -> int -> unitval pp_print_custom_break :
formatter ->
fits:((string * int * string) as 'c) ->
breaks:'c ->
unitval pp_open_tbox : unit printerval pp_close_tbox : unit printerval pp_set_tab : unit printerval pp_print_tab : unit printerval pp_print_tbreak : formatter -> int -> int -> unitval pp_print_if_newline : unit printerval pp_force_newline : unit printerval pp_print_flush : unit printerval pp_print_newline : unit printerval comma : unit printerval pp_two_columns :
?sep:string ->
?max_lines:int ->
formatter ->
(string * string) list ->
unitpp_two_columns ?sep ?max_lines ppf l prints the lines in l as two columns separated by sep ("|" by default). max_lines can be used to indicate a maximum number of lines to print -- an ellipsis gets inserted at the middle if the input has too many lines.
Example:
pp_two_columns ~max_lines:3 Format.std_formatter [ "abc", "hello"; "def", "zzz"; "a" , "bllbl"; "bb" , "dddddd"; ]
prints
abc | hello ... bb | dddddd