Expand description
Hand-written recursive-descent parser for Bynk v0.
Token grammar in spec §4. The expression parser uses one function per precedence level (§4.4). Errors carry spans and short fix-oriented messages; the parser does not currently attempt synchronisation, which means at most one parse error is reported per compilation.
Functions§
- parse
- Parse a token slice into a
CommonsAST. - parse_
unit - Parse a token slice into a
SourceUnit— either a commons or a context. - parse_
unit_ with_ recovery - Parse a token slice into a
SourceUnitwith error recovery, returning a best-effort partial AST plus the full list of parse errors and warnings. - parse_
unit_ with_ warnings parse_unitwith the non-fatal diagnostics threaded out alongside the AST (ADR 0117) — seeparse_units_with_warnings.- parse_
unit_ with_ warnings_ from parse_unit_with_warnings, continuingExprIdallocation fromnext_idinstead of starting at 0, and writing the id one past the last one this parse handed out back into it. T3.4 (R2.4): every top-level parse entry point in this file constructs its ownParserand therefore its own zero-based id space; a caller that will check two files’ output together in one pass (a multi-file commons —bynk-emit’scollect_unit_methodsmerges a type’s methods from sibling files into the file that declares the type, before onecheck_recordcall) must thread one counter across every file it parses, or two independently-numbered files collide on the same id in the sameexpr_typesmap. Every other caller (a single buffer, an LSP hover/completion query, a fixture test) never merges its output with another file’s before checking, so starting at 0 every time is correct —parse_unit_with_warningsabove is that default, unchanged.- parse_
units - Parse a token slice into all the top-level
SourceUnits in one file (v0.113, testing track slice 1b). A.bynkfile may hold more than one top-level declaration — an atomic file withcommons/contextand asuitetogether (DECISION S) — so the compiler parses aVec, not a single unit. Test-ness is a property of each declaration, not of the file. - parse_
units_ with_ drain_ check parse_units_with_warningsplus whether every comment’s trivia was drained into the AST (TriviaTable::is_fully_drained). Finding #66:bynk-fmt’s comment-preservation guard re-tokenized its own rendered output just to diff comment bodies against the input — wasted work in the overwhelming common case where nothing was left behind. That guard uses this drain signal, computed from the same parse it already needs for rendering, as a fast-path:truemeans every comment landed in the AST, so re-checking the output can be skipped outright. No other caller needs the signal, so it rides its own entry point rather than wideningparse_units_with_warnings.- parse_
units_ with_ drain_ check_ from parse_units_with_drain_check, continuingExprIdallocation fromnext_id— seeparse_unit_with_warnings_from.- parse_
units_ with_ recovery parse_unit_with_recovery, keeping every top-level unit instead of discarding all but the first (finding #29/#30). Used by the IDE’s own parse entry point, which needs to see a trailingsuitein an atomiccommons+suitefile, not just the primary declaration.- parse_
units_ with_ warnings parse_unitswith the non-fatal diagnostics threaded out alongside the AST (ADR 0117): a successful parse returnsOk((units, warnings))instead of hard-failing on a warning-severity diagnostic (an orphan doc block used to abort file discovery and throw the good AST away). A failed parse still returns every diagnostic — errors then warnings — in theErr.- parse_
units_ with_ warnings_ from parse_units_with_warnings, continuingExprIdallocation fromnext_idrather than starting at 0 — seeparse_unit_with_warnings_fromfor why this exists. The one production caller isbynk-emit’s per-file parse loop (phase_parse), which owns one counter across every file in a single project parse so two files whose methods later get merged into onecheck_recordcall (a multi-file commons) never collide.- parse_
with_ warnings parsewith the non-fatal diagnostics threaded out alongside the AST (ADR 0117) — seeparse_units_with_warnings.