Skip to content

Commit 06f7e22

Browse files
authored
fix: Fix determination of anonymous code blocks in Postgres Mode (fixes #4790)
1 parent 649dd68 commit 06f7e22

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

demo/kitchen-sink/docs/pgsql.pgsql

+11
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ lines - use dollar quotes
116116
$$;
117117
118118
END;
119+
120+
-- Anonymous code block
121+
DO LANGUAGE plpgsql $$
122+
BEGIN
123+
-- code block
124+
END $$;
125+
126+
DO $$
127+
BEGIN
128+
-- code block
129+
END; $$;

lib/ace/mode/_test/tokens_pgsql.json

+48
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,52 @@
886886
["statementEnd",";"]
887887
],[
888888
"start"
889+
],[
890+
"start",
891+
["comment","-- Anonymous code block"]
892+
],[
893+
"dollarSql",
894+
["keyword.statementBegin","DO"],
895+
["text"," "],
896+
["keyword","LANGUAGE"],
897+
["text"," "],
898+
["identifier","plpgsql"],
899+
["text"," "],
900+
["string","$$"]
901+
],[
902+
"dollarSql",
903+
["keyword","BEGIN"]
904+
],[
905+
"dollarSql",
906+
["text"," "],
907+
["comment","-- code block"]
908+
],[
909+
"start",
910+
["keyword","END"],
911+
["text"," "],
912+
["string","$$"],
913+
["statementEnd",";"]
914+
],[
915+
"start"
916+
],[
917+
"dollarSql",
918+
["keyword.statementBegin","DO"],
919+
["text"," "],
920+
["string","$$"]
921+
],[
922+
"dollarSql",
923+
["keyword","BEGIN"]
924+
],[
925+
"dollarSql",
926+
["text"," "],
927+
["comment","-- code block"]
928+
],[
929+
"start",
930+
["keyword","END"],
931+
["statementEnd",";"],
932+
["text"," "],
933+
["string","$$"],
934+
["statementEnd",";"]
935+
],[
936+
"start"
889937
]]

lib/ace/mode/pgsql_highlight_rules.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ var PgsqlHighlightRules = function() {
527527
next : "javascript-start"
528528
}, {
529529
token : "string",
530-
regex : "\\$[\\w_0-9]*\\$$", // dollar quote at the end of a line
530+
regex : "\\$\\$$",
531531
next : "dollarSql"
532532
}, {
533533
token : "string",
@@ -544,8 +544,8 @@ var PgsqlHighlightRules = function() {
544544
regex : "\\/\\*",
545545
next : "commentDollarSql"
546546
}, {
547-
token : "string", // end quoting with dollar at the start of a line
548-
regex : "^\\$[\\w_0-9]*\\$",
547+
token : ["keyword", "statementEnd", "text", "string"], // end quoting with dollar at the start of a line
548+
regex : "(^|END)(;)?(\\s*)(\\$\\$)",
549549
next : "statement"
550550
}, {
551551
token : "string",

0 commit comments

Comments
 (0)