Skip to content

CodeBuilder

1 min read

Import: import system.codegen;

CodeBuilder

Accumulates Dream source lines for generator emit_extend / emit_file bodies. Indentation mirrors C# / Rust IndentedTextWriter: indent() / dedent() adjust depth; line / append apply the current indent only at the start of a line.

public class CodeBuilder

constructor

Creates a builder that indents with four spaces.

public constructor()

with_spaces

Creates a builder whose indent unit is spaces ASCII spaces.

public static fun with_spaces(spaces: int): CodeBuilder

indent

Increases the indent depth by one unit.

public fun indent(): void

dedent

Decreases the indent depth by one unit (no-op at zero).

public fun dedent(): void

line

Writes text as a full line at the current indent, then starts a new line.

public fun line(text: string): void

append

Appends text without a trailing newline (indent applied only at line start).

public fun append(text: string): void

to_string

Returns the accumulated source text.

public override fun to_string(): string