Add initial support of TRUNCATE statement

Extend support of COMMENT and INSERT
pull/315/head
Maksim Novikov 2022-06-12 16:29:24 +07:00
parent 2685131425
commit 5340f94f45
No known key found for this signature in database
GPG Key ID: 2F1C320B72DA6C55
6 changed files with 38266 additions and 37133 deletions

@ -89,6 +89,7 @@ module.exports = grammar({
$.drop_statement,
$.create_statement,
$.alter_statement,
$.truncate_statement,
$.create_type_statement,
$.create_domain_statement,
$.create_index_statement,
@ -102,6 +103,14 @@ module.exports = grammar({
optional(";"),
),
truncate_statement: $ =>
seq(
kw("TRUNCATE"),
optional(kw("TABLE")),
optional(kw("ONLY")),
commaSep1($._identifier),
),
comment_statement: $ =>
seq(
kw("COMMENT ON"),
@ -449,7 +458,7 @@ module.exports = grammar({
create_table_statement: $ =>
seq(
kw("CREATE"),
optional(kw("TEMPORARY")),
optional(choice(kw("TEMPORARY"), kw("TEMP"))),
kw("TABLE"),
optional(kw("IF NOT EXISTS")),
$._identifier,

105
src/grammar.json vendored

@ -62,6 +62,10 @@
"type": "SYMBOL",
"name": "alter_statement"
},
{
"type": "SYMBOL",
"name": "truncate_statement"
},
{
"type": "SYMBOL",
"name": "create_type_statement"
@ -114,6 +118,79 @@
}
]
},
"truncate_statement": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[tT][rR][uU][nN][cC][aA][tT][eE]"
},
"named": false,
"value": "TRUNCATE"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[tT][aA][bB][lL][eE]"
},
"named": false,
"value": "TABLE"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[oO][nN][lL][yY]"
},
"named": false,
"value": "ONLY"
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_identifier"
}
]
}
}
]
}
]
},
"comment_statement": {
"type": "SEQ",
"members": [
@ -3321,13 +3398,27 @@
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[tT][eE][mM][pP][oO][rR][aA][rR][yY]"
},
"named": false,
"value": "TEMPORARY"
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[tT][eE][mM][pP][oO][rR][aA][rR][yY]"
},
"named": false,
"value": "TEMPORARY"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[tT][eE][mM][pP]"
},
"named": false,
"value": "TEMP"
}
]
},
{
"type": "BLANK"

@ -3943,6 +3943,10 @@
"type": "set_statement",
"named": true
},
{
"type": "truncate_statement",
"named": true
},
{
"type": "update_statement",
"named": true
@ -4109,6 +4113,25 @@
"named": true,
"fields": {}
},
{
"type": "truncate_statement",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "dotted_name",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "tuple",
"named": true,

75204
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -18,6 +18,26 @@ INSERT INTO table2 SELECT * FROM generate_series(1, 100, 1);
(number)
(string
(content)))))
(insert_statement
(identifier)
(identifier)
(values_clause
(values_clause_body
(number))))
(insert_statement
(identifier)
(identifier)
(values_clause
(values_clause_body
(number))))
(insert_statement
(identifier)
(identifier)
(identifier)
(values_clause
(values_clause_body
(number)
(number))))
(insert_statement
(identifier)
(select_statement

@ -886,6 +886,9 @@ CREATE TEMPORARY TABLE my_table2 (col1 INT, col2 INT);
(identifier)
(type
(identifier)))))
(create_table_statement
(identifier)
(table_parameters))
(create_table_statement
(identifier)
(table_parameters
@ -2318,5 +2321,38 @@ COMMENT ON COLUMN foo.bar.baz IS 'This is a comment.';
(dotted_name
(identifier)
(identifier)))
(string
(content)))
(comment_statement
(dotted_name
(identifier)
(identifier)
(identifier))
(string
(content))))
================================================================================
TRUNCATE STATEMENT
================================================================================
TRUNCATE mytable;
TRUNCATE ONLY mytable;
TRUNCATE TABLE mytable;
TRUNCATE TABLE ONLY mytable;
TRUNCATE mytable1, mytable1, "My Table 3";
--------------------------------------------------------------------------------
(source_file
(truncate_statement
(identifier))
(truncate_statement
(identifier))
(truncate_statement
(identifier))
(truncate_statement
(identifier))
(truncate_statement
(identifier)
(identifier)
(identifier)))