From 3064a92e730dd88080b4b20f45f83db60b736d58 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 8 Mar 2024 21:26:49 -0500 Subject: [PATCH] Pass tests --- src/abstract_tree/type.rs | 16 ++++++++++++++++ src/abstract_tree/value_node.rs | 13 ++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/abstract_tree/type.rs b/src/abstract_tree/type.rs index 8dabb79..213562b 100644 --- a/src/abstract_tree/type.rs +++ b/src/abstract_tree/type.rs @@ -14,6 +14,10 @@ pub enum Type { Boolean, Custom(Identifier), Float, + Function { + parameter_types: Vec, + return_type: Box, + }, Integer, List, ListOf(Box), @@ -131,6 +135,18 @@ impl Display for Type { Type::None => write!(f, "none"), Type::Range => write!(f, "range"), Type::String => write!(f, "string"), + Type::Function { + parameter_types, + return_type, + } => { + write!(f, "(")?; + + for r#type in parameter_types { + write!(f, "{} ", r#type)?; + } + + write!(f, ") : {return_type}") + } } } } diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index 418c049..c0be308 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -44,7 +44,18 @@ impl AbstractTree for ValueNode { ValueNode::Range(_) => Type::Range, ValueNode::String(_) => Type::String, ValueNode::Enum(name, _) => Type::Custom(name.clone()), - ValueNode::Function { .. } => todo!(), + ValueNode::Function { + parameters, + return_type, + .. + } => Type::Function { + parameter_types: parameters + .into_iter() + .map(|(_, r#type)| r#type) + .cloned() + .collect(), + return_type: Box::new(return_type.clone()), + }, }; Ok(r#type)