Skip to content

Add CASE expression support to tree-sitter grammar#432

Merged
georgestagg merged 1 commit intoposit-dev:mainfrom
cpsievert:fix/431-case-expression-grammar
May 7, 2026
Merged

Add CASE expression support to tree-sitter grammar#432
georgestagg merged 1 commit intoposit-dev:mainfrom
cpsievert:fix/431-case-expression-grammar

Conversation

@cpsievert
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a structural case_expression rule that brackets CASE...END, preventing END from being consumed as a bare identifier inside function arguments
  • Follows the same prec(3) bracketing pattern used by cast_expression
  • Adds case_expression to from_statement, select_body, subquery_body, and position_arg (all positions where cast_expression already exists)

Fixes #431

Test plan

  • 6 new corpus tests: basic CASE in aggregate, CASE with ELSE, CASE in select list, nested CASE, CASE with IN list, CASE inside ROUND inside aggregate
  • All 82 tree-sitter corpus tests pass
  • All 1,449 Rust workspace tests pass
  • Manually verified the exact example from CASE...END inside function arguments produces parse errors #431 parses without errors
  • Verified edge cases: simple CASE form (CASE x WHEN...), function calls inside CASE conditions, BETWEEN inside CASE

Fixes posit-dev#431 — CASE...END inside function arguments (e.g.
COUNT(CASE WHEN x = 1 THEN 1 END)) previously caused parse errors
because END was consumed as a bare identifier. Adds a structural
case_expression rule that brackets CASE...END, preventing its interior
tokens from leaking into the enclosing function_call.

This comment was marked as resolved.

Copy link
Copy Markdown
Collaborator

@georgestagg georgestagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@georgestagg georgestagg merged commit 23c50f1 into posit-dev:main May 7, 2026
6 checks passed
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.

CASE...END inside function arguments produces parse errors

3 participants