Skip to content

Commit

Permalink
Change set statement to accept on/off as keyword and not identifier.
Browse files Browse the repository at this point in the history
Add test to set/reset statement.
Correct keyword typos.
Add test on function arguments with default value and IN/OUT mode.
  • Loading branch information
antoineB committed Oct 15, 2023
1 parent 8421bb7 commit 88ff038
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 5 deletions.
21 changes: 16 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = grammar({
keyword_lateral: _ => make_keyword("lateral"),
keyword_natural: _ => make_keyword("natural"),
keyword_on: _ => make_keyword("on"),
keyword_off: _ => make_keyword("off"),
keyword_where: _ => make_keyword("where"),
keyword_order: _ => make_keyword("order"),
keyword_group: _ => make_keyword("group"),
Expand Down Expand Up @@ -273,10 +274,10 @@ module.exports = grammar({
keyword_session: _ => make_keyword("session"),
keyword_isolation: _ => make_keyword("isolation"),
keyword_level: _ => make_keyword("level"),
keyword_serializable: _ => make_keyword("seria"),
keyword_repeatable: _ => make_keyword("repeatable: _ ="),
keyword_read: _ => make_keyword("read: _ =>"),
keyword_write: _ => make_keyword("wr"),
keyword_serializable: _ => make_keyword("serializable"),
keyword_repeatable: _ => make_keyword("repeatable"),
keyword_read: _ => make_keyword("read"),
keyword_write: _ => make_keyword("write"),
keyword_committed: _ => make_keyword("committed"),
keyword_uncommitted: _ => make_keyword("uncommitted"),
keyword_deferrable: _ => make_keyword("deferrable"),
Expand Down Expand Up @@ -994,7 +995,17 @@ module.exports = grammar({
seq(
optional(choice($.keyword_session, $.keyword_local)),
choice(
seq($.object_reference, choice($.keyword_to, '='), choice($.literal, $.keyword_default, $.identifier)),
seq(
$.object_reference,
choice($.keyword_to, '='),
choice(
$.literal,
$.keyword_default,
$.identifier,
$.keyword_on,
$.keyword_off,
),
),
seq($.keyword_schema, $.literal),
seq($.keyword_names, $.literal),
seq($.keyword_time, $.keyword_zone, choice($.literal, $.keyword_local, $.keyword_default)),
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
(keyword_constraints)
(keyword_snapshot)
(keyword_characteristics)
(keyword_off)
] @keyword

[
Expand Down
25 changes: 25 additions & 0 deletions test/corpus/comment_stat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,28 @@ COMMENT ON EXTENSION ext_test IS 'A testing extension';
(identifier))
(keyword_is)
(literal))))

================================================================================
Comment on function with arg mode
================================================================================

COMMENT ON FUNCTION schema_test.do_somthing(OUT arg1 text) IS 'Do something';

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

(program
(statement
(comment_statement
(keyword_comment)
(keyword_on)
(keyword_function)
(object_reference
(identifier)
(identifier))
(function_arguments
(function_argument
(keyword_out)
(identifier)
(keyword_text)))
(keyword_is)
(literal))))
49 changes: 49 additions & 0 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,52 @@ $function$
(identifier))
(keyword_end)
(dollar_quote)))))

================================================================================
SQL function creation with complex arguments
================================================================================

create or replace function public.fn(IN arg1 text, OUT arg2 int DEFAULT 12, IN OUT arg3 text = 'test')
returns int
language sql
return 1;

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

(program
(statement
(create_function
(keyword_create)
(keyword_or)
(keyword_replace)
(keyword_function)
(object_reference
(identifier)
(identifier))
(function_arguments
(function_argument
(keyword_in)
(identifier)
(keyword_text))
(function_argument
(keyword_out)
(identifier)
(int
(keyword_int))
(keyword_default)
(literal))
(function_argument
(keyword_in)
(keyword_out)
(identifier)
(keyword_text)
(literal)))
(keyword_returns)
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_return)
(literal)))))
93 changes: 93 additions & 0 deletions test/corpus/set.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
================================================================================
Set statement
================================================================================

SET client_encoding = 'UTF8';

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

(program
(statement
(set_statement
(keyword_set)
(object_reference
(identifier))
(literal))))

================================================================================
Set statement on
================================================================================

SET standard_conforming_strings = on;

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

(program
(statement
(set_statement
(keyword_set)
(object_reference
(identifier))
(keyword_on))))

================================================================================
Set statement off
================================================================================

SET standard_conforming_strings = off;

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

(program
(statement
(set_statement
(keyword_set)
(object_reference
(identifier))
(keyword_off))))

================================================================================
Set statement default
================================================================================

SET standard_conforming_strings TO DEFAULT;

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

(program
(statement
(set_statement
(keyword_set)
(object_reference
(identifier))
(keyword_to)
(keyword_default))))

================================================================================
Reset statement
================================================================================

RESET standard_conforming_strings;

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

(program
(statement
(reset_statement
(keyword_reset)
(object_reference
(identifier)))))

================================================================================
Reset all
================================================================================

RESET ALL;

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

(program
(statement
(reset_statement
(keyword_reset)
(keyword_all))))

0 comments on commit 88ff038

Please sign in to comment.