Skip to content

Parser: tolerant mode with error recovery and error nodes #450

Closed

Description

@blacktrs

Why

The parser stops at the first syntax error (ParseError, 21 throw sites via error()/expect()) and returns no AST. An editor tool needs the rest of the file: symbols, types and diagnostics must survive a half-typed line.

Scope

  • New entry point Parser::parseTolerant(source, file) returning Program plus a list of ParseError. Strict parseSource stays byte-for-byte unchanged.
  • Synchronisation at statement, class-member and argument/element level.
  • ErrorStmt / ErrorExpr nodes appended to the Stmt/Expr hierarchies (never produced in strict mode).
  • Lexer: record unknown bytes and unterminated strings/comments as errors in tolerant mode (today an unknown byte is silently skipped, Lexer.php:672).

Acceptance

  • Truncation fuzz over src/ and the corpus: no throw, no hang, at least one error, statements before the cut equal the strict parse of the prefix.
  • dump-ast output identical before/after on the corpus; AOT suite, difftest and self-host fixpoint unchanged; no compile-time regression.
  • analyze reports all parse errors of a file, not only the first.

Design: docs/superpowers/specs/2026-10-25-lsp-foundation-design.md (Phase 1).

Activity

  1. added
    enhancement
    needs-design
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions