DerekStride / tree-sitter-sql

SQL grammar for tree-sitter
http://derek.stride.host/tree-sitter-sql/
MIT License
147 stars 47 forks source link

Syntax highlighting breaks when using $ in VALUES #237

Open happenslol opened 7 months ago

happenslol commented 7 months ago

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: image

Even with a single function, the RETURNING line breaks:

-- name: CreateUser :one
INSERT INTO users (id, name)
VALUES ($1, $2);
RETURNING *;

image

matthias-Q commented 7 months ago

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.

happenslol commented 7 months ago

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:

image

antoineB commented 7 months ago

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 ($).

eklmv commented 5 months ago

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: image With removed ;: image