grammar: add unlogged rule

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-06 00:29:36 +03:00
parent 75e081f335
commit ce72078360
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
6 changed files with 61394 additions and 66196 deletions

View file

@ -1,13 +1,9 @@
function kw(word, aliasAsWord = true) { function kw(word) {
let pattern = ""; let pattern = Array.from(word).reduce(
for (const letter of word) { (acc, letter) => acc + `[${letter}${letter.toUpperCase()}]`,
pattern += `[${letter}${letter.toUpperCase()}]`; ""
} );
let result = new RegExp(pattern); return new RegExp(pattern);
if (aliasAsWord) {
result = alias(result, word);
}
return result;
} }
function separated(separator, rule) { function separated(separator, rule) {
@ -189,7 +185,7 @@ module.exports = grammar({
seq( seq(
kw("create"), kw("create"),
optional($.temporary), optional($.temporary),
optional(kw("unlogged")), optional($.unlogged),
kw("table"), kw("table"),
optional($.if_not_exists), optional($.if_not_exists),
$.identifier, $.identifier,
@ -507,13 +503,19 @@ module.exports = grammar({
sequence_increment: ($) => sequence_increment: ($) =>
seq(kw("increment"), optional(kw("by")), $.number), seq(kw("increment"), optional(kw("by")), $.number),
sequence_min: ($) => sequence_min: ($) =>
choice(seq(kw("no"), kw("minvalue")), seq(kw("minvalue"), $.number)), choice(seq(kw("no"), kw("minvalue")), seq(kw("minvalue"), $.number)),
sequence_max: ($) => sequence_max: ($) =>
choice(seq(kw("no"), kw("maxvalue")), seq(kw("maxvalue"), $.number)), choice(seq(kw("no"), kw("maxvalue")), seq(kw("maxvalue"), $.number)),
sequence_start: ($) => seq(kw("start"), optional(kw("with")), $.number), sequence_start: ($) => seq(kw("start"), optional(kw("with")), $.number),
sequence_cache: ($) => seq(kw("cache"), $.number), sequence_cache: ($) => seq(kw("cache"), $.number),
sequence_cycle: ($) => seq(optional(kw("no")), kw("cycle")), sequence_cycle: ($) => seq(optional(kw("no")), kw("cycle")),
sequence_owned: ($) => sequence_owned: ($) =>
seq(kw("owned"), kw("by"), choice(kw("none"), $.identifier)), seq(kw("owned"), kw("by"), choice(kw("none"), $.identifier)),
@ -863,6 +865,8 @@ module.exports = grammar({
temporary: ($) => choice(kw("temp"), kw("temporary")), temporary: ($) => choice(kw("temp"), kw("temporary")),
unlogged: ($) => kw("unlogged"),
if_not_exists: ($) => seq(kw("if"), kw("not"), kw("exists")), if_not_exists: ($) => seq(kw("if"), kw("not"), kw("exists")),
if_exists: ($) => seq(kw("if"), kw("exists")), if_exists: ($) => seq(kw("if"), kw("exists")),

File diff suppressed because it is too large Load diff

View file

@ -291,11 +291,6 @@
] ]
} }
}, },
{
"type": "and",
"named": true,
"fields": {}
},
{ {
"type": "array_constructor", "type": "array_constructor",
"named": true, "named": true,
@ -985,6 +980,10 @@
{ {
"type": "temporary", "type": "temporary",
"named": true "named": true
},
{
"type": "unlogged",
"named": true
} }
] ]
} }
@ -1342,11 +1341,6 @@
] ]
} }
}, },
{
"type": "false",
"named": true,
"fields": {}
},
{ {
"type": "fk_action", "type": "fk_action",
"named": true, "named": true,
@ -3847,11 +3841,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "true",
"named": true,
"fields": {}
},
{ {
"type": "update_set", "type": "update_set",
"named": true, "named": true,
@ -3987,14 +3976,6 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "%rowtype",
"named": false
},
{
"type": "%type",
"named": false
},
{ {
"type": "[", "type": "[",
"named": false "named": false
@ -4203,14 +4184,6 @@
"type": "%", "type": "%",
"named": false "named": false
}, },
{
"type": "%rowtype",
"named": false
},
{
"type": "%type",
"named": false
},
{ {
"type": "&&", "type": "&&",
"named": false "named": false
@ -4327,673 +4300,33 @@
"type": "]", "type": "]",
"named": false "named": false
}, },
{
"type": "action",
"named": false
},
{
"type": "add",
"named": false
},
{
"type": "after",
"named": false
},
{
"type": "all",
"named": false
},
{
"type": "alter",
"named": false
},
{ {
"type": "and", "type": "and",
"named": false "named": true
},
{
"type": "array",
"named": false
},
{
"type": "as",
"named": false
},
{
"type": "asc",
"named": false
},
{
"type": "at",
"named": false
},
{
"type": "authorization",
"named": false
},
{
"type": "before",
"named": false
},
{
"type": "begin",
"named": false
},
{
"type": "between",
"named": false
},
{
"type": "by",
"named": false
},
{
"type": "cache",
"named": false
},
{
"type": "cascade",
"named": false
}, },
{ {
"type": "cast", "type": "cast",
"named": true "named": true
}, },
{
"type": "check",
"named": false
},
{
"type": "column",
"named": false
},
{ {
"type": "comment", "type": "comment",
"named": true "named": true
}, },
{
"type": "concurrently",
"named": false
},
{
"type": "conflict",
"named": false
},
{
"type": "constraint",
"named": false
},
{
"type": "create",
"named": false
},
{
"type": "cross",
"named": false
},
{
"type": "current",
"named": false
},
{
"type": "current_user",
"named": false
},
{
"type": "cycle",
"named": false
},
{
"type": "data",
"named": false
},
{
"type": "day",
"named": false
},
{
"type": "declare",
"named": false
},
{
"type": "default",
"named": false
},
{
"type": "deferrable",
"named": false
},
{
"type": "deferred",
"named": false
},
{
"type": "definer",
"named": false
},
{
"type": "delete",
"named": false
},
{
"type": "desc",
"named": false
},
{
"type": "diagnostics",
"named": false
},
{
"type": "do",
"named": false
},
{
"type": "drop",
"named": false
},
{
"type": "each",
"named": false
},
{
"type": "else",
"named": false
},
{
"type": "elseif",
"named": false
},
{
"type": "elsif",
"named": false
},
{
"type": "end",
"named": false
},
{
"type": "enum",
"named": false
},
{
"type": "execute",
"named": false
},
{
"type": "exists",
"named": false
},
{ {
"type": "false", "type": "false",
"named": false "named": true
},
{
"type": "first",
"named": false
},
{
"type": "for",
"named": false
},
{
"type": "foreign",
"named": false
},
{
"type": "from",
"named": false
},
{
"type": "full",
"named": false
},
{
"type": "function",
"named": false
},
{
"type": "functions",
"named": false
},
{
"type": "get",
"named": false
},
{
"type": "grant",
"named": false
},
{
"type": "group",
"named": false
},
{
"type": "having",
"named": false
},
{
"type": "hour",
"named": false
},
{
"type": "if",
"named": false
},
{
"type": "ilike",
"named": false
},
{
"type": "immediate",
"named": false
},
{
"type": "immutable",
"named": false
},
{
"type": "in",
"named": false
},
{
"type": "include",
"named": false
},
{
"type": "increment",
"named": false
},
{
"type": "index",
"named": false
},
{
"type": "initially",
"named": false
},
{
"type": "inner",
"named": false
},
{
"type": "insert",
"named": false
},
{
"type": "instead of",
"named": false
},
{
"type": "interval",
"named": false
},
{
"type": "into",
"named": false
},
{
"type": "invoker",
"named": false
},
{
"type": "is",
"named": false
},
{
"type": "is distinct from",
"named": false
},
{
"type": "is not distinct from",
"named": false
},
{
"type": "is not null",
"named": false
},
{
"type": "is null",
"named": false
},
{
"type": "isnull",
"named": false
},
{
"type": "join",
"named": false
},
{
"type": "key",
"named": false
},
{
"type": "language",
"named": false
},
{
"type": "last",
"named": false
},
{
"type": "left",
"named": false
},
{
"type": "like",
"named": false
},
{
"type": "limit",
"named": false
},
{
"type": "loop",
"named": false
},
{
"type": "materialized",
"named": false
},
{
"type": "maxvalue",
"named": false
},
{
"type": "minute",
"named": false
},
{
"type": "minvalue",
"named": false
},
{
"type": "month",
"named": false
},
{
"type": "natural",
"named": false
},
{
"type": "no",
"named": false
},
{
"type": "none",
"named": false
},
{
"type": "not",
"named": false
},
{
"type": "nothing",
"named": false
},
{
"type": "notnull",
"named": false
},
{
"type": "null",
"named": false
},
{
"type": "nulls",
"named": false
}, },
{ {
"type": "number", "type": "number",
"named": true "named": true
}, },
{
"type": "numeric",
"named": false
},
{
"type": "offset",
"named": false
},
{
"type": "on",
"named": false
},
{
"type": "open",
"named": false
},
{
"type": "or",
"named": false
},
{
"type": "order",
"named": false
},
{
"type": "outer",
"named": false
},
{
"type": "owned",
"named": false
},
{
"type": "perform",
"named": false
},
{
"type": "primary",
"named": false
},
{
"type": "privileges",
"named": false
},
{
"type": "procedure",
"named": false
},
{
"type": "public",
"named": false
},
{
"type": "query",
"named": false
},
{
"type": "raise",
"named": false
},
{
"type": "references",
"named": false
},
{
"type": "rename",
"named": false
},
{
"type": "replace",
"named": false
},
{
"type": "restrict",
"named": false
},
{
"type": "return",
"named": false
},
{
"type": "returning",
"named": false
},
{
"type": "returns",
"named": false
},
{
"type": "reverse",
"named": false
},
{
"type": "right",
"named": false
},
{
"type": "routine",
"named": false
},
{
"type": "row",
"named": false
},
{
"type": "rows",
"named": false
},
{
"type": "schema",
"named": false
},
{
"type": "second",
"named": false
},
{
"type": "security",
"named": false
},
{
"type": "select",
"named": false
},
{
"type": "sequence",
"named": false
},
{
"type": "sequences",
"named": false
},
{
"type": "session_user",
"named": false
},
{
"type": "set",
"named": false
},
{
"type": "setof",
"named": false
},
{
"type": "stable",
"named": false
},
{
"type": "start",
"named": false
},
{
"type": "statement",
"named": false
},
{
"type": "strict",
"named": false
},
{
"type": "table",
"named": false
},
{
"type": "tables",
"named": false
},
{
"type": "temp",
"named": false
},
{
"type": "temporary",
"named": false
},
{
"type": "then",
"named": false
},
{
"type": "time",
"named": false
},
{
"type": "to",
"named": false
},
{
"type": "trigger",
"named": false
},
{ {
"type": "true", "type": "true",
"named": false "named": true
},
{
"type": "truncate",
"named": false
},
{
"type": "type",
"named": false
},
{
"type": "unique",
"named": false
}, },
{ {
"type": "unlogged", "type": "unlogged",
"named": false "named": true
},
{
"type": "update",
"named": false
},
{
"type": "using",
"named": false
},
{
"type": "values",
"named": false
},
{
"type": "volatile",
"named": false
},
{
"type": "when",
"named": false
},
{
"type": "where",
"named": false
},
{
"type": "with",
"named": false
},
{
"type": "year",
"named": false
},
{
"type": "zone",
"named": false
}, },
{ {
"type": "||", "type": "||",

123662
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -1,37 +1,36 @@
================================================================================ ================================================================================
empty table create an empty table
================================================================================ ================================================================================
create table foo(); create table foo();
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(create_table_statement (create_table_statement
(identifier))) (identifier)
)
)
================================================================================ ================================================================================
temp create temporary table
================================================================================ ================================================================================
create temp table foo(); create temp table foo();
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(temporary)
(identifier)))
================================================================================
temporary
================================================================================
create temporary table foo(); create temporary table foo();
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(create_table_statement (create_table_statement
(temporary) (temporary)
(identifier))) (identifier)
)
(create_table_statement
(temporary)
(identifier)
)
)
================================================================================ ================================================================================
if not exists create table if not exists
================================================================================ ================================================================================
create table if not exists foo(); create table if not exists foo();
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -39,17 +38,22 @@ create table if not exists foo();
(source_file (source_file
(create_table_statement (create_table_statement
(if_not_exists) (if_not_exists)
(identifier))) (identifier)
)
)
================================================================================ ================================================================================
unlogged create unlogged table
================================================================================ ================================================================================
create unlogged table foo(); create unlogged table foo();
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(create_table_statement (create_table_statement
(identifier))) (unlogged)
(identifier)
)
)
================================================================================ ================================================================================
constraints with deferred constraints with deferred

Binary file not shown.