use of org.hibernate.query.sqm.ParsingException in project hibernate-orm by hibernate.
the class StandardHqlTranslator method parseHql.
private HqlParser.StatementContext parseHql(String hql) {
// Build the lexer
final HqlLexer hqlLexer = HqlParseTreeBuilder.INSTANCE.buildHqlLexer(hql);
// Build the parse tree
final HqlParser hqlParser = HqlParseTreeBuilder.INSTANCE.buildHqlParser(hql, hqlLexer);
// try to use SLL(k)-based parsing first - its faster
hqlLexer.addErrorListener(ERR_LISTENER);
hqlParser.getInterpreter().setPredictionMode(PredictionMode.SLL);
hqlParser.removeErrorListeners();
hqlParser.addErrorListener(ERR_LISTENER);
hqlParser.setErrorHandler(new BailErrorStrategy());
try {
return hqlParser.statement();
} catch (ParseCancellationException e) {
// reset the input token stream and parser state
hqlLexer.reset();
hqlParser.reset();
// fall back to LL(k)-based parsing
hqlParser.getInterpreter().setPredictionMode(PredictionMode.LL);
hqlParser.setErrorHandler(new DefaultErrorStrategy());
return hqlParser.statement();
} catch (ParsingException ex) {
throw new SemanticException("A query exception occurred", hql, ex);
}
}
Aggregations