diff --git a/src/ast.rs b/src/ast.rs index f6cd97e..325c43c 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -96,6 +96,14 @@ pub enum ExprNode { /// A reference to a variable. Variable { name: Token }, + /// A lambda function. + Lambda { + /// The `fun` token which creates the lambda. + token: Token, + params: Vec, + body: Vec, + }, + /// A function call. Call { /// Expression that corresponds to the callable. @@ -242,6 +250,26 @@ impl AstDumper for ExprNode { panic!("Unexpected token type for token {:#?}", value) } } + + ExprNode::Lambda { + token: _, + params, + body, + } => { + format!( + "( fun ({}) {} )", + params + .iter() + .map(|token| &token.lexeme as &str) + .collect::>() + .join(" "), + body.iter() + .map(|stmt| stmt.dump()) + .collect::>() + .join(" ") + ) + } + ExprNode::Call { callee, right_paren: _,