Skip to content

Commit

Permalink
feat(pg): create columns as array and matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Jul 27, 2023
1 parent 9d45b03 commit 3877ef6
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 55 deletions.
126 changes: 71 additions & 55 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,61 +384,77 @@ module.exports = grammar({

keyword_array: _ => make_keyword("array"), // not included in _type since it's a constructor literal

_type: $ => choice(
$.keyword_boolean,
$.bit,
$.keyword_binary,

$.keyword_smallserial,
$.keyword_serial,
$.keyword_bigserial,

$.tinyint,
$.smallint,
$.mediumint,
$.int,
$.bigint,
$.decimal,
$.numeric,
$.double,
$.float,

$.keyword_money,

$.char,
$.varchar,
$.numeric,
$.keyword_string,
$.keyword_text,

$.keyword_uuid,

$.keyword_json,
$.keyword_jsonb,
$.keyword_xml,

$.keyword_bytea,
$.keyword_inet,

$.enum,

$.keyword_date,
$.keyword_datetime,
$.keyword_timestamp,
$.keyword_timestamptz,
$.keyword_interval,

$.keyword_geometry,
$.keyword_geography,
$.keyword_box2d,
$.keyword_box3d,

$.keyword_oid,
$.keyword_name,
$.keyword_regclass,
$.keyword_regnamespace,
$.keyword_regproc,
$.keyword_regtype,
_type: $ => seq(
choice(
$.keyword_boolean,
$.bit,
$.keyword_binary,

$.keyword_smallserial,
$.keyword_serial,
$.keyword_bigserial,

$.tinyint,
$.smallint,
$.mediumint,
$.int,
$.bigint,
$.decimal,
$.numeric,
$.double,
$.float,

$.keyword_money,

$.char,
$.varchar,
$.numeric,
$.keyword_string,
$.keyword_text,

$.keyword_uuid,

$.keyword_json,
$.keyword_jsonb,
$.keyword_xml,

$.keyword_bytea,
$.keyword_inet,

$.enum,

$.keyword_date,
$.keyword_datetime,
$.keyword_timestamp,
$.keyword_timestamptz,
$.keyword_interval,

$.keyword_geometry,
$.keyword_geography,
$.keyword_box2d,
$.keyword_box3d,

$.keyword_oid,
$.keyword_name,
$.keyword_regclass,
$.keyword_regnamespace,
$.keyword_regproc,
$.keyword_regtype,
),
optional($.array_size_definition)
),

array_size_definition: $ => seq(
choice(
seq(optional($.keyword_array), $._array_size_definition),
seq( $._array_size_definition, $._array_size_definition),
$.keyword_array,
),
),
_array_size_definition: $ => seq(
'[',
optional(field("size", alias($._integer, $.literal))),
']'
),

tinyint: $ => unsigned_type($, parametric_type($, $.keyword_tinyint)),
Expand Down
57 changes: 57 additions & 0 deletions test/corpus/create.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1555,3 +1555,60 @@ CREATE TABLE "Session" (
type: (keyword_inet)
(keyword_not)
(keyword_null))))))

================================================================================
CREATE TABLE with ARRAYS and MATRIX
================================================================================

CREATE TABLE tab (
name text,
array2 integer[3],
matrix text[][],
square integer[3][3],
array4 integer ARRAY[4],
array_ integer ARRAY
);

--------------------------------------------------------------------------------

(program
(statement
(create_table
(keyword_create)
(keyword_table)
(object_reference
(identifier))
(column_definitions
(column_definition
(identifier)
(keyword_text))
(column_definition
(identifier)
(int
(keyword_int))
(array_size_definition
(literal)))
(column_definition
(identifier)
(keyword_text)
(array_size_definition))
(column_definition
(identifier)
(int
(keyword_int))
(array_size_definition
(literal)
(literal)))
(column_definition
(identifier)
(int
(keyword_int))
(array_size_definition
(keyword_array)
(literal)))
(column_definition
(identifier)
(int
(keyword_int))
(array_size_definition
(keyword_array)))))))

0 comments on commit 3877ef6

Please sign in to comment.