Fix expression precedence while preserving explicit parentheses - #326
Merged
Merged
Conversation
Bind unary signs after postfix access and casts, associate comparisons and membership at the same level, and allow comparisons in BETWEEN bounds. Keep postfix access outside cast targets. Share operator precedence with the formatter and add parentheses where needed to preserve constructed or edited expression trees in both modes. Keep existing public AST types and precedence constant values. Add parser, formatter, edited-AST, and golden regression tests. Verify 45 expression cases against ClickHouse 26.7.1.1315. Pass make test, make lint, and make with Go 1.21.13.
git-hulk
commented
Sep 14, 2026
git-hulk
marked this pull request as ready for review
September 14, 2026 06:10
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Problem
Unary signs bind before postfix operations, comparisons and membership bind at different levels, and cast targets consume following array access. These produce expression trees that disagree with ClickHouse. BETWEEN bounds also reject comparisons that ClickHouse accepts.
Reproduction
Fix
Centralize operator binding levels and correct unary/postfix, comparison/membership, cast, and BETWEEN parsing. Preserve public AST types and existing precedence constant values.
Formatting retains explicit parentheses from the SQL without inferring additional parentheses from the expression tree. Callers constructing or editing an AST must supply explicit grouping nodes when needed. Unary signs are written directly beside their operands, retaining a space between consecutive minus signs to avoid a line comment. Keyword operators retain their separating space.
Test
TestFormatter_ExplicitExpressionParenthesesto check source parentheses and unary-sign spacing in compact and beautified formatting, including nested negation and signed numeric operands, andTestFormatter_EditedExpressionRequiresExplicitParenthesesto verify the caller supplies grouping.make test(race and compatibility checks) andmake lint(CI-pinned golangci-lint v1.53.3) with Go 1.21.13.