Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix parsing for single-quoted resolvables #6

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ element {
Parens { ParenL element* ParenR } |
Braces { BraceL element* BraceR } |
Brackets { BracketL element* BracketR } |
orphanWrappedResolvable {
(OrphanSingleQuote Whitespace? Resolvable Whitespace? OrphanSingleQuote)
} |
Resolvable |
Whitespace
}

@tokens {
OrphanSingleQuote { "'" }

Resolvable { ResolvableStart resolvableContent* ResolvableEnd }

ResolvableStart[closedBy="ResolvableEnd"] { "{{" }
Expand Down
16 changes: 16 additions & 0 deletions test/test-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ describe("Parse n8n resolvables", () => {

ist(parser.parse("SELECT my_column FROM {{ 'my_table' }};"), 'Script(Statement(Keyword,Whitespace,Identifier,Whitespace,Keyword,Whitespace,Resolvable,";"))')
})

it("parses single-quoted resolvable with no whitespace", () => {
ist(parser.parse("SELECT my_column FROM '{{ 'my_table' }}';"), 'Script(Statement(Keyword,Whitespace,Identifier,Whitespace,Keyword,Whitespace,OrphanSingleQuote,Resolvable,OrphanSingleQuote,";"))')
});

it("parses single-quoted resolvable with leading whitespace", () => {
ist(parser.parse("SELECT my_column FROM ' {{ 'my_table' }}';"), 'Script(Statement(Keyword,Whitespace,Identifier,Whitespace,Keyword,Whitespace,OrphanSingleQuote,Whitespace,Resolvable,OrphanSingleQuote,";"))')
});

it("parses single-quoted resolvable with trailing whitespace", () => {
ist(parser.parse("SELECT my_column FROM '{{ 'my_table' }} ';"), 'Script(Statement(Keyword,Whitespace,Identifier,Whitespace,Keyword,Whitespace,OrphanSingleQuote,Resolvable,Whitespace,OrphanSingleQuote,";"))')
});

it("parses single-quoted resolvable with surrounding whitespace", () => {
ist(parser.parse("SELECT my_column FROM ' {{ 'my_table' }} ';"), 'Script(Statement(Keyword,Whitespace,Identifier,Whitespace,Keyword,Whitespace,OrphanSingleQuote,Whitespace,Resolvable,Whitespace,OrphanSingleQuote,";"))')
});
})