Skip to content

Add parser error tokens#47

Merged
tjobi merged 4 commits into
mainfrom
add-parser-error-tokens
May 11, 2026
Merged

Add parser error tokens#47
tjobi merged 4 commits into
mainfrom
add-parser-error-tokens

Conversation

@PatrickMatthiesen
Copy link
Copy Markdown
Member

This pull request introduces robust support for parse error reporting in the AST and parser. It adds new EError and PError nodes to the core AST, updates the parser to generate these nodes for common syntax errors, and ensures all downstream consumers (pretty-printer, equality, language service, and transformations) handle these cases gracefully. This will improve error messages and IDE integration for incomplete or incorrect code.

AST Extensions for Error Handling

  • Added EError and PError constructors to the core AST types in ast_core.ml to represent expressions and patterns with parse errors, and updated all relevant pattern-matching code to handle these new cases. [1] [2] [3]

Parser Improvements

  • Updated the parser (parser.mly) to generate EError nodes for missing expressions in let, if-then-else, and match constructs, and for missing match case bodies, providing more precise syntax error localization. [1] [2] [3]

Pretty-Printing and Equality

  • Updated the pretty-printer (ast_pp.ml) to display parse errors in red and the equality module (ast_eq.ml) to compare error nodes by their messages, ensuring errors are visible and comparable. [1] [2] [3] [4] [5]

Language Service and Analysis

  • Updated the language service (language_service.ml) to support the new error nodes in all relevant traversals, including hover text, completions, symbol analysis, and semantic tokens, so that tools and IDE features gracefully handle and report parse errors. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]

Transformation Passes

  • Updated the ANF transformation (anf.ml) to treat EError as a simple value, ensuring error nodes are preserved through normalization.

These changes together provide end-to-end support for parse error recovery and reporting, making the language tooling more robust and user-friendly.

- Introduced `error` helper function in `ast_test_helpers.ml` to create error expressions.
- Enhanced parser tests in `test_parser.ml` to check for missing expressions in `if` statements and `match` constructs, ensuring proper error diagnostics.
- Updated existing tests to validate the parser's behavior when encountering incomplete expressions.
@PatrickMatthiesen PatrickMatthiesen requested a review from tjobi May 8, 2026 22:08
@PatrickMatthiesen PatrickMatthiesen self-assigned this May 8, 2026
@PatrickMatthiesen PatrickMatthiesen added the enhancement New feature or request label May 8, 2026
@PatrickMatthiesen PatrickMatthiesen force-pushed the add-parser-error-tokens branch from 773e275 to 82bfa11 Compare May 9, 2026 10:15
Copy link
Copy Markdown
Contributor

@tjobi tjobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

@tjobi tjobi merged commit ae0a5ea into main May 11, 2026
3 checks passed
@tjobi tjobi deleted the add-parser-error-tokens branch May 11, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants