Skip to content

fix(parser): support CAST and TRY_CAST expressions#113

Merged
thomasp85 merged 3 commits intoposit-dev:mainfrom
cpsievert:fix/parser-cast-expression
Feb 18, 2026
Merged

fix(parser): support CAST and TRY_CAST expressions#113
thomasp85 merged 3 commits intoposit-dev:mainfrom
cpsievert:fix/parser-cast-expression

Conversation

@cpsievert
Copy link
Collaborator

Summary

  • Adds a dedicated cast_expression rule to handle CAST(expr AS type) and TRY_CAST(expr AS type) syntax
  • Previously these were parsed as regular function calls, which failed because the AS keyword inside function arguments was unexpected
  • The rule is added to select_body, subquery_body, and positional_arg so casts work at top level, in subqueries, and nested inside function arguments (e.g. SUM(CAST(x AS INT)))

Test plan

  • All 56 existing tree-sitter corpus tests pass
  • 2 new corpus tests added: CAST expression and TRY_CAST nested in function argument
  • Verified original failing queries from ggsqlbot now parse without errors

🤖 Generated with Claude Code

Add a dedicated cast_expression rule to handle CAST(expr AS type) and
TRY_CAST(expr AS type) syntax. Previously these were parsed as regular
function calls, which failed because the AS keyword inside function
arguments was unexpected.

The cast_expression rule is added to select_body, subquery_body, and
positional_arg so casts work at top level, in subqueries, and nested
inside function arguments (e.g. SUM(CAST(x AS INT))).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
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, once the merge conflict is resolved.

…ssion

# Conflicts:
#	tree-sitter-ggsql/test/corpus/basic.txt
@cpsievert cpsievert force-pushed the fix/parser-cast-expression branch from 350424c to e79da48 Compare February 17, 2026 23:29
@thomasp85 thomasp85 merged commit 60fdab5 into posit-dev:main Feb 18, 2026
3 checks passed
@thomasp85
Copy link
Collaborator

Thanks!

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.

3 participants