mv ruleIndex, add alt

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9061]
This commit is contained in:
parrt 2011-09-09 13:00:58 -08:00
parent 62937ca639
commit f13fd1973e
3 changed files with 12 additions and 4 deletions

View File

@ -53,12 +53,21 @@ public class ParserRuleContext extends RuleContext {
public Object tree; public Object tree;
public ST st; public ST st;
/** Set during parsing to identify which rule parser is in. */
public int ruleIndex;
/** Set during parsing to identify which alt of rule parser is in. */
public int alt;
public ParserRuleContext() { super(); } public ParserRuleContext() { super(); }
public ParserRuleContext(RuleContext parent, int stateNumber) { public ParserRuleContext(RuleContext parent, int stateNumber) {
super(parent, stateNumber); super(parent, stateNumber);
} }
@Override
public int getRuleIndex() { return ruleIndex; }
public Object getTree() { return tree; } public Object getTree() { return tree; }
public ST getTemplate() { return st; } public ST getTemplate() { return st; }
public Token getStart() { return start; } public Token getStart() { return start; }

View File

@ -84,9 +84,6 @@ public class RuleContext implements ParseTree.RuleNode {
*/ */
public int s = -1; public int s = -1;
/** Set during parsing to identify which rule parser is in. */
public int ruleIndex;
/** What state invoked the rule associated with this context? /** What state invoked the rule associated with this context?
* The "return address" is the followState of invokingState * The "return address" is the followState of invokingState
* If parent is null, this should be -1. * If parent is null, this should be -1.
@ -274,6 +271,8 @@ public class RuleContext implements ParseTree.RuleNode {
public int getChildCount() { return children!=null ? children.size() : 0; } public int getChildCount() { return children!=null ? children.size() : 0; }
public int getRuleIndex() { return -1; }
public Interval getSourceInterval() { public Interval getSourceInterval() {
if ( getChildCount()==0 ) return Interval.ZeroLength; if ( getChildCount()==0 ) return Interval.ZeroLength;
int start = getChild(0).getSourceInterval().a; int start = getChild(0).getSourceInterval().a;

View File

@ -60,7 +60,7 @@ public class Trees {
public static String getNodeText(Tree t, BaseRecognizer recog) { public static String getNodeText(Tree t, BaseRecognizer recog) {
if ( recog!=null ) { if ( recog!=null ) {
if ( t instanceof ParseTree.RuleNode ) { if ( t instanceof ParseTree.RuleNode ) {
int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().ruleIndex; int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex();
String ruleName = recog.getRuleNames()[ruleIndex]; String ruleName = recog.getRuleNames()[ruleIndex];
return ruleName; return ruleName;
} }