use of org.antlr.v4.runtime.RuleContext in project antlr4 by antlr.
the class ParseTreeWalker method enterRule.
/**
* The discovery of a rule node, involves sending two events: the generic
* {@link ParseTreeListener#enterEveryRule} and a
* {@link RuleContext}-specific event. First we trigger the generic and then
* the rule specific. We to them in reverse order upon finishing the node.
*/
protected void enterRule(ParseTreeListener listener, RuleNode r) {
ParserRuleContext ctx = (ParserRuleContext) r.getRuleContext();
listener.enterEveryRule(ctx);
ctx.enterRule(listener);
}
use of org.antlr.v4.runtime.RuleContext in project antlr4 by antlr.
the class TestXPath method getNodeStrings.
public List<String> getNodeStrings(String input, String xpath, String startRuleName, String parserName, String lexerName) throws Exception {
Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
Parser parser = pl.a;
ParseTree tree = execStartRule(startRuleName, parser);
List<String> nodes = new ArrayList<String>();
for (ParseTree t : XPath.findAll(tree, xpath, parser)) {
if (t instanceof RuleContext) {
RuleContext r = (RuleContext) t;
nodes.add(parser.getRuleNames()[r.getRuleIndex()]);
} else {
TerminalNode token = (TerminalNode) t;
nodes.add(token.getText());
}
}
return nodes;
}
use of org.antlr.v4.runtime.RuleContext in project antlr4 by antlr.
the class StructDecl method addDispatchMethods.
public void addDispatchMethods(Rule r) {
dispatchMethods = new ArrayList<DispatchMethod>();
if (!r.hasAltSpecificContexts()) {
// no enter/exit for this ruleContext if rule has labels
if (factory.getGrammar().tool.gen_listener) {
dispatchMethods.add(new ListenerDispatchMethod(factory, true));
dispatchMethods.add(new ListenerDispatchMethod(factory, false));
}
if (factory.getGrammar().tool.gen_visitor) {
dispatchMethods.add(new VisitorDispatchMethod(factory));
}
}
}
Aggregations