arrays as value_expressions

This commit is contained in:
Christian De la Hoz 2021-09-02 19:54:27 +02:00
parent f1278b0462
commit a4cbb1ab05
2 changed files with 36 additions and 1 deletions

View file

@ -56,6 +56,38 @@ SELECT foo, foo.bar;
(select_item
(identifier))))
================================================================================
arrays
================================================================================
SELECT
ARRAY[],
array[1, 2],
array[array[1, 2], array[3, 4]],
array[]::integer[];
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(array_constructor))
(select_item
(array_constructor
(number)
(number)))
(select_item
(array_constructor
(array_constructor
(number)
(number))
(array_constructor
(number)
(number))))
(select_item
(op_expression
(array_constructor)
(cast)
(identifier)))))
================================================================================
binary_expression
================================================================================

View file

@ -742,6 +742,7 @@ module.exports = grammar({
seq("(", $.select_statement, ")"),
seq("(", commaSep1($._value_expression), ")"),
$.function_call,
$.array_constructor,
$.op_expression,
$.time_expression,
// TODO(chrde): this one feels a bit hacky? perhaps move to identifier regexp
@ -749,6 +750,8 @@ module.exports = grammar({
$.identifier,
),
array_constructor: $ => seq(kw("array"), "[", commaSep($._value_expression), "]"),
// TODO(chrde): it does not handle nested dollar quotes... perhaps move to an external scanner?
dollar_quote_string: $ => seq(
"$", $._identifier, "$",
@ -790,7 +793,7 @@ module.exports = grammar({
),
op_expression: $ => choice(
prec.left(12, seq($._value_expression, $.cast, $.identifier)),
prec.left(12, seq($._value_expression, $.cast, $._type)),
// array access
prec.right(10, seq(choice($.minus, $.plus), $._value_expression)),
// ^