mdz_opcodes_to_nodes.ts

Converts a stream of mdz opcodes to the MdzNode[] tree representation.

Stack-based replay over a single flat children buffer: leaves push to the shared buffer, and each open frame records where its children begin (children_start). close slices the frame's range out into the built node; revert dissolves the frame boundary in place — its accumulated children become the parent's without copying — and merges the replacement delimiter text into an adjacent text node. Adjacent text left behind by reverts is coalesced once per container by mdz_merge_adjacent_text at close, so cascading reverts of deeply nested unclosed containers cost O(n) total instead of re-parenting (O(n²)) at every level.

The output is identical to mdz_parse() from mdz.ts, enabling validation of the streaming parser against the existing fixture suite.

view source

Declarations
#

mdz_opcodes_to_nodes
#

mdz_opcodes_to_nodes.ts view source

(opcodes: MdzOpcode[]): MdzNode[] import {mdz_opcodes_to_nodes} from '@fuzdev/mdz/mdz_opcodes_to_nodes.js';

Convert an array of mdz opcodes to the MdzNode[] tree. Produces output identical to mdz_parse().

opcodes

type MdzOpcode[]

returns

MdzNode[]

Depends on
#