diff --git a/corpus/select_statement/value_expression.txt b/corpus/select_statement/value_expression.txt index ecadf07..a49a9a0 100644 --- a/corpus/select_statement/value_expression.txt +++ b/corpus/select_statement/value_expression.txt @@ -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 ================================================================================ diff --git a/grammar.js b/grammar.js index 012cd93..bb1640a 100644 --- a/grammar.js +++ b/grammar.js @@ -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)), // ^