Expand description
the hand-written parser: Parser::parse turns the lexer’s Vec<Token>
into an untyped Ast, or the first syntax error. recursive descent for
items and statements, a Pratt (binding-power) loop for expressions.
fail-fast: returns Result<Ast, QalaError> and stops at the first error.
multi-error collection is the type checker’s job (Phase 3); the parser does
not synchronize. (the lexer’s module doc mentions “Phase 2’s parser has
resync points” – a wording drift; recovery is deferred per CONTEXT.md.)
a [depth] counter on Parser guards every recursive production against
pathologically nested input. Rust has no tail-call optimization; on WASM a
stack overflow aborts the module. past MAX_DEPTH the parser returns a
clean QalaError::Parse instead.
no unwrap / expect / panic! / unreachable! is reachable from a
malformed token stream – the same discipline the lexer documents; load-
bearing for Phase 6 where the compiler runs in a browser tab.
Structs§
- Parser
- the parser state.
Constants§
- MAX_
DEPTH - the recursion-depth cap, in productions. chosen generously enough that real programs never approach it (a hand-written program rarely nests more than a dozen levels deep) and conservatively enough that the native and WASM call stacks have headroom. 256 frames at the rough budget of a Pratt-recursion frame fits comfortably inside the default 1 MiB WASM stack and the default 8 MiB native one.