Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions test/whitespace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down