Implemented callable expressions in parser

This commit is contained in:
Erin 2021-08-01 18:36:09 +02:00 committed by ondra05
parent 3df3cbbf6d
commit 83a4f67121

View file

@ -345,13 +345,12 @@ impl<'source> Parser<'source> {
// Functio call // Functio call
Token::LeftParen => { Token::LeftParen => {
if let Some(Expr { break self.functio_call_flow(buf.take().ok_or_else(|| {
kind: ExprKind::Variable(iden), Error::new(
span, ErrorKind::UnexpectedToken(Token::LeftParen),
}) = buf self.lexer.span(),
{ )
break self.functio_call_flow(Iden::new(iden, span))?; })?)?;
}
} }
// Variable Assignment // Variable Assignment
@ -480,7 +479,7 @@ impl<'source> Parser<'source> {
} }
/// Parse functio call flow /// Parse functio call flow
fn functio_call_flow(&mut self, iden: Iden) -> Result<StmtKind, Error> { fn functio_call_flow(&mut self, expr: Expr) -> Result<StmtKind, Error> {
let mut args = vec![]; let mut args = vec![];
let mut buf = None; let mut buf = None;
loop { loop {
@ -509,7 +508,7 @@ impl<'source> Parser<'source> {
} }
self.require(Token::Semicolon)?; self.require(Token::Semicolon)?;
Ok(StmtKind::Call { iden, args }) Ok(StmtKind::Call { expr, args })
} }
/// Parse variable declaration /// Parse variable declaration