diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java index b3c2ef031..7a1d233ed 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java @@ -30,12 +30,6 @@ package org.antlr.v4.analysis; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import org.antlr.runtime.TokenStream; @@ -57,6 +51,12 @@ import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupFile; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + /** Using a tree walker on the rules, determine if a rule is directly left-recursive and if it follows * our pattern. */ @@ -68,7 +68,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { public LinkedHashMap binaryAlts = new LinkedHashMap(); public LinkedHashMap ternaryAlts = new LinkedHashMap(); public LinkedHashMap suffixAlts = new LinkedHashMap(); - public List prefixAlts = new ArrayList(); + public List prefixAndOtherAlts = new ArrayList(); /** Pointer to ID node of ^(= ID element) */ public List> leftRecursiveRuleRefLabels = @@ -187,7 +187,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { LeftRecursiveRuleAltInfo a = new LeftRecursiveRuleAltInfo(alt, altText, null, altLabel, false, originalAltTree); a.nextPrec = nextPrec; - prefixAlts.add(a); + prefixAndOtherAlts.add(a); //System.out.println("prefixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText); } @@ -223,7 +223,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { new LeftRecursiveRuleAltInfo(alt, altText, null, altLabel, false, originalAltTree); // We keep other alts with prefix alts since they are all added to the start of the generated rule, and // we want to retain any prior ordering between them - prefixAlts.add(a); + prefixAndOtherAlts.add(a); // System.out.println("otherAlt " + alt + ": " + altText); } @@ -255,7 +255,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { ruleST.add("opAlts", altST); } - ruleST.add("primaryAlts", prefixAlts); + ruleST.add("primaryAlts", prefixAndOtherAlts); tool.log("left-recursion", ruleST.render()); @@ -439,7 +439,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { "binaryAlts=" + binaryAlts + ", ternaryAlts=" + ternaryAlts + ", suffixAlts=" + suffixAlts + - ", prefixAlts=" + prefixAlts + + ", prefixAndOtherAlts=" +prefixAndOtherAlts+ '}'; } } diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java index 53ab68e57..45cb5170a 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java @@ -168,7 +168,7 @@ public class LeftRecursiveRuleTransformer { // track recursive alt info for codegen r.recPrimaryAlts = new ArrayList(); - r.recPrimaryAlts.addAll(leftRecursiveRuleWalker.prefixAlts); + r.recPrimaryAlts.addAll(leftRecursiveRuleWalker.prefixAndOtherAlts); if (r.recPrimaryAlts.isEmpty()) { tool.errMgr.grammarError(ErrorType.NO_NON_LR_ALTS, g.fileName, ((GrammarAST)r.ast.getChild(0)).getToken(), r.name); }