Skip to content

Commit

Permalink
Merge pull request #289 from matthias-Q/show_statements
Browse files Browse the repository at this point in the history
feat: add `SHOW` commands
  • Loading branch information
matthias-Q authored Nov 19, 2024
2 parents 4240085 + 66363f4 commit 40d1503
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
33 changes: 33 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = grammar({
keyword_update: _ => make_keyword("update"),
keyword_truncate: _ => make_keyword("truncate"),
keyword_merge: _ => make_keyword("merge"),
keyword_show: _ => make_keyword("show"),
keyword_into: _ => make_keyword("into"),
keyword_overwrite: _ => make_keyword("overwrite"),
keyword_values: _ => make_keyword("values"),
Expand Down Expand Up @@ -741,10 +742,42 @@ module.exports = grammar({
choice(
$._select_statement,
$.set_operation,
$._show_statement,
),
),
),

_show_statement: $ => seq(
$.keyword_show,
choice(
$._show_create,
$.keyword_all, // Postgres
$._show_tables // trino/presto
),
),

_show_tables: $ => seq(
$.keyword_tables,
optional(seq($.keyword_from, $._qualified_field)),
optional(seq($.keyword_like, $._expression))
),

_show_create: $ => seq(
$.keyword_create,
choice(
// Trino/Presto/MySQL
$.keyword_schema,
$.keyword_table,
seq(optional($.keyword_materialized), $.keyword_view),
// MySQL
$.keyword_user,
$.keyword_trigger,
$.keyword_procedure,
$.keyword_function
),
$.object_reference
),

cte: $ => seq(
$.identifier,
optional(paren_list(field("argument", $.identifier))),
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
(keyword_primary)
(keyword_delete)
(keyword_create)
(keyword_show)
(keyword_insert)
(keyword_merge)
(keyword_distinct)
Expand Down
95 changes: 95 additions & 0 deletions test/corpus/show.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
================================================================================
SHOW CREATE TABLE
================================================================================

SHOW CREATE TABLE mytable;

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

(program
(statement
(keyword_show)
(keyword_create)
(keyword_table)
(object_reference
(identifier))))

================================================================================
SHOW CREATE VIEW
================================================================================

SHOW CREATE VIEW myview;

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

(program
(statement
(keyword_show)
(keyword_create)
(keyword_view)
(object_reference
(identifier))))

================================================================================
SHOW CREATE SCHEMA
================================================================================

SHOW CREATE SCHEMA myschema;

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

(program
(statement
(keyword_show)
(keyword_create)
(keyword_schema)
(object_reference
(identifier))))

================================================================================
SHOW CREATE USER
================================================================================

SHOW CREATE USER einstein;

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

(program
(statement
(keyword_show)
(keyword_create)
(keyword_user)
(object_reference
(identifier))))

================================================================================
SHOW ALL
================================================================================

SHOW ALL;

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

(program
(statement
(keyword_show)
(keyword_all)))

================================================================================
SHOW TABLES with PATTERN
================================================================================

SHOW TABLES FROM tpch.tiny LIKE 'p%';

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

(program
(statement
(keyword_show)
(keyword_tables)
(keyword_from)
(object_reference
(identifier))
(identifier)
(keyword_like)
(literal)))

0 comments on commit 40d1503

Please sign in to comment.