Skip to content

Commit

Permalink
feat: Add ONLY for ALTER TABLE statement.
Browse files Browse the repository at this point in the history
feat: Add comment on FUNCTION and EXTENSION.
feat: Add SET and RESET statement.
  • Loading branch information
antoineB committed Oct 8, 2023
1 parent 970b548 commit 1a2b0da
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ For a complete list of features see the the [tests](test/corpus)
though I may not have been strict early on in the prototyping.
* [Phoenix Language Reference](https://forcedotcom.github.io/phoenix/index.html) - A reference diagram.
* [SQLite's railroad diagram for expr](https://www.sqlite.org/lang_expr.html) - Another reference diagram.
* [Postgresql syntax documentation](https://www.postgresql.org/docs/current/sql-commands.html)
* [Mariadb syntax documentation](https://mariadb.com/kb/en/sql-statements-structure/)

### Other projects

Expand Down
85 changes: 83 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@ module.exports = grammar({
keyword_cost: _ => make_keyword("cost"),
keyword_rows: _ => make_keyword("rows"),
keyword_support: _ => make_keyword("support"),
keyword_extension: _ => make_keyword("extension"),
keyword_out: _ => make_keyword("out"),
keyword_inout: _ => make_keyword("inout"),
keyword_variadic: _ => make_keyword("variadic"),

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_committed: _ => make_keyword("committed"),
keyword_uncommitted: _ => make_keyword("uncommitted"),
keyword_deferrable: _ => make_keyword("deferrable"),
keyword_names: _ => make_keyword("names"),
keyword_zone: _ => make_keyword("zone"),
keyword_immediate: _ => make_keyword("immediate"),
keyword_deferred: _ => make_keyword("deferred"),
keyword_constraints : _ => make_keyword("constraints"),
keyword_snapshot: _ => make_keyword("snapshot"),
keyword_characteristics: _ => make_keyword("characteristics"),

// Hive Keywords
keyword_external: _ => make_keyword("external"),
Expand Down Expand Up @@ -644,6 +666,8 @@ module.exports = grammar({
$._optimize_statement,
$._merge_statement,
$.comment_statement,
$.set_statement,
$.reset_statement,
),

_cte: $ => seq(
Expand Down Expand Up @@ -735,6 +759,14 @@ module.exports = grammar({
),
),

_argmode: $ => choice(
$.keyword_in,
$.keyword_out,
$.keyword_inout,
$.keyword_variadic,
seq($.keyword_in, $.keyword_out),
),

_comment_target: $ => choice(
// TODO: access method
// TODO: aggregate
Expand All @@ -745,11 +777,11 @@ module.exports = grammar({
// TODO: conversion
seq($.keyword_database, $.identifier),
// TODO: domain
// TODO: extension
seq($.keyword_extension, $.object_reference),
// TODO: event trigger
// TODO: foreign data wrapper
// TODO: foreign table
// TODO: function
seq($.keyword_function, $.object_reference, optional(paren_list(seq(optional($._argmode), optional($.identifier), $._type), false))),
seq($.keyword_index, $.object_reference),
// TODO: large object
seq($.keyword_materialized, $.keyword_view, $.object_reference),
Expand Down Expand Up @@ -904,6 +936,54 @@ module.exports = grammar({
),
),

reset_statement: $ => seq(
$.keyword_reset,
choice(
$.object_reference,
$.keyword_all,
seq($.keyword_session, $.keyword_authorization),
$.keyword_role,
),
),

_transaction_mode: $ => seq(
$.keyword_isolation,
$.keyword_level,
choice(
$.keyword_serializable,
seq($.keyword_repeatable, $.keyword_read),
seq($.keyword_read, $.keyword_committed),
seq($.keyword_read, $.keyword_uncommitted),
),
choice(
seq($.keyword_read, $.keyword_write),
seq($.keyword_read, $.keyword_only),
),
optional($.keyword_not),
$.keyword_deferrable,
),

set_statement: $ => seq(
$.keyword_set,
choice(
seq(
optional(choice($.keyword_session, $.keyword_local)),
choice(
seq($.object_reference, choice($.keyword_to, '='), choice($.literal, $.keyword_default)),
seq($.keyword_schema, $.literal),
seq($.keyword_names, $.literal),
seq($.keyword_time, $.keyword_zone, choice($.literal, $.keyword_local, $.keyword_default)),
seq($.keyword_session, $.keyword_authorization, choice($.identifier, $.keyword_default)),
seq($.keyword_role, choice($.identifier, $.keyword_none)),
),
),
seq($.keyword_constraints, choice($.keyword_all, comma_list($.identifier, true)), choice($.keyword_deferred, $.keyword_immediate)),
seq($.keyword_transaction, $._transaction_mode),
seq($.keyword_transaction, $.keyword_snapshot, $._transaction_mode),
seq($.keyword_session, $.keyword_characteristics, $.keyword_as, $.keyword_transaction, $._transaction_mode),
),
),

create_query: $ => $._dml_read,

create_view: $ => prec.right(
Expand Down Expand Up @@ -1377,6 +1457,7 @@ module.exports = grammar({
$.keyword_alter,
$.keyword_table,
optional($._if_exists),
optional($.keyword_only),
$.object_reference,
choice(
seq(
Expand Down
21 changes: 21 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@
(keyword_user)
(keyword_valid)
(keyword_action)
(keyword_extension)
(keyword_out)
(keyword_inout)
(keyword_variadic)
(keyword_session)
(keyword_isolation)
(keyword_level)
(keyword_serializable)
(keyword_repeatable)
(keyword_read)
(keyword_write)
(keyword_committed)
(keyword_uncommitted)
(keyword_deferrable)
(keyword_names)
(keyword_zone)
(keyword_immediate)
(keyword_deferred)
(keyword_constraints)
(keyword_snapshot)
(keyword_characteristics)
] @keyword

[
Expand Down
42 changes: 42 additions & 0 deletions test/corpus/comment_stat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,45 @@ COMMENT ON TRIGGER on_insert ON users IS "new user has been added";
name: (identifier))
(keyword_is)
(literal))))

================================================================================
Comment on function
================================================================================

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

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

(program
(statement
(comment_statement
(keyword_comment)
(keyword_on)
(keyword_function)
(object_reference
(identifier)
(identifier))
(identifier)
(keyword_text)
(keyword_is)
(literal))))


================================================================================
Comment on extension
================================================================================

COMMENT ON EXTENSION ext_test IS 'A testing extension';

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

(program
(statement
(comment_statement
(keyword_comment)
(keyword_on)
(keyword_extension)
(object_reference
(identifier))
(keyword_is)
(literal))))

0 comments on commit 1a2b0da

Please sign in to comment.