Skip to content

feat: add CREATE PROCEDURE grammar support#355

Merged
matthias-Q merged 3 commits intoDerekStride:mainfrom
NotMyself:feat/create-procedure
Feb 11, 2026
Merged

feat: add CREATE PROCEDURE grammar support#355
matthias-Q merged 3 commits intoDerekStride:mainfrom
NotMyself:feat/create-procedure

Conversation

@NotMyself
Copy link
Copy Markdown

@NotMyself NotMyself commented Feb 10, 2026

Summary

  • Adds create_procedure statement rule with support for PostgreSQL (dollar-quoted bodies, OR REPLACE, LANGUAGE, SECURITY), T-SQL (AS BEGIN...END with optional DECLARE), and MySQL/MariaDB (DEFINER clause, IF NOT EXISTS)
  • Adds drop_procedure with IF EXISTS and CASCADE support
  • Resolves the // TODO: procedure in comment.js by adding COMMENT ON PROCEDURE support

Context

Filed as #354 — the original issue reported both CREATE PROCEDURE and CREATE TRIGGER as missing, but after examining the grammar, CREATE TRIGGER is already fully implemented. The real gap was CREATE PROCEDURE only (the issue has been updated with this correction).

Implementation

Mirrors the existing create-function.js pattern:

  • New file grammar/statements/create-procedure.js with create_procedure, procedure_body, and _tsql_procedure_body_statement rules
  • procedure_body reuses _function_body_statement and function_declaration from the function grammar
  • Key difference from functions: no RETURNS clause, and the T-SQL body variant doesn't require a RETURN statement

Test plan

  • tree-sitter generate succeeds with no new warnings
  • 10 new test cases in test/corpus/procedures.txt covering:
    • PostgreSQL: simple procedure, OR REPLACE, no parameters, SECURITY DEFINER
    • T-SQL: basic, with DECLARE, nested BEGIN-END
    • DROP PROCEDURE: basic, IF EXISTS, CASCADE
  • Fixed test expectations to match actual parser output:
    • integer type: use (int (keyword_int)) consistent with existing function tests
    • INSERT: include (keyword_values) node, bare field references in list (no term wrapper)
    • DELETE/SELECT: from as sibling of delete/select under statement, matching delete.txt and select.txt patterns

Closes #354

🤖 Generated with Claude Code

Add `create_procedure` statement rule supporting:
- PostgreSQL: dollar-quoted bodies, OR REPLACE, LANGUAGE, SECURITY
- T-SQL: AS BEGIN...END with optional DECLARE
- MySQL/MariaDB: DEFINER clause, IF NOT EXISTS

Also adds:
- `drop_procedure` with IF EXISTS and CASCADE support
- COMMENT ON PROCEDURE support (resolves TODO in comment.js)
- Test corpus with 10 test cases across dialects

Closes DerekStride#354

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
NotMyself and others added 2 commits February 10, 2026 13:43
- integer type: use (int (keyword_int)) instead of (keyword_integer)
- INSERT: add (keyword_values) node, remove (term value:) wrapper
- DELETE: split into (delete)/(from) siblings instead of nesting
- SELECT: move (from) out of (select) as sibling under (statement)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The object_reference grammar rule uses field('schema', ...) and
field('name', ...) for schema-qualified identifiers. The test
expectations for schema-qualified procedure names (public.refresh_cache,
dbo.GetUsers, etc.) were missing these field labels.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NotMyself
Copy link
Copy Markdown
Author

Fixed the 4 failing corpus tests (Procedure with OR REPLACE (PostgreSQL), TSQL procedure, TSQL procedure with DECLARE, TSQL procedure with nested BEGIN-END).

The issue was that test expectations for schema-qualified procedure names (e.g. public.refresh_cache, dbo.GetUsers) were missing field labels on the object_reference node. The grammar defines object_reference with field('schema', ...) and field('name', ...) for two-part identifiers, so the parser produces schema: (identifier) and name: (identifier) — but the tests expected bare (identifier) nodes without field labels.

Copy link
Copy Markdown
Collaborator

@matthias-Q matthias-Q 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 for the PR.

@matthias-Q matthias-Q merged commit f548094 into DerekStride:main Feb 11, 2026
4 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.

Missing grammar support for CREATE PROCEDURE and CREATE TRIGGER

2 participants