Skip to content

Parser: tolerant mode, source ranges and written names (LSP foundation, phase 1) - #481

Merged
blacktrs merged 28 commits into
mainfrom
parser-tolerant
Oct 26, 2026
Merged

blacktrs merged 28 commits into
mainfrom
parser-tolerant

Conversation

@blacktrs

Copy link
Copy Markdown
Contributor

What

Phase 1 of the LSP foundation (epic #456): the parser becomes usable by editor tooling without changing what the compiler sees. One parser, two modes; strict stays byte-identical.

  • Parser::parseTolerant(source, file, ranges, names): ParseResult — never throws, never loops, returns a Program plus every syntax error (cap 100, nesting cap 1000 with a single error).
  • Recovery: missing tokens (synthetic zero-width), missing expressions (ErrorExpr), statement/member boundary sync with brace/paren/bracket balancing (ErrorStmt).
  • Lexer reports unknown bytes and unterminated literals in tolerant mode only.
  • End positions: ParseError end fields, RangedSpan/RangedToken (ranges exist only in ranges mode, so strict memory stays flat), range invariant checker.
  • Written names: NameRef table (written spelling, resolved FQN, kind).
  • dump-ast --tolerant/--ranges/--names/--check-ranges/--check-names.
  • analyze now reports every syntax error per file.
  • tests/parser/ (goldens, truncation + garbage fuzz, strict-invariance, memory check), run in tools/docker/gate.sh.
  • Dump fix: enum cases were dumped from an indexed object, so output was nondeterministic (the only intended default dump-ast change, 57 enum files).

Not in scope

Analyzer walkers are not Error-aware yet, no ErrorMember, interpolation parts share the whole-string range, no hoisted-anon-class marker — Phase 2 (#453).

Evidence

  • tests/parser/run.sh 111/111; fuzz clean; strict-invariance OK over 2816 files; range/name checks 0 violations over 5760 runs.
  • tests/analyze: same 4 failures as main.
  • Strict memory vs main: hello_world +1.2%, dump-ast +0.5%, openssl_cms +1.4% (run-to-run noise ~1 MB).

Gates owed

Full AOT suite, tools/difftest.sh, tools/selfhost_fixpoint.sh, Linux gate (nesting cap 1000 was measured on macOS only).

Found on the way: #478, #479 (repros included).

Fixes #450 Fixes #451 Fixes #452

blacktrs and others added 28 commits October 25, 2026 17:16
…ery balances open braces, Throwable entry kept
…ent; goto-label tail is complete; rebased template golden
@blacktrs
blacktrs merged commit 661d71e into main Oct 26, 2026
56 of 57 checks passed
@blacktrs
blacktrs deleted the parser-tolerant branch October 26, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant