From 0df95981a2958dea41663df87258a8bed0aaef39 Mon Sep 17 00:00:00 2001 From: Kacper Kula Date: Sun, 29 Mar 2026 11:13:16 +0100 Subject: [PATCH] fix: fixing parsing with SELECT keywords outside sql queries --- src/modules/editor/parser.test.ts | 57 +++++++++++++++++++++++++++++++ src/modules/editor/parser.ts | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/modules/editor/parser.test.ts b/src/modules/editor/parser.test.ts index 56d0f0b..316eaf5 100644 --- a/src/modules/editor/parser.test.ts +++ b/src/modules/editor/parser.test.ts @@ -450,4 +450,61 @@ SELECT id, value FROM data`, DEFAULT_VIEWS, DEFAULTS)).toEqual({ }] }) }) + + it('should not treat "select" as SQL keyword when it appears as a quoted config property key', () => { + // Test case for fix: quoted string "select" as a property key should not break the parser + expect(parseWithDefaults(` +GRID { + "select": 4 +} +SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({ + flags: { explain: false, refresh: true }, + query: 'SELECT * FROM files', + renderer: { + type: 'GRID', + options: `{ + "select": 4 +}`, + }, + tables: [] + }) + }) + + it('should not treat "select" as SQL keyword when it appears as an unquoted config property key', () => { + // Bonus test: unquoted property key with colon immediately following + expect(parseWithDefaults(` +GRID { + select: 4 +} +SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({ + flags: { explain: false, refresh: true }, + query: 'SELECT * FROM files', + renderer: { + type: 'GRID', + options: `{ + select: 4 +}`, + }, + tables: [] + }) + }) + + it('should handle "select" as property key with space before colon', () => { + // Edge case: space between quoted key and colon + expect(parseWithDefaults(` +GRID { + "select" : 4 +} +SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({ + flags: { explain: false, refresh: true }, + query: 'SELECT * FROM files', + renderer: { + type: 'GRID', + options: `{ + "select" : 4 +}`, + }, + tables: [] + }) + }) }) \ No newline at end of file diff --git a/src/modules/editor/parser.ts b/src/modules/editor/parser.ts index c274304..5209ba9 100644 --- a/src/modules/editor/parser.ts +++ b/src/modules/editor/parser.ts @@ -53,7 +53,7 @@ export const SQLSealLangDefinition = (views: ViewDefinition[], flags: readonly F anyObject = "{" (~selectKeyword any)* handlebarsTemplate = (~selectKeyword any)* javascriptTemplate = (~selectKeyword any)* - selectKeyword = (caseInsensitive<"WITH"> | caseInsensitive<"SELECT">) ~(alnum | "_") + selectKeyword = (caseInsensitive<"WITH"> | caseInsensitive<"SELECT">) &(space | nl | end) tableKeyword = caseInsensitive<"TABLE"> nl = "\n" character = (alnum | "." | "-" | space | "_")