Skip to main content

Module grammar

Module grammar 

Source
Expand description

L-system grammar expansion: pure, deterministic string rewriting. Applies a production rule set to an axiom depth times — each character is replaced by its successor (or kept if no rule matches). expand is a build-time step (runs inside Scene::configure, off the hot path), not per-frame work. Stream is the per-frame half: an allocation-free lazy depth-first walk of the same derivation, one symbol per Stream::next_symbol, over stacks preallocated at load, which an endless figure advances every frame.

Deterministic by construction: a fixed (axiom, rules, depth) always yields the exact same string (NFR 6), which is what makes it directly unit-testable.

Structs§

Stream
The derivation of an axiom to a fixed depth, produced one symbol at a time by a depth-first walk, instead of expanded into a string: the leaves in exactly the order expand would write them, at the cost of one frame per level.

Constants§

STREAM_DEPTH
The derivation depth an endless figure’s stream walks: the grammar is expanded this many times, lazily, and the stream is its leaves in order.

Functions§

bracket_bound
The most branch pushes the stream can hold open at once, for a grammar whose successors balance their brackets: the axiom’s own nesting, plus each of the depth expansion levels opening at most its deepest successor’s. An unbalanced grammar can open more; the turtle’s stack is sized to this and refuses a push past it.
expand
Expand axiom by applying rules depth times. Each rule is (predecessor, successor); a character with no matching rule maps to itself (the standard context-free L-system semantics). Pure and deterministic.
is_draw
Whether ch is a draw step: the symbols the turtle strokes a segment for.
nesting
The deepest run of open [ in s: the most branch pushes any prefix of it leaves open. A stray ] closes nothing.
stream_draws
How many draw steps the derivation of axiom under rules to depth holds, counted without expanding it: per rule, the draws its successor yields one level down, built up level by level. Saturates at u64::MAX.