From 66363f4ef63ef2d890fd15dead084257ad27e0f2 Mon Sep 17 00:00:00 2001 From: Matthias Queitsch Date: Sat, 16 Nov 2024 00:29:08 +0100 Subject: [PATCH] feat: add `SHOW` commands --- grammar.js | 33 +++++++++++++++ queries/highlights.scm | 1 + test/corpus/show.txt | 95 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 test/corpus/show.txt diff --git a/grammar.js b/grammar.js index cb3d2ff..3970224 100644 --- a/grammar.js +++ b/grammar.js @@ -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"), @@ -740,10 +741,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))), diff --git a/queries/highlights.scm b/queries/highlights.scm index 385caff..b0dd07e 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -110,6 +110,7 @@ (keyword_primary) (keyword_delete) (keyword_create) + (keyword_show) (keyword_insert) (keyword_merge) (keyword_distinct) diff --git a/test/corpus/show.txt b/test/corpus/show.txt new file mode 100644 index 0000000..59cb8d6 --- /dev/null +++ b/test/corpus/show.txt @@ -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)))