44 */
55package org .hibernate .query .hql .internal ;
66
7- import java .util .BitSet ;
8-
97import org .antlr .v4 .runtime .CommonToken ;
108import org .antlr .v4 .runtime .InputMismatchException ;
119import org .antlr .v4 .runtime .NoViableAltException ;
2927
3028import org .antlr .v4 .runtime .ANTLRErrorListener ;
3129import org .antlr .v4 .runtime .BailErrorStrategy ;
30+ import org .antlr .v4 .runtime .BaseErrorListener ;
3231import org .antlr .v4 .runtime .DefaultErrorStrategy ;
33- import org .antlr .v4 .runtime .Parser ;
3432import org .antlr .v4 .runtime .RecognitionException ;
3533import org .antlr .v4 .runtime .Recognizer ;
36- import org .antlr .v4 .runtime .atn .ATNConfigSet ;
3734import org .antlr .v4 .runtime .atn .PredictionMode ;
38- import org .antlr .v4 .runtime .dfa .DFA ;
3935import org .antlr .v4 .runtime .misc .ParseCancellationException ;
4036
4137import static java .util .stream .Collectors .toList ;
@@ -50,7 +46,6 @@ public class StandardHqlTranslator implements HqlTranslator {
5046 private final SqmCreationContext sqmCreationContext ;
5147 private final SqmCreationOptions sqmCreationOptions ;
5248
53-
5449 public StandardHqlTranslator (
5550 SqmCreationContext sqmCreationContext ,
5651 SqmCreationOptions sqmCreationOptions ) {
@@ -101,30 +96,9 @@ private HqlParser.StatementContext parseHql(String hql) {
10196 // Build the parse tree
10297 final HqlParser hqlParser = HqlParseTreeBuilder .INSTANCE .buildHqlParser ( hql , hqlLexer );
10398
104- ANTLRErrorListener errorListener = new ANTLRErrorListener () {
105- @ Override
106- public void syntaxError (Recognizer <?, ?> recognizer , Object offendingSymbol , int line , int charPositionInLine , String msg , RecognitionException e ) {
107- throw new SyntaxException ( prettifyAntlrError ( offendingSymbol , line , charPositionInLine , msg , e , hql , true ), hql );
108- }
109-
110- @ Override
111- public void reportAmbiguity (Parser recognizer , DFA dfa , int startIndex , int stopIndex , boolean exact , BitSet ambigAlts , ATNConfigSet configs ) {
112- }
113-
114- @ Override
115- public void reportAttemptingFullContext (Parser recognizer , DFA dfa , int startIndex , int stopIndex , BitSet conflictingAlts , ATNConfigSet configs ) {
116- }
117-
118- @ Override
119- public void reportContextSensitivity (Parser recognizer , DFA dfa , int startIndex , int stopIndex , int prediction , ATNConfigSet configs ) {
120- }
121- };
122-
12399 // try to use SLL(k)-based parsing first - its faster
124- hqlLexer .addErrorListener ( errorListener );
125100 hqlParser .getInterpreter ().setPredictionMode ( PredictionMode .SLL );
126101 hqlParser .removeErrorListeners ();
127- hqlParser .addErrorListener ( errorListener );
128102 hqlParser .setErrorHandler ( new BailErrorStrategy () );
129103
130104 try {
@@ -139,6 +113,14 @@ public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex,
139113 hqlParser .getInterpreter ().setPredictionMode ( PredictionMode .LL );
140114 hqlParser .setErrorHandler ( new DefaultErrorStrategy () );
141115
116+ final ANTLRErrorListener errorListener = new BaseErrorListener () {
117+ @ Override
118+ public void syntaxError (Recognizer <?, ?> recognizer , Object offendingSymbol , int line , int charPositionInLine , String msg , RecognitionException e ) {
119+ throw new SyntaxException ( prettifyAntlrError ( offendingSymbol , line , charPositionInLine , msg , e , hql , true ), hql );
120+ }
121+ };
122+ hqlParser .addErrorListener ( errorListener );
123+
142124 return hqlParser .statement ();
143125 }
144126 catch ( ParsingException ex ) {
0 commit comments