diff --git a/corpus/drop_function_statement.txt b/corpus/drop_function_statement.txt new file mode 100644 index 0000000..2ea047d --- /dev/null +++ b/corpus/drop_function_statement.txt @@ -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)))) diff --git a/grammar.js b/grammar.js index c7686db..c12b497 100644 --- a/grammar.js +++ b/grammar.js @@ -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), ")"),