Repository: DerekStride/tree-sitter-sql (language: python)

Issue:
Feature request: `RENAME TABLE tbl_old TO tbl_new`
```sql
RENAME TABLE `tbl_old` TO `tbl_new`;
```

### Documentation

https://mariadb.com/kb/en/rename-table/

### Error
![grafik](https://github.com/DerekStride/tree-sitter-sql/assets/22329650/84c4b11e-e2d5-4519-91d3-ec82bf2c2f34)

### Syntax

```
RENAME TABLE[S] [IF EXISTS] tbl_name 
  [WAIT n | NOWAIT]
  TO new_tbl_name
    [, tbl_name2 TO new_tbl_name2] ...
```

### Adjustments

New `$._rename_statement`, or directly `$.rename_table` at:
https://github.com/DerekStride/tree-sitter-sql/blob/main/grammar.js#L484-L488

Definition of `rename_table`, similar to, but simpler than `alter_table`.


Discussion / hints:

Fix patch:
diff --git a/grammar.js b/grammar.js
index 508c7457..bd741561 100644
--- a/grammar.js
+++ b/grammar.js
@@ -75,6 +75,7 @@ module.exports = grammar({
     keyword_drop: _ => make_keyword("drop"),
     keyword_add: _ => make_keyword("add"),
     keyword_table: _ => make_keyword("table"),
+    keyword_tables: _ => make_keyword("tables"),
     keyword_view: _ => make_keyword("view"),
     keyword_materialized: _ => make_keyword("materialized"),
     keyword_column: _ => make_keyword("column"),
@@ -183,6 +184,8 @@ module.exports = grammar({
     keyword_current_timestamp: _ => make_keyword("current_timestamp"),
     keyword_check: _ => make_keyword("check"),
     keyword_option: _ => make_keyword("option"),
+    keyword_wait: _ => make_keyword("wait"),
+    keyword_nowait: _ => make_keyword("nowait"),
 
     keyword_trigger: _ => make_keyword('trigger'),
     keyword_function: _ => make_keyword("function"),
@@ -485,6 +488,7 @@ module.exports = grammar({
       $._create_statement,
       $._alter_statement,
       $._drop_statement,
+      $._rename_statement,
     ),
 
     _cte: $ => seq(
@@ -1026,6 +1030,39 @@ module.exports = grammar({
       ),
     ),
 
+    _rename_statement: $ => seq(
+      $.keyword_rename,
+      choice(
+        $.keyword_table,
+        $.keyword_tables,
+      ),
+      optional($._if_exists),
+      $.table_reference,
+      optional(
+        choice(
+          $.keyword_nowait,
+          seq(
+            $.keyword_wait,
+            field('timeout', alias($._natural_number, $.literal))
+          )
+        )
+      ),
+      $.keyword_to,
+      $.table_reference,
+      repeat(
+        seq(
+          ',',
+          $._rename_table_names,
+        )
+      ),
+    ),
+
+    _rename_table_names: $ => seq(
+      $.table_reference,
+      $.keyword_to,
+      $.table_reference,
+    ),
+
     alter_table: $ => seq(
       $.keyword_alter,
       $.keyword_table,


Test patch:
diff --git a/test/corpus/alter.txt b/test/corpus/alter.txt
index 09001013..d2102bb9 100644
--- a/test/corpus/alter.txt
+++ b/test/corpus/alter.txt
@@ -599,3 +599,32 @@ FOREIGN KEY ("accountId") REFERENCES "Account" ("accountId") ON DELETE CASCADE;
           (keyword_on)
           (keyword_delete)
           (keyword_cascade))))))
+
+================================================================================
+MySQL: Rename table
+================================================================================
+
+RENAME TABLES IF EXISTS old_table
+NOWAIT
+TO backup_table,
+new_table TO old_table;
+
+--------------------------------------------------------------------------------
+
+(program
+  (statement
+    (keyword_rename)
+    (keyword_tables)
+    (keyword_if)
+    (keyword_exists)
+    (table_reference
+      (identifier))
+    (keyword_nowait)
+    (keyword_to)
+    (table_reference
+      (identifier))
+    (table_reference
+      (identifier))
+    (keyword_to)
+    (table_reference
+      (identifier))))