1
0

Pass tests

This commit is contained in:
Jeff 2024-03-08 21:26:49 -05:00
parent 05c9e70d49
commit 3064a92e73
2 changed files with 28 additions and 1 deletions

View File

@ -14,6 +14,10 @@ pub enum Type {
Boolean, Boolean,
Custom(Identifier), Custom(Identifier),
Float, Float,
Function {
parameter_types: Vec<Type>,
return_type: Box<Type>,
},
Integer, Integer,
List, List,
ListOf(Box<Type>), ListOf(Box<Type>),
@ -131,6 +135,18 @@ impl Display for Type {
Type::None => write!(f, "none"), Type::None => write!(f, "none"),
Type::Range => write!(f, "range"), Type::Range => write!(f, "range"),
Type::String => write!(f, "string"), 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}")
}
} }
} }
} }

View File

@ -44,7 +44,18 @@ impl AbstractTree for ValueNode {
ValueNode::Range(_) => Type::Range, ValueNode::Range(_) => Type::Range,
ValueNode::String(_) => Type::String, ValueNode::String(_) => Type::String,
ValueNode::Enum(name, _) => Type::Custom(name.clone()), 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) Ok(r#type)