From 2e7a897c4728eb83145d523d340a15421f3323d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 2 Jan 2023 15:05:41 +0100 Subject: [PATCH] AST - Function call expression node --- src/ast.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index bf1c630..e90578f 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -73,6 +73,17 @@ pub enum ExprNode { /// A reference to a variable. Variable { name: Token }, + + /// A function call. + Call { + /// Token that contains the name of the function. + name: Token, + /// Right parenthesis that closes the list of arguments. Used to + /// report errors. + right_paren: Token, + /// The list of function arguments. + arguments: Vec, + }, } /* -------------------------------- * @@ -189,6 +200,25 @@ impl AstDumper for ExprNode { panic!("Unexpected token type for token {:#?}", value) } } + ExprNode::Call { + name, + right_paren: _, + arguments, + } => { + if arguments.len() > 0 { + format!( + "( call {} {} )", + name.lexeme, + arguments + .iter() + .map(|arg| arg.dump()) + .collect::>() + .join(" ") + ) + } else { + format!("( call {} )", name.lexeme) + } + } } } }