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 (select_item
(identifier)))) (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 binary_expression
================================================================================ ================================================================================

View file

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