Skip to content

feat!: give located trees every position Rules need; move the tokenizer into sqlquack-tokenize; remove sqlquack-lint - #273

Merged
kvlonge merged 1 commit into
mainfrom
feat/located-trees-notes
Nov 23, 2026
Merged

kvlonge merged 1 commit into
mainfrom
feat/located-trees-notes

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Why

Lint Rules moved to SQLClean and must read structure from SQLQuack's tree, never from tokens or a re-parse. This gives located trees every position those readers need, and moves the tokenizer out of the crate the Rules depend on.

Changes

  • Located parses record clause keywords, operators, call names, join keywords and commas, set-operation branches, a MERGE's WITH and a LATERAL alias as written; new QueriesLocated and AsWrittenLocated call modes and tree queries.
  • The tokenizer and lossless tokenizer move to the new sqlquack-tokenize crate.
  • sqlquack-lint is removed; its Rules live in SQLClean.
  • A WITH before VALUES is kept; SQLite trigger bodies parse as statements.
  • About 1.4% more parse instructions, within the 2% budget.

The commit message lists every moved path and new public item under BREAKING CHANGE. This is one commit on purpose: squash merges take their message from the commits.

Verification

  • The full gate passed on this tree, including instruction counts, the depth probe, corpus verdicts and syntax coverage.
  • SQLClean, pinned to this tree, passes its tests and a full corpus comparison with every changed finding read.
  • An independent review checked the change against the code.

…er into sqlquack-tokenize; remove sqlquack-lint

Located parses (`CallMode::FaithfulLocated`, and the new `QueriesLocated` and `AsWrittenLocated`)
now record, in the tree, every position a reader of the tree needs, so that a tool working from a
tree never has to re-read SQL or tokens:

- clause keywords, select items and their heads, binary and comparison operators (with where the
  operation ends), call names and argument lists, CASE keywords and its ELSE, SELECT DISTINCT, the
  start of a query's row limit, join keywords and FROM commas, set-operation keywords and each
  branch's range, a MERGE's WITH, SQL/JSON calls, and a LATERAL alias as written (quotes included);
- `QueriesLocated` also records each query's and set-operation branch's own range, and
  `AsWrittenLocated` keeps every dialect's calls as written: the tree that lint Rules read;
- tree queries over located trees: `Expression::query_scopes` (each query's relations and what it
  can see), `with_clause`, `set_operation`, `column_count`, `first_branch`/`last_branch`,
  `projects_wildcard`, `may_read_earlier`, `items_after_commas` and `written_call`.

Parser fixes:

- A WITH before VALUES is kept, with its range, on every dialect that accepts it: the statement is
  read as `SELECT * FROM (VALUES …)` carrying the WITH, as PostgreSQL's own parser already did.
  The shared parser and SQLite's parser used to drop the WITH.
- SQLite trigger programs (`BEGIN … END`) are read as statements (`TriggerBody::Statements`) on
  SQLite, the one engine here that runs them; a program with a statement that does not parse stays
  text. DuckDB and Snowflake, whose engines reject triggers, keep the body as text.
- A written star over VALUES reads as a wildcard.
- DuckDB `AS ''` is unchanged: DuckDB itself treats it as no alias.

The tokenizer, its dialect configuration and the lossless tokenizer move out of `sqlquack-syntax`
into the new crate `sqlquack-tokenize`, so that a crate depending on `sqlquack-syntax` alone can
read trees but cannot tokenize or parse SQL. Strict parsing runs about 1.4% more instructions than
0.22.1 for the positions it records (within the 2% guard).

New public items: `tokens::models::{SeparatorSpans, OperatorSpan, ItemSpans}`,
`expressions::functions::models::WrittenCall`, `traversal::models::{SetOperation, SetOperator,
FromItemKind, CommaItem, ScopedRelation, QueryScope, QueryScopes, QualifiedColumn}`,
`Case::{case_keyword, branch_keywords, else_keyword, end_keyword}`, `OrderBy::written_at`,
`CommaItem::may_read_earlier` and `OperatorSpan::{operator, operation}`.
`TokenGuardStats::observe` is now public, for `sqlquack-tokenize`.

BREAKING CHANGE: `sqlquack-lint` is removed; its Rules now live in SQLClean. The tokenizer moved
to `sqlquack-tokenize`: `sqlquack_syntax::{LosslessToken, TokenKind, TokenizeFailure}` are now
`sqlquack_tokenize::{LosslessToken, TokenKind, TokenizeFailure}`, `sqlquack_syntax::lossless::*`
is `sqlquack_tokenize::lossless::*`, `sqlquack_syntax::tokens::models::{Tokenizer,
TokenizerConfig}` are `sqlquack_tokenize::tokens::models::{Tokenizer, TokenizerConfig}` (also
`sqlquack_tokenize::{Tokenizer, TokenizerConfig}`), and
`sqlquack_syntax::tokens::main::parse_dollar_string_token` is
`sqlquack_tokenize::tokens::main::parse_dollar_string_token`; depend on `sqlquack-tokenize` to
use them. `sqlquack_parse::tokenize` and the token, span and dialect types (`Token`, `TokenType`,
`Span`, `Dialect`, `CallMode`) keep their paths. `CallMode` gains `QueriesLocated` and
`AsWrittenLocated`, `TriggerBody` gains `Statements`, and tree nodes gain position fields
(for example `Lateral::alias_span`, `Select::select_span`, `BinaryOp::operator_span`), so an
exhaustive match on `CallMode` or `TriggerBody`, or a struct literal of those nodes, no longer
compiles. A WITH before VALUES now parses as a SELECT over the VALUES carrying the WITH.
@kvlonge
kvlonge added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit c4acfd1 Nov 23, 2026
15 checks passed
@kvlonge
kvlonge deleted the feat/located-trees-notes branch November 23, 2026 06:45
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