use of org.kie.dmn.feel.runtime.events.SyntaxErrorEvent in project drools by kiegroup.
the class FEELParser method checkVariableName.
public static List<FEELEvent> checkVariableName(String source) {
if (source == null || source.isEmpty()) {
return Collections.singletonList(new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.INVALID_VARIABLE_NAME_EMPTY), null, 0, 0, null));
}
ANTLRInputStream input = new ANTLRInputStream(source);
FEEL_1_1Lexer lexer = new FEEL_1_1Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
FEEL_1_1Parser parser = new FEEL_1_1Parser(tokens);
parser.setHelper(new ParserHelper());
parser.setErrorHandler(new FEELErrorHandler());
FEELParserErrorListener errorChecker = new FEELParserErrorListener(null);
// removes the error listener that prints to the console
parser.removeErrorListeners();
parser.addErrorListener(errorChecker);
FEEL_1_1Parser.NameDefinitionContext nameDef = parser.nameDefinition();
if (!errorChecker.hasErrors() && nameDef != null && source.trim().equals(parser.getHelper().getOriginalText(nameDef))) {
return Collections.emptyList();
}
return errorChecker.getErrors();
}
use of org.kie.dmn.feel.runtime.events.SyntaxErrorEvent in project drools by kiegroup.
the class DMNFEELHelper method processEvents.
public void processEvents(DMNModelImpl model, DMNElement element, Msg.Message msg, Object... msgParams) {
Queue<FEELEvent> feelEvents = listener.getFeelEvents();
while (!feelEvents.isEmpty()) {
FEELEvent event = feelEvents.remove();
if (!isDuplicateEvent(model, msg, element)) {
if (event instanceof SyntaxErrorEvent || event.getSeverity() == FEELEvent.Severity.ERROR) {
if (msg instanceof Msg.Message2) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, element, model, null, event, (Msg.Message2) msg, msgParams[0], msgParams[1]);
} else if (msg instanceof Msg.Message3) {
Object message3 = null;
if (msgParams.length == 3) {
message3 = msgParams[2];
} else {
// wrap the originating FEEL error as the last message
message3 = event.getMessage();
}
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, element, model, null, event, (Msg.Message3) msg, msgParams[0], msgParams[1], message3);
} else if (msg instanceof Msg.Message4) {
String message = null;
if (event.getOffendingSymbol() == null) {
message = "";
} else if (event instanceof UnknownVariableErrorEvent) {
message = event.getMessage();
} else if (event.getOffendingSymbol() instanceof CommonToken) {
message = "syntax error near '" + ((CommonToken) event.getOffendingSymbol()).getText() + "'";
} else {
message = "syntax error near '" + event.getOffendingSymbol() + "'";
}
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, element, model, null, event, (Msg.Message4) msg, msgParams[0], msgParams[1], msgParams[2], message);
}
}
}
}
}
Aggregations