use of antlr.MismatchedTokenException in project hibernate-orm by hibernate.
the class HqlParser method handleIdentifierError.
/**
* Overrides the base behavior to retry keywords as identifiers.
*
* @param token The token.
* @param ex The recognition exception.
*
* @return AST - The new AST.
*
* @throws antlr.RecognitionException if the substitution was not possible.
* @throws antlr.TokenStreamException if the substitution was not possible.
*/
@Override
public AST handleIdentifierError(Token token, RecognitionException ex) throws RecognitionException, TokenStreamException {
// If the token can tell us if it could be an identifier...
if (token instanceof HqlToken) {
HqlToken hqlToken = (HqlToken) token;
// a mismatched token error ...
if (hqlToken.isPossibleID() && (ex instanceof MismatchedTokenException)) {
MismatchedTokenException mte = (MismatchedTokenException) ex;
// ... and the expected token type was an identifier, then:
if (mte.expecting == HqlTokenTypes.IDENT) {
// Use the token as an identifier.
reportWarning("Keyword '" + token.getText() + "' is being interpreted as an identifier due to: " + mte.getMessage());
// Add the token to the AST.
ASTPair currentAST = new ASTPair();
token.setType(HqlTokenTypes.WEIRD_IDENT);
astFactory.addASTChild(currentAST, astFactory.create(token));
consume();
return currentAST.root;
}
}
// if
}
// Otherwise, handle the error normally.
return super.handleIdentifierError(token, ex);
}
use of antlr.MismatchedTokenException in project groovy-core by groovy.
the class SourceUnit method failedWithUnexpectedEOF.
/**
* Convenience routine, primarily for use by the InteractiveShell,
* that returns true if parse() failed with an unexpected EOF.
*/
public boolean failedWithUnexpectedEOF() {
// If you find another way, please add it.
if (getErrorCollector().hasErrors()) {
Message last = (Message) getErrorCollector().getLastError();
Throwable cause = null;
if (last instanceof SyntaxErrorMessage) {
cause = ((SyntaxErrorMessage) last).getCause().getCause();
}
if (cause != null) {
if (cause instanceof NoViableAltException) {
return isEofToken(((NoViableAltException) cause).token);
} else if (cause instanceof NoViableAltForCharException) {
char badChar = ((NoViableAltForCharException) cause).foundChar;
return badChar == CharScanner.EOF_CHAR;
} else if (cause instanceof MismatchedCharException) {
char badChar = (char) ((MismatchedCharException) cause).foundChar;
return badChar == CharScanner.EOF_CHAR;
} else if (cause instanceof MismatchedTokenException) {
return isEofToken(((MismatchedTokenException) cause).token);
}
}
}
return false;
}
use of antlr.MismatchedTokenException in project groovy by apache.
the class SourceUnit method failedWithUnexpectedEOF.
/**
* Convenience routine, primarily for use by the InteractiveShell,
* that returns true if parse() failed with an unexpected EOF.
*/
public boolean failedWithUnexpectedEOF() {
// If you find another way, please add it.
if (getErrorCollector().hasErrors()) {
Message last = (Message) getErrorCollector().getLastError();
Throwable cause = null;
if (last instanceof SyntaxErrorMessage) {
cause = ((SyntaxErrorMessage) last).getCause().getCause();
}
if (cause != null) {
if (cause instanceof NoViableAltException) {
return isEofToken(((NoViableAltException) cause).token);
} else if (cause instanceof NoViableAltForCharException) {
char badChar = ((NoViableAltForCharException) cause).foundChar;
return badChar == CharScanner.EOF_CHAR;
} else if (cause instanceof MismatchedCharException) {
char badChar = (char) ((MismatchedCharException) cause).foundChar;
return badChar == CharScanner.EOF_CHAR;
} else if (cause instanceof MismatchedTokenException) {
return isEofToken(((MismatchedTokenException) cause).token);
}
}
}
return false;
}
Aggregations