error-recovery
Goal
A formatter may refuse broken input; a language server may not — an editor
buffer is mid-edit most of the time, and "no symbols, no highlighting, no
diagnostics until the file parses" is exactly the experience TODO.md §6 exists
to avoid. This feature adds a second entry point to vlog_parser,
parse_source_tolerant(src) -> (SourceFile, Vec<ParseDiagnostic>), that never
fails: where the grammar gives up it records a diagnostic, skips to a sync
token, wraps the skipped text in an ItemKind::Error / StmtKind::Error leaf
and carries on. The strict parse_source keeps its exact behavior — the two
entry points share the grammar code, not a copy of it, so there is no second
parser to keep in sync. On a file that parses cleanly the tolerant tree is
the same tree and the diagnostic list is empty, which is what lets the
formatter keep its "zero errors or nothing" contract unchanged.
The recovery strategy
Deliberately one paragraph long, because a recovery strategy nobody can predict is worse than a crude one everybody can:
- Recovery happens only in item and statement lists. Those are the
places a parse can resume from: file scope, module and package bodies,
generate regions and generate blocks,
begin/endandfork/joinbodies, function and task bodies, and a case item's statement. An error deeper inside a construct (a for-header, a port list, a case label) is not caught where it happens — it propagates out to the nearest enclosing list, and that whole item or statement becomes one error node. Nothing else in the grammar knows recovery exists. - Record, then skip. The diagnostic is the
ParseErrorthe strict parser would have returned — same message, same line:col — plus the byte span of the token the parser gave up on. - Skip to a sync token. From the failure point, skip forward until one
of:
;— consumed; it terminated the broken construct.- a sync-stop keyword — not consumed, because the construct it closes or opens is somebody else's to parse (see the table below).
- end of file.
Brackets opened while skipping are skipped as a unit, so the
;s inside a brokenfor (i = 0; ...)header do not end the skip early.
- Wrap. The text from where the failed construct started through the
sync point becomes an
ItemKind::Error(RawText)orStmtKind::Error(RawText)— a verbatim AST leaf exactly likeMacroCallandDirectivealready are, carryingtext,colandspan. - Always advance. If the failed construct consumed no tokens at all, the skip takes one anyway, so an enclosing loop can never spin.
The sync tokens, and why each one
| token | consumed? | why |
|---|---|---|
; |
yes | The statement/declaration terminator: the one token that reliably ends a construct in this grammar, and the only one worth eating — the broken text ended there. |
end, endmodule, endpackage, endgenerate, endfunction, endtask, endcase, join, join_any, join_none |
no | Each closes a construct whose parse loop is still on the stack. Consuming one would leave that construct unclosed and cascade the damage outward — this is exactly what "an error inside a generate block must not eat the endgenerate" means. endcase and the joins are in the set for the same reason the ones the task named are, and are cheap to add. |
module, macromodule, package |
no | These can only begin a construct at file scope. Without them, garbage written between two modules skips forward looking for a ; and swallows the second module's header. With them, garbage between two modules costs exactly one error node. |
| end of file | — | Nothing left to sync to. |
a closing )/]/} with a matching open in the skipped range |
yes | Part of the garbage being skipped. |
a closing )/]/} with nothing open |
yes | Also skipped. Recovery only ever runs in an item or statement list, and no such list sits inside brackets, so a stray ) belongs to the broken expression, not to a caller. Treating it as a stop point was tried first and made every leftover ) of assign x = (((1 + ))); its own error node — 26 diagnostics for one typo. |
Unclosed constructs
The sync-token rules alone would turn a file whose endmodule is not typed
yet into one file-sized error node — the single most common mid-edit state,
and the one where an LSP most needs the tree. So two small companions:
- In tolerant mode a body loop also ends at any sync stop, not just at its own
closing keyword. An unclosed
begintherefore ends where the next construct begins instead of eating the rest of the file. expect_closer(used for everyend*/joinkeyword) recordsexpected `end`as a diagnostic instead of failing, and treats the construct as closed where the parser stopped.
The result: module m; initial begin x = 1; endmodule yields one diagnostic
(missing end), a module with its initial block, and the block with its
statement — no error node at all.
A file that is all garbage
…becomes one error item covering it. So does a file the lexer rejects (see Assumptions), which is the only case where the tolerant tree carries no structure at all.
Assumptions
- Recovery is a parse-level mechanism; the lexer stays all-or-nothing. An
unterminated string or block comment has no sensible resumption point
(everything after it is inside the string), so
parse_source_tolerantturns aLexErrorinto one diagnostic plus one file-wide error item rather than guessing. Making the lexer tolerant is a separate, larger decision; truncated files hit this path often enough that it is worth revisiting if the LSP finds it too coarse. - A missing
;costs the construct after it. The sync point is the next;, not the next line, sowire a(no semicolon) followed bywire b;produces one error node covering both. Line-based heuristics ("resync at a token that starts a line") would do better on this one shape and worse on wrapped constructs; the boring rule is the one that is predictable. - A broken construct can produce more than one diagnostic. A half-typed
for (i = 0; i < ; i = i + 1)fails inside the header, resyncs at the;inside the header, and reports again on the remains. Every extra diagnostic is at a real position and the file still parses to the end; no attempt is made to suppress cascades. - Comments attached to a construct that failed to parse are dropped from the
tolerant tree. They were harvested into the failed node's
Metabefore the error, and comments inside the skipped range survive only as bytes of the error node's raw text. This does not weaken CLAUDE.md invariant #3: that invariant is about what the formatter emits, and the formatter never parses tolerantly (see Handshakes). An LSP consuming a broken buffer can still reach every comment through the token stream. - Every successful item/statement parse consumes at least one token. The termination argument rests on it (with the always-advance rule covering the failure side). It is true of every arm in the grammar today; a future arm that could succeed on zero tokens would need the loops to guard against it.
sourcemust be the exact text the tokens were lexed from.parse_tolerant(tokens, source)copies spans out of it; a mismatched string would put wrong text in the error nodes.parse_source_tolerant(src)is the entry point that cannot get this wrong, and is what callers should use.
Handshakes
Promised to vlog_formatter — the formatter must not format a file with
diagnostics, and this round did not change how it formats anything:
format_sourcestill callsvlog_parser::parse_source, i.e. the strict parser, which still fails on the first error and makes the CLI leave the file untouched. Error nodes cannot appear in a tree the formatter builds.- Four lines were added to
format.rsanyway, and they are the one thing this feature could not do inside its own crate: adding a variant toItemKind/StmtKindmakes the formatter's exhaustivematches fail to compile, so each got one arm (ItemKind::Error(d) => self.raw_text(d), and the statement twin) plus a comment saying it is unreachable fromformat_source. Verbatim pass-through was chosen over emitting nothing so that, if a future entry point ever did hand the formatter such a tree,verify.rs's token-equivalence check would see the tokens rather than silently lose them. No behavior change: the full.cases, fixture, snapshot and idempotency suite is green with zero churn. verify.rsis untouched. No normalization was added, broadened or weakened, so CLAUDE.md hard invariant #4 does not apply to this round.- When the LSP lands, its contract with the formatter is: format only when the diagnostic list is empty; otherwise publish the diagnostics and serve the partial tree for everything else (symbols, highlighting, hover).
Consumed from docs/features/recursion-limit/README.md (the handshake that
was written for this feature): recovery must not reset depth or
links. It does not touch either. It cannot need to: both are released by
the gated frames themselves on every path out, including error paths
(leave() after the inner call, self.links = outer_links after it), so by
the time an error reaches the list loop that recovers, both counters are back
at exactly that loop's level. Recovery resumes there. Two tests pin it — one
white-box (both counters are 0 after a tolerant parse of a broken file), one
black-box in each direction: 100 broken 25-deep expressions in a row produce
100 diagnostics and never a nesting too deep (no leak), and a broken
statement 55 blocks deep followed by 20 more blocks does produce one (no
reset). Both were mutation-tested by injecting self.depth = 0 and
self.depth += 1 into recover; each mutation fails a test.
Consumed from docs/features/spans/README.md: error nodes are ordinary
AST leaves under the existing span convention — span = code extent, comments
excluded, so a child's span nests inside its parent's. tests/spans.rs's
exhaustive nesting walker now runs over recovered trees too
(recovered_error_nodes_nest_inside_their_parent), which is deliberate reuse:
a new node shape cannot quietly skip the invariant. An error node's text is
asserted to be its own source slice, so source[span] == text holds for the
new leaf as it does for RawText elsewhere.
Requested of nobody. No other module needs a change.
API
// vlog_parser
pub fn parse_source_tolerant(source: &str) -> (ast::SourceFile, Vec<ParseDiagnostic>);
pub fn parse_tolerant(tokens: Vec<Token>, source: &str) -> (SourceFile, Vec<ParseDiagnostic>);
pub struct ParseDiagnostic {
pub message: String, // exactly what ParseError would have said
pub line: u32, // 1-based, as on ParseError
pub col: u32, // 1-based, in bytes
pub span: TextRange, // extent of the token the parser gave up on
}
ParseDiagnostic displays as line:col: message, like ParseError. Its
span and its line:col are two views of the same token — asserted, so a
terminal that prints the position and an editor that highlights the range
agree. The extent that was skipped is not on the diagnostic; it is the error
node's span in the tree, which is where a consumer that wants it should look.
parse(tokens) and parse_source(source) are unchanged, including their
signatures.
Status / TODO
parse_tolerant/parse_source_tolerant;ParseDiagnosticwith message, line, col and span.ItemKind::Error(RawText)/StmtKind::Error(RawText)leaves carrying the skipped text and its span.- Sync-token set documented above; skipping balances brackets.
- Recovery at all nine item/statement list sites; nothing else in the grammar changed shape.
- Unclosed constructs: tolerant body-loop exit +
expect_closer. - Lex errors → one diagnostic + one file-wide error item.
- Guarantee (a): tolerant == strict on 500 valid sources (fixtures + every
.casesinput and expected output), asserted on theDebugshape of the whole tree, with zero diagnostics. - Guarantee (b): diagnostics inside the file, positions consistent with
spans, error-node text == its source slice, error nodes nest (in
tests/spans.rs, via the existing exhaustive walker). - Guarantee (c): budgets neither leak nor reset; mutation-tested.
- Guarantee (d): 5299 byte-prefix truncations of the fixtures, ~11k token-boundary truncations of the case-table sources (the exact count grows with the case table; QA re-measured 11570), and every single-character deletion of every fixture — no panic, no hang, all invariants hold on every one.
- Mid-edit shapes tested by name: missing
;, unclosedbegin, unclosedmodule,wire [7:,sub u0 (.a(, garbage between two modules (six kinds), error inside a generate block, error inside a function body, all-garbage file, strayendmodule, lex error, empty file. cargo test --workspacegreen,cargo clippy -p vlog_parser --all-targetssilent,cargo fmt --checkclean.- TODO.md §6 error-tolerant checkbox.
- Not done, deliberately: a tolerant lexer. See Assumptions.
- Not done: cascade suppression (a "don't report twice within N tokens" rule). Wait for the LSP to show whether the cascades are actually noisy in practice.
- Not done: recovery inside headers and lists (port lists, parameter
lists, for-headers). Those need per-construct resync points, and the
first consumer should say whether the coarse-grained answer is enough.
Note (QA finding, lead-confirmed): today a broken header doesn't just
go unrecovered — it distorts the surrounding tree (the module body
re-parses as file-scope items and the orphaned
endmodulebecomes a second error item, 2 diagnostics for one typo). The LSP consumer should expect that shape until header recovery lands.
Work log
2026-08-19 — dev agent
- Read CLAUDE.md, README.md, TODO.md §6,
docs/features/spans/README.mdand the recursion-limit Handshakes before touching code. Baseline:cargo test --workspace161 passed, clippy silent, fmt clean. - Chose "recover in list loops only". The alternative — recovery points
inside every construct — multiplies the number of places that can invent a
resync rule, and each one is a new way for the two entry points to diverge.
One
item_or_recover/stmt_or_recoverpair, called from the nine loops that build aVec<Item>/Vec<Stmt>, keeps the grammar code shared literally rather than by convention: every other function is untouched and cannot tell which mode it is running in. tolerantis a flag onParser, not a second parser.parseandparse_tolerantdiffer by that flag and by thesourceslice recovery copies error-node text from. Strict mode passes""because it never recovers, which is stated at the field.- Two changes to the strict path's shape, none to its behavior: body
loop conditions moved into
at_body_end(kw)(identical whentolerantis false) andexpect_kw("end…")becameexpect_closer("end…")(identical error, identical message, whentolerantis false). The formatter's whole suite, including snapshots and.cases, is green with zero churn, and a unit test asserts strict parsing still stops at the first error with the same message tolerant mode files first. - The stray-closing-bracket rule was wrong on the first try, and the tests
caught it.
)with nothing open originally stopped the skip, on the theory that it belonged to an enclosing construct. It does not — recovery never runs inside brackets — and the price was one error node per leftover): the 100-broken-expressions budget test reported 2600 diagnostics instead of 100, and the depth-limit test 32 instead of 1. Skipping them fixed both and is what the table above now documents. - Unclosed constructs got two companions on purpose. With sync tokens
alone,
module m; wire a;(noendmoduleyet) is one file-sized error node — i.e. the tolerant parser would be useless in the state an editor is in most often. The tolerant body-loop exit plusexpect_closercost about fifteen lines and turn that case into "one diagnostic, whole tree intact". - Comments attached to a failed construct are dropped from the tree — they
went into the failed node's
Metabefore the error was raised, and pulling them back out would mean restructuring wheretake_metais called. Wrote it down in Assumptions instead of hiding it; it is sound only because the formatter never parses tolerantly, which is the handshake above. - Reused
tests/spans.rs's exhaustive nesting walker for the recovered trees rather than writing a second one. It is compiler-checked exhaustive, so the new leaves had to be handled there anyway; running it on broken sources costs ten lines and makes the nesting guarantee total. - Mutation-tested the budget claim rather than asserting it from the code:
self.depth = 0inrecoverfails both budget tests,self.depth += 1fails the leak test. Reverted;grep MUTATIONis 0. - Probed behavior with a throwaway
examples/probe.rs(mid-edit shapes, then every byte prefix of every fixture) before writing any assertions, so the tests encode measured behavior rather than hoped-for behavior. The example was deleted; it is not part of the diff. - Did not touch
verify.rs,tools/,corpus/, orcrates/lucisv. Did not rungit commit/git push. - Concurrency note: another agent's format-off-fence work
(
crates/vlog_formatter/src/fence.rs,doc.rs,format.rs,printer.rs,docs/features/format-fences/) is live in the same working tree. My only edit inside that crate is the four lines described in Handshakes, made with exact-string edits so their in-progress work was not disturbed; their diff informat.rsis untouched around them. One clippy warning currently comes from theirfence.rs:58(map_or→is_none_or) — theirs to fix, left alone;cargo clippy -p vlog_parser --all-targetsis silent.
Results: cargo test --workspace 188 passed, 0 failed (up from 161:
+2 vlog_parser unit tests, +19 in the new tests/error_recovery.rs, +1 in
tests/spans.rs; the rest is the concurrent fence work). cargo clippy -p vlog_parser --all-targets silent. cargo fmt --all --check clean. Files
touched: crates/vlog_parser/src/{parser,ast,lib}.rs,
crates/vlog_parser/tests/error_recovery.rs (new),
crates/vlog_parser/tests/spans.rs (one test + two match arms),
crates/vlog_formatter/src/format.rs (four lines, see Handshakes), TODO.md
(§6 checkbox), this README.
QA log
2026-08-19 — QA agent
Read CLAUDE.md, this README, the diffs in crates/vlog_parser/src/{lib,ast,parser}.rs,
crates/vlog_parser/tests/{error_recovery.rs,spans.rs}, and the four added
format.rs match arms before testing. Scope: -p vlog_parser; did not touch
the concurrent format-fences work. Verdict: no BLOCKING findings. All
claims verified, two LOW-severity documentation/behavior notes below.
Tool results (exact):
cargo test -p vlog_parser: unit 49 passed,error_recovery.rs19 passed,spans.rs12 passed — 80/80, 0 failed.cargo clippy -p vlog_parser --all-targets: silent, 0 warnings.cargo fmt --check -p vlog_parser: clean.cargo test --workspace: green, 194 passed total (up from the dev's logged 188 — the delta is the concurrent format-fences suite, confirmed by reading its test file names, not this feature).cargo test -p vlog_formatter: 55/55 green (8+1+4+6+2+32+0 doctests) — the strict-path/snapshot/.cases/idempotency suite has zero churn from this feature, confirming the Handshakes claim.
Claim 1 (parse/parse_source unchanged, one Parser + tolerant flag): PASS.
Traced the code: parse/parse_source build Parser::new(tokens, "", false);
every recovery call site (item_or_recover/stmt_or_recover) only diverges
from the strict Err propagation when self.tolerant is true (Err(e) if self.tolerant => …, other => other), so strict mode is byte-identical to
before. strict_parsing_still_stops_at_the_first_error (parser.rs) and
format_source's green suite both confirm no observable change.
Claim 2 (sync tokens, bracket balancing, stray closers, unclosed
constructs): PASS on every sub-claim, confirmed both by the dev's own
tests and independently in a scratch harness
(/private/tmp/…/scratchpad/qa_probe, deleted nothing in-repo):
module/endmodule/endgenerate/join*etc. correctly left unconsumed even when the literal text "module" appears inside a string or a comment inside a broken construct — the lexer tags those asString/Commenttokens, notKeyword, soat_sync_stopnever misfires on them. Verified with three adversarial sources ("module fake"in a string,// … module …in a line comment,/* module … */in a block comment) — each produced exactly 1 diagnostic, no false stop.- Stray closing brackets do not cascade: 50 consecutive stray
)between two modules collapsed into one error node / one diagnostic, not 50 — matches the work log's account of the fix. - Unclosed constructs:
module m; initial begin x=1; endmoduleshape (dev's ownan_unclosed_begin_keeps_the_statements_inside_it) gives exactly 1 diagnostic (expected \end``), both statements intact, zero error nodes. Confirmed. - Bracket-balanced skipping confirmed at 10 levels of nested
generate/ifwith a brokenwire ;at the bottom: 1 diagnostic, the error node sits at the correct innermost level, and the outer 10 levels of structure plus the module's trailing sibling item are all intact (probe5/probe2 output).
Claim 3a (tolerant == strict on ≥500 valid sources): PASS. Dev's test
reports 550 valid sources (fixtures + .cases inputs/outputs), all
Debug-equal, all zero-diagnostic. Independently re-verified with my own
extractor (not reusing tests/error_recovery.rs's helper) over 30
pseudo-randomly sampled .cases inputs: 30/30 consistent (Debug-equal tree,
empty diagnostics).
Claim 3b (spans, char-boundary safety, LineIndex agreement, nesting):
PASS. Independently re-checked char-boundary-safety and
LineIndex::offset agreement on a case the dev's BROKEN list doesn't
include — a BOM-prefixed file (\u{FEFF}module m; …), both well-formed and
broken — no panic, diagnostic span is in-file and char-boundary-safe, and
LineIndex::offset(line, col) == span.start held. spans.rs's exhaustive
walker running over recovered_error_nodes_nest_inside_their_parent
confirmed as claimed.
Claim 3c (depth/links neither leak nor reset): PASS, and independently
stress-tested beyond the dev's fixed-shape tests: 50 valid expression chains
each at MAX_CHAIN_LENGTH - 1 (255 links), each interleaved with a broken
statement forcing a recovery in between — 50 diagnostics (one per broken
statement), zero chain too long / nesting too deep anywhere (no
leak across the 50 recoveries), and all 100 items survived as siblings of
the module. Complement: one expression at 306 links (over the 256 limit)
between two good statements produced exactly one diagnostic
(expression chain too long (limit 256)), recovered as a single clean
error node, with both the preceding and following good statements intact
in the tree — the "restore discipline" claim holds in both directions.
Claim 3d (no panic, extended): PASS. Re-ran the dev's approach and then
extended it: independently re-implemented the .cases-file input extractor
(not reusing the dev's) and byte-truncated (not just token-boundary) every
.cases input section at every char-boundary offset — 21,988 cuts,
well under the 3-minute time-box (66 ms), zero panics, all spans in-file and
char-boundary-safe. A second independent pass did token-boundary truncation
(5,510 cuts) with the same result. Also fuzzed: ;;;; alone (2 diagnostics,
each swallowing two ;s per the always-advance rule — expected, not a
bug), a 1 MB file of only ; (500,000 diagnostics/items, 344 ms release
build, no hang), an unterminated string at EOF and an unterminated block
comment (both correctly hit the lex-error path: 1 diagnostic, 1 file-wide
error item), and a BOM'd file (no panic; see note below). None panicked.
Minor discrepancy in claim 3d's exact number: the README's Status/TODO
line says "10756 token-boundary truncations of the case-table sources";
re-running the exact same dev test today (cargo test -p vlog_parser --test error_recovery -- --nocapture truncating_a_case_table_source_never_panics)
prints 11570. The byte-prefix number (5299) still matches exactly. The
drift is because the case-table corpus has grown since that number was
written (concurrent .cases files added by other in-flight feature work in
this same tree), not a functional problem — but a number stated this
precisely will keep silently rotting as the corpus grows. Suggest wording
it approximately (or dropping the exact count) rather than re-chasing it
every time a .cases file is added.
Claim 4 (lex errors are all-or-nothing): PASS. Confirmed via dev tests
plus independently on an unterminated string, an unterminated block
comment, and a BOM'd file — each produces exactly one diagnostic and one
file-wide ItemKind::Error covering the whole source, never a partial tree.
Claim 5 (tool results, unreachable format.rs arms): PASS. Tool results
above. Confirmed the two added format.rs arms
(ItemKind::Error(d) => self.raw_text(d) at line 493,
StmtKind::Error(d) => self.raw_text(d) at line 1565) are exact-string
minimal (one line of code each, plus a comment) and genuinely unreachable
from format_source: format_once calls vlog_parser::parse_source,
which is strict (tolerant: false), and ItemKind::Error/StmtKind::Error
are constructed only inside item_or_recover/stmt_or_recover's
Err(e) if self.tolerant arm — a path strict parsing never takes. git diff --stat crates/vlog_formatter/src/verify.rs is empty, confirming
"verify.rs is untouched" (CLAUDE.md invariant #4 does not apply to this
round, as claimed).
Finding — LOW, non-blocking (header/list recovery produces a garbage
tree, not a clean single failure): the README's Status/TODO already
records header/port-list/for-header recovery as not done, and asked me
to check which of the two documented possibilities ("clean single failure"
vs. "garbage tree") actually happens. Answer: garbage tree. For
module m #(parameter W = , parameter X = 4) (input a); wire ok; endmodule, the tree is not one error item — it's three top-level items:
one error item covering the header through its closing ;, then wire ok;
re-parsed as an ordinary top-level DataDecl item (not inside any
module — semantically wrong shape for the tree), then a second, spurious
error item covering the orphaned endmodule keyword. That's 2 diagnostics
for one typo, and a module body statement now appears to live at file
scope. This doesn't break any stated guarantee (the module's body content
is still src[span]-correct in whichever node it ends up in, and nothing
panics), and it's explicitly flagged as a follow-up decision for "the first
consumer" in the TODO — but "not covered" undersells it: it's not just that
the header itself isn't recovered, the tree shape after it is
misleading. Recommend the Assumptions section say this explicitly (a header
failure produces extra, oddly-placed items/diagnostics, not just "one
failure covering the header") so a future LSP author isn't surprised.
Reproduction: see probe5 sources above; any of the four listed there
reproduces it.
Finding — LOW, out of scope for this feature (BOM lex-error message is
mojibake, pre-existing): a BOM-prefixed file (\u{FEFF}module m; …)
correctly takes the lex-error path (1 diagnostic, 1 file-wide error item,
no panic, span char-boundary-safe and in-file — all of this feature's
guarantees hold). But the message itself, "unexpected character 'ï'", is
mojibake: it looks like the lexer is decoding a single byte of the BOM's
UTF-8 encoding rather than the codepoint. crates/vlog_parser/src/lexer.rs
is untouched by this diff (git diff --stat confirms), so this is
pre-existing and out of this feature's scope — flagging for whoever next
touches lexer.rs, since BOM'd files are a common artifact from
Windows/VS Code and will reach the LSP path this feature exists to serve.
(2026-08-19: delivered by lexer-cleanup — a leading BOM now lexes, a
mid-file BOM errors by name; docs/features/lexer-cleanup/README.md.)
CLAUDE.md compliance: public items documented (ParseDiagnostic and its
fields, parse_tolerant, parse_source_tolerant, ItemKind::Error,
StmtKind::Error all carry doc comments). No unwrap()/expect()/panic!
in library code paths — the three hits from grep are inside
#[cfg(test)] mod tests, which CLAUDE.md permits. README has all required
sections, current and honest (TODO.md §6 checkbox matches what's actually
shipped, non-goals — tolerant lexer, cascade suppression, header/list
recovery — are recorded). Did not edit the Review section.
Not independently reproduced: the mutation-testing claim in the
Handshakes section (self.depth = 0 / self.depth += 1 injected into
recover, each failing a test) — took it on the dev's word since
mutating shipped code to re-verify a already-passing regression class
was judged lower value than the adversarial probing above; the black-box
budget tests (3c) independently exercise the same invariant from the
outside and passed.
Review
2026-08-19 — lead. Verdict: accepted; commits jointly with
format-fences (the two features interlock in format.rs via the new
Error variants' match arms, so separate commits would not compile).
The LSP's parser is now real: never fails, positioned diagnostics, Error leaves that obey the span nesting invariant, and — the part that took discipline — the strict path provably untouched (shared grammar code with a flag, not a fork; byte-identical behavior traced by QA). The evidence standard here was the best yet: truncation fuzz at byte and token granularity (27k+ cuts, zero panics), budget guarantees mutation-tested in both directions, and the stray-closer cascade bug caught by the dev's own tests before QA ever saw it.
Points reviewed and accepted:
- Sync-token set: consuming
;but not the closers/openers is the right asymmetry, and treatingmodule/packageas recovery openers is what keeps garbage from swallowing the next module. Bracket-balanced skipping (the;-inside-broken-for case) is the subtle rule; it's tested. - Lex errors stay all-or-nothing — honest scoping; a tolerant lexer is its own feature and the Assumption says so.
- The 4 exhaustive-match arms in format.rs were structurally
unavoidable, exact-string minimal, and QA traced their
unreachability from
format_source. Accepted as the one cross-scope touch. - QA's low findings both addressed at review: the truncation count is now stated approximately (it grows with the case table), and the Assumptions now say plainly that a broken header distorts the surrounding tree shape (2 diagnostics, body re-parsed at file scope) — the LSP consumer must expect that until header recovery lands. Cascade suppression and header recovery remain deliberate non-goals awaiting a real consumer.
The BOM mojibake message QA noticed in passing is a lexer
message-quality nit; it can ride with the @(* ) lexer item already
on TODO §1.