Repository navigation
Match MySQL operator precedence for XOR and bitwise operators - #2838
Merged
manticore-projects merged 1 commit intoOct 22, 2026
Merged
manticore-projects merged 1 commit into
manticore-projects merged 1 commit into
Conversation
XOR sat on the same level as OR, and |, &, <<, >> shared one left-associative level, in every dialect. MySQL puts XOR between AND and OR, and tiers the bitwise operators as <<, >> above & above |. Gate the tiers on Dialect.MYSQL so the default dialect keeps the shared levels established in JSQLParser#2833. SimpleExpression now enters the arithmetic loop at floor 2 under MySQL so | is admitted. Fixes JSQLParser#2834, fixes JSQLParser#2835
Contributor
|
Thank you much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Pratt expression loops give
XORthe same precedence asORand place|,&,<<,>>on one left-associative level, in every dialect. MySQL's table differs on both counts:XORsits betweenANDandOR, so1 OR 1 XOR 1must parse as1 OR (1 XOR 1)and not(1 OR 1) XOR 1(MySQL dialect gives logical XOR the same tier as OR #2835)<<and>>bind tighter than&, which binds tighter than|, so1 | 2 & 4must parse as1 | (2 & 4)and3 & 1 << 2as3 & (1 << 2)(MySQL bitwise |, &, and shifts still share one parser precedence tier #2834)Both tiers are gated on
Dialect.MYSQL. Every other dialect keeps the shared, left-associative levels that #2833 established, so the default behavior and its regression tests are untouched. Under MySQLSimpleExpressionnow enters the arithmetic loop at floor 2 so|is admitted at all.One subtlety this uncovered: the javacc plugin can leave
target/generated-sourcesstale across incremental compiles, which made the fix look broken locally until a full regen.Test plan
1 | 2 & 4under MySQL parses asBitwiseOr(1, BitwiseAnd(2, 4))3 & 1 << 2under MySQL parses asBitwiseAnd(3, BitwiseLeftShift(1, 2))1 OR 1 XOR 1under MySQL parses asOrExpression(1, XorExpression(1, 1))1 XOR 1 AND 1under MySQL parses asXorExpression(1, AndExpression(1, 1))4 | 1 & 0still parses as(4 | 1) & 0(fix: bind bitwise operators looser than + and - #2833 test intact)ExpressionPrecedenceTest