use of org.antlr.runtime.NoViableAltException in project drools by kiegroup.
the class DSLMapParser method key_sentence.
// $ANTLR start "key_sentence"
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:154:1: key_sentence : ( variable_definition |cb= key_chunk -> VT_LITERAL[$cb.start, text] );
public final DSLMapParser.key_sentence_return key_sentence() throws RecognitionException {
DSLMapParser.key_sentence_return retval = new DSLMapParser.key_sentence_return();
retval.start = input.LT(1);
Object root_0 = null;
ParserRuleReturnScope cb = null;
ParserRuleReturnScope variable_definition16 = null;
RewriteRuleSubtreeStream stream_key_chunk = new RewriteRuleSubtreeStream(adaptor, "rule key_chunk");
String text = "";
try {
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:158:5: ( variable_definition |cb= key_chunk -> VT_LITERAL[$cb.start, text] )
int alt9 = 2;
int LA9_0 = input.LA(1);
if ((LA9_0 == LEFT_CURLY)) {
alt9 = 1;
} else if ((LA9_0 == COLON || (LA9_0 >= LEFT_SQUARE && LA9_0 <= LITERAL) || LA9_0 == RIGHT_SQUARE)) {
alt9 = 2;
} else {
if (state.backtracking > 0) {
state.failed = true;
return retval;
}
NoViableAltException nvae = new NoViableAltException("", 9, 0, input);
throw nvae;
}
switch(alt9) {
case 1:
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:158:7: variable_definition
{
root_0 = (Object) adaptor.nil();
pushFollow(FOLLOW_variable_definition_in_key_sentence608);
variable_definition16 = variable_definition();
state._fsp--;
if (state.failed)
return retval;
if (state.backtracking == 0)
adaptor.addChild(root_0, variable_definition16.getTree());
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:159:7: cb= key_chunk
{
pushFollow(FOLLOW_key_chunk_in_key_sentence618);
cb = key_chunk();
state._fsp--;
if (state.failed)
return retval;
if (state.backtracking == 0)
stream_key_chunk.add(cb.getTree());
if (state.backtracking == 0) {
text = (cb != null ? input.toString(cb.start, cb.stop) : null);
}
// wildcard labels:
if (state.backtracking == 0) {
retval.tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.getTree() : null);
root_0 = (Object) adaptor.nil();
// 160:5: -> VT_LITERAL[$cb.start, text]
{
adaptor.addChild(root_0, (Object) adaptor.create(VT_LITERAL, (cb != null ? (cb.start) : null), text));
}
retval.tree = root_0;
}
}
break;
}
retval.stop = input.LT(-1);
if (state.backtracking == 0) {
retval.tree = (Object) adaptor.rulePostProcessing(root_0);
adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);
} finally {
// do for sure before leaving
}
return retval;
}
use of org.antlr.runtime.NoViableAltException 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