diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 52f7d7b19..7f3029a3b 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -433,14 +433,13 @@ public class Tool { public boolean checkForRuleIssues(final Grammar g) { // check for redefined rules GrammarAST RULES = (GrammarAST)g.ast.getFirstChildWithType(ANTLRParser.RULES); - - List rules = (List)RULES.getChildren(); - if (rules == null) { - rules = Collections.emptyList(); + List rules = new ArrayList(RULES.getAllChildrenWithType(ANTLRParser.RULE)); + for (GrammarAST mode : g.ast.getAllChildrenWithType(ANTLRParser.MODE)) { + rules.addAll(mode.getAllChildrenWithType(ANTLRParser.RULE)); } final Map ruleToAST = new HashMap(); - for (Object r : rules) { + for (GrammarAST r : rules) { RuleAST ruleAST = (RuleAST)r; GrammarAST ID = (GrammarAST)ruleAST.getChild(0); String ruleName = ID.getText();