sqlode/codegen/builder

Minimal line-oriented builder for emitting generated Gleam source code.

A Block is an ordered list of already-rendered lines. Callers stitch blocks together with concat, add blank separators with blank, and attach leading indentation with indent. render flattens a block to the final String by joining on "\n".

The builder intentionally does not try to model reflow (Wadler-style Doc) — generated Gleam code is layout-deterministic and lists of lines are the idiom already used across the codegen modules.

Types

pub opaque type Block

Values

pub fn blank() -> Block

A block containing a single empty line, used as a visual separator.

pub fn concat(parts: List(Block)) -> Block

Concatenate the lines of several blocks in order.

pub fn empty() -> Block

A block containing no lines at all. Useful for conditional sections.

pub fn indent(block: Block, by by: Int) -> Block

Prepend by spaces to every non-empty line in the block. Empty lines stay empty so the output never has trailing whitespace.

pub fn line(value: String) -> Block

A block containing a single line of text.

pub fn lines(values: List(String)) -> Block

A block from an explicit list of pre-split lines.

pub fn render(block: Block) -> String

Render the block by joining its lines with newlines.

Search Document