package wax-lib
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4361e1324b7754a4c08ab5b505df32061f3ce0cea60443fd0d3699e0fa796b32
sha512=fcc756d2f160ba90a9aa1131f2ab22ed7f45466ccd658c21cf9df6868a6aab0cee7f404719d698a379958802f9820398f2fe0685ecc4dda018ca4f653294e39b
doc/wax-lib.utils/Wax_utils/Printer/index.html
Module Wax_utils.PrinterSource
The state of the pretty-printer, managing indentation, pending spaces/newlines, and attached comments/blank lines.
Prints a string to the formatter, flushing any pending items first.
Prints a string with a specified display length to the formatter.
Queues a space to be printed, if no newlines are pending and a non-blank string has been emitted.
Queues a newline to be printed, if no non-blank string has been emitted.
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.
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.
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.
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.
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.
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.
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.
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.
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.
run_channel ?width oc f creates a new printer, runs f, and lays the document out straight into the channel — no intermediate string. width is the target line width (default 78). The hot output path.
Like run_channel, but lays the document out into a buffer and returns its contents. width is the target line width (default 78).
Like run_channel to stderr, then emits a trailing newline and flushes. The replacement for the Format.eprintf "%a@." debug idiom.
Run f with a printer that produces no output and does no layout — for a dry pass run only for its side effects (recording looked-up locations via Wax_utils.Trivia collect). Avoids building and laying out the whole document only to throw it away.