Skip to content

Replace ANTLR parser with CongoCC - #958

Merged
snazy merged 3 commits into
projectnessie:mainfrom
snazy:congocc
Aug 20, 2026
Merged

Replace ANTLR parser with CongoCC#958
snazy merged 3 commits into
projectnessie:mainfrom
snazy:congocc

Conversation

@snazy

@snazy snazy commented Aug 18, 2026

Copy link
Copy Markdown
Member

Move CEL grammar generation into cel-core using CongoCC and remove the generated-antlr module, shadow jar dependency, and ANTLR runtime wiring.

The generated parser now builds internal AST nodes with typed CEL expression conversion hooks, keeping parser construction close to the grammar while preserving the existing parser API and source-location handling.

This simplifies dependency management for downstream consumers, removes the relocated ANTLR artifact from the build graph, and makes future grammar changes easier to review in the core module.

@snazy
snazy requested a review from XN137 August 18, 2026 08:38
} else if (ctx instanceof Token) {
Token token = (Token) ctx;
location = source.newLocation(token.getLine(), token.getCharPositionInLine());
if (ctx instanceof Node) {

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.

nit: arent we on java 17 now?

if (e.isEmpty()) {
assertThat(actualErr).isEmpty();
} else {
assertThat(actualErr).isNotEmpty();

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.

isnt this a serious loss of coverage i.e. the expected errors now dont get asserted?

.isInstanceOf(ScriptCreateException.class)
.hasMessageStartingWith(
"parse failed: ERROR: <input>:1:3: Syntax error: mismatched input ',' expecting IDENTIFIER");
"parse failed: ERROR: <input>:1:3: Syntax error: Encountered an error");

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.

is there no way to keep providing more context to the user?


parser.addParseListener(parserListener);

parser.setErrorHandler(new RecoveryLimitErrorStrategy(options.getErrorRecoveryLimit()));

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.

options.getErrorRecoveryLimit() still exists but is no longer respected ?
are we missing test coverage here ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yea, that's a downside - documented it.

return reportError(node, "invalid literal");
}

private boolean isNegativeNumericLiteral(Node operand) {

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.

pardon my ignorance, but where is the "negative" property checked in the method body?

return text;
}

private Node firstExpressionChild(List<Node> children, Node ctx) {

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.

cant many of these helper methods be static?

snazy added 3 commits August 20, 2026 11:16
Move CEL grammar generation into cel-core using CongoCC and remove the generated-antlr module, shadow jar dependency, and ANTLR runtime wiring.

The generated parser now builds internal AST nodes with typed CEL expression conversion hooks, keeping parser construction close to the grammar while preserving the existing parser API and source-location handling.

This simplifies dependency management for downstream consumers, removes the relocated ANTLR artifact from the build graph, and makes future grammar changes easier to review in the core module.

@XN137 XN137 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.

thanks for the updates

guess i'll trust your judgment that the benefits of switching to congocc outweigh the drawbacks mentioned

* Returns the maximum number of parser error-recovery attempts.
*
* <p>This setting is currently not respected because CongoCC stops parsing after the first syntax
* error and does not provide error recovery.

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.

should we just remove this option or is there a realistic chance we can support it again in the future?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just leaving it to not break existing call sites. Maybe there's a way to get that back with CongoCC, but that would then likely be a bigger change.

} else if (e.contains(": Syntax error:")) {
// Parser implementations may format syntax diagnostics differently, but they must point to
// the same first invalid source location.
assertThat(actualErr).startsWith(firstErrorLocation(e) + ": Syntax error:");

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.

wondering:
why is it better to adjust the check here instead of updating our tests to the new error reporting format?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Less work ;)

@snazy
snazy merged commit 2bbe263 into projectnessie:main Aug 20, 2026
3 checks passed
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.

2 participants