use of org.antlr.v4.codegen.model.chunk.ActionChunk in project antlr4 by antlr.
the class ActionTranslator method translateAction.
public static List<ActionChunk> translateAction(OutputModelFactory factory, RuleFunction rf, Token tokenWithinAction, ActionAST node) {
String action = tokenWithinAction.getText();
if (action != null && action.length() > 0 && action.charAt(0) == '{') {
int firstCurly = action.indexOf('{');
int lastCurly = action.lastIndexOf('}');
if (firstCurly >= 0 && lastCurly >= 0) {
// trim {...}
action = action.substring(firstCurly + 1, lastCurly);
}
}
return translateActionChunk(factory, rf, action, node);
}
use of org.antlr.v4.codegen.model.chunk.ActionChunk 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.codegen.model.chunk.ActionChunk in project antlr4 by antlr.
the class ActionTranslator method setNonLocalAttr.
@Override
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
gen.g.tool.log("action-translator", "setNonLocalAttr " + x + "::" + y + "=" + rhs);
Rule r = factory.getGrammar().getRule(x.getText());
List<ActionChunk> rhsChunks = translateActionChunk(factory, rf, rhs.getText(), node);
SetNonLocalAttr s = new SetNonLocalAttr(nodeContext, x.getText(), y.getText(), r.index, rhsChunks);
chunks.add(s);
}
use of org.antlr.v4.codegen.model.chunk.ActionChunk in project antlr4 by antlr.
the class ActionTranslator method setAttr.
@Override
public void setAttr(String expr, Token x, Token rhs) {
gen.g.tool.log("action-translator", "setAttr " + x + " " + rhs);
List<ActionChunk> rhsChunks = translateActionChunk(factory, rf, rhs.getText(), node);
SetAttr s = new SetAttr(nodeContext, x.getText(), rhsChunks);
chunks.add(s);
}
Aggregations