Skip to content

Handle incomplete syntax trees through parser error recovery - #132

Open
Aschenbath wants to merge 1 commit into
solidity-parser:masterfrom
Aschenbath:fix/syntax-error-recovery-131-20261120
Open

Aschenbath wants to merge 1 commit into
solidity-parser:masterfrom
Aschenbath:fix/syntax-error-recovery-131-20261120

Conversation

@Aschenbath

Copy link
Copy Markdown

Malformed Solidity can leave required ANTLR children missing. parse() currently visits that incomplete tree before checking syntax errors, so callers get an internal TypeError instead of ParserError.

Check diagnostics before building the AST in strict mode. In tolerant mode, keep declarations that can be built and omit a top-level declaration whose recovered tree cannot be converted; return the diagnostics and requested metadata as usual. Recovery is enabled only when syntax errors were actually reported, so AST errors on syntactically valid input still propagate. Document the omission behavior.

Fixes #131.

Validation on Windows / Node.js 24: 11 new regression cases fail on the original source and the valid-input error control passes. With the fix, all 193 Node tests, 3 bundle integration tests, and the headless Chrome browser test pass. ESLint, TypeScript checks, Prettier on changed files, Node/browser bundle builds, and git diff --check pass. The existing generated grammar is unchanged; the ANTLR generator was not rerun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse() throws TypeError instead of ParserError on some syntax errors (AST is built before the syntax-error check)

1 participant