Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 21, 2026
ccoltx
force-pushed
the
lexer/3-lexer-adapter
branch
from
October 21, 2026 18:32
bb01ec8 to
dbdc0d1
Compare
Adds sql/tokens.ts, which maps the official ClickHouse lexer's tokens to a few kinds by name, and sql/lexer_rewriter.ts, which removes trailing semicolons with tokens so that comments, strings and heredocs are handled correctly. Nothing uses it yet. @clickhouse/lexer is a dev dependency, used only by tests. An ESLint rule stops the clients' source from importing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ccoltx
force-pushed
the
lexer/3-lexer-adapter
branch
from
October 21, 2026 18:43
dbdc0d1 to
cd667a1
Compare
Contributor
Author
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.
Tracking issue: #1074. Stack: #1065 → #1066 → #1067 → #1068 → #1069 → #1070 → #1071 → #1072
Part 3 of the lexer stack. Depends on #1066. No user-visible change: nothing calls the new code yet.
Why
The client's string-based handling of trailing semicolons can't tell a
;inside a comment, string or heredoc from a real one (#973). The official lexer,@clickhouse/lexer, is ClickHouse's ownLexer.cppcompiled to WASM, so it splits a query exactly as the server does. This PR adds the code that uses it, on its own, so it can be reviewed before any public API is involved.What
sql/tokens.ts:ClickHouseSqlLexer: our own description of the four lexer members we use (loadLexer,tokenizeSync,isError,TOKEN_NAMES).import * as lexer from "@clickhouse/lexer"fits it as-is, and the client doesn't depend on the package's types.createSqlTokenizer: maps the lexer's token types to a few kinds, by name, because the numbers change between lexer releases. Unknown names map toother.nullwhen:sql/lexer_rewriter.ts:stripTrailingSemiremoves the semicolons after the last statement token and keeps comments, soSELECT 1; -- notebecomesSELECT 1 -- note.null, it falls back to the existing string-based logic.withFormatis unchanged for now; part 5 switches it over.@clickhouse/lexer@1.0.1: a root dev dependency, pinned exactly and used only by tests. The lockfile diff is only the new entry.no-restricted-importsblocks@clickhouse/lexerin the clients' source. The package is ESM-only, and an import there would compile to arequire()that fails on Node versions before 20.19. Users pass it in instead (part 4).Testing
New
sql_lexer_rewriter.test.tsruns against the real WASM lexer in both the Node and browser suites. It covers:Full Node unit suite, typecheck and lint pass.
🤖 Generated with Claude Code