Completed the parsing of multi-parameter functions. It now works!

This commit is contained in:
PaddiM8 2020-05-29 14:49:52 +02:00
parent 6d67797565
commit 32cd3a4e9e

View File

@ -184,7 +184,7 @@ impl Parser {
TokenKind::OpenParenthesis => self.parse_group(),
TokenKind::Pipe => self.parse_abs(),
TokenKind::Identifier => self.parse_identifier(),
_ => Expr::Literal(self.consume(TokenKind::Literal).value.clone()),
_ => Expr::Literal(self.advance().value.clone()),
};
if !self.is_at_end() && self.peek().kind.is_unit() {
@ -215,10 +215,18 @@ impl Parser {
if self.match_token(TokenKind::OpenParenthesis) {
self.advance();
let parameter = self.parse_expr();
let mut parameters = Vec::new();
parameters.push(self.parse_expr());
while self.match_token(TokenKind::Comma) {
self.advance();
parameters.push(self.parse_expr());
}
self.consume(TokenKind::ClosedParenthesis);
Expr::FnCall(identifier.value, vec![parameter])
Expr::FnCall(identifier.value, parameters)
} else {
Expr::Var(identifier.value)
}