Skip to main content

Module parser

Module parser 

Source
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 Commons AST.
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 SourceUnit with error recovery, returning a best-effort partial AST plus the full list of parse errors and warnings.
parse_unit_with_warnings
parse_unit with the non-fatal diagnostics threaded out alongside the AST (ADR 0117) — see parse_units_with_warnings.
parse_unit_with_warnings_from
parse_unit_with_warnings, continuing ExprId allocation from next_id instead 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 own Parser and 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’s collect_unit_methods merges a type’s methods from sibling files into the file that declares the type, before one check_record call) must thread one counter across every file it parses, or two independently-numbered files collide on the same id in the same expr_types map. 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_warnings above 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 .bynk file may hold more than one top-level declaration — an atomic file with commons/context and a suite together (DECISION S) — so the compiler parses a Vec, not a single unit. Test-ness is a property of each declaration, not of the file.
parse_units_with_drain_check
parse_units_with_warnings plus 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: true means 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 widening parse_units_with_warnings.
parse_units_with_drain_check_from
parse_units_with_drain_check, continuing ExprId allocation from next_id — see parse_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 trailing suite in an atomic commons+suite file, not just the primary declaration.
parse_units_with_warnings
parse_units with the non-fatal diagnostics threaded out alongside the AST (ADR 0117): a successful parse returns Ok((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 the Err.
parse_units_with_warnings_from
parse_units_with_warnings, continuing ExprId allocation from next_id rather than starting at 0 — see parse_unit_with_warnings_from for why this exists. The one production caller is bynk-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 one check_record call (a multi-file commons) never collide.
parse_with_warnings
parse with the non-fatal diagnostics threaded out alongside the AST (ADR 0117) — see parse_units_with_warnings.