Repository navigation
[core] ANTLR: Report syntax errors as processing errors - #6764
Conversation
This error listener can be used during lexing and parsing with ANTLR. It creates the correct LexExceptions and ParseExceptions.
|
Compared to main: (comment created at 2026-06-18 15:16:43+00:00 for 93c0caa) |
Needs to inherit from the old class so that existing subclasses stay compatible
There was a problem hiding this comment.
Pull request overview
This PR centralizes ANTLR lexer/parser error handling in pmd-core so ANTLR-based language modules can consistently convert syntax errors into PMD ProcessingErrors, while allowing individual languages (e.g. Swift) to opt out of throwing.
Changes:
- Added
AntlrErrorListenerandAntlrBaseParserWithErrorHandlinginpmd-coreto collect ANTLR lexer/parser errors and throw them as PMD analysis exceptions after parsing. - Migrated Kotlin and Swift parsers to the new base class and updated API/docs to deprecate
AntlrBaseParser. - Updated release notes and devdocs to document the new default error-handling behavior for ANTLR-based languages.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/PmdSwiftParser.java | Migrates Swift to the new core ANTLR base parser and attempts to preserve “warn-only” behavior. |
| pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java | Migrates Kotlin to the new core ANTLR base parser while preserving timeout + interpreter customization. |
| pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrGeneratedParserBase.java | Updates Javadoc to reference the new base parser adapter. |
| pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrErrorListener.java | Introduces a reusable ANTLR error listener that aggregates errors as suppressed exceptions. |
| pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParserWithErrorHandling.java | Introduces a new generic base parser that installs error listeners and throws processing errors by default. |
| pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java | Deprecates the old adapter in favor of the new error-handling base class. |
| docs/pages/release_notes.md | Adds release notes entry and documents the API deprecation/change. |
| docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md | Updates devdocs to recommend the new base class for ANTLR languages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Describe the PR
This PR moves the ANTLR error listener from pmd-kotlin up to pmd-core, so that it can be used by any ANTLR based language.
pmd-swift keeps at current logic by just issuing a warning instead of throwing parse exceptions, when syntax exceptions occur.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)