tree-sitter-sql
tree-sitter-sql copied to clipboard
Syntax highlighting breaks when using $ in VALUES
I'm using sqlc where multiple queries are written in a single sql file, from which code is then generated. Arguments are written as $1, $2 and so on. The dollar signs seem to break syntax highlighting.
The following example shows the bug:
-- name: CreateUser :one
INSERT INTO users (id, name)
VALUES ($1, $2);
RETURNING *;
-- name: CreatePost :one
INSERT INTO posts (id, content)
VALUES ($1, $2)
RETURNING *;
This results in the following:
Even with a single function, the RETURNING line breaks:
-- name: CreateUser :one
INSERT INTO users (id, name)
VALUES ($1, $2);
RETURNING *;
Thanks for reporting. I think this has to do with the dollar quoting that has been introduced a couple of weeks ago. I will try to take a closer look.
Btw.: your second example seems to have an additional ; in the second to last line. That might be one issue.
Btw.: your second example seems to have an additional ; in the second to last line. That might be one issue.
Ah, totally missed that. Disregard that one then, the highlighting works correctly there. The first case however still breaks:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING The tag, if any, of a dollar-quoted string follows the same rules as an unquoted identifier
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($).
You need to check if you not using too old version of a parser, I made fix exactly for that problem: #235.
That how it looks for me:
With removed
;: