Found while shipping #139 (shared SQL span-scanner)
#139 unified the literal/comment lexer shared by src/core/sql-split.js
(splitStatements) and src/core/query-params.js (detectParams) into
src/core/sql-spans.js scanSpans. But a third SQL lexer still lives in
src/core/sql-highlight.js tokenize (the editor highlighter + its maskLiterals
mask, used for bracket matching #24, signature help #27, and auto-close), and its
string-scanning rules differ:
tokenize (src/core/sql-highlight.js:57-66) does not honor doubled-quote
('') escapes — its loop stops at the first unescaped closing quote. So
'it''s' tokenizes as 'it' (string) + s (ident) + ' (unterminated
string), whereas scanSpans / splitStatements correctly treat 'it''s' as
one literal.
Impact (low, pre-existing): cosmetic mis-highlighting of a string containing a
doubled single-quote, and — via maskLiterals — a slightly wrong literal mask
there, so bracket-matching / auto-close / signature-help can misbehave while the
caret is inside such a string. Not a correctness bug in query execution (split and
param detection use the correct scanSpans).
Why deferred from #139: scanSpans yields only coarse code/string/comment
spans; the highlighter needs finer token types (keyword / func / number /
operator / ident), so it can't consume scanSpans as-is. Unifying means either
extending scanSpans to a full tokenizer or layering the highlighter's
type-classification on top of the shared literal/comment pass — a bigger change
than #139's scope (which named only sql-split + query-params).
Proposal: either (a) fix tokenize's string loop to honor '' (and \)
consistently with scanSpans, or (b) rebuild the highlighter on top of the shared
span pass so all three consumers share one set of literal/comment rules. See the
docstring note in src/core/sql-spans.js for the code-vs-comment-vs-string
distinction that must be preserved.
file:line — src/core/sql-highlight.js:57-66 (tokenize string branch).
Found while shipping #139 (shared SQL span-scanner)
#139 unified the literal/comment lexer shared by
src/core/sql-split.js(
splitStatements) andsrc/core/query-params.js(detectParams) intosrc/core/sql-spans.jsscanSpans. But a third SQL lexer still lives insrc/core/sql-highlight.jstokenize(the editor highlighter + itsmaskLiteralsmask, used for bracket matching #24, signature help #27, and auto-close), and its
string-scanning rules differ:
tokenize(src/core/sql-highlight.js:57-66) does not honor doubled-quote(
'') escapes — its loop stops at the first unescaped closing quote. So'it''s'tokenizes as'it'(string) +s(ident) +'(unterminatedstring), whereas
scanSpans/splitStatementscorrectly treat'it''s'asone literal.
Impact (low, pre-existing): cosmetic mis-highlighting of a string containing a
doubled single-quote, and — via
maskLiterals— a slightly wrong literal maskthere, so bracket-matching / auto-close / signature-help can misbehave while the
caret is inside such a string. Not a correctness bug in query execution (split and
param detection use the correct
scanSpans).Why deferred from #139:
scanSpansyields only coarse code/string/commentspans; the highlighter needs finer token types (keyword / func / number /
operator / ident), so it can't consume
scanSpansas-is. Unifying means eitherextending
scanSpansto a full tokenizer or layering the highlighter'stype-classification on top of the shared literal/comment pass — a bigger change
than #139's scope (which named only sql-split + query-params).
Proposal: either (a) fix
tokenize's string loop to honor''(and\)consistently with
scanSpans, or (b) rebuild the highlighter on top of the sharedspan pass so all three consumers share one set of literal/comment rules. See the
docstring note in
src/core/sql-spans.jsfor the code-vs-comment-vs-stringdistinction that must be preserved.
file:line —
src/core/sql-highlight.js:57-66(tokenizestring branch).