Expand description
The RON parser: tokens → a lossless rowan green tree, wrapped in CstDocument.
Hand-written recursive-descent (AD-006) feeding rowan::GreenNodeBuilder.
It covers the full RON 0.12 value surface (T014): structs (named + anonymous),
tuples, lists/sequences, maps (incl. non-string keys), enum variants, unit
(), Option/implicit_some, and extension attributes.
§Trivia (AD-001, T015)
Trivia is attached per the rule documented in crate::syntax: leading
trivia (whitespace / comments / BOM) binds to the following significant
token; trailing trivia at EOF binds to the SyntaxKind::Root node. The
parser realizes this by, before consuming any significant token, flushing all
pending trivia tokens into the current open node, then any trailing trivia at
EOF into the still-open Root node.
§Losslessness (INV-1/INV-2)
Every lexer token — significant or trivia — is emitted into the green tree exactly once, in source order, so concatenating all token texts reproduces the input byte-for-byte. This holds for valid input and for malformed input that triggers error recovery (INV-3).
§Error recovery + diagnostics (OBJ2, T021–T024)
Malformed or incomplete input never panics and never drops bytes. The parser:
- wraps unexpected tokens in
SyntaxKind::Errornodes and represents absent constructs as missing/empty nodes, using recovery sets on,)]}and field identifiers (T021), so the tree always covers all input (INV-3); - emits exactly one
Diagnosticper recovery point with a precise byte range (T022, TR-006/TR-013) and enforces the must-consume-a-token invariant — every loop iteration consumes ≥ 1 token — so parsing always terminates (HINT-004); - enforces a configurable nesting-depth guard (default 128,
ParseOptions) that stops descent at the limit, emits aDiagnosticCode::NestingDepthExceededdiagnostic, and still tokenizes the remaining bytes intoErrornodes so no stack overflow occurs and byte coverage holds (T023, INV-5); - is deterministic — identical input yields an identical tree and an identical diagnostics set (same codes, order, and ranges), since parsing is a pure function of the token stream with no nondeterministic inputs (T024, INV-6/TR-012).
Structs§
- CstDocument
- The parsed, lossless concrete syntax tree of a RON document.
- Parse
Options - Configuration for
parse_with_options.
Constants§
- DEFAULT_
MAX_ DEPTH - The default nesting-depth guard (AD-005 / TR-014). Descent past this many nested composite values stops and emits an over-limit diagnostic instead of risking a stack overflow.
Functions§
- parse
- Parse a UTF-8
&strinto a losslessCstDocumentwith the defaultParseOptions(depth guardDEFAULT_MAX_DEPTH). Never panics. - parse_
bytes - Parse raw bytes into a
CstDocument, rejecting non-UTF-8 cleanly. - parse_
with_ options - Parse a UTF-8
&strinto a losslessCstDocumentwith explicitParseOptions(e.g. a custom nesting-depth guard). Never panics.