grammar: add primary key column constraint

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-07 22:48:02 +03:00
parent 13896dfb7b
commit e4e1756164
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
6 changed files with 1832 additions and 1623 deletions

View File

@ -56,16 +56,16 @@ module.exports = grammar({
$._not_null,
$.keyword_null,
seq($.keyword_default, $._expression),
// TODO: add index_parameters in UNIQUE, PRIMARY KEY
seq(
$.keyword_unique,
optional(
seq($.keyword_nulls, optional($.keyword_not), $.keyword_distinct)
)
)
),
$.keyword_primary_key
// TODO: CHECK
// TODO: GENERATED
// TODO: UNIQUE
// TODO: PRIMARY KEY
// TODO: FOREIGN KEY
)
// TODO: DEFERRABLE
@ -195,6 +195,7 @@ module.exports = grammar({
keyword_nulls: (_) => mkKeyword("nulls"),
keyword_distinct: (_) => mkKeyword("distinct"),
keyword_unique: (_) => mkKeyword("unique"),
keyword_primary_key: (_) => seq(mkKeyword("primary"), mkKeyword("key")),
// References: https://www.postgresql.org/docs/15/datatype-xml.html
keyword_xml: (_) => mkKeyword("xml"),
// References: https://www.postgresql.org/docs/15/datatype-uuid.html

View File

@ -284,6 +284,10 @@
]
}
]
},
{
"type": "SYMBOL",
"name": "keyword_primary_key"
}
]
}
@ -993,6 +997,19 @@
"type": "PATTERN",
"value": "unique|UNIQUE"
},
"keyword_primary_key": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "primary|PRIMARY"
},
{
"type": "PATTERN",
"value": "key|KEY"
}
]
},
"keyword_xml": {
"type": "PATTERN",
"value": "xml|XML"

View File

@ -73,6 +73,10 @@
"type": "keyword_nulls",
"named": true
},
{
"type": "keyword_primary_key",
"named": true
},
{
"type": "keyword_unique",
"named": true
@ -321,6 +325,11 @@
"named": true,
"fields": {}
},
{
"type": "keyword_primary_key",
"named": true,
"fields": {}
},
{
"type": "keyword_temporary",
"named": true,

File diff suppressed because it is too large Load Diff

View File

@ -172,6 +172,7 @@ create table foo (
Create a table with column constraints
================================================================================
create table foo (
id uuid primary key,
c1 text not null,
c2 text null,
c3 text not null default 'hello'
@ -187,6 +188,13 @@ create table foo (
name: (identifier)
)
(column_definitions
(column_definition
name: (identifier)
datatype: (keyword_uuid)
(column_constraint
(keyword_primary_key)
)
)
(column_definition
name: (identifier)
datatype: (keyword_text)
@ -223,6 +231,7 @@ create table foo (
Create a table with named column constraints
================================================================================
create table foo (
id uuid constraint foo_pkey primary key,
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',
@ -239,6 +248,15 @@ create table foo (
name: (identifier)
)
(column_definitions
(column_definition
name: (identifier)
datatype: (keyword_uuid)
(column_constraint
(keyword_constraint)
name: (identifier)
(keyword_primary_key)
)
)
(column_definition
name: (identifier)
datatype: (keyword_text)

Binary file not shown.