Skip to content

Commit

Permalink
Correct position for "grammar has no rules" error
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kochurkin <kvanttt@gmail.com>
  • Loading branch information
KvanTTT committed Jul 8, 2022
1 parent 4038e8b commit f49d563
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class TestToolSyntaxErrors {
"grammar A;\n" +
"",
// YIELDS
"error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
"error(" + ErrorType.NO_RULES.code + "): A.g4:1:0: grammar A has no rules\n",

"lexer grammar A;\n" +
"",
"error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
"error(" + ErrorType.NO_RULES.code + "): A.g4:1:6: grammar A has no rules\n",

"A;",
"error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:1:0: syntax error: 'A' came as a complete surprise to me\n",
Expand Down
3 changes: 1 addition & 2 deletions tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ void checkNumRules(GrammarAST rulesNode) {
if ( rulesNode.getChildCount()==0 ) {
GrammarAST root = (GrammarAST)rulesNode.getParent();
GrammarAST IDNode = (GrammarAST)root.getChild(0);
g.tool.errMgr.grammarError(ErrorType.NO_RULES, g.fileName,
null, IDNode.getText(), g);
g.tool.errMgr.grammarError(ErrorType.NO_RULES, g.fileName, root.token, IDNode.getText(), g);
}
}

Expand Down

0 comments on commit f49d563

Please sign in to comment.