mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #100 from h-sphere/fix/parsing-jsonpath-and-other-arguments
fix: fix for arguments passed to the file function
This commit is contained in:
commit
63d5f79b1e
3 changed files with 33 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}]
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -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<filename, ","> tableDefinitionClosing -- file
|
||||
| tableOpening alnum+ tableDefinitionClosing -- mdtable
|
||||
TableDefinition = fileOpening NonemptyListOf<listElement, ","> 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue