From 2f101372e3311f1ccf7f8ec093c7fde9f4373439 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 10 Aug 2025 22:33:48 +0300 Subject: Implemented functions --- src/type/display.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/type/display.rs') diff --git a/src/type/display.rs b/src/type/display.rs index ded97a0..758fee4 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -1,6 +1,6 @@ use std::fmt; -use crate::r#type::{Type, TypeError, Type::*, TypeError::*}; +use crate::r#type::{Type, TypeError, FunDefError, Type::*, TypeError::*, FunDefError::*}; impl fmt::Display for Type { @@ -113,8 +113,45 @@ impl fmt::Display for TypeError { ) }, FunAsAtom => write!(f, "'fn' used as atom doesn't make sense"), + InvalidFunDef(exp, err) => write!(f, "invalid function definition '{exp}': {err}"), OtherError => write!(f, "uncategorized error"), } } } + +impl fmt::Display for FunDefError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + NoFunToken => + write!( + f, + "no '{}'-token at start of definition", + crate::sexp::SLeaf::Fun + ), + NoArgumentList => + write!( + f, + "no list of argument names" + ), + NoTypeList => + write!( + f, + "no list of argument types" + ), + NoReturnType => + write!( + f, + "no return type supplied" + ), + NoFunctionBody => + write!( + f, + "function has no body" + ), + InvalidArgumentList => write!(f, "invalid argument list"), + InvalidTypeList => write!(f, "invalid argument type list"), + InvalidReturnType => write!(f, "invalid return type"), + } + } +} -- cgit v1.2.3