use of org.antlr.v4.runtime.Recognizer in project drools by kiegroup.
the class FEELParserErrorListener method syntaxError.
@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
final SyntaxErrorEvent error;
final CommonToken token = (CommonToken) offendingSymbol;
final int tokenIndex = token.getTokenIndex();
final Parser parser = (Parser) recognizer;
if (parser.getRuleInvocationStack().contains("nameDefinitionWithEOF")) {
error = generateInvalidVariableError(offendingSymbol, line, charPositionInLine, e, token);
} else if ("}".equals(token.getText()) && tokenIndex > 1 && ":".equals(parser.getTokenStream().get(tokenIndex - 1).getText())) {
error = new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.MISSING_EXPRESSION, parser.getTokenStream().get(tokenIndex - 2).getText()), e, line, charPositionInLine, offendingSymbol);
} else if (e != null && parser.getRuleInvocationStack().get(0).equals("ifExpression")) {
final List<String> expected = toList(e.getExpectedTokens(), e.getRecognizer().getVocabulary());
if (expected.contains("ELSE")) {
error = new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IF_MISSING_ELSE, token.getText(), msg), e, line, charPositionInLine, offendingSymbol);
} else if (expected.contains("THEN")) {
error = new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IF_MISSING_THEN, token.getText(), msg), e, line, charPositionInLine, offendingSymbol);
} else {
// fallback.
error = new SyntaxErrorEvent(FEELEvent.Severity.ERROR, msg, e, line, charPositionInLine, offendingSymbol);
}
} else {
error = new SyntaxErrorEvent(FEELEvent.Severity.ERROR, msg, e, line, charPositionInLine, offendingSymbol);
}
// if the event manager is set, notify listeners, otherwise store the error in the errors list
if (eventsManager != null) {
FEELEventListenersManager.notifyListeners(eventsManager, () -> error);
} else {
if (errors == null) {
errors = new ArrayList<>();
}
errors.add(error);
}
}
Aggregations