Skip to documentation
SLOP

tiny.pretty

Reference tiny.pretty

Overview · API · Code relationships · Verification · Audit

Overview

Pretty is a width-aware document layout and structured output package.

Design rationale and problem model

Pretty printing separates declarative document structure from geometric layout to resolve formatting choices without output backtracking: formatters cannot determine whether an expression fits on a single line until both the expression and its trailing syntactic context are known. An algebraic tree (Doc) defers line-break selection to the renderer.

The package enforces strict separation between construction and rendering:

Continuation-sensitive layout and mode inheritance

Line-break decisions require continuation lookahead: evaluating a group in isolation is insufficient because trailing tokens on the same line (such as closing delimiters or commas) could force an immediate overflow. The renderer therefore tests whether the candidate and its inline sibling continuation fit the saturating remaining width width -| col.

Mode inheritance is deliberately asymmetric:

Lookahead revisits subtrees to measure flat width prior to emission, and recursive descent operates without an explicit stack ceiling. Unconditional breaks (hardline) emit a newline followed by the current nesting indentation in all modes.

Layout metrics, control breaks, and styling

Column advancement strictly measures raw byte length (bytes.len), omitting Unicode scalar, grapheme, and terminal display-width semantics. Raw escape bytes inside text count as bytes. When indivisible text exceeds the margin, it emits across it without error, prioritizing semantic data preservation over rigid column boundaries.

Only carriage returns and line feeds reset the column:

Semantic styling (styled) emits ANSI sequences under ColorMode.ansi. These escape sequences consume zero layout columns, ensuring monochrome and styled outputs make identical line-break decisions.

Worked example: Why continuation lookahead matters

The trailing-continuation witness from test.zig demonstrates why groups cannot evaluate fit in isolation:

zig
const grouped = try builder.group(try builder.concat(&.{    builder.text("abc"),    pretty.softline,    builder.text("de"),}));const doc = try builder.concat(&.{ grouped, builder.text("XY") });

At width 6, grouped alone has a flat width of 6 ("abc de"). Evaluated in isolation, it would fit flat. However, trailing sibling "XY" shares the same output line without an intervening break, requiring 8 columns total.

Continuation lookahead inspects "XY", detects that 6+2>6, and forces grouped to break, emitting "abc\ndeXY" instead of overflowing to "abc deXY".

Verification boundary

Evidence is partitioned across formal models and test suites:

Definitions

Actions

Public operations.

Types and contracts

Public types and contracts.

Namespaces

Public namespaces.

Values and defaults

Public values and defaults.

Code relationships

Direct static dependencies extracted from parsed source by semantic graph analysis.

Uses: tiny.coz, tiny.sdfii, tiny.smg
Used by: tiny.choir, tiny.glom, tiny.smg, tiny.tracy

Verification

No verification records are cataloged for this module in this build.

Audit

EvidenceValue
Sourcelib/pretty/core/src/root.zig
Definitions3 of 21 documented
Members0 of 0 documented
Public names21 API, 151 indexed
Version26.7.0
Revisiondaab053ee433