grammar: add varchar predefined type

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-06 00:40:41 +03:00
parent ce72078360
commit 6e78cac399
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 70965 additions and 69043 deletions

View file

@ -875,7 +875,7 @@ module.exports = grammar({
_type: ($) => _type: ($) =>
seq( seq(
choice($.predefined_types, $.identifier), choice($.predefined_type, $.identifier),
optional(choice(repeat1(seq("[", "]")), kw("%rowtype"), kw("%type"))) optional(choice(repeat1(seq("[", "]")), kw("%rowtype"), kw("%type")))
), ),
@ -907,10 +907,16 @@ module.exports = grammar({
// | VARCHAR l = type_length? { VarChar(l) } // | VARCHAR l = type_length? { VarChar(l) }
// (* | schema_qualified_name_nontype (LEFT_PAREN vex (COMMA vex)* RIGHT_PAREN)? *) // (* | schema_qualified_name_nontype (LEFT_PAREN vex (COMMA vex)* RIGHT_PAREN)? *)
// TODO(chrde): moar types!! // TODO(chrde): moar types!!
predefined_types: ($) => choice(seq(kw("numeric"), optional($.precision))), predefined_type: ($) =>
choice(
seq(kw("numeric"), optional($.precision)),
seq(kw("varchar"), optional($.type_length))
),
precision: ($) => seq("(", $.number, optional(seq(",", $.number)), ")"), precision: ($) => seq("(", $.number, optional(seq(",", $.number)), ")"),
type_length: ($) => seq("(", $.number, ")"),
string: ($) => string: ($) =>
seq("'", repeat(choice(prec(1, /''/), prec(2, /[^']/))), "'"), seq("'", repeat(choice(prec(1, /''/), prec(2, /[^']/))), "'"),

View file

@ -5869,7 +5869,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "predefined_types" "name": "predefined_type"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -5916,7 +5916,7 @@
} }
] ]
}, },
"predefined_types": { "predefined_type": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -5939,6 +5939,27 @@
] ]
} }
] ]
},
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[vV][aA][rR][cC][hH][aA][rR]"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_length"
},
{
"type": "BLANK"
}
]
}
]
} }
] ]
}, },
@ -5980,6 +6001,23 @@
} }
] ]
}, },
"type_length": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "number"
},
{
"type": "STRING",
"value": ")"
}
]
},
"string": { "string": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

View file

@ -107,7 +107,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
}, },
{ {
@ -1163,7 +1163,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
}, },
{ {
@ -1770,7 +1770,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
}, },
{ {
@ -1841,7 +1841,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
} }
] ]
@ -2577,7 +2577,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
}, },
{ {
@ -2749,7 +2749,7 @@
} }
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
@ -2759,6 +2759,10 @@
{ {
"type": "precision", "type": "precision",
"named": true "named": true
},
{
"type": "type_length",
"named": true
} }
] ]
} }
@ -2854,7 +2858,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
} }
] ]
@ -3584,7 +3588,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
} }
] ]
@ -3841,6 +3845,21 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "type_length",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "number",
"named": true
}
]
}
},
{ {
"type": "update_set", "type": "update_set",
"named": true, "named": true,
@ -3989,7 +4008,7 @@
"named": true "named": true
}, },
{ {
"type": "predefined_types", "type": "predefined_type",
"named": true "named": true
} }
] ]

139867
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -55,6 +55,54 @@ create unlogged table foo();
) )
) )
================================================================================
create table with predefined types
================================================================================
create table foo(
col1 numeric,
col2 numeric(2),
col3 numeric(2, 4),
col4 varchar,
col5 varchar(255)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_column_item
(identifier)
(predefined_type)
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (precision (number)))
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (precision (number) (number)))
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type)
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (type_length (number)))
)
)
)
)
================================================================================ ================================================================================
constraints with deferred constraints with deferred
================================================================================ ================================================================================
@ -85,7 +133,7 @@ create table foo(
(create_table_item (create_table_item
(table_column_item (table_column_item
(identifier) (identifier)
(predefined_types (predefined_type
(precision (precision
(number) (number)
(number))) (number)))
@ -137,7 +185,7 @@ create table foo(
(create_table_item (create_table_item
(table_column_item (table_column_item
(identifier) (identifier)
(predefined_types (predefined_type
(precision (precision
(number) (number)
(number))) (number)))

Binary file not shown.