Skip to content

[core] ANTLR: Report syntax errors as processing errors - #6764

Merged
adangel merged 12 commits into
pmd:mainfrom
adangel:core/antlr-error-listener
Jun 22, 2026
Merged

adangel merged 12 commits into
pmd:mainfrom
adangel:core/antlr-error-listener

Conversation

@adangel

@adangel adangel commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

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?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

adangel added 2 commits June 5, 2026 12:12
This error listener can be used during lexing
and parsing with ANTLR. It creates the correct
LexExceptions and ParseExceptions.
@pmd-actions-helper

pmd-actions-helper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-18 15:16:43+00:00 for 93c0caa)

@adangel adangel added the an:enhancement An improvement on existing features / rules label Jun 12, 2026
@adangel adangel changed the title [core] ANTLR: Automatically add error listener [core] ANTLR: Report syntax errors as processing errors Jun 18, 2026
@adangel adangel added this to the 7.26.0 milestone Jun 18, 2026
@adangel
adangel marked this pull request as ready for review June 18, 2026 13:43
@adangel
adangel requested review from UncleOwen and Copilot June 18, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 AntlrErrorListener and AntlrBaseParserWithErrorHandling in pmd-core to 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.

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@adangel
adangel merged commit 168e910 into pmd:main Jun 22, 2026
13 checks passed
@adangel
adangel deleted the core/antlr-error-listener branch June 22, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

an:enhancement An improvement on existing features / rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants