From 9951627c8c6428063cdd03e196c949abe0eccba8 Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 31 Aug 2021 19:18:31 +0300 Subject: [PATCH] pulling parser changes from prev branch --- parser/src/parser/expression.rs | 4 +++- parser/src/parser/type_.rs | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index d9ebcfc944..2f9cf4929f 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -604,7 +604,9 @@ impl ParserContext { } let first = self.parse_spread_or_expression()?; if self.eat(Token::Semicolon).is_some() { - let dimensions = self.parse_array_dimensions()?; + let dimensions = self + .parse_array_dimensions()? + .ok_or_else(|| ParserError::unable_to_parse_array_dimensions(span))?; let end = self.expect(Token::RightSquare)?; let first = match first { SpreadOrExpression::Spread(first) => { diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 60d5b01d05..65eb3d3dd4 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -58,9 +58,11 @@ impl ParserContext { /// /// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type. /// - pub fn parse_array_dimensions(&mut self) -> Result { + pub fn parse_array_dimensions(&mut self) -> Result> { Ok(if let Some((int, _)) = self.eat_int() { - ArrayDimensions(vec![int]) + Some(ArrayDimensions(vec![int])) + } else if self.eat(Token::Underscore).is_some() { + None } else { self.expect(Token::LeftParen)?; let mut dimensions = Vec::new(); @@ -76,7 +78,7 @@ impl ParserContext { } } self.expect(Token::RightParen)?; - ArrayDimensions(dimensions) + Some(ArrayDimensions(dimensions)) }) }