Skip to content

Commit

Permalink
Match EOF at the end of the compilation unit (apache#5930)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurloc authored and tkobayas committed Oct 11, 2024
1 parent 6412984 commit 3c6e364
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DRL6Expressions, JavaParser;
* | query
* ;
*/
compilationUnit : packagedef? unitdef? drlStatementdef* ;
compilationUnit : packagedef? unitdef? drlStatementdef* EOF ;

drlStatementdef
: importdef SEMI?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.drools.drl.ast.descr.AndDescr;
import org.drools.drl.ast.descr.AttributeDescr;
import org.drools.drl.ast.descr.BaseDescr;
import org.drools.drl.ast.descr.ExprConstraintDescr;
import org.drools.drl.ast.descr.PatternDescr;
Expand Down Expand Up @@ -58,11 +55,15 @@ public static <T extends BaseDescr> T populateCommonProperties(T descr, ParserRu
// However, it doesn't look reasonable. When we will update LanguageLevel, we can remove this +1.
descr.setEndCharacter(stopToken.getStopIndex() + 1);
descr.setLocation(startToken.getLine(), startToken.getCharPositionInLine());
descr.setEndLocation(stopToken.getLine(), stopToken.getCharPositionInLine() + stopToken.getText().length() - 1); // last column of the end token
descr.setEndLocation(stopToken.getLine(), stopToken.getCharPositionInLine() + stopTokenLength(stopToken) - 1); // last column of the end token
}
return descr;
}

private static int stopTokenLength(Token token) {
return token.getType() == Token.EOF ? 0 : token.getText().length();
}

public static <T extends BaseDescr> T populateCommonProperties(T descr, List<? extends ParserRuleContext> ctxList) {
if (ctxList.isEmpty()) {
return descr;
Expand Down

0 comments on commit 3c6e364

Please sign in to comment.