grammar: move constraint to hidden rule

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-06 01:01:38 +03:00
parent 78fa02efd1
commit dc314830d2
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 30316 additions and 30329 deletions

View file

@ -160,7 +160,7 @@ module.exports = grammar({
conflict_target: ($) => conflict_target: ($) =>
choice( choice(
seq(kw("on"), kw("constraint"), $.identifier), seq(kw("on"), $._constraint, $.identifier),
seq("(", commaSep($._value_expression), ")") seq("(", commaSep($._value_expression), ")")
), ),
@ -298,7 +298,7 @@ module.exports = grammar({
), ),
seq( seq(
kw("drop"), kw("drop"),
kw("constraint"), $._constraint,
optional($.if_exists), optional($.if_exists),
$.identifier, $.identifier,
optional($.alter_table_fk_ref_action) optional($.alter_table_fk_ref_action)
@ -330,7 +330,7 @@ module.exports = grammar({
table_constraint: ($) => table_constraint: ($) =>
seq( seq(
optional(seq(kw("constraint"), $.identifier)), optional(seq($._constraint, $.identifier)),
$.table_constraint_ty, $.table_constraint_ty,
optional($.constraint_when) optional($.constraint_when)
), ),
@ -379,19 +379,17 @@ module.exports = grammar({
alter_column_type: ($) => alter_column_type: ($) =>
seq($._type, optional(seq(kw("using"), $._value_expression))), seq($._type, optional(seq(kw("using"), $._value_expression))),
alter_table_fk_ref_action: ($) => choice(kw("restrict"), kw("cascade")), alter_table_fk_ref_action: ($) => choice(kw("restrict"), kw("cascade")),
table_column_item: ($) => table_column_item: ($) =>
seq($.identifier, $._type, repeat($.column_constraint)), seq($.identifier, $._type, repeat($.column_constraint)),
column_constraint: ($) => column_constraint: ($) =>
choice( seq(
seq( optional(seq($._constraint, $.identifier)),
kw("constraint"), $.column_constraint_ty,
$.identifier, optional($.constraint_when)
$.column_constraint_ty,
optional($.constraint_when)
),
seq($.column_constraint_ty, optional($.constraint_when))
), ),
column_constraint_ty: ($) => column_constraint_ty: ($) =>
@ -413,9 +411,12 @@ module.exports = grammar({
kw("to"), kw("to"),
$.identifier $.identifier
), ),
alter_table_rename_constraint: ($) => alter_table_rename_constraint: ($) =>
seq(kw("rename"), kw("constraint"), $.identifier, kw("to"), $.identifier), seq(kw("rename"), $._constraint, $.identifier, kw("to"), $.identifier),
alter_table_rename_table: ($) => seq(kw("rename"), kw("to"), $.identifier), alter_table_rename_table: ($) => seq(kw("rename"), kw("to"), $.identifier),
alter_table_change_schema: ($) => alter_table_change_schema: ($) =>
seq(kw("set"), kw("schema"), $.identifier), seq(kw("set"), kw("schema"), $.identifier),
@ -517,7 +518,7 @@ module.exports = grammar({
create_trigger_statement: ($) => create_trigger_statement: ($) =>
seq( seq(
kw("create"), kw("create"),
optional(kw("constraint")), optional($._constraint),
kw("trigger"), kw("trigger"),
$.identifier, $.identifier,
$.trigger_when, $.trigger_when,
@ -1083,5 +1084,8 @@ module.exports = grammar({
_identifier: ($) => /[a-zA-Z0-9_]+(\.?[a-zA-Z0-9_]+)*/, _identifier: ($) => /[a-zA-Z0-9_]+(\.?[a-zA-Z0-9_]+)*/,
// ^ // ^
// |- we dont want to match consecutive dots, e.g: 1..2 consists of 3 tokens // |- we dont want to match consecutive dots, e.g: 1..2 consists of 3 tokens
//--------------------------
_constraint: ($) => kw("constraint"),
}, },
}); });

View file

@ -955,8 +955,8 @@
"value": "[oO][nN]" "value": "[oO][nN]"
}, },
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" "name": "_constraint"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -1919,8 +1919,8 @@
"value": "[dD][rR][oO][pP]" "value": "[dD][rR][oO][pP]"
}, },
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" "name": "_constraint"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -2153,8 +2153,8 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" "name": "_constraint"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -2488,55 +2488,42 @@
] ]
}, },
"column_constraint": { "column_constraint": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "PATTERN", "type": "SEQ",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "column_constraint_ty"
},
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "constraint_when" "name": "_constraint"
}, },
{ {
"type": "BLANK" "type": "SYMBOL",
"name": "identifier"
} }
] ]
},
{
"type": "BLANK"
} }
] ]
}, },
{ {
"type": "SEQ", "type": "SYMBOL",
"name": "column_constraint_ty"
},
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "column_constraint_ty" "name": "constraint_when"
}, },
{ {
"type": "CHOICE", "type": "BLANK"
"members": [
{
"type": "SYMBOL",
"name": "constraint_when"
},
{
"type": "BLANK"
}
]
} }
] ]
} }
@ -2660,8 +2647,8 @@
"value": "[rR][eE][nN][aA][mM][eE]" "value": "[rR][eE][nN][aA][mM][eE]"
}, },
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" "name": "_constraint"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -3457,8 +3444,8 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" "name": "_constraint"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -7044,6 +7031,10 @@
"_identifier": { "_identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[a-zA-Z0-9_]+(\\.?[a-zA-Z0-9_]+)*" "value": "[a-zA-Z0-9_]+(\\.?[a-zA-Z0-9_]+)*"
},
"_constraint": {
"type": "PATTERN",
"value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]"
} }
}, },
"extras": [ "extras": [

60546
src/parser.c

File diff suppressed because it is too large Load diff