Skip to content

Commit

Permalink
feat: Add create extension statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineB committed Oct 15, 2023
1 parent 385aff4 commit 87c1401
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
23 changes: 23 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ module.exports = grammar({
keyword_attribute: _ => make_keyword("attribute"),
keyword_authorization: _ => make_keyword("authorization"),
keyword_action: _ => make_keyword("action"),
keyword_extension: _ => make_keyword("extension"),

keyword_trigger: _ => make_keyword('trigger'),
keyword_function: _ => make_keyword("function"),
Expand All @@ -262,6 +263,7 @@ module.exports = grammar({
keyword_cost: _ => make_keyword("cost"),
keyword_rows: _ => make_keyword("rows"),
keyword_support: _ => make_keyword("support"),
keyword_version: _ => make_keyword("version"),

// Hive Keywords
keyword_external: _ => make_keyword("external"),
Expand Down Expand Up @@ -845,6 +847,7 @@ module.exports = grammar({
$.create_database,
$.create_role,
$.create_sequence,
$.create_extension,
prec.left(seq(
$.create_schema,
repeat($._create_statement),
Expand Down Expand Up @@ -1290,6 +1293,17 @@ module.exports = grammar({
),
),

create_extension: $ => seq(
$.keyword_create,
$.keyword_extension,
optional($._if_not_exists),
$.identifier,
optional($.keyword_with),
optional(seq($.keyword_schema, $.identifier)),
optional(seq($.keyword_version, choice($.identifier, $._literal_string))),
optional($.keyword_cascade),
),

create_type: $ => seq(
$.keyword_create,
$.keyword_type,
Expand Down Expand Up @@ -1738,6 +1752,7 @@ module.exports = grammar({
$.drop_database,
$.drop_role,
$.drop_sequence,
$.drop_extension,
),
),

Expand Down Expand Up @@ -1816,6 +1831,14 @@ module.exports = grammar({
),
),

drop_extension: $ => seq(
$.keyword_drop,
$.keyword_extension,
optional($._if_exists),
comma_list($.identifier, true),
optional(choice($.keyword_cascade, $.keyword_restrict)),
),

rename_object: $ => seq(
$.keyword_rename,
$.keyword_to,
Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@
(keyword_user)
(keyword_valid)
(keyword_action)
(keyword_extension)
(keyword_version)
] @keyword

[
Expand Down
21 changes: 21 additions & 0 deletions test/corpus/create.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1948,3 +1948,24 @@ OWNED BY numbers.number_sequences;
(object_reference
(identifier)
(identifier)))))

================================================================================
Create extension
================================================================================

CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;

--------------------------------------------------------------------------------

(program
(statement
(create_extension
(keyword_create)
(keyword_extension)
(keyword_if)
(keyword_not)
(keyword_exists)
(identifier)
(keyword_with)
(keyword_schema)
(identifier))))
15 changes: 15 additions & 0 deletions test/corpus/drop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,18 @@ DROP SEQUENCE IF EXISTS serial RESTRICT;
(object_reference
(identifier))
(keyword_restrict))))

================================================================================
Drop extension
================================================================================

DROP EXTENSION my_extension;

--------------------------------------------------------------------------------

(program
(statement
(drop_extension
(keyword_drop)
(keyword_extension)
(identifier))))

0 comments on commit 87c1401

Please sign in to comment.