use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method sempred.
/**
* Build what amounts to an epsilon transition with a semantic
* predicate action. The {@code pred} is a pointer into the AST of
* the {@link ANTLRParser#SEMPRED} token.
*/
@NotNull
@Override
public Handle sempred(@NotNull PredAST pred) {
// System.out.println("sempred: "+ pred);
ATNState left = newState(pred);
ATNState right = newState(pred);
AbstractPredicateTransition p;
if (pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
p = new PrecedencePredicateTransition(right, precedence);
} else {
boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
}
left.addTransition(p);
pred.atnState = left;
return new Handle(left, right);
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method tokenRef.
/**
* From label {@code A} build graph {@code o-A->o}.
*/
@NotNull
@Override
public Handle tokenRef(@NotNull TerminalAST node) {
ATNState left = newState(node);
ATNState right = newState(node);
int ttype = g.getTokenType(node.getText());
left.addTransition(new AtomTransition(right, ttype));
node.atnState = left;
return new Handle(left, right);
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
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}.
*/
@NotNull
@Override
public Handle action(@NotNull 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.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method rule.
/* start->ruleblock->end */
@NotNull
@Override
public Handle rule(@NotNull GrammarAST ruleAST, @NotNull String name, @NotNull Handle blk) {
Rule r = g.getRule(name);
RuleStartState start = atn.ruleToStartState[r.index];
epsilon(start, blk.left);
RuleStopState stop = atn.ruleToStopState[r.index];
epsilon(blk.right, stop);
Handle h = new Handle(start, stop);
// ATNPrinter ser = new ATNPrinter(g, h.left);
// System.out.println(ruleAST.toStringTree()+":\n"+ser.asString());
ruleAST.atnState = start;
return h;
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method _ruleRef.
@NotNull
public Handle _ruleRef(@NotNull GrammarAST node) {
Rule r = g.getRule(node.getText());
if (r == null) {
g.tool.errMgr.grammarError(ErrorType.INTERNAL_ERROR, g.fileName, node.getToken(), "Rule " + node.getText() + " undefined");
return null;
}
RuleStartState start = atn.ruleToStartState[r.index];
ATNState left = newState(node);
ATNState right = newState(node);
int precedence = 0;
if (((GrammarASTWithOptions) node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
precedence = Integer.parseInt(((GrammarASTWithOptions) node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
}
RuleTransition call = new RuleTransition(start, r.index, precedence, right);
left.addTransition(call);
node.atnState = left;
return new Handle(left, right);
}
Aggregations