fix: keep glued lexemes intact when formatting - #36
Merged
Merged
Conversation
The formatter inserted a space between two word tokens that the lexer split from one QuestDB lexeme: 0x1F became 0 x1F, 16777217.0f became 16777217.0 f, geohash(5c) became geohash(5 c). Some of those formatted queries ran and returned different results. Two word pieces with no whitespace between them in the source now keep no gap, and no clause starts on such a piece. A dot stays apart from any digit-led token, not only NumberLiteral, so `t. 5m` does not become the single token `.5m`. Two new oracles guard this: whitespace-stripped equality catches insertions, and main-lexer token equality catches merges. A new test sweeps every pair of 82 lexemes with three separators. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Problem
The formatter inserted a space between two word tokens that the lexer split from one QuestDB lexeme. The lexer never errors on these, so the "leave unknown text alone" path never ran.
0x1F0 x1F16777217.0f16777217.0 fgeohash(5c)geohash(5 c)1500ns1500n sSELECT id, 0x1F FROM tformatted, ran green, and returned INT 0 in a column namedx1F. Geohash DDL failed with "invalid GEOHASH size".Fix
spacing.ts: two word pieces with no whitespace between them in the source keep no gap. The dot rule treats any digit-led token as a number, sot. 5mno longer becomes the single token.5m.layout.ts: all phrase matching goes through one guard. A clause never starts on a word glued to the previous word, so10.5mFROMno longer gets a newline inside it.Two word tokens with no whitespace between them are never two lexemes in SQL. The rule closes hex, float suffixes, geohash precision, nanosecond durations, and future suffixes without listing literal shapes.
Tests
oracles.ts:assertPreservedgains two oracles. Whitespace-stripped equality catches insertions. Main-lexer token equality catches merges. The existing stream oracle uses the formatter's own lexer, so it split0x1Fthe same way on both sides and could not see this.lexemes.test.ts: eleven split lexemes in seven contexts, and an exhaustive sweep of 82 lexemes in every pair with three separators.A random fuzzer over the same alphabet, 60,000 inputs on three seeds, reports zero character or lexeme changes after the fix. Before the fix it reported 353 extra failures.
🤖 Generated with Claude Code