use of org.antlr.v4.tool.ast.ActionAST in project antlr4 by antlr.
the class OutputFile method buildNamedActions.
public Map<String, Action> buildNamedActions(Grammar g) {
Map<String, Action> namedActions = new HashMap<String, Action>();
for (String name : g.namedActions.keySet()) {
ActionAST ast = g.namedActions.get(name);
namedActions.put(name, new Action(factory, ast));
}
return namedActions;
}
use of org.antlr.v4.tool.ast.ActionAST in project antlr4 by antlr.
the class ActionTranslator method translateActionChunk.
public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) {
Token tokenWithinAction = node.token;
ActionTranslator translator = new ActionTranslator(factory, node);
translator.rf = rf;
factory.getGrammar().tool.log("action-translator", "translate " + action);
String altLabel = node.getAltLabel();
if (rf != null) {
translator.nodeContext = rf.ruleCtx;
if (altLabel != null)
translator.nodeContext = rf.altLabelCtxs.get(altLabel);
}
ANTLRStringStream in = new ANTLRStringStream(action);
in.setLine(tokenWithinAction.getLine());
in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine());
ActionSplitter trigger = new ActionSplitter(in, translator);
// forces eval, triggers listener methods
trigger.getActionTokens();
return translator.chunks;
}
use of org.antlr.v4.tool.ast.ActionAST in project antlr4 by antlr.
the class ParserATNFactory method action.
/** Build what amounts to an epsilon transition with an action.
* The action goes into ATN though it is ignored during prediction
* if {@link ActionTransition#actionIndex actionIndex}{@code <0}.
*/
@Override
public Handle action(ActionAST action) {
//System.out.println("action: "+action);
ATNState left = newState(action);
ATNState right = newState(action);
ActionTransition a = new ActionTransition(right, currentRule.index);
left.addTransition(a);
action.atnState = left;
return new Handle(left, right);
}
use of org.antlr.v4.tool.ast.ActionAST in project antlr4 by antlr.
the class RuleFunction method fillNamedActions.
public void fillNamedActions(OutputModelFactory factory, Rule r) {
if (r.finallyAction != null) {
finallyAction = new Action(factory, r.finallyAction);
}
namedActions = new HashMap<String, Action>();
for (String name : r.namedActions.keySet()) {
ActionAST ast = r.namedActions.get(name);
namedActions.put(name, new Action(factory, ast));
}
}
Aggregations