diff --git a/CHANGELOG.md b/CHANGELOG.md index 050cf12..c7a6139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ - Added TEMPLATE view that allow to render your template with custom Handlebars template. - Improved syntax highlighting - now lines with errors will get highlighted with appropriate colour to indicate the issue +Fixes: +- Fixed parsing arguments to the `file` function. Now parameters with symbols like `[]*` should work properly (i.e. JSONPath arguments) + # 0.27.0 (2025-02-17) - Better syntax highlighting! Now it highlights SQL query parts - Support for comments. You can now add comments like `--` and `/* */` to you queries diff --git a/src/grammar/parser.test.ts b/src/grammar/parser.test.ts index aacd6b3..956d85c 100644 --- a/src/grammar/parser.test.ts +++ b/src/grammar/parser.test.ts @@ -344,4 +344,26 @@ SELECT * FROM data`, [...DEFAULT_VIEWS, { argument: 'anyObject?', name: 'chart', ], }) }) + + it('should properly parse json5 with JSONPath', () => { + expect(parseWithDefaults(` + TABLE data = file(data.json5, $.results.latest[*], "abcd,()e") +SELECT id, value FROM data`, DEFAULT_VIEWS, DEFAULTS)).toEqual({ + flags: { + explain: false, + refresh: true + }, + query: 'SELECT id, value FROM data', + renderer: { + type: 'GRID', + name: 'GRID', + options: '' + }, + tables: [{ + arguments: ['data.json5', '$.results.latest[*]', 'abcd,()e'], + tableAlias: 'data', + type: 'file' + }] +}) + }) }) \ No newline at end of file diff --git a/src/grammar/parser.ts b/src/grammar/parser.ts index 7d617ee..c9eca13 100644 --- a/src/grammar/parser.ts +++ b/src/grammar/parser.ts @@ -25,8 +25,8 @@ export const SQLSealLangDefinition = (views: ViewDefinition[], enableErrors: boo | caseInsensitive<"NO REFRESH"> -- norefresh | caseInsensitive<"EXPLAIN"> -- explain TableExpression = tableKeyword identifier "=" TableDefinition - TableDefinition = fileOpening NonemptyListOf tableDefinitionClosing -- file - | tableOpening alnum+ tableDefinitionClosing -- mdtable + TableDefinition = fileOpening NonemptyListOf tableDefinitionClosing -- file + | tableOpening alnum+ tableDefinitionClosing -- mdtable identifier = (alnum | "_")+ filename = (alnum | "." | "-" | space | "_" | "/" | "\\" | "$" | "[" | "]" | "\"")+ fileOpening = caseInsensitive<"file("> @@ -34,6 +34,9 @@ export const SQLSealLangDefinition = (views: ViewDefinition[], enableErrors: boo tableDefinitionClosing = ")" errorLine = (~(nl|selectKeyword) any)* nl + listElement = "\"" (~"\"" any)+ "\"" -- quoted + | (~ ("," | ")") any)+ -- unquoted + ViewExpression = ${viewsDefinitions} anyObject = "{" (~selectKeyword any)* handlebarsTemplate = (~selectKeyword any)* @@ -95,7 +98,7 @@ const generateSemantic = (grammar: ohm.Grammar) => { }, TableDefinition_file: (_file, args, _close) => { return { - arguments: args.asIteration().children.map((c: ohm.Node) => c.sourceString.trim()), + arguments: args.asIteration().children.map((c: ohm.Node) => c.toObject().trim()), type: 'file' } }, @@ -121,6 +124,8 @@ const generateSemantic = (grammar: ohm.Grammar) => { options: (options.sourceString ?? '').trim() } }, + listElement_quoted: (_q, value, _q2) => value.sourceString, + listElement_unquoted: (v) => v.sourceString, _terminal() { return this.sourceString }