HHH-14148 Fix ANTLR grammar non-determinism

This commit is contained in:
Christian Beikov 2020-09-14 12:35:33 +02:00
parent 886083ab77
commit 20e5a5659b
1 changed files with 5 additions and 8 deletions

View File

@ -146,7 +146,7 @@ selectStatement
from
( #(WHERE { out(" where "); } whereExpr ) )?
( #(GROUP { out(" group by "); } groupExprs ( #(HAVING { out(" having "); } booleanExpr[false]) )? ) )?
( #(ORDER { out(" order by "); } orderBySqlFragmentOrExprs ) )?
( #(ORDER { out(" order by "); } orderExprs ) )?
)
;
@ -191,18 +191,15 @@ whereClauseExpr
| booleanExpr[ false ]
;
orderBySqlFragmentOrExprs
: sqlToken // for the purpose of mapping-defined orderBy SQL fragment
| orderExprs
;
orderExprs { String ordExp = null; String ordDir = null; String ordNul = null; }
// TODO: remove goofy space before the comma when we don't have to regression test anymore.
// Dialect is provided a hook to render each ORDER BY element, so the expression is being captured instead of
// printing to the SQL output directly. See Dialect#renderOrderByElement(String, String, String, NullPrecedence).
: { captureExpressionStart(); } ( expr ) { captureExpressionFinish(); ordExp = resetCapture(); }
: { captureExpressionStart(); } ( e:expr ) { captureExpressionFinish(); ordExp = resetCapture(); }
(dir:orderDirection { ordDir = #dir.getText(); })? (ordNul=nullOrdering)?
{ out( renderOrderByElement( ordExp, ordDir, ordNul ) ); }
// SQL Tokens without a direction and null ordering can be passed through as-is.
// These tokens could be mapping defined order by fragments which are already rendered via the dialect hook
{ out( #e.getType() == SQL_TOKEN && ordDir == null && ordNul == null ? ordExp : renderOrderByElement( ordExp, ordDir, ordNul ) ); }
( {out(", "); } orderExprs )?
;