use of org.antlr.v4.runtime.Recognizer in project titan.EclipsePlug-ins by eclipse.
the class TitanListener method syntaxError.
@Override
public void syntaxError(@NotNull final Recognizer<?, ?> recognizer, @Nullable final Object offendingSymbol, final int line, final int charPositionInLine, @NotNull final String msg, @Nullable final RecognitionException e) {
SyntacticErrorStorage errorStorage;
if (offendingSymbol instanceof CommonToken) {
final CommonToken token = (CommonToken) offendingSymbol;
errorStorage = new SyntacticErrorStorage(line, token.getStartIndex(), token.getStopIndex() + 1, msg, e);
} else {
errorStorage = new SyntacticErrorStorage(line, charPositionInLine, charPositionInLine + 1, msg, e);
}
errorsStored.add(errorStorage);
}
use of org.antlr.v4.runtime.Recognizer 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.Recognizer in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportError.
@Override
public void reportError(Parser recognizer, RecognitionException e) {
// yet successfully, don't report any errors.
if (inErrorRecoveryMode(recognizer)) {
// don't report spurious errors
return;
}
beginErrorCondition(recognizer);
if (e instanceof NoViableAltException) {
reportNoViableAlternative(recognizer, (NoViableAltException) e);
} else if (e instanceof InputMismatchException) {
reportInputMismatch(recognizer, (InputMismatchException) e);
} else if (e instanceof FailedPredicateException) {
reportFailedPredicate(recognizer, (FailedPredicateException) e);
} else {
// System.err.println("unknown recognition error type: " + e.getClass().getName());
BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
// exception.token = this.getGrammarToken(e.getOffendingToken());
exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
throw exception;
}
}
use of org.antlr.v4.runtime.Recognizer 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.Recognizer in project kripton by xcesco.
the class MigrationSQLChecker method prepareParser.
protected Pair<ParserRuleContext, CommonTokenStream> prepareParser(final String jql) {
JqlLexer lexer = new JqlLexer(CharStreams.fromString(jql));
CommonTokenStream tokens = new CommonTokenStream(lexer);
JqlParser parser = new JqlParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new JQLBaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
AssertKripton.assertTrue(false, "unespected char at pos %s of SQL '%s'", charPositionInLine, jql);
}
});
ParserRuleContext context = parser.parse();
return new Pair<>(context, tokens);
}
Aggregations