Skip to content

Add InterBase SQL support in focused parser and highlighting changes - #378

Closed
AntoineGS wants to merge 5 commits into
DerekStride:mainfrom
AntoineGS:feat/interbase-sql
Closed

AntoineGS wants to merge 5 commits into
DerekStride:mainfrom
AntoineGS:feat/interbase-sql

Conversation

@AntoineGS

Copy link
Copy Markdown

Summary

Add InterBase procedural SQL support while reusing the existing expression, type, and DML grammar. This is a draft for review of the dialect and delimiter policy.

The branch is intentionally organized into five focused commits. Each parser revision was generated and tested in its own source snapshot before the next layer was committed.

Suggested review order

  1. 49ee0ad — Parenthesized scalar subqueries
    • Fix comparisons such as WHERE ((SELECT id FROM t) = 1).
    • Preserve the tree for extra parentheses around table subqueries.
    • Standalone fix; does not depend on InterBase syntax.
  2. ff7ddb0 — Named parameters and dollar identifiers
    • Add :parameter references and identifiers such as RDB$DATABASE.
    • Update three recovery snapshots for deliberately malformed PostgreSQL input. Their inputs are unchanged and remain rejected.
  3. 633dc05 — InterBase procedural SQL
    • Procedures, triggers, declarations, assignments, conditional/loop statements, exceptions, and EXECUTE PROCEDURE.
    • Trailing INTO, ROWS, generators, BLOB attributes, and highlight captures.
    • Uses ordinary semicolon script delimiters so the procedural rules can be reviewed separately from caret handling.
  4. a6b186d — Caret-delimited scripts
    • Add ^ script terminators and syntactic SET TERM support.
    • Distinguish arithmetic carets using external-scanner lookahead, retaining operator precedence.
    • Cover EOF, comments, strings, identifier operands, statement boundaries, and REPLACE.
  5. 8640a5d — Neovim integration
    • Add current Neovim capture names and an opt-in local preview helper.
    • The helper loads the local parser early and extends the normal SQL queries in memory, including with Lazy.nvim startup.

Validation

Revision Corpus tests Highlight assertions
Subquery fix 514 27
Parameters / identifiers 515 27
Procedural SQL 517 49
Caret scripts / final parser 522 49
  • Parser generation and the corpus/highlight suite passed for each parser revision.
  • scripts/test-keywords.sh passed for each revision; its inventory comparison now deduplicates context-specific captures.
  • Neovim checks verified procedure, variable, parameter, conditional, loop, and built-in type captures.
  • Five incremental caret/comment/statement-boundary edits produced the same trees as fresh parses.
  • Fixtures are synthetic. Generated parser files are not committed, following this repository's main-branch convention.

Delimiter policy requiring upstream agreement

SET TERM is parsed syntactically; this implementation does not keep an active delimiter setting or implement arbitrary custom delimiters. Both ; and ^ can terminate top-level statements.

The shared grammar also supports arithmetic ^. Lookahead treats EOF or a recognized statement-start keyword after trivia as a delimiter boundary; otherwise it allows an arithmetic operand. In particular, the following currently remains one arithmetic expression:

SELECT 1 FROM t WHERE id = 1^
(SELECT 2 FROM t);

A parenthesized query is a legal arithmetic operand in other dialects, so that spelling cannot be interpreted both ways without a dialect/delimiter policy. This behavior and the semicolon alternative are documented in docs/interbase.md. The draft status is intentional so this policy can be agreed before merging the caret layer.

Separate query bodies from statement-level parentheses and retain nested table subqueries through explicit ambiguity handling. Add regressions for both forms.

Verified: 514 corpus tests, 27 highlight assertions, keyword inventory.
Recognize colon-prefixed parameters and dollar signs within unquoted identifiers. Update three malformed PostgreSQL recovery snapshots for the broader identifier token; their inputs remain rejected.

Verified: 515 corpus tests, 27 highlight assertions, keyword inventory.
Add procedures, triggers, declarations, control flow, exception handling, EXECUTE PROCEDURE, trailing INTO, ROWS, generators, and BLOB attributes. Keep PSQL statement bodies separate from top-level DDL and add matching highlight captures.

This commit uses ordinary semicolon script delimiters; caret support is layered separately.

Verified: 517 corpus tests, 49 highlight assertions, keyword inventory.
Add caret statement terminators and SET TERM syntax. Use an external arithmetic-caret token to preserve operator precedence while recognizing statement boundaries, including comments and REPLACE statements.

Document the multi-dialect ambiguity before parenthesized queries and the non-stateful delimiter policy for upstream discussion.

Verified: 522 corpus tests, 49 highlight assertions, keyword inventory.
Provide current Neovim captures and an early-loading preview helper that survives Lazy.nvim runtimepath resets. Document build, startup, and delimiter limitations.

Verified with the existing Neovim configuration: procedure, parameter, variable, control-flow, and built-in type captures; incremental edits match fresh parses.
@AntoineGS

Copy link
Copy Markdown
Author

Tf I was working on this with Claude and it opened the PR... I haven't reviewed any of this so I am closing it, I may eventually open smaller PRs for these items but not before I have gone through a few iterations myself.

@AntoineGS AntoineGS closed this Sep 23, 2026
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.

1 participant