Implemented cart indexing parsing

This commit is contained in:
Erin 2021-07-27 12:09:36 +02:00 committed by ondra05
parent ab1515cdb0
commit e7bd81e12a

View file

@ -98,6 +98,7 @@ impl<'source> Parser<'source> {
| Token::Integer(_) | Token::Integer(_)
| Token::Abool(_) | Token::Abool(_)
| Token::Bool(_) | Token::Bool(_)
| Token::LeftBracket
| Token::LeftParen => Ok(Stmt::new( | Token::LeftParen => Ok(Stmt::new(
self.value_flow(token)?, self.value_flow(token)?,
start..self.lexer.span().end, start..self.lexer.span().end,
@ -188,6 +189,17 @@ impl<'source> Parser<'source> {
start..self.lexer.span().end, start..self.lexer.span().end,
)), )),
Token::LeftBracket => match buf.take() {
Some(buf) => Ok(Expr::new(
ExprKind::Index {
cart: Box::new(buf),
index: Box::new(self.expr_flow(Token::RightBracket)?),
},
start..self.lexer.span().end,
)),
None => todo!("cart construction"),
},
// Operations // Operations
Token::Plus Token::Plus
| Token::Minus | Token::Minus
@ -213,6 +225,7 @@ impl<'source> Parser<'source> {
}, },
start..self.lexer.span().end, start..self.lexer.span().end,
)), )),
Token::LeftParen => self.expr_flow(Token::RightParen), Token::LeftParen => self.expr_flow(Token::RightParen),
t => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())), t => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())),
} }