Conversation
Contributor
…ions (#71) Replace the LOOKAHEAD( VariableDeclarationExpression() ";" ) used to disambiguate local variable declarations from other statements with a purely syntactic lookahead: LOOKAHEAD( Modifiers() Type() Identifier() ( ArrayBracketPair() )* ( "," | "=" | ";" ) ) Performing a full parse of the declarator inside the lookahead swallows the parse error of malformed input such as `int i = ;`: error recovery then reports the start of the statement instead of the offending token. The syntactic lookahead keeps the same disambiguation while letting the actual VariableDeclarationExpression() parse report the precise error. This restores the error positions required by KeY (see KeYProject/key commit b7b5bb1), which can now be reverted together with the corresponding error-message test modifications. Adds a regression test asserting the error is reported at the offending '=' token and not at the statement start.
wadoon
force-pushed
the
fix/issue-71-error-reporting
branch
from
October 2, 2026 23:02
f3c4f8d to
8fabf60
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #71
Summary
Replaces the statement-level lookahead in
javaparser-core/src/main/javacc/java.jj:with a purely syntactic lookahead:
Performing a full parse of the declarator inside the lookahead swallows
the parse error for malformed input such as
int i = ;: error recoveryreports the start of the statement instead of the offending token. The
syntactic lookahead keeps the same disambiguation between local variable
declarations and other (incl. JML) statements, while letting the actual
VariableDeclarationExpression()parse report the exact error position.Motivation
This restores the precise error positions documented in the issue, so
KeYProject/key#b7b5bb1
(and the accompanying error-message test changes) can be reverted.
Verification
Before:
int i = ;reported(line 1,col 20) Parse error. Found "int"(statement start)After:
(line 1,col 28) Parse error. Found ";"(the offending=/;)Parser regenerated with javacc, 0 errors.
Added regression test
VariableDeclarationErrorPositionTest.Full
:jmlparser-core-testing:test,:jmlparser-jml-tests:test,:javaparser-key-testing:testand:jmlparser-symbol-solver-testing:testpass.