drop function

This commit is contained in:
Christian De la Hoz 2021-08-31 19:09:32 +02:00
parent e7f520d7e5
commit 0c286e0edf
2 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,102 @@
================================================================================
basic
================================================================================
drop function foo(bigint, text);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier)
(identifier))))
================================================================================
many at once
================================================================================
drop function foo(bigint, text), foo(bigint);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier)
(identifier))
(drop_function_item
(identifier)
(identifier))))
================================================================================
without args
================================================================================
drop function foo;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier))))
================================================================================
with no args
================================================================================
drop function foo();
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier))))
================================================================================
cascade
================================================================================
drop function foo(bigint) cascade;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier))))
================================================================================
restrict
================================================================================
drop function foo(bigint) restrict;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier))))
================================================================================
if exists
================================================================================
drop function if exists foo();
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(if_exists)
(identifier))))
================================================================================
with argnames
================================================================================
drop function if exists foo(bar text, bigint);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(if_exists)
(identifier)
(var_declaration
(identifier)
(identifier))
(identifier))))

View File

@ -45,6 +45,7 @@ module.exports = grammar({
_statement: $ => choice(
$.psql_statement,
$.create_function_statement,
$.drop_function_statement,
$.create_table_statement,
$.create_schema_statement,
$.create_type_statement,
@ -59,6 +60,24 @@ module.exports = grammar({
$.do_block,
),
drop_function_statement: $ => seq(
kw("drop"), kw("function"),
commaSep1($.drop_function_item),
optional(choice(kw("cascade"), kw("restrict")))
),
drop_function_item: $ => seq(
optional($.if_exists),
$.identifier,
optional(
seq(
"(",
commaSep(
choice($.var_declaration, $._type,)
),
")",
))),
create_type_statement: $ => seq(
kw("create"), kw("type"), $.identifier, optional(choice(
seq(kw("as"), kw("enum"), "(", commaSep1($.string), ")"),