diff --git a/src/parser.pegjs b/src/parser.pegjs index 04376e9f..2e5e2ce6 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -9589,6 +9589,7 @@ __hspace__ // Comments comment = line_comment + / &only_postgres x:psql_restrict_command { return x; } / conditional_comment / !postgres x:pound_sign_comment { return x; } / !postgres x:block_comment { return x; } @@ -9631,6 +9632,14 @@ line_comment }); } +psql_restrict_command + = "\\" ("restrict " / "unrestrict ") (!end_of_line .)* { + return loc({ + type: "line_comment", + text: text(), + }); + } + pound_sign_comment = "#" (!end_of_line .)* { return loc({ diff --git a/test/whitespace.test.ts b/test/whitespace.test.ts index 527f2908..6e7c816a 100644 --- a/test/whitespace.test.ts +++ b/test/whitespace.test.ts @@ -179,6 +179,13 @@ describe("whitespace", () => { test("SELECT 1 + -- comment 1\n -- comment 2\n 2"); }); + dialect("postgresql", () => { + it("parses pg_dump restrict commands", () => { + const key = "aB3".repeat(21); // 63 alphanumeric characters + test(`\\restrict ${key}\nSELECT 1;\n\\unrestrict ${key}\n`); + }); + }); + dialect(["bigquery", "sqlite", "mysql", "mariadb"], () => { it("parses hash comments", () => { test("SELECT 1 + # comment 1\n # comment 2\n 2");