use of antlr.ASTPair 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.ASTPair in project hibernate-orm by hibernate.
the class HqlParser method matchOptionalFrom.
@Override
public void matchOptionalFrom() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST optionalFrom_AST = null;
if (LA(1) == FROM) {
if (LA(2) != DOT) {
match(FROM);
optionalFrom_AST = (AST) currentAST.root;
returnAST = optionalFrom_AST;
}
}
}
Aggregations