use of org.antlr.v4.runtime.Recognizer in project kalang by kasonyang.
the class AntlrErrorString method noViableAlt.
public static String noViableAlt(Parser recognizer, NoViableAltException e) {
TokenStream tokens = recognizer.getInputStream();
String input = null;
if (tokens != null) {
Token startToken = e.getStartToken();
if (startToken.getType() == Token.EOF) {
input = "<EOF>";
} else {
input = tokens.getText(startToken, e.getOffendingToken());
}
}
return "syntax error at input:" + input;
}
use of org.antlr.v4.runtime.Recognizer in project ksql by confluentinc.
the class KsqlParserErrorStrategy method reportUnwantedToken.
protected void reportUnwantedToken(Parser recognizer) {
if (!this.inErrorRecoveryMode(recognizer)) {
this.beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = this.getTokenErrorDisplay(t);
IntervalSet expecting = this.getExpectedTokens(recognizer);
String msg = "extraneous input " + tokenName + " expecting " + expecting.toString(recognizer.getVocabulary());
recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
}
}
use of org.antlr.v4.runtime.Recognizer in project batfish by batfish.
the class BatfishANTLRErrorStrategy method consumeBlocksUntilWanted.
/**
* Consume all tokens a whole line at a time until the next token is one expected by the current
* rule. Each line (as delimited by supplied separator token) starting from the current line up to
* the last line consumed is placed in an {@link ErrorNode} and inserted as a child of the current
* rule.
*
* @param recognizer The {@link Parser} to whom to delegate creation of each {@link ErrorNode}
*/
private void consumeBlocksUntilWanted(Parser recognizer) {
IntervalSet expecting = recognizer.getExpectedTokens();
IntervalSet whatFollowsLoopIterationOrRule = expecting.or(getErrorRecoverySet(recognizer));
int nextToken;
do {
// Eat tokens until we are at the end of the line
consumeUntilEndOfLine(recognizer);
// Get the line number and separator text from the separator token
Token separatorToken = recognizer.getCurrentToken();
// Insert the current line as an {@link ErrorNode} as a child of the current rule
createErrorNode(recognizer, recognizer.getContext(), separatorToken);
// Eat the separator token
recognizer.consume();
nextToken = recognizer.getInputStream().LA(1);
} while (!whatFollowsLoopIterationOrRule.contains(nextToken) && nextToken != Lexer.EOF);
}
use of org.antlr.v4.runtime.Recognizer in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportUnwantedToken.
protected void reportUnwantedToken(@NotNull Parser recognizer) {
if (inErrorRecoveryMode(recognizer)) {
return;
}
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = getTokenErrorDisplay(t);
IntervalSet expecting = getExpectedTokens(recognizer);
String msg = "多余输入 " + tokenName + " 期望 " + expecting.toString(recognizer.getTokenNames());
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg);
// exception.token = this.getGrammarToken(t);
exception.pushToken(this.getGrammarToken(t));
throw exception;
}
use of org.antlr.v4.runtime.Recognizer in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportInputMismatch.
protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e) {
Token t1 = recognizer.getInputStream().LT(-1);
String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 " + e.getExpectedTokens().toString(recognizer.getTokenNames());
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
// exception.token = this.getGrammarToken(e.getOffendingToken());
exception.pushToken(this.getGrammarToken(t1));
throw exception;
}
Aggregations