Community
Participate
Working Groups
For the following code public class Foo1 { public static void main(String[] args) /** mising { **/ } } The problems below are reported. Notice that the "Syntax error on token "}", "{" expected" is reported twice. This is confusing, but if it this is an issue for this particluar scenario only, then it isn't critical. Kind Status Priority Description Resource In Folder Location Error Syntax error on token "}", "{" expected Foo1.java JUnit/junit/samples line 18 Error Unmatched bracket Foo1.java JUnit/junit/samples line 18 Error Syntax error on token "}", "{" expected Foo1.java JUnit/junit/samples line 18 Error Unmatched bracket Foo1.java JUnit/junit/samples line 19
Suspecting this is a consequence of our dual parsing story with recovery.
Parser needs subtle modifications to fix this problem. Will consider for 2.2.
A possible fix is to modify Parser#parse() with the following code: protected void parse() { ... ProcessTerminals : for (;;) { ... if (act == ERROR_ACTION || restartRecovery) { int errorPos = scanner.currentPosition; if (!hasReportedError){ if(referenceContext instanceof AbstractMethodDeclaration){ if(errorPos != lastDietErrorPos || (errorPos > ((AbstractMethodDeclaration)referenceContext).bodyStart) && (errorPos < ((AbstractMethodDeclaration)referenceContext).bodyEnd + 1)) { this.reportSyntaxError (ERROR_ACTION, currentToken, stateStackTop); hasReportedError = true; } } else { this.reportSyntaxError(ERROR_ACTION, currentToken, stateStackTop); hasReportedError = true; lastDietErrorPos = errorPos; } } ... } ... } endParse(act); } and to initialize the new field in goForCompilationUnit() public void goForCompilationUnit(){ //tells the scanner to go for compilation unit parsing lastDietErrorPos = -1; // new field firstToken = TokenNamePLUS_PLUS ; scanner.linePtr = -1; scanner.foundTaskCount = 0; scanner.recordLineSeparator = true; scanner.currentLine= null; }
reopen
Fixed.
Verified.