From e7bd81e12a0e482a4271b5aa15b0711bc7883efe Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 27 Jul 2021 12:09:36 +0200 Subject: [PATCH] Implemented cart indexing parsing --- src/parser.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index d2761541..7a3ca6f1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -98,6 +98,7 @@ impl<'source> Parser<'source> { | Token::Integer(_) | Token::Abool(_) | Token::Bool(_) + | Token::LeftBracket | Token::LeftParen => Ok(Stmt::new( self.value_flow(token)?, start..self.lexer.span().end, @@ -188,6 +189,17 @@ impl<'source> Parser<'source> { 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 Token::Plus | Token::Minus @@ -213,6 +225,7 @@ impl<'source> Parser<'source> { }, start..self.lexer.span().end, )), + Token::LeftParen => self.expr_flow(Token::RightParen), t => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())), }