use of org.antlr.runtime.MismatchedNotSetException in project drools by kiegroup.
the class DroolsParserExceptionFactory method createErrorMessage.
/**
* This will take a RecognitionException, and create a sensible error
* message out of it
*/
private List<String> createErrorMessage(RecognitionException e) {
List<String> codeAndMessage = new ArrayList<String>(2);
String message;
if (e instanceof MismatchedTokenException) {
MismatchedTokenException mte = (MismatchedTokenException) e;
String expecting = mte instanceof DroolsMismatchedTokenException ? ((DroolsMismatchedTokenException) mte).getTokenText() : getBetterToken(mte.expecting);
if (tokenNames != null && mte.expecting >= 0 && mte.expecting < tokenNames.length) {
message = String.format(MISMATCHED_TOKEN_MESSAGE_COMPLETE, e.line, e.charPositionInLine, getBetterToken(e.token), expecting, formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 102");
} else {
message = String.format(MISMATCHED_TOKEN_MESSAGE_PART, e.line, e.charPositionInLine, getBetterToken(e.token), formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 102");
}
} else if (e instanceof MismatchedTreeNodeException) {
MismatchedTreeNodeException mtne = (MismatchedTreeNodeException) e;
if (mtne.expecting >= 0 && mtne.expecting < tokenNames.length) {
message = String.format(MISMATCHED_TREE_NODE_MESSAGE_COMPLETE, e.line, e.charPositionInLine, getBetterToken(e.token), getBetterToken(mtne.expecting), formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 106");
} else {
message = String.format(MISMATCHED_TREE_NODE_MESSAGE_PART, e.line, e.charPositionInLine, getBetterToken(e.token), formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 106");
}
} else if (e instanceof NoViableAltException) {
// NoViableAltException nvae = (NoViableAltException) e;
message = String.format(NO_VIABLE_ALT_MESSAGE, e.line, e.charPositionInLine, getBetterToken(e.token), formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 101");
} else if (e instanceof EarlyExitException) {
// EarlyExitException eee = (EarlyExitException) e;
message = String.format(EARLY_EXIT_MESSAGE, e.line, e.charPositionInLine, getBetterToken(e.token), formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 105");
} else if (e instanceof MismatchedSetException) {
MismatchedSetException mse = (MismatchedSetException) e;
String expected = expectedTokensAsString(mse.expecting);
message = String.format(MISMATCHED_SET_MESSAGE, e.line, e.charPositionInLine, getBetterToken(e.token), expected, formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 107");
} else if (e instanceof DroolsMismatchedSetException) {
DroolsMismatchedSetException mse = (DroolsMismatchedSetException) e;
String expected = Arrays.asList(mse.getTokenText()).toString();
message = String.format(MISMATCHED_SET_MESSAGE, e.line, e.charPositionInLine, getBetterToken(e.token), expected, formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 107");
} else if (e instanceof MismatchedNotSetException) {
MismatchedNotSetException mse = (MismatchedNotSetException) e;
String expected = expectedTokensAsString(mse.expecting);
message = String.format(MISMATCHED_NOT_SET_MESSAGE, e.line, e.charPositionInLine, getBetterToken(e.token), expected, formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 108");
} else if (e instanceof FailedPredicateException) {
FailedPredicateException fpe = (FailedPredicateException) e;
message = String.format(FAILED_PREDICATE_MESSAGE, e.line, e.charPositionInLine, fpe.ruleName, fpe.predicateText, formatParserLocation());
codeAndMessage.add(message);
codeAndMessage.add("ERR 103");
}
if (codeAndMessage.get(0).length() == 0) {
codeAndMessage.add("?????");
}
return codeAndMessage;
}
Aggregations