forked from jasder/antlr
Throw error if lexer does not contain non-fragment rules, extend TestToolSyntaxErrors testA, fix #3000
This commit is contained in:
parent
92bee7d929
commit
67f6089261
|
@ -18,11 +18,16 @@ public class TestToolSyntaxErrors extends BaseJavaToolTest {
|
|||
"grammar A;\n" +
|
||||
"",
|
||||
// YIELDS
|
||||
"error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n",
|
||||
"error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no non-fragment 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::: grammar A has no non-fragment rules\n",
|
||||
|
||||
"lexer grammar A;\n" +
|
||||
"fragment FRAGMENT: 'FRAGMENT';\n" +
|
||||
"",
|
||||
"error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no non-fragment rules\n",
|
||||
|
||||
"A;",
|
||||
"error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:1:0: syntax error: 'A' came as a complete surprise to me\n",
|
||||
|
|
|
@ -321,7 +321,16 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
|
|||
}
|
||||
|
||||
void checkNumRules(GrammarAST rulesNode) {
|
||||
if ( rulesNode.getChildCount()==0 ) {
|
||||
Boolean emptyGrammar = true;
|
||||
|
||||
for (Rule rule : ruleCollector.rules.values()) {
|
||||
if (!rule.isFragment()) {
|
||||
emptyGrammar = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (emptyGrammar) {
|
||||
GrammarAST root = (GrammarAST)rulesNode.getParent();
|
||||
GrammarAST IDNode = (GrammarAST)root.getChild(0);
|
||||
g.tool.errMgr.grammarError(ErrorType.NO_RULES, g.fileName,
|
||||
|
|
|
@ -341,7 +341,7 @@ public enum ErrorType {
|
|||
* <li>implicitly generated grammar <em>grammar</em> has no rules</li>
|
||||
* </ul>
|
||||
*/
|
||||
NO_RULES(99, "<if(arg2.implicitLexerOwner)>implicitly generated <endif>grammar <arg> has no rules", ErrorSeverity.ERROR),
|
||||
NO_RULES(99, "<if(arg2.implicitLexerOwner)>implicitly generated <endif>grammar <arg> has no non-fragment rules", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 105.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue