Skip to content

Commit 49b4f58

Browse files
committed
add strict position tracking, prevent equals operator in DECLARE assignments
1 parent 2809cab commit 49b4f58

3 files changed

Lines changed: 4 additions & 12 deletions

File tree

src/parser/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ export const allTokens: TokenType[] = [
869869
// Lexer Instance
870870
// =============================================================================
871871

872-
export const QuestDBLexer = new Lexer(allTokens)
872+
export const QuestDBLexer = new Lexer(allTokens, { positionTracking: "full" })
873873

874874
export function tokenize(input: string) {
875875
const result = QuestDBLexer.tokenize(input)

src/parser/parser.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,7 @@ class QuestDBParser extends CstParser {
14031403
private declareAssignment = this.RULE("declareAssignment", () => {
14041404
this.OPTION(() => this.CONSUME(Overridable))
14051405
this.CONSUME(VariableReference)
1406-
this.OR([
1407-
{ ALT: () => this.CONSUME(ColonEquals) },
1408-
{ ALT: () => this.CONSUME(Equals) },
1409-
])
1406+
this.CONSUME(ColonEquals)
14101407
this.SUBRULE(this.expression)
14111408
})
14121409

tests/parser.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,16 +4720,11 @@ orders PIVOT (sum(amount) FOR status IN ('open'))`
47204720

47214721
// --- Fix 8-10: DECLARE, PARTITION BY WEEK ---
47224722

4723-
it("should parse DECLARE with variable assignment using equals", () => {
4723+
it("should REJECT DECLARE assignments using `=` (server requires `:=`)", () => {
47244724
const result = parseToAst(
47254725
"DECLARE @cutoff = '2024-01-01' SELECT * FROM t WHERE ts < @cutoff",
47264726
)
4727-
expect(result.errors).toHaveLength(0)
4728-
const stmt = result.ast[0] as AST.SelectStatement
4729-
expect(stmt.type).toBe("select")
4730-
expect(stmt.declare).toBeDefined()
4731-
expect(stmt.declare?.assignments).toHaveLength(1)
4732-
expect(stmt.declare?.assignments[0].name).toBe("cutoff")
4727+
expect(result.errors.length).toBeGreaterThan(0)
47334728
})
47344729

47354730
it("should parse CREATE MATERIALIZED VIEW with PARTITION BY WEEK", () => {

0 commit comments

Comments
 (0)