Open
Description
this particular case causes antlr4 to pop out "can't find rule grammarSpec or tree structure error" without the mutual recursion error that identifies the rules in violation. Commenting out the recursion in rule2 allows for the mutual recursion error to surface.
grammar T;
rule1:
rule2
| rule3
;
rule2:
rule1
| rule2
;
rule3:
rule1
| rule3
;
gets exception
can't find rule grammarSpec or tree structure error: (COMBINED_GRAMMAR T (RULES (RULE rule1 (BLOCK (ALT rule2) (ALT rule3))) (RULE rule2 (BLOCK (ALT rule1) (ALT rule2))) (RULE rule3 (BLOCK (ALT rule1) (ALT rule3)))))
...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
at org.antlr.v4.semantics.SymbolCollector.discoverOuterAlt(SymbolCollector.java:111)
at org.antlr.v4.parse.GrammarTreeVisitor.outerAlternative(GrammarTreeVisitor.java:2285)
at org.antlr.v4.parse.GrammarTreeVisitor.ruleBlock(GrammarTreeVisitor.java:2198)
at org.antlr.v4.parse.GrammarTreeVisitor.rule(GrammarTreeVisitor.java:1664)
at org.antlr.v4.parse.GrammarTreeVisitor.rules(GrammarTreeVisitor.java:1242)
at org.antlr.v4.parse.GrammarTreeVisitor.grammarSpec(GrammarTreeVisitor.java:481)
... 12 more
Exception in thread "main" java.lang.NullPointerException
at org.antlr.v4.tool.Rule.getAltLabels(Rule.java:217)
at org.antlr.v4.tool.LeftRecursiveRule.getAltLabels(LeftRecursiveRule.java:90)
at org.antlr.v4.tool.Rule.hasAltSpecificContexts(Rule.java:200)
at org.antlr.v4.tool.LeftRecursiveRule.hasAltSpecificContexts(LeftRecursiveRule.java:61)
at org.antlr.v4.semantics.SymbolChecks.checkForLabelConflicts(SymbolChecks.java:157)
at org.antlr.v4.semantics.SymbolChecks.process(SymbolChecks.java:105)
at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:107)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:397)
at org.antlr.v4.Tool.process(Tool.java:384)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
at org.antlr.v4.Tool.main(Tool.java:190)