Module Wax_utils.PrinterSource

Sourcetype t

The state of the pretty-printer, managing indentation, pending spaces/newlines, and attached comments/blank lines.

Sourceval indent : t -> int -> (unit -> unit) -> unit

indent pp n f runs f with the break-indentation set to n — the offset applied when a space/newline/cut within f breaks the line. The enclosing box resets this offset to 0, so n is measured from the box's own indentation. The previous value is restored after f completes.

Sourceval string : t -> string -> unit

Prints a string to the formatter, flushing any pending items first.

Sourceval string_as : t -> int -> string -> unit

Prints a string with a specified display length to the formatter.

Sourceval space : t -> unit -> unit

Queues a space to be printed, if no newlines are pending and a non-blank string has been emitted.

Sourceval cut : t -> unit -> unit

Prints a cut (break with 0 width) to the formatter.

Sourceval newline : t -> unit -> unit

Queues a newline to be printed, if no non-blank string has been emitted.

Sourceval blank_line : t -> unit -> unit

Queues a blank line to be printed.

Sourceval defer_eol : t -> (unit -> unit) -> unit

defer_eol pp emit records a trailing line comment to be emitted at the end of the current line. It is flushed before the next ordinary token or box (or at end of output), but a separator printed within with_held_eol stays on the comment's line, before the comment. Emitting it ends the line.

Sourceval with_held_eol : t -> (unit -> unit) -> unit

with_held_eol pp f runs f without flushing a pending end-of-line comment first, so a list separator (e.g. a comma) printed by f appears on the comment's line, ahead of the deferred comment.

Sourceval has_pending_eol : t -> bool

Whether a trailing end-of-line comment is currently deferred (set by defer_eol, not yet flushed). Lets a caller suppress a trailing comma when the last element already carries a trailing comment — adding the comma would push the comment off that element and shift where it re-attaches on a reparse.

Sourceval if_broken : t -> (unit -> unit) -> unit

if_broken pp f emits the content produced by f only when the enclosing box is laid out broken (multi-line); in a flat (single-line) box it produces nothing. Used for a trailing comma after the last element of a list that wraps. It never counts toward the box's fit decision.

Sourceval box : t -> ?skip_space:bool -> ?indent:int -> (unit -> unit) -> unit

box pp ?skip_space ?indent f creates a "box" for pretty-printing. The content generated by f will be formatted within this box. If it fits on a single line, it will be printed on one line. Otherwise, it will be broken into multiple lines. ?indent specifies an additional indentation level for lines broken within the box. If ?skip_space is true, no space will be added before the box if it starts on the same line as previous content.

Sourceval hvbox : t -> ?skip_space:bool -> ?indent:int -> (unit -> unit) -> unit

hvbox pp ?skip_space ?indent f creates a "horizontal-vertical" box. The content generated by f will be formatted horizontally if it fits on the current line; otherwise, it will be formatted vertically, breaking lines where appropriate. ?indent specifies an additional indentation level for lines broken within the box. If ?skip_space is true, no space will be added before the box.

Sourceval hbox : t -> ?skip_space:bool -> (unit -> unit) -> unit

hbox pp ?skip_space f creates a "horizontal" box: breaks within never wrap, so the content always stays on one line. If ?skip_space is true, no space is added before the box.

Sourceval hovbox : t -> ?skip_space:bool -> ?indent:int -> (unit -> unit) -> unit

hovbox pp ?skip_space ?indent f creates a "packing" box: as much content as fits is placed on each line, wrapping greedily, breaking only where needed.

Sourceval vbox : t -> ?skip_space:bool -> ?indent:int -> (unit -> unit) -> unit

vbox pp ?skip_space ?indent f creates a "vertical" box. The content generated by f will always be formatted vertically, breaking lines where appropriate. ?indent specifies an additional indentation level for lines broken within the box. If ?skip_space is true, no space will be added before the box.

Sourceval run : ?width:int -> Format.formatter -> (t -> unit) -> unit

run ?width fmt f creates a new printer on the given formatter, runs f, and renders the result. width is the target line width (default 78).