Structural parser for TOON format that handles indentation-based nesting.
This parser processes TOON input by analyzing indentation levels and building a hierarchical structure from the flat text representation.
Performance Design (Jason-level efficiency)
This parser is optimized for single-pass, zero-copy decoding:
- Binary pattern matching replaces
String.starts_with?,String.contains?,String.ends_with?, and regex calls in hot paths with O(1) byte checks. - Sub-binary references via
binary_part/3avoid copying — BEAM shares the underlying binary when slicing. - Tail-recursive accumulators with
:lists.reverse/1instead of appending. @compile {:inline, ...}for hot functions to eliminate call overhead.- Struct pattern matching in function heads replaces
cond+ map access. binary_part/3for slicing instead ofString.slice/3(avoids UTF-8 scan).
Summary
Functions
Parses TOON input string into a structured format.
Types
@type line_info() :: %{ content: String.t(), indent: non_neg_integer(), line_number: non_neg_integer(), original: String.t(), is_blank: boolean() }
Functions
@spec parse(String.t(), map()) :: {:ok, {term(), parse_metadata()}} | {:error, ToonEx.DecodeError.t()}
Parses TOON input string into a structured format.
Returns a tuple of {result, metadata} where metadata contains quoted_keys and key_order.