WHERE expressions: matrix cells + predicate_tail grammar fix (ADR-0026 step 6)
Adds tests/typing_surface/where_expression.rs — 9 matrix cells for the complex WHERE / show-data limit typing surface: operator candidates after an operand, AND / OR after a predicate, NOT, BETWEEN / IN bounds, and `show data` where / limit. Writing the cells surfaced a grammar bug. `predicate_tail`'s `[NOT] negatable` branch started with `Optional(not)`, and an Optional-first `Seq` always "commits" — so on an incomplete input the walker's `Choice` returned that branch's `Incomplete` early and discarded every sibling branch's expected set, dropping `is` and the comparison operators from completion after a column. Fixed by splitting it into explicit `NOT negatable` and bare `negatable` branches — no `predicate_tail` branch starts with an `Optional` now. The matched terminal sequence is unchanged, so `build_expr` is untouched. Docs: ADR-0026 gains an "As-built notes" section recording the option-1 builder realization, its two deviations from the §3 sketch, and the deferral of §7 diagnostic flagging to ADR-0027. requirements.md C5a -> [x] (steps 1-4) with the test baseline refreshed to 1079; CLAUDE.md's deferred list reconciled (C5a implemented; the QA1/QA2 note now points at ADR-0028).
This commit is contained in:
@@ -178,17 +178,24 @@ not yet implemented:
|
|||||||
1–4 of ADR-0015). Pending pieces: `export` / `import` (Iter
|
1–4 of ADR-0015). Pending pieces: `export` / `import` (Iter
|
||||||
5), `--resume` + persistent input history hydration +
|
5), `--resume` + persistent input history hydration +
|
||||||
migration framework scaffold (Iter 6).
|
migration framework scaffold (Iter 6).
|
||||||
- **Complex WHERE expressions** (C5a): AND/OR/comparison/LIKE
|
- **Complex WHERE expressions** (C5a): implemented through
|
||||||
in UPDATE/DELETE/show-data filters. The bridge from DSL
|
ADR-0026 steps 1–4 — the stratified expression grammar
|
||||||
fluency to real SQL.
|
(AND/OR/NOT, the six comparisons, LIKE/IN/BETWEEN/IS NULL,
|
||||||
|
parentheses) reached through a new `Subgrammar` node, the
|
||||||
|
recursive `Expr` AST + parameterised SQL, and `where` /
|
||||||
|
`limit` on `show data`. Type-mismatched comparisons run
|
||||||
|
permissively (§7). Still pending: the §7 advisory
|
||||||
|
*flagging* of type mismatches / `= NULL`, the seam with
|
||||||
|
ADR-0027's diagnostics-severity model.
|
||||||
- **SQL handling in advanced mode** (Q1): `sqlparser-rs` parser
|
- **SQL handling in advanced mode** (Q1): `sqlparser-rs` parser
|
||||||
+ a defined SQL subset (Q4 — its own ADR).
|
+ a defined SQL subset (Q4 — its own ADR).
|
||||||
- **Column drops/renames/type changes** (B2 / C2 partial): the
|
- **Column drops/renames/type changes** (B2 / C2 partial): the
|
||||||
rebuild-table primitive (ADR-0013) is in place; the grammar
|
rebuild-table primitive (ADR-0013) is in place; the grammar
|
||||||
and dispatch are pending.
|
and dispatch are pending.
|
||||||
- **Indexes**: `add index` / `drop index` done (ADR-0025).
|
- **Indexes**: `add index` / `drop index` done (ADR-0025).
|
||||||
`EXPLAIN QUERY PLAN` rendering for QA1 still pending (needs
|
`EXPLAIN QUERY PLAN` (QA1 / QA2) is designed in ADR-0028 —
|
||||||
its own QA2 rendering ADR).
|
the `explain` prefix command + span-styled plan tree —
|
||||||
|
but not yet implemented.
|
||||||
- **Modify relationship** (C3a): drop+add covers the use case
|
- **Modify relationship** (C3a): drop+add covers the use case
|
||||||
today.
|
today.
|
||||||
- **m:n convenience** (C4): auto-generates a junction table
|
- **m:n convenience** (C4): auto-generates a junction table
|
||||||
|
|||||||
@@ -416,6 +416,66 @@ suite and the typing-surface matrix:
|
|||||||
walker.
|
walker.
|
||||||
6. Typing-surface matrix cells for the new surface.
|
6. Typing-surface matrix cells for the new surface.
|
||||||
|
|
||||||
|
### As-built notes (2026-05-18)
|
||||||
|
|
||||||
|
Steps 1–4 are implemented and committed; step 5 (the §7
|
||||||
|
diagnostic flagging) is deferred — see below. Realization
|
||||||
|
choices, and where they deviate from the design sketch above:
|
||||||
|
|
||||||
|
- **§3 builder — option 1 ("reconstruct in builder"),**
|
||||||
|
chosen with the project owner before implementation. The
|
||||||
|
stratified grammar is walked normally; its terminals flow
|
||||||
|
into the flat `MatchedPath` unchanged (driving highlight /
|
||||||
|
completion / the expected-set). `grammar::expr::build_expr`
|
||||||
|
then folds that flat terminal slice into the `Expr` — a
|
||||||
|
deterministic recursive descent mirroring the grammar
|
||||||
|
tiers, run only at submit-time dispatch, never per
|
||||||
|
keystroke. Two honest deviations from the §3 wording:
|
||||||
|
- **No `MatchedKind::Expr` variant.** `MatchedPath` stays
|
||||||
|
purely terminals — arguably more faithful to "MatchedPath
|
||||||
|
stays flat" than carrying a built `Expr` in it. The
|
||||||
|
`Expr` is assembled in the command `ast_builder`s
|
||||||
|
(`build_update` / `build_delete` / `build_show`), which
|
||||||
|
already reconstruct structured `Command`s from the flat
|
||||||
|
path; `build_expr` is the same pattern, one tier deeper.
|
||||||
|
- **There is a second structural pass** over the
|
||||||
|
expression tokens, scoped to submit-time dispatch. "No
|
||||||
|
second parse" is read as "no separate parser framework":
|
||||||
|
the walk validates and drives assistance, `build_expr`
|
||||||
|
is the single `ast_builder` for the fragment — the same
|
||||||
|
category as `build_insert`.
|
||||||
|
- **Grammar shape.** `predicate` is factored as `operand
|
||||||
|
predicate_tail` (shared operand prefix), and the infix
|
||||||
|
`NOT` is factored in front of the `LIKE` / `BETWEEN` /
|
||||||
|
`IN` choice — so the walker's first-commit-wins `Choice`
|
||||||
|
semantics discriminate branches on a cleanly-failing first
|
||||||
|
token.
|
||||||
|
- **`Subgrammar` depth.** `MAX_SUBGRAMMAR_DEPTH = 64` counts
|
||||||
|
active `Subgrammar` recursion frames. The stratified
|
||||||
|
grammar descends ~4–5 frames per parenthesis level, so the
|
||||||
|
effective parenthesis-nesting limit is roughly a dozen —
|
||||||
|
far past any hand-written filter; the cap is purely a
|
||||||
|
stack-overflow guard.
|
||||||
|
- **§8 hints.** The expression's right-hand operands resolve
|
||||||
|
through a schema-aware `DynamicSubgrammar` (`where_rhs_
|
||||||
|
operand`) so the hint panel narrows to the compared
|
||||||
|
column's type, exactly as the pre-ADR `where col = val`
|
||||||
|
slot did. The operand grammar carries no validators —
|
||||||
|
permissive per §7.
|
||||||
|
- **Step 5 deferred to ADR-0027.** The §7 *behaviour*
|
||||||
|
relaxation is done: `bind_where_literal` binds a
|
||||||
|
type-mismatched WHERE literal by its syntactic shape, and
|
||||||
|
the pre-ADR bind-time rejection is gone. The §7
|
||||||
|
*diagnostic flagging* — surfacing a type-mismatched
|
||||||
|
comparison or `= NULL` as an error-class highlight + hint
|
||||||
|
— is the seam with ADR-0027, which designs the walker
|
||||||
|
diagnostics-severity model that flagging belongs in (and
|
||||||
|
whose WARNING severity is defined to have "no triggers
|
||||||
|
until ADR-0026 is implemented"). Building the flagging as
|
||||||
|
a standalone mechanism first would be reworked by
|
||||||
|
ADR-0027; the recommendation is to implement it as the
|
||||||
|
first triggers of ADR-0027's model.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- ADR-0009 — DSL command syntax conventions (`--` flags,
|
- ADR-0009 — DSL command syntax conventions (`--` flags,
|
||||||
|
|||||||
+20
-11
@@ -26,12 +26,13 @@ repo is pushed).
|
|||||||
|
|
||||||
## Test baseline
|
## Test baseline
|
||||||
|
|
||||||
After ADR-0025 (indexes): **1037 passing, 0 failing, 1
|
After ADR-0026 steps 1–4 (complex WHERE expressions):
|
||||||
ignored** (`cargo test` — the one ignored test is a
|
**1070 passing, 0 failing, 1 ignored** (`cargo test` — the
|
||||||
long-standing `` ```ignore `` doc-test in
|
one ignored test is a long-standing `` ```ignore `` doc-test
|
||||||
`src/friendly/mod.rs`). Clippy clean with the nursery lint
|
in `src/friendly/mod.rs`). Clippy clean with the nursery lint
|
||||||
group enabled. (Earlier reference points: 1006 after ADR-0024
|
group enabled. (Earlier reference points: 1039 after ADR-0025
|
||||||
+ the handoff-14 cleanup; 449 after B2/C2.)
|
(indexes); 1006 after ADR-0024 + the handoff-14 cleanup; 449
|
||||||
|
after B2/C2.)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -157,12 +158,20 @@ group enabled. (Earlier reference points: 1006 after ADR-0024
|
|||||||
writes. Bulk insert, complex WHERE expressions, and SELECT
|
writes. Bulk insert, complex WHERE expressions, and SELECT
|
||||||
in advanced mode are explicitly tracked separately — see
|
in advanced mode are explicitly tracked separately — see
|
||||||
C5a below.)*
|
C5a below.)*
|
||||||
- [ ] **C5a** Complex WHERE expressions (AND/OR, comparison
|
- [x] **C5a** Complex WHERE expressions (AND/OR, comparison
|
||||||
operators, LIKE, IS NULL, IN, BETWEEN) for UPDATE/DELETE/
|
operators, LIKE, IS NULL, IN, BETWEEN) for UPDATE/DELETE/
|
||||||
show-data filtering; also adds `where` and `limit` to
|
show-data filtering; `show data` also gains `where` and
|
||||||
`show data`. Tracks the natural progression from DSL into
|
`limit`.
|
||||||
real SQL fluency that motivates the playground. Designed in
|
*(ADR-0026 steps 1–4: the stratified expression grammar
|
||||||
ADR-0026; implementation pending.
|
reached through a new `Subgrammar` node, the recursive
|
||||||
|
`Expr` AST + `build_expr`, wiring into update / delete /
|
||||||
|
show data, and `Expr` → parameterised SQL with an implicit
|
||||||
|
primary-key `ORDER BY` for `limit`. Type-mismatched WHERE
|
||||||
|
comparisons are permissive — they run rather than being
|
||||||
|
rejected (§7). The §7 advisory **flagging** of type
|
||||||
|
mismatches / `= NULL` is the seam with ADR-0027's
|
||||||
|
diagnostics-severity model and is tracked there — see
|
||||||
|
ADR-0026 "As-built notes".)*
|
||||||
|
|
||||||
## SQL handling
|
## SQL handling
|
||||||
|
|
||||||
|
|||||||
+24
-18
@@ -201,37 +201,43 @@ static IN_FORM_NODES: &[Node] = &[
|
|||||||
Node::Punct(')'),
|
Node::Punct(')'),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// The negatable predicates — each starts with a distinct
|
/// The negatable predicate bodies — each starts with a
|
||||||
/// keyword, so this `Choice` discriminates cleanly.
|
/// distinct keyword, so this `Choice` discriminates cleanly.
|
||||||
static NEGATABLE_CHOICES: &[Node] = &[
|
static NEGATABLE_CHOICES: &[Node] = &[
|
||||||
Node::Seq(LIKE_FORM_NODES),
|
Node::Seq(LIKE_FORM_NODES),
|
||||||
Node::Seq(BETWEEN_FORM_NODES),
|
Node::Seq(BETWEEN_FORM_NODES),
|
||||||
Node::Seq(IN_FORM_NODES),
|
Node::Seq(IN_FORM_NODES),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// `[NOT] (LIKE … | BETWEEN … | IN …)`.
|
/// `NOT (LIKE … | BETWEEN … | IN …)` — the infix `NOT` is
|
||||||
static NEGATABLE_NODES: &[Node] = &[
|
/// factored in front of the negatable choice (rather than
|
||||||
Node::Optional(&Node::Word(Word::keyword("not"))),
|
/// repeated inside each, which would strand `not between` on
|
||||||
|
/// the `LIKE` branch).
|
||||||
|
static NOT_NEGATABLE_NODES: &[Node] = &[
|
||||||
|
Node::Word(Word::keyword("not")),
|
||||||
Node::Choice(NEGATABLE_CHOICES),
|
Node::Choice(NEGATABLE_CHOICES),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// `predicate_tail := cmp_op operand | IS [NOT] NULL | [NOT]
|
/// `predicate_tail := cmp_op operand | IS [NOT] NULL
|
||||||
/// negatable`.
|
/// | NOT negatable | negatable`.
|
||||||
///
|
///
|
||||||
/// Branch discrimination: a `Choice` branch falls through to
|
/// Branch discrimination relies on each branch's *first* child
|
||||||
/// the next branch only when its *first* child reports a clean
|
/// reporting a clean `NoMatch` on a non-match: branch 1 is a
|
||||||
/// `NoMatch`. Branch 1's first child is `Choice(CMP_OP_CHOICES)`
|
/// `Choice` of punctuation operators, the rest start with a
|
||||||
/// (all punctuation — clean `NoMatch` on a non-operator);
|
/// `Word`. Crucially **no branch starts with an `Optional`** —
|
||||||
/// branch 2's is `Word("is")`. Branch 3 starts with
|
/// an `Optional`-first `Seq` always "commits", which turns its
|
||||||
/// `Optional(not)`, which always "matches" — so it must be
|
/// failure into an `Incomplete` that the walker's `Choice`
|
||||||
/// **last**, and the infix `NOT` is factored out in front of
|
/// returns early, discarding every sibling branch's expected
|
||||||
/// the `LIKE` / `BETWEEN` / `IN` choice rather than repeated
|
/// set (and so its completion candidates). The infix `NOT` is
|
||||||
/// inside each (which would strand `not between` on the `LIKE`
|
/// therefore its own explicit `NOT negatable` branch, with a
|
||||||
/// branch).
|
/// bare `negatable` branch alongside.
|
||||||
static PREDICATE_TAIL_CHOICES: &[Node] = &[
|
static PREDICATE_TAIL_CHOICES: &[Node] = &[
|
||||||
Node::Seq(COMPARE_FORM_NODES),
|
Node::Seq(COMPARE_FORM_NODES),
|
||||||
Node::Seq(IS_NULL_NODES),
|
Node::Seq(IS_NULL_NODES),
|
||||||
Node::Seq(NEGATABLE_NODES),
|
Node::Seq(NOT_NEGATABLE_NODES),
|
||||||
|
Node::Seq(LIKE_FORM_NODES),
|
||||||
|
Node::Seq(BETWEEN_FORM_NODES),
|
||||||
|
Node::Seq(IN_FORM_NODES),
|
||||||
];
|
];
|
||||||
|
|
||||||
// =================================================================
|
// =================================================================
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub mod insert_form_c;
|
|||||||
pub mod update_with_where;
|
pub mod update_with_where;
|
||||||
pub mod update_all_rows;
|
pub mod update_all_rows;
|
||||||
pub mod delete_with_where;
|
pub mod delete_with_where;
|
||||||
|
pub mod where_expression;
|
||||||
pub mod delete_all_rows;
|
pub mod delete_all_rows;
|
||||||
pub mod create_table;
|
pub mod create_table;
|
||||||
pub mod drop_column;
|
pub mod drop_column;
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Customers where id=1 \" cursor=33"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Customers where id=1 ",
|
||||||
|
cursor: 33,
|
||||||
|
state: Valid,
|
||||||
|
hint: Some(
|
||||||
|
Candidates {
|
||||||
|
items: [
|
||||||
|
Candidate {
|
||||||
|
text: "and",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "or",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selected: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
33,
|
||||||
|
33,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "and",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "or",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Ok(
|
||||||
|
"Delete",
|
||||||
|
),
|
||||||
|
}
|
||||||
+95
@@ -0,0 +1,95 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Customers where not \" cursor=32"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Customers where not ",
|
||||||
|
cursor: 32,
|
||||||
|
state: IncompleteAtEof,
|
||||||
|
hint: Some(
|
||||||
|
Candidates {
|
||||||
|
items: [
|
||||||
|
Candidate {
|
||||||
|
text: "not",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "null",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "true",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "false",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "(",
|
||||||
|
kind: Punct,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "Email",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "Name",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "id",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selected: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
32,
|
||||||
|
32,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "not",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "null",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "true",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "false",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "(",
|
||||||
|
kind: Punct,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "Email",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "Name",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "id",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Err(
|
||||||
|
"Invalid(at_eof)",
|
||||||
|
),
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Customers where Email \" cursor=34"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Customers where Email ",
|
||||||
|
cursor: 34,
|
||||||
|
state: IncompleteAtEof,
|
||||||
|
hint: Some(
|
||||||
|
Candidates {
|
||||||
|
items: [
|
||||||
|
Candidate {
|
||||||
|
text: "is",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "not",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "like",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "between",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "in",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selected: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
34,
|
||||||
|
34,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "is",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "not",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "like",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "between",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "in",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Err(
|
||||||
|
"Invalid(at_eof)",
|
||||||
|
),
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Things where k between \" cursor=35"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Things where k between ",
|
||||||
|
cursor: 35,
|
||||||
|
state: IncompleteAtEof,
|
||||||
|
hint: Some(
|
||||||
|
Prose(
|
||||||
|
"for `k`: Type an integer (e.g. 42, -7) or null",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
35,
|
||||||
|
35,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "null",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "true",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "false",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "auto",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "b",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "d",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "data",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "dt",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "k",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "note",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "r",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "sid",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "ts",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Err(
|
||||||
|
"Invalid(at_eof)",
|
||||||
|
),
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"show data Customers where id=1 limit 10\" cursor=39"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "show data Customers where id=1 limit 10",
|
||||||
|
cursor: 39,
|
||||||
|
state: Valid,
|
||||||
|
hint: Some(
|
||||||
|
Prose(
|
||||||
|
"Submit with Enter",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
completion: None,
|
||||||
|
parse_result: Ok(
|
||||||
|
"ShowData",
|
||||||
|
),
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Things where k > 1 and t like 'a%' or k = 9\" cursor=55"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Things where k > 1 and t like 'a%' or k = 9",
|
||||||
|
cursor: 55,
|
||||||
|
state: Valid,
|
||||||
|
hint: Some(
|
||||||
|
Prose(
|
||||||
|
"Submit with Enter",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
completion: None,
|
||||||
|
parse_result: Ok(
|
||||||
|
"Delete",
|
||||||
|
),
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"delete from Things where k in (\" cursor=31"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "delete from Things where k in (",
|
||||||
|
cursor: 31,
|
||||||
|
state: IncompleteAtEof,
|
||||||
|
hint: Some(
|
||||||
|
Prose(
|
||||||
|
"for `k`: Type an integer (e.g. 42, -7) or null",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
31,
|
||||||
|
31,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "null",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "true",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "false",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "auto",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "b",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "d",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "data",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "dt",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "k",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "note",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "r",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "sid",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "ts",
|
||||||
|
kind: Identifier,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Err(
|
||||||
|
"Invalid(at_eof)",
|
||||||
|
),
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"show data Customers \" cursor=20"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "show data Customers ",
|
||||||
|
cursor: 20,
|
||||||
|
state: Valid,
|
||||||
|
hint: Some(
|
||||||
|
Candidates {
|
||||||
|
items: [
|
||||||
|
Candidate {
|
||||||
|
text: "where",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "limit",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selected: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
20,
|
||||||
|
20,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "where",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "limit",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Ok(
|
||||||
|
"ShowData",
|
||||||
|
),
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
source: tests/typing_surface/where_expression.rs
|
||||||
|
description: "input=\"show data Customers where id=1 \" cursor=31"
|
||||||
|
expression: "& a"
|
||||||
|
---
|
||||||
|
Assessment {
|
||||||
|
input: "show data Customers where id=1 ",
|
||||||
|
cursor: 31,
|
||||||
|
state: Valid,
|
||||||
|
hint: Some(
|
||||||
|
Candidates {
|
||||||
|
items: [
|
||||||
|
Candidate {
|
||||||
|
text: "and",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "or",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "limit",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selected: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
completion: Some(
|
||||||
|
Completion {
|
||||||
|
replaced_range: (
|
||||||
|
31,
|
||||||
|
31,
|
||||||
|
),
|
||||||
|
partial_prefix: "",
|
||||||
|
candidates: [
|
||||||
|
Candidate {
|
||||||
|
text: "and",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "or",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
Candidate {
|
||||||
|
text: "limit",
|
||||||
|
kind: Keyword,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
parse_result: Ok(
|
||||||
|
"ShowData",
|
||||||
|
),
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
//! Matrix coverage for the complex WHERE-expression surface
|
||||||
|
//! and `show data` `where` / `limit` (ADR-0026).
|
||||||
|
//!
|
||||||
|
//! The simple `where col = val` cells live in
|
||||||
|
//! `delete_with_where` / `update_with_where`; this file covers
|
||||||
|
//! the expression grammar's wider surface — operators, the
|
||||||
|
//! AND / OR connectives, the negatable predicates, and the
|
||||||
|
//! `show data` filter / limit clauses.
|
||||||
|
|
||||||
|
use crate::typing_surface::*;
|
||||||
|
use rdbms_playground::input_render::InputState;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn after_where_column_offers_predicate_operators() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end("delete from Customers where Email ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::IncompleteAtEof));
|
||||||
|
// After an operand the grammar expects a predicate tail —
|
||||||
|
// the negatable keywords surface as candidates.
|
||||||
|
assert_candidate_present(&a, &["like", "between", "in", "is"]);
|
||||||
|
crate::snap!("after_column", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn after_complete_predicate_offers_and_or() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end("delete from Customers where id=1 ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::Valid));
|
||||||
|
// A complete predicate can be extended with a connective.
|
||||||
|
assert_candidate_present(&a, &["and", "or"]);
|
||||||
|
crate::snap!("after_predicate", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn after_not_keyword_expects_a_predicate() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end("delete from Customers where not ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::IncompleteAtEof));
|
||||||
|
// `not` is followed by another predicate — the column
|
||||||
|
// operands of the active table are offered.
|
||||||
|
assert_candidate_present(&a, &["Email", "Name"]);
|
||||||
|
crate::snap!("after_not", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn between_expects_a_low_bound() {
|
||||||
|
let schema = schema_every_type();
|
||||||
|
let a = assess_at_end("delete from Things where k between ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::IncompleteAtEof));
|
||||||
|
crate::snap!("between_low", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_list_open_paren_expects_an_item() {
|
||||||
|
let schema = schema_every_type();
|
||||||
|
let a = assess_at_end("delete from Things where k in (", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::IncompleteAtEof));
|
||||||
|
crate::snap!("in_open_paren", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn complex_and_or_expression_parses() {
|
||||||
|
let schema = schema_every_type();
|
||||||
|
let a = assess_at_end(
|
||||||
|
"delete from Things where k > 1 and t like 'a%' or k = 9",
|
||||||
|
&schema,
|
||||||
|
);
|
||||||
|
assert!(matches!(a.state, InputState::Valid));
|
||||||
|
assert_eq!(a.parse_result.as_deref(), Ok("Delete"));
|
||||||
|
crate::snap!("complex_and_or", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn show_data_after_table_offers_where_and_limit() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end("show data Customers ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::Valid));
|
||||||
|
assert_candidate_present(&a, &["where", "limit"]);
|
||||||
|
crate::snap!("show_after_table", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn show_data_after_where_predicate_offers_limit() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end("show data Customers where id=1 ", &schema);
|
||||||
|
assert!(matches!(a.state, InputState::Valid));
|
||||||
|
assert_candidate_present(&a, &["limit", "and", "or"]);
|
||||||
|
crate::snap!("show_after_where", a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn complete_show_data_with_where_and_limit_parses() {
|
||||||
|
let schema = schema_serial_pk();
|
||||||
|
let a = assess_at_end(
|
||||||
|
"show data Customers where id=1 limit 10",
|
||||||
|
&schema,
|
||||||
|
);
|
||||||
|
assert!(matches!(a.state, InputState::Valid));
|
||||||
|
assert_eq!(a.parse_result.as_deref(), Ok("ShowData"));
|
||||||
|
crate::snap!("complete_show_where_limit", a);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user