Repository navigation
feat!: give located trees every position Rules need; move the tokenizer into sqlquack-tokenize; remove sqlquack-lint - #273
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
QueriesLocatedandAsWrittenLocatedcall modes and tree queries.sqlquack-tokenizecrate.sqlquack-lintis removed; its Rules live in SQLClean.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