forked from jasder/antlr
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:
parent
01020ee1bb
commit
528d6df1e3
|
@ -688,6 +688,7 @@ public abstract class BaseRecognizer extends Recognizer<ParserATNSimulator> {
|
||||||
* parse trees as well.
|
* parse trees as well.
|
||||||
*/
|
*/
|
||||||
public void enterRule(int ruleIndex) {
|
public void enterRule(int ruleIndex) {
|
||||||
|
_ctx.ruleIndex = ruleIndex;
|
||||||
if ( buildParseTrees ) {
|
if ( buildParseTrees ) {
|
||||||
if ( _ctx.parent!=null ) _ctx.parent.addChild(_ctx);
|
if ( _ctx.parent!=null ) _ctx.parent.addChild(_ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ import org.stringtemplate.v4.ST;
|
||||||
* satisfy the superclass interface.
|
* satisfy the superclass interface.
|
||||||
*/
|
*/
|
||||||
public class ParserRuleContext extends RuleContext {
|
public class ParserRuleContext extends RuleContext {
|
||||||
|
/** Set during parsing to identify which rule parser is in. */
|
||||||
|
public int ruleIndex;
|
||||||
|
|
||||||
public Token start, stop;
|
public Token start, stop;
|
||||||
public Object tree;
|
public Object tree;
|
||||||
public ST st;
|
public ST st;
|
||||||
|
|
|
@ -44,6 +44,8 @@ public class <parser.name> extends Parser {
|
||||||
"\<INVALID>", "\<INVALID>", "\<INVALID>",
|
"\<INVALID>", "\<INVALID>", "\<INVALID>",
|
||||||
<parser.tokenNames:{k | "<k>"}; separator=", ", wrap, anchor>
|
<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 = {
|
public static final String[] ruleNames = {
|
||||||
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
|
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class Parser extends OutputModelObject {
|
||||||
public Map<String,Integer> tokens;
|
public Map<String,Integer> tokens;
|
||||||
public String[] tokenNames;
|
public String[] tokenNames;
|
||||||
public Set<String> ruleNames;
|
public Set<String> ruleNames;
|
||||||
|
public Collection<Rule> rules;
|
||||||
public ParserFile file;
|
public ParserFile file;
|
||||||
|
|
||||||
@ModelElement public List<RuleFunction> funcs = new ArrayList<RuleFunction>();
|
@ModelElement public List<RuleFunction> funcs = new ArrayList<RuleFunction>();
|
||||||
|
@ -59,6 +60,7 @@ public class Parser extends OutputModelObject {
|
||||||
}
|
}
|
||||||
tokenNames = g.getTokenDisplayNames();
|
tokenNames = g.getTokenDisplayNames();
|
||||||
ruleNames = g.rules.keySet();
|
ruleNames = g.rules.keySet();
|
||||||
|
rules = g.rules.values();
|
||||||
atn = new SerializedATN(factory, g.atn);
|
atn = new SerializedATN(factory, g.atn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue