antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.25k stars 3.72k forks source link

[postgresql] Fix for #4332 -- fix ambiguity with '=' (rewrite Floyd operator precedence grammar) #4334

Closed kaby76 closed 4 days ago

kaby76 commented 6 days ago

This is a fix for #4332.

The problem raised in the issue was the ambiguity with select * from tmptz where f1 at time zone 'utc' = '2017-01-18 00:00';. But, the problem was the haphazard implementation of the operator precedence grammar for a_expr.

I rewrote the rules associated with a_expr to use the Antlr style for expressions, fixing the ambiguity. In addition, the parse trees for expressions are much more concise. I will need to unfold c_expr into a_expr and refactor the order of alts to correspond to the correct precedence--and remove ambiguity that I introduced with the rewrite of a_expr. This is important because Antlr does not implement precedence like Bison. Some of the alts for a_expr were removed because they overlapped with those in c_expr.

Not only are the trees much smaller, but it is also a little faster, taking ~7s for the examples/ test suite vs. ~8s before this PR.

To do: Add expression tests with parse trees.

kaby76 commented 4 days ago

Added a bunch of ambiguity. Will need to clean up before submitting.