From f13fd1973e5613abf710546c204d666003c7d749 Mon Sep 17 00:00:00 2001 From: parrt Date: Fri, 9 Sep 2011 13:00:58 -0800 Subject: [PATCH] mv ruleIndex, add alt [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9061] --- .../Java/src/org/antlr/v4/runtime/ParserRuleContext.java | 9 +++++++++ runtime/Java/src/org/antlr/v4/runtime/RuleContext.java | 5 ++--- runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java index 3ff4ccfe6..3837d857d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java @@ -53,12 +53,21 @@ public class ParserRuleContext extends RuleContext { public Object tree; 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(RuleContext parent, int stateNumber) { super(parent, stateNumber); } + @Override + public int getRuleIndex() { return ruleIndex; } + public Object getTree() { return tree; } public ST getTemplate() { return st; } public Token getStart() { return start; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java index c108a98aa..2692309ea 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java @@ -84,9 +84,6 @@ public class RuleContext implements ParseTree.RuleNode { */ 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? * The "return address" is the followState of invokingState * 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 getRuleIndex() { return -1; } + public Interval getSourceInterval() { if ( getChildCount()==0 ) return Interval.ZeroLength; int start = getChild(0).getSourceInterval().a; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java index 0168d642b..8e1c7604b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java @@ -60,7 +60,7 @@ public class Trees { public static String getNodeText(Tree t, BaseRecognizer recog) { if ( recog!=null ) { if ( t instanceof ParseTree.RuleNode ) { - int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().ruleIndex; + int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex(); String ruleName = recog.getRuleNames()[ruleIndex]; return ruleName; }