From 83a4f671214041b651966eeda2d110722d550c63 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 1 Aug 2021 18:36:09 +0200 Subject: [PATCH] Implemented callable expressions in parser --- src/parser.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index c29f475d..f42873e5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -345,13 +345,12 @@ impl<'source> Parser<'source> { // Functio call Token::LeftParen => { - if let Some(Expr { - kind: ExprKind::Variable(iden), - span, - }) = buf - { - break self.functio_call_flow(Iden::new(iden, span))?; - } + break self.functio_call_flow(buf.take().ok_or_else(|| { + Error::new( + ErrorKind::UnexpectedToken(Token::LeftParen), + self.lexer.span(), + ) + })?)?; } // Variable Assignment @@ -480,7 +479,7 @@ impl<'source> Parser<'source> { } /// Parse functio call flow - fn functio_call_flow(&mut self, iden: Iden) -> Result { + fn functio_call_flow(&mut self, expr: Expr) -> Result { let mut args = vec![]; let mut buf = None; loop { @@ -509,7 +508,7 @@ impl<'source> Parser<'source> { } self.require(Token::Semicolon)?; - Ok(StmtKind::Call { iden, args }) + Ok(StmtKind::Call { expr, args }) } /// Parse variable declaration