Skip to content

Match MySQL operator precedence for XOR and bitwise operators - #2838

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
princejain756:mysql-operator-precedence
Oct 22, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
princejain756:mysql-operator-precedence

Conversation

@princejain756

Copy link
Copy Markdown
Contributor

Summary

The Pratt expression loops give XOR the same precedence as OR and place |, &, <<, >> on one left-associative level, in every dialect. MySQL's table differs on both counts:

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 MySQL SimpleExpression now enters the arithmetic loop at floor 2 so | is admitted at all.

One subtlety this uncovered: the javacc plugin can leave target/generated-sources stale across incremental compiles, which made the fix look broken locally until a full regen.

Test plan

  • 1 | 2 & 4 under MySQL parses as BitwiseOr(1, BitwiseAnd(2, 4))
  • 3 & 1 << 2 under MySQL parses as BitwiseAnd(3, BitwiseLeftShift(1, 2))
  • 1 OR 1 XOR 1 under MySQL parses as OrExpression(1, XorExpression(1, 1))
  • 1 XOR 1 AND 1 under MySQL parses as XorExpression(1, AndExpression(1, 1))
  • Default dialect 4 | 1 & 0 still parses as (4 | 1) & 0 (fix: bind bitwise operators looser than + and - #2833 test intact)
  • New regression tests in ExpressionPrecedenceTest
  • Full suite: 10,663 tests, 0 failures

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
@manticore-projects
manticore-projects merged commit bfafeaa into JSQLParser:master Oct 22, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants