use of org.antlr.v4.tool.ast.RuleAST in project antlr4 by antlr.
the class RuleCollector method discoverRule.
@Override
public void discoverRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, ActionAST arg, ActionAST returns, GrammarAST thrws, GrammarAST options, ActionAST locals, List<GrammarAST> actions, GrammarAST block) {
int numAlts = block.getChildCount();
Rule r;
if (LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(rule, ID.getText())) {
r = new LeftRecursiveRule(g, ID.getText(), rule);
} else {
r = new Rule(g, ID.getText(), rule, numAlts);
}
rules.put(r.name, r);
if (arg != null) {
r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g);
r.args.type = AttributeDict.DictType.ARG;
r.args.ast = arg;
arg.resolver = r.alt[currentOuterAltNumber];
}
if (returns != null) {
r.retvals = ScopeParser.parseTypedArgList(returns, returns.getText(), g);
r.retvals.type = AttributeDict.DictType.RET;
r.retvals.ast = returns;
}
if (locals != null) {
r.locals = ScopeParser.parseTypedArgList(locals, locals.getText(), g);
r.locals.type = AttributeDict.DictType.LOCAL;
r.locals.ast = locals;
}
for (GrammarAST a : actions) {
// a = ^(AT ID ACTION)
ActionAST action = (ActionAST) a.getChild(1);
r.namedActions.put(a.getChild(0).getText(), action);
action.resolver = r;
}
}
use of org.antlr.v4.tool.ast.RuleAST in project antlr4 by antlr.
the class RuleCollector method discoverLexerRule.
@Override
public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, GrammarAST block) {
int numAlts = block.getChildCount();
Rule r = new Rule(g, ID.getText(), rule, numAlts);
r.mode = currentModeName;
if (!modifiers.isEmpty())
r.modifiers = modifiers;
rules.put(r.name, r);
}
Aggregations