use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class LexerATNFactory method createLexerAction.
@Nullable
private LexerAction createLexerAction(@NotNull GrammarAST ID, @Nullable GrammarAST arg) {
String command = ID.getText();
checkCommands(command, ID.getToken());
if ("skip".equals(command) && arg == null) {
return LexerSkipAction.INSTANCE;
} else if ("more".equals(command) && arg == null) {
return LexerMoreAction.INSTANCE;
} else if ("popMode".equals(command) && arg == null) {
return LexerPopModeAction.INSTANCE;
} else if ("mode".equals(command) && arg != null) {
String modeName = arg.getText();
Integer mode = getModeConstantValue(modeName, arg.getToken());
if (mode == null) {
return null;
}
return new LexerModeAction(mode);
} else if ("pushMode".equals(command) && arg != null) {
String modeName = arg.getText();
Integer mode = getModeConstantValue(modeName, arg.getToken());
if (mode == null) {
return null;
}
return new LexerPushModeAction(mode);
} else if ("type".equals(command) && arg != null) {
String typeName = arg.getText();
Integer type = getTokenConstantValue(typeName, arg.getToken());
if (type == null) {
return null;
}
return new LexerTypeAction(type);
} else if ("channel".equals(command) && arg != null) {
String channelName = arg.getText();
Integer channel = getChannelConstantValue(channelName, arg.getToken());
if (channel == null) {
return null;
}
return new LexerChannelAction(channel);
} else {
return null;
}
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method plus.
/**
* From {@code (blk)+} build
*
* <pre>
* |---------|
* v |
* [o-blk-o]->o->o
* </pre>
*
* We add a decision for loop back node to the existing one at {@code blk}
* start.
*/
@NotNull
@Override
public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
PlusBlockStartState blkStart = (PlusBlockStartState) blk.left;
BlockEndState blkEnd = (BlockEndState) blk.right;
preventEpsilonClosureBlocks.add(Tuple.create(currentRule, blkStart, blkEnd));
PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
loop.nonGreedy = !((QuantifierAST) plusAST).isGreedy();
// no way to express SLL restriction
loop.sll = false;
atn.defineDecisionState(loop);
LoopEndState end = newState(LoopEndState.class, plusAST);
blkStart.loopBackState = loop;
end.loopBackState = loop;
plusAST.atnState = loop;
// blk can see loop back
epsilon(blkEnd, loop);
BlockAST blkAST = (BlockAST) plusAST.getChild(0);
if (((QuantifierAST) plusAST).isGreedy()) {
if (expectNonGreedy(blkAST)) {
g.tool.errMgr.grammarError(ErrorType.EXPECTED_NON_GREEDY_WILDCARD_BLOCK, g.fileName, plusAST.getToken(), plusAST.getToken().getText());
}
// loop back to start
epsilon(loop, blkStart);
// or exit
epsilon(loop, end);
} else {
// if not greedy, priority to exit branch; make it first
// exit
epsilon(loop, end);
// loop back to start
epsilon(loop, blkStart);
}
return new Handle(blkStart, end);
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method wildcard.
/**
* Build an atom with all possible values in its label.
*/
@NotNull
@Override
public Handle wildcard(@NotNull GrammarAST node) {
ATNState left = newState(node);
ATNState right = newState(node);
left.addTransition(new WildcardTransition(right));
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 epsilon.
/**
* From an empty alternative build {@code o-e->o}.
*/
@NotNull
@Override
public Handle epsilon(@NotNull GrammarAST node) {
ATNState left = newState(node);
ATNState right = newState(node);
epsilon(left, right);
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 epsilon.
protected void epsilon(ATNState a, @NotNull ATNState b, boolean prepend) {
for (Transition t : a.getTransitions()) {
if (t.getSerializationType() != Transition.EPSILON) {
continue;
}
if (t.target == b && ((EpsilonTransition) t).outermostPrecedenceReturn() == -1) {
// This transition was already added
return;
}
}
if (a != null) {
int index = prepend ? 0 : a.getNumberOfTransitions();
a.addTransition(index, new EpsilonTransition(b));
}
}
Aggregations