diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 index 018375dd5d7..edc28b2d6aa 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 @@ -14,7 +14,7 @@ import DRL6Expressions, JavaParser; * | query * ; */ -compilationUnit : packagedef? unitdef? drlStatementdef* ; +compilationUnit : packagedef? unitdef? drlStatementdef* EOF ; drlStatementdef : importdef SEMI? diff --git a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DescrHelper.java b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DescrHelper.java index a822b5ddf76..02a4f38d276 100644 --- a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DescrHelper.java +++ b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DescrHelper.java @@ -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; @@ -58,11 +55,15 @@ public static 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 populateCommonProperties(T descr, List ctxList) { if (ctxList.isEmpty()) { return descr;