Commit 7397e60
authored
refactor(vnext): share bounded SQL lexer (#187)
## Summary
- extract the streaming bounded SQL lexer from the relation-site state
machine into one package-private module
- preserve the exact PostgreSQL, DuckDB, BigQuery, and Dremio lexical
profiles, UTF-16 offsets, embedded-region barriers, quote/comment
behavior, one-token pushback, and 16,384-lexeme ceiling
- keep query-site keyword, comment-cursor, region, and resource
semantics local to the consumer
- translate generic lexer resource evidence through an exhaustive
package-owned map
- add direct boundary tests without exposing tokens or lexer APIs from
the package
This is a zero-semantics prerequisite for the separate bounded CTE
layout/visibility recognizer. The recognizers will initially use
separate streaming traversals over the same lexical implementation; any
traversal fusion remains benchmark-driven.
## Performance
An initial broader helper extraction caused a reproducible Vite SSR
namespace-call regression on the hot path. The boundary was narrowed
before commit.
Stable means at the exact head are back at the PR #186 baseline:
- exact 10 KiB statement: about 0.56–0.59 ms
- 1,000 classified aliases: about 0.36–0.38 ms
- 1,000 authenticated `USING` columns: about 0.21 ms
The lexer remains streaming and does not allocate a token tape.
## Verification
- 1,543 tests passed plus 1 expected failure
- changed coverage: 97.05% statements, 95.79% branches, 100% functions,
97.04% lines
- bounded lexer coverage: 98.92% statements/lines, 98.78% branches, 100%
functions
- repository coverage: 95.34% statements, 92.05% branches, 96.15%
functions, 95.33% lines
- source, test, loose-optional, and demo typechecks pass
- repository oxlint, test-integrity, and diff checks pass
- browser, package, worker-placement, demo, and benchmark gates pass
- 20,000 deterministic differential lexer comparisons passed across
dialects, masked regions, subranges, UTF-16, comments, quotes,
punctuation, and pushback
- independent SQL/API and concurrency/performance reviewers approved
exact commit `ed079df0f68aadaf8957a7ca5e6c497e91b74860`
Part of #169.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Refactored vNext to share a streaming bounded SQL lexer and the
embedded-region lookup, and switched `query-site` to use them. Behavior
is unchanged across PostgreSQL, DuckDB, BigQuery, and Dremio; this
unblocks the bounded CTE recognizer in #169.
- **Refactors**
- Moved the lexer into package-private `src/vnext/bounded-sql-lexer.ts`.
- Centralized `findSqlEmbeddedRegionAtOrAfter` in `src/vnext/source.ts`
and reused it in the lexer and `query-site` (with tests).
- Preserves lexical profiles, UTF-16 offsets, embedded-region barriers,
quote/comment rules, one-token pushback, and the 16,384-lexeme cap.
- Kept consumer-specific semantics in `query-site`; mapped lexer
resource signals to local `query-site` resources.
- Removed duplicated lexer and region-lookup code from
`src/vnext/query-site.ts` and wired it to the shared modules.
<sup>Written for commit 76190f9.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/187?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->1 parent 8347817 commit 7397e60
5 files changed
Lines changed: 504 additions & 284 deletions
File tree
- src/vnext
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
191 | 206 | | |
192 | 207 | | |
193 | 208 | | |
| |||
0 commit comments