use of org.antlr.v4.runtime.misc.NotNull in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportNoViableAlternative.
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) {
TokenStream tokens = recognizer.getInputStream();
String input;
if (tokens instanceof TokenStream) {
if (e.getStartToken().getType() == Token.EOF)
input = "<文件尾>";
else
input = tokens.getText(e.getStartToken(), e.getOffendingToken());
} else {
input = "<未知输入>";
}
BeetlException exception = null;
if (keys.contains(e.getOffendingToken().getText())) {
exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, "不允许" + e.getOffendingToken().getText() + "关键出现在这里" + ":" + escapeWSAndQuote(input), e);
} else {
exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, escapeWSAndQuote(input), e);
}
// String msg = "no viable alternative at input " + escapeWSAndQuote(input);
exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
throw exception;
}
use of org.antlr.v4.runtime.misc.NotNull in project ihmc-pub-sub by ihmcrobotics.
the class DefaultErrorStrategy method reportUnwantedToken.
@Override
protected void reportUnwantedToken(@NotNull Parser recognizer) {
if (inErrorRecoveryMode(recognizer)) {
return;
}
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = getTokenErrorDisplay(t);
String msg = "Unexpected input " + ColorMessage.bold(tokenName);
recognizer.notifyErrorListeners(t, msg, null);
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method _createATN.
protected void _createATN(@NotNull Collection<Rule> rules) {
createRuleStartAndStopATNStates();
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
for (Rule r : rules) {
// find rule's block
GrammarAST blk = (GrammarAST) r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor, blk);
ATNBuilder b = new ATNBuilder(nodes, this);
try {
setCurrentRuleName(r.name);
Handle h = b.ruleBlock(null);
rule(r.ast, r.name, h);
} catch (RecognitionException re) {
ErrorManager.fatalInternalError("bad grammar AST structure", re);
}
}
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method set.
/**
* From set build single edge graph {@code o->o-set->o}. To conform to
* what an alt block looks like, must have extra state on left.
* This also handles {@code ~A}, converted to {@code ~{A}} set.
*/
@NotNull
@Override
public Handle set(@NotNull GrammarAST associatedAST, @NotNull List<GrammarAST> terminals, boolean invert) {
ATNState left = newState(associatedAST);
ATNState right = newState(associatedAST);
IntervalSet set = new IntervalSet();
for (GrammarAST t : terminals) {
int ttype = g.getTokenType(t.getText());
set.add(ttype);
}
if (invert) {
left.addTransition(new NotSetTransition(right, set));
} else {
left.addTransition(new SetTransition(right, set));
}
associatedAST.atnState = left;
return new Handle(left, right);
}
use of org.antlr.v4.runtime.misc.NotNull in project antlr4 by tunnelvisionlabs.
the class ParserATNFactory method newState.
@NotNull
public ATNState newState(@Nullable GrammarAST node) {
ATNState n = new BasicState();
n.setRuleIndex(currentRule.index);
atn.addState(n);
return n;
}
Aggregations