jon.recoil.org

Module Format_doc.Doc

Definitions and immutable API for composing documents

Type definitions and core functions

type box_type =
  1. | H
  2. | V
  3. | HV
  4. | HoV
  5. | B

Format box types

type stag = Stdlib.Format.stag
type element =
  1. | Text of string
  2. | With_size of int
  3. | Open_box of {
    1. kind : Format_doc.Doc.box_type;
    2. indent : int;
    }
  4. | Close_box
  5. | Open_tag of Stdlib.Format.stag
  6. | Close_tag
  7. | Open_tbox
  8. | Tab_break of {
    1. width : int;
    2. offset : int;
    }
  9. | Set_tab
  10. | Close_tbox
  11. | Simple_break of {
    1. spaces : int;
    2. indent : int;
    }
  12. | Break of {
    1. fits : (string * int * string) as 'a;
    2. breaks : 'a;
    }
  13. | Flush of {
    1. newline : bool;
    }
  14. | Newline
  15. | If_newline
  16. | Deprecated of Stdlib.Format.formatter -> unit
    (*

    Escape hatch: a Format printer used to provide backward-compatibility for user-defined printer (from the #install_printer toplevel directive for instance).

    *)

Base formatting instruction recognized by Format

type t

Immutable document type

type ('a, 'b) fmt = ('a, Format_doc.Doc.t, Format_doc.Doc.t, 'b) Stdlib.format4
type 'a printer = 'a -> Format_doc.Doc.printer0
val empty : Format_doc.Doc.t

Empty document

format ppf doc sends the format instruction of doc to the Format's formatter doc.

val fold : ('acc -> Format_doc.Doc.element -> 'acc) -> 'acc -> Format_doc.Doc.t -> 'acc

Fold over a document as a sequence of instructions

val msg : ('a, Format_doc.Doc.t) Format_doc.Doc.fmt -> 'a

msg and kmsg produce a document from a format string and its argument

val kmsg : (Format_doc.Doc.t -> 'b) -> ('a, 'b) Format_doc.Doc.fmt -> 'a

printf and kprintf produce a printer from a format string and its argument

val kprintf : (Format_doc.Doc.t -> 'b) -> ('a, Format_doc.Doc.t -> 'b) Format_doc.Doc.fmt -> 'a

The functions below mirror Format printers, without the pp_print_ prefix naming convention

val close_box : Format_doc.Doc.printer0
val text : string Format_doc.Doc.printer
val string : string Format_doc.Doc.printer
val bytes : bytes Format_doc.Doc.printer
val with_size : int Format_doc.Doc.printer
val float : float Format_doc.Doc.printer
val char : char Format_doc.Doc.printer
val bool : bool Format_doc.Doc.printer
val break : spaces:int -> indent:int -> Format_doc.Doc.printer0
val custom_break : fits:((string * int * string) as 'a) -> breaks:'a -> Format_doc.Doc.printer0
val force_newline : Format_doc.Doc.printer0
val if_newline : Format_doc.Doc.printer0
val force_stop : Format_doc.Doc.printer0
val open_tbox : Format_doc.Doc.printer0
val tab_break : width:int -> offset:int -> Format_doc.Doc.printer0
val close_tbox : Format_doc.Doc.printer0
val close_tag : Format_doc.Doc.printer0
val iter : ?sep:Format_doc.Doc.printer0 -> iter:(('a -> unit) -> 'b -> unit) -> 'a Format_doc.Doc.printer -> 'b Format_doc.Doc.printer

Alignment functions

val align_prefix : (Format_doc.Doc.t * int) list -> Format_doc.Doc.t list

Align the right side of one "@{<ralign>...@}" tag box by inserting spaces at the beginning of boxes. Those function do nothing if the tag box appears after a break hint.

val align_prefix2 : (Format_doc.Doc.t * int) -> (Format_doc.Doc.t * int) -> Format_doc.Doc.t * Format_doc.Doc.t