diff --git a/Cargo.lock b/Cargo.lock index 62dcd1d..cbe4196 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "bq2cst" -version = "0.4.21" +version = "0.4.22" dependencies = [ "console_error_panic_hook", "difference", diff --git a/src/parser.rs b/src/parser.rs index ebacf71..ece5736 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -377,9 +377,13 @@ impl Parser { let type_ = self.parse_type(false)?; self.next_token()?; // > -> [ let mut arr = self.construct_node(NodeType::ArrayLiteral)?; - self.next_token()?; // [ -> exprs - arr.push_node_vec("exprs", self.parse_exprs(&vec![], false)?); - self.next_token()?; // exprs -> ] + self.next_token()?; // [ -> exprs | ] + if self.get_token(0)?.is("]") { + arr.push_node_vec("exprs", vec![]); + } else { + arr.push_node_vec("exprs", self.parse_exprs(&vec![], false)?); + self.next_token()?; // exprs -> ] + } arr.push_node("rparen", self.construct_node(NodeType::Symbol)?); arr.push_node("type", type_); left = arr; diff --git a/src/parser/tests/tests_core.rs b/src/parser/tests/tests_core.rs index 1e0dd75..28650d0 100644 --- a/src/parser/tests/tests_core.rs +++ b/src/parser/tests/tests_core.rs @@ -567,6 +567,28 @@ exprs: // array with type declaration Box::new(SuccessTestCase::new( "\ +SELECT ARRAY[] +", + "\ +self: SELECT (SelectStatement) +exprs: +- self: [ (ArrayLiteral) + exprs: [] + rparen: + self: ] (Symbol) + type: + self: ARRAY (Type) + type_declaration: + self: < (GroupedType) + rparen: + self: > (Symbol) + type: + self: STRING (Type) +", + 0, + )), + Box::new(SuccessTestCase::new( + "\ SELECT ARRAY[1] ", "\