added list of rule consts; parser ctx tracks rule index

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9043]
This commit is contained in:
parrt 2011-09-05 08:28:24 -08:00
parent 01020ee1bb
commit 528d6df1e3
4 changed files with 8 additions and 0 deletions

View File

@ -688,6 +688,7 @@ public abstract class BaseRecognizer extends Recognizer<ParserATNSimulator> {
* parse trees as well.
*/
public void enterRule(int ruleIndex) {
_ctx.ruleIndex = ruleIndex;
if ( buildParseTrees ) {
if ( _ctx.parent!=null ) _ctx.parent.addChild(_ctx);
}

View File

@ -49,6 +49,9 @@ import org.stringtemplate.v4.ST;
* satisfy the superclass interface.
*/
public class ParserRuleContext extends RuleContext {
/** Set during parsing to identify which rule parser is in. */
public int ruleIndex;
public Token start, stop;
public Object tree;
public ST st;

View File

@ -44,6 +44,8 @@ public class <parser.name> extends Parser {
"\<INVALID>", "\<INVALID>", "\<INVALID>",
<parser.tokenNames:{k | "<k>"}; separator=", ", wrap, anchor>
};
public static final int
<parser.rules:{r | RULE_<r.name> = <r.index>}; separator=", ", wrap, anchor>;
public static final String[] ruleNames = {
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
};

View File

@ -40,6 +40,7 @@ public class Parser extends OutputModelObject {
public Map<String,Integer> tokens;
public String[] tokenNames;
public Set<String> ruleNames;
public Collection<Rule> rules;
public ParserFile file;
@ModelElement public List<RuleFunction> funcs = new ArrayList<RuleFunction>();
@ -59,6 +60,7 @@ public class Parser extends OutputModelObject {
}
tokenNames = g.getTokenDisplayNames();
ruleNames = g.rules.keySet();
rules = g.rules.values();
atn = new SerializedATN(factory, g.atn);
}
}