grammar: add unique column constraint
This commit is contained in:
parent
cc6fa3e0f7
commit
98c15a25dc
6 changed files with 1878 additions and 1443 deletions
11
grammar.js
11
grammar.js
|
@ -55,7 +55,13 @@ module.exports = grammar({
|
|||
choice(
|
||||
$._not_null,
|
||||
$.keyword_null,
|
||||
seq($.keyword_default, $._expression)
|
||||
seq($.keyword_default, $._expression),
|
||||
seq(
|
||||
$.keyword_unique,
|
||||
optional(
|
||||
seq($.keyword_nulls, optional($.keyword_not), $.keyword_distinct)
|
||||
)
|
||||
)
|
||||
// TODO: CHECK
|
||||
// TODO: GENERATED
|
||||
// TODO: UNIQUE
|
||||
|
@ -102,6 +108,9 @@ module.exports = grammar({
|
|||
keyword_default: (_) => mkKeyword("default"),
|
||||
keyword_true: (_) => mkKeyword("true"),
|
||||
keyword_false: (_) => mkKeyword("false"),
|
||||
keyword_nulls: (_) => mkKeyword("nulls"),
|
||||
keyword_distinct: (_) => mkKeyword("distinct"),
|
||||
keyword_unique: (_) => mkKeyword("unique"),
|
||||
|
||||
// References: https://www.postgresql.org/docs/15/datatype.html
|
||||
_type: ($) =>
|
||||
|
|
|
@ -242,6 +242,48 @@
|
|||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "keyword_unique"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "keyword_nulls"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "keyword_not"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "keyword_distinct"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -406,6 +448,18 @@
|
|||
"type": "PATTERN",
|
||||
"value": "false|FALSE"
|
||||
},
|
||||
"keyword_nulls": {
|
||||
"type": "PATTERN",
|
||||
"value": "nulls|NULLS"
|
||||
},
|
||||
"keyword_distinct": {
|
||||
"type": "PATTERN",
|
||||
"value": "distinct|DISTINCT"
|
||||
},
|
||||
"keyword_unique": {
|
||||
"type": "PATTERN",
|
||||
"value": "unique|UNIQUE"
|
||||
},
|
||||
"_type": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
|
|
@ -57,6 +57,10 @@
|
|||
"type": "keyword_default",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_distinct",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_not",
|
||||
"named": true
|
||||
|
@ -65,6 +69,14 @@
|
|||
"type": "keyword_null",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_nulls",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_unique",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "literal",
|
||||
"named": true
|
||||
|
@ -560,6 +572,10 @@
|
|||
"type": "keyword_default",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_distinct",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_exists",
|
||||
"named": true
|
||||
|
@ -596,6 +612,10 @@
|
|||
"type": "keyword_null",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_nulls",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_numeric",
|
||||
"named": true
|
||||
|
@ -628,6 +648,10 @@
|
|||
"type": "keyword_true",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_unique",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword_unlogged",
|
||||
"named": true
|
||||
|
|
3215
src/parser.c
3215
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -174,7 +174,7 @@ Create a table with column constraints
|
|||
create table foo (
|
||||
c1 text not null,
|
||||
c2 text null,
|
||||
c2 text not null default 'hello'
|
||||
c3 text not null default 'hello'
|
||||
);
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -225,7 +225,8 @@ Create a table with named column constraints
|
|||
create table foo (
|
||||
c1 text constraint strong_c1 not null,
|
||||
c2 text constraint weak_c2 null,
|
||||
c3 text constraint "c3 with power" not null constraint "c2 set default hello" default 'hello'
|
||||
c3 text constraint "c3 with power" not null constraint "c2 set default hello" default 'hello',
|
||||
c4 text constraint "c4 unique" unique nulls not distinct
|
||||
);
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -273,6 +274,18 @@ create table foo (
|
|||
(literal)
|
||||
)
|
||||
)
|
||||
(column_definition
|
||||
name: (identifier)
|
||||
datatype: (keyword_text)
|
||||
(column_constraint
|
||||
(keyword_constraint)
|
||||
name: (identifier)
|
||||
(keyword_unique)
|
||||
(keyword_nulls)
|
||||
(keyword_not)
|
||||
(keyword_distinct)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue