/// Converts type parse trees into actual types.
Converts type parse trees into actual types.
Converts type parse trees into actual types .
fn analyse_type(src: &parser::Type) -> Result<Type> {
        match src {
            parser::Type::Unit => Ok(Type::Unit),
            parser::Type::Ident(ident) => match ident.as_ref() {
                "Bool" => Ok(Type::Bool),
                "Int" => Ok(Type::Int),
                _ => Err(Error::TypeMismatch(format!("Unknown type {}", ident)))
            }
            parser::Type::Func(ty1, ty2) => Ok(
                Type::Func(
                    Box::new(Analyser::analyse_type(ty1)?),
                    Box::new(Analyser::analyse_type(ty2)?),
                )
            ),
            parser::Type::Tuple(fst, snd, rest) => Ok(
                Type::Tuple(
                    Box::new(Analyser::analyse_type(fst)?),
                    Box::new(Analyser::analyse_type(snd)?),
                    rest.iter().map(|ty| Analyser::analyse_type(ty)).collect::<Result<Vec<_>>>()?,
                )
            ),
        }
    }
fn analyse_type ( src : & parser :: Type ) -> Result < Type > { match src { parser :: Type :: Unit => Ok ( Type :: Unit ) , parser :: Type :: Ident ( ident ) => match ident . as_ref ( ) { " " => Ok ( Type :: Bool ) , " " => Ok ( Type :: Int ) , _ => Err ( Error :: TypeMismatch ( format ! ( " " ident ) ) ) } parser :: Type :: Func ( ty1 , ty2 ) => Ok ( Type :: Func ( Box :: new ( Analyser :: analyse_type ( ty1 ) ? ) , Box :: new ( Analyser :: analyse_type ( ty2 ) ? ) , ) ) , parser :: Type :: Tuple ( fst , snd , rest ) => Ok ( Type :: Tuple ( Box :: new ( Analyser :: analyse_type ( fst ) ? ) , Box :: new ( Analyser :: analyse_type ( snd ) ? ) , rest . iter ( ) . map ( | ty | Analyser :: analyse_type ( ty ) ) . collect :: < Result < Vec < _ > > > ( ) ? , ) ) , } }
Converts type parse trees into actual types.
Converts type parse trees into actual types .
src
&parser::Type