pulling parser changes from prev branch

This commit is contained in:
damirka 2021-08-31 19:18:31 +03:00
parent 24e5c4d69e
commit 9951627c8c
2 changed files with 8 additions and 4 deletions

View File

@ -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) => {

View File

@ -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<ArrayDimensions> {
pub fn parse_array_dimensions(&mut self) -> Result<Option<ArrayDimensions>> {
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))
})
}