From dc0ff18f188680c32ebf6d5e71746e7e5f1b7dc3 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 6 Jan 2023 00:54:05 +0300 Subject: [PATCH] grammar: improve table constraint --- grammar.js | 12 ++++-------- src/grammar.json | 47 +++++++++++++++++------------------------------ 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/grammar.js b/grammar.js index 99d316e..1a02de8 100644 --- a/grammar.js +++ b/grammar.js @@ -329,14 +329,10 @@ module.exports = grammar({ ), table_constraint: ($) => - choice( - seq($.table_constraint_ty, optional($.constraint_when)), - seq( - kw("constraint"), - $.identifier, - $.table_constraint_ty, - optional($.constraint_when) - ) + seq( + optional(seq(kw("constraint"), $.identifier)), + $.table_constraint_ty, + optional($.constraint_when) ), constraint_when: ($) => diff --git a/src/grammar.json b/src/grammar.json index 4baedf3..97935e4 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -2144,55 +2144,42 @@ ] }, "table_constraint": { - "type": "CHOICE", + "type": "SEQ", "members": [ { - "type": "SEQ", + "type": "CHOICE", "members": [ { - "type": "SYMBOL", - "name": "table_constraint_ty" - }, - { - "type": "CHOICE", + "type": "SEQ", "members": [ { - "type": "SYMBOL", - "name": "constraint_when" + "type": "PATTERN", + "value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" }, { - "type": "BLANK" + "type": "SYMBOL", + "name": "identifier" } ] + }, + { + "type": "BLANK" } ] }, { - "type": "SEQ", + "type": "SYMBOL", + "name": "table_constraint_ty" + }, + { + "type": "CHOICE", "members": [ - { - "type": "PATTERN", - "value": "[cC][oO][nN][sS][tT][rR][aA][iI][nN][tT]" - }, { "type": "SYMBOL", - "name": "identifier" + "name": "constraint_when" }, { - "type": "SYMBOL", - "name": "table_constraint_ty" - }, - { - "type": "CHOICE", - "members": [ - { - "type": "SYMBOL", - "name": "constraint_when" - }, - { - "type": "BLANK" - } - ] + "type": "BLANK" } ] }