use of org.antlr.runtime.UnwantedTokenException in project phoenix by apache.
the class PhoenixParserException method getErrorMessage.
public static String getErrorMessage(Throwable e, String[] tokenNames) {
String msg;
if (e instanceof MissingTokenException) {
MissingTokenException mte = (MissingTokenException) e;
String tokenName;
if (mte.expecting == Token.EOF) {
tokenName = "EOF";
} else {
tokenName = tokenNames[mte.expecting];
}
msg = "Missing \"" + tokenName + "\" at " + getTokenLocation(mte);
} else if (e instanceof UnwantedTokenException) {
UnwantedTokenException ute = (UnwantedTokenException) e;
String tokenName;
if (ute.expecting == Token.EOF) {
tokenName = "EOF";
} else {
tokenName = tokenNames[ute.expecting];
}
msg = "Unexpected input. Expecting \"" + tokenName + "\", got \"" + ute.getUnexpectedToken().getText() + "\" at " + getTokenLocation(ute);
} else if (e instanceof MismatchedTokenException) {
MismatchedTokenException mte = (MismatchedTokenException) e;
String tokenName;
if (mte.expecting == Token.EOF) {
tokenName = "EOF";
} else {
tokenName = tokenNames[mte.expecting];
}
msg = "Mismatched input. Expecting \"" + tokenName + "\", got \"" + mte.token.getText() + "\" at " + getTokenLocation(mte);
} else if (e instanceof RecognitionException) {
RecognitionException re = (RecognitionException) e;
msg = "Encountered \"" + re.token.getText() + "\" at " + getTokenLocation(re);
} else if (e instanceof UnknownFunctionException) {
UnknownFunctionException ufe = (UnknownFunctionException) e;
msg = "Unknown function: \"" + ufe.getFuncName() + "\".";
} else {
msg = e.getMessage();
}
return msg;
}
Aggregations