use core::fmt; use super::Identifier; #[derive(Clone, Debug)] pub struct Variant { pub name: Identifier, pub elements: Vec, } impl fmt::Display for Variant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} {}", self.name, self.elements.iter() .map(|e| e.to_string()) .collect::>() .join(" "), ) } } #[derive(Clone, Debug)] pub enum Type { UserDefined(Vec), Function(Box, Box), Primitive(PrimitiveType), } impl fmt::Display for Type { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::UserDefined(variants) => f.write_str( variants.into_iter() .map(ToString::to_string) .collect::>() .join(" | ") .as_str() ), Self::Function(args, return_type) => write!(f, "{} -> {}", args, return_type ), Self::Primitive(p) => p.fmt(f), } } } #[derive(Clone, Debug, Copy)] pub enum PrimitiveType { Int, Str, Type, } impl fmt::Display for PrimitiveType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str( match self { Self::Int => "int", Self::Str => "str", Self::Type => "Type", } ) } }