Skip to content

Commit

Permalink
Merge pull request #2 from dgehlich/fix-dollar-quotes
Browse files Browse the repository at this point in the history
Support $$ quote function body with spaces and comments afterwards
  • Loading branch information
tkopets authored Mar 3, 2020
2 parents 16b81cb + 585c065 commit 79feb01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions PostgreSQL.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ repository:

dollar_quotes:
patterns:
- comment: "Assume multiline dollar quote is SQL; start if quote is at the end of the line."
- comment: "Assume multiline dollar quote is SQL body!
Start if double dollar quote is followed by no dollar quote till line ending.
See match for dollar quotes as string: string.unquoted.dollar.pgsql.
This could easily support other PL languages like PHP and Ruby -- see PHP heredoc as an example."
# name: meta.dollar-quote.pgsql
contentName: meta.dollar-quote.pgsql
begin: (\$[\w_0-9]*\$)$
begin: (\$[\w_]*\$)(?=[^\$]*$)
beginCaptures:
'1': {name: punctuation.dollar-quote.begin.pgsql}
end: \1
Expand Down Expand Up @@ -186,9 +189,11 @@ repository:
- comment: Double quoting treated like strings, but they are really identifiers.
name: variable.other.pgsql
match: (")[^"#]*(")
- comment: Color as a string if dollar quote did not start at the end of a line.
- comment: "Color dollar double quotes as a string if in one line.
No multiline supported because function body is with dollar quotes,
see meta.dollar-quote.pgsql."
name: string.unquoted.dollar.pgsql
begin: (\$[\w_0-9]*\$)
begin: (\$[\w_]*\$)
end: \1

vars:
Expand Down
8 changes: 4 additions & 4 deletions PostgreSQL.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<array>
<dict>
<key>begin</key>
<string>(\$[\w_0-9]*\$)$</string>
<string>(\$[\w_]*\$)(?=[^\$]*$)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand All @@ -105,7 +105,7 @@
</dict>
</dict>
<key>comment</key>
<string>Assume multiline dollar quote is SQL; start if quote is at the end of the line.</string>
<string>Assume multiline dollar quote is SQL body! Start if double dollar quote is followed by no dollor quote till line ending. See match for dollar quotes as string: string.unquoted.dollar.pgsql. This could easily support other PL languages like PHP and Ruby -- see PHP heredoc as an example.</string>
<key>contentName</key>
<string>meta.dollar-quote.pgsql</string>
<key>end</key>
Expand Down Expand Up @@ -558,9 +558,9 @@
</dict>
<dict>
<key>begin</key>
<string>(\$[\w_0-9]*\$)</string>
<string>(\$[\w_]*\$)</string>
<key>comment</key>
<string>Color as a string if dollar quote did not start at the end of a line.</string>
<string>Color dollar double quotes as a string if in one line. No multiline supported because function body is with dollar quotes, see meta.dollar-quote.pgsql.</string>
<key>end</key>
<string>\1</string>
<key>name</key>
Expand Down

0 comments on commit 79feb01

Please sign in to comment.