labels on tokens in left-recursive rules caused codegen exception.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9866]
This commit is contained in:
parrt 2012-01-14 10:18:19 -08:00
parent 5bd780c235
commit 1ddf609e25
3 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,9 @@
ANTLR v4 Honey Badger early access
Jan 14, 2012
* labels on tokens in left-recursive rules caused codegen exception.
Jan 11, 2012
* -> id labels work now for outermost alternatives, even for left-recursive

View File

@ -3,7 +3,7 @@ grammar A;
s : q=e {System.out.println("result = "+$e.v);} ;
e returns [int v]
: a=e '*' b=e {$v = $a.v * $b.v;} -> mult
: a=e op='*' b=e {$v = $a.v * $b.v;} -> mult
| a=e '+' b=e {$v = $a.v + $b.v;} -> add
| INT {$v = $INT.int;}
| '(' x=e ')' {$v = $x.v;}

View File

@ -33,6 +33,7 @@ import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.model.decl.RuleContextDecl;
import org.antlr.v4.tool.LabelElementPair;
import org.antlr.v4.tool.LabelType;
import org.antlr.v4.tool.LeftRecursiveRule;
import org.antlr.v4.tool.Rule;
import org.stringtemplate.v4.misc.MultiMap;
@ -52,9 +53,11 @@ public class LeftRecursiveRuleFunction extends RuleFunction {
String label = iterator.next();
LabelElementPair l = r.getAnyLabelDef(label);
Rule targetRule = factory.getGrammar().getRule(l.element.getText());
String ctxName = gen.target.getRuleFunctionContextStructName(targetRule);
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
addContextDecl(d);
if ( l.type == LabelType.RULE_LABEL ) {
String ctxName = gen.target.getRuleFunctionContextStructName(targetRule);
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
addContextDecl(d);
}
}
}
}