README

marianoguerra/wax/printer does not have a README file

#
BreakStrength

pub(all) enum BreakStrength {
Cut
Space
Newline
BlankLine
} derive(Eq,
Debug
)

How strongly a break wants to end the line.

Cut and Space are SOFT: they flatten inside a group that fits. Newline and BlankLine always break. Two adjacent breaks coalesce into the stronger.

#
BreakStrength::strength

fn BreakStrength::strength(self : BreakStrength) -> Int

#
Engine

type Engine

The engine.

#
Engine::new

fn Engine::new(width? : Int) -> Engine

#
Frame

A live layout frame: where breaks indent to, and how they behave.

#
GKind

pub(all) enum GKind {
GBox
GHov
GHv
GV
GH
} derive(Eq,
Debug
)

How a group lays its soft breaks out.

#
Mode

pub(all) enum Mode {
Flat
Brkm
Fill
} derive(Eq,
Debug
)

A live layout mode.

#
Printer

pub struct Printer {
engine : Engine
pending_break : BreakStrength?
has_emitted : Bool
pending_eol : () -> Unit?
holding_eol : Bool
}

A printer.

#
Printer::blank_line

fn Printer::blank_line(self : Printer) -> Unit

A break that always leaves a blank line.

#
Printer::box

fn Printer::box(self : Printer, f : () -> Unit, skip_space? : Bool, indent? : Int) -> Unit

Fill: each soft break wraps independently, as needed.

#
Printer::cut

fn Printer::cut(self : Printer) -> Unit

A break of zero width when flat.

#
Printer::defer_eol

fn Printer::defer_eol(self : Printer, emit_comment : () -> Unit) -> Unit

Record a trailing line comment, to be emitted at the end of the current line.

It is flushed before the next ordinary token or group, or at end of output. Emitting it ends the line.

#
Printer::has_pending_eol

fn Printer::has_pending_eol(self : Printer) -> Bool

Whether a trailing comment is currently deferred.

Lets a caller suppress a trailing comma when the last element already carries a comment: adding the comma would push the comment off that element and change where it re-attaches on a reparse.

#
Printer::hbox

fn Printer::hbox(self : Printer, f : () -> Unit, skip_space? : Bool) -> Unit

Soft breaks never wrap; hard ones still do.

#
Printer::hovbox

fn Printer::hovbox(self : Printer, f : () -> Unit, skip_space? : Bool, indent? : Int) -> Unit

#
Printer::hvbox

fn Printer::hvbox(self : Printer, f : () -> Unit, skip_space? : Bool, indent? : Int) -> Unit

All-or-nothing: the whole group flat, or every soft break wraps.

#
Printer::if_broken

fn Printer::if_broken(self : Printer, f : () -> Unit) -> Unit

Emit f's content only when the enclosing group is laid out broken.

#
Printer::indent

fn Printer::indent(self : Printer, n : Int, f : () -> Unit) -> Unit

Run f with break-indentation increased by n.

#
Printer::new

fn Printer::new(width? : Int) -> Printer

#
Printer::newline

fn Printer::newline(self : Printer) -> Unit

A break that always ends the line.

#
Printer::space

fn Printer::space(self : Printer) -> Unit

A break that becomes a space when flat.

Suppressed at the start of a line: there is nothing to separate from.

#
Printer::string

fn Printer::string(self : Printer, s : String) -> Unit

Print a string, measured at its DISPLAY width.

#
Printer::string_as

fn Printer::string_as(self : Printer, len : Int, s : String) -> Unit

Print a string with an explicitly stated display width.

For text whose printed width is not its measured width -- a coloured span, where the escape sequences occupy no columns.

#
Printer::vbox

fn Printer::vbox(self : Printer, f : () -> Unit, skip_space? : Bool, indent? : Int) -> Unit

Every soft break wraps.

#
Printer::with_held_eol

fn Printer::with_held_eol(self : Printer, f : () -> Unit) -> Unit

Run f without flushing a pending end-of-line comment first.

A list separator printed inside f then appears on the comment's line, AHEAD of the comment -- which is where a reader expects the comma of foo, // why.

#
ScanResult

type ScanResult derive(Eq,
Debug
)

The outcome of a fit scan.

Susp means the scan ran out of buffered input and parked its state, to be resumed on the next fed token -- so each buffered token is scanned once rather than re-scanned from scratch.

#
Token

pub(all) enum Token {
TText(Int, String)
TBreak(BreakStrength)
TBegin(GKind)
TNest(Int)
TIfBroken
TEnd
} derive(Eq,
Debug
)

One token of the flat stream the builder feeds the engine.

A group, nest or if-broken opens with its own token and closes with a matching TEnd.

#
run_discard

fn run_discard(f : (Printer) -> Unit) -> Unit

Run f producing NO output.

For the dry pass that only needs the printer's side effects -- recording which source spans get looked up, so trivia can be associated to them -- without building and laying out a document just to discard it.

#
run_string

fn run_string(f : (Printer) -> Unit, width? : Int) -> String

Lay f out and return the text.

#
run_tokens

fn run_tokens(f : (Printer) -> Unit, width? : Int) -> Array[Token]

Run f and return the TOKEN STREAM it builds, laying nothing out.

The builder is engine-independent -- width never reaches it -- so this is the whole document, in the form a layout engine consumes it. It exists so an alternative engine can be fed exactly what this one is fed; see printer_pp.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io