diff --git a/src/interpreter/functions.rs b/src/interpreter/functions.rs index 00d31e9..8335283 100644 --- a/src/interpreter/functions.rs +++ b/src/interpreter/functions.rs @@ -14,19 +14,19 @@ use super::{Callable, EnvironmentRef, Value}; /// A function implemented in the Lox-ish language. #[derive(Debug)] pub(crate) struct Function { - name: Token, + name: Option, params: Vec, body: Vec, } impl Function { pub(crate) fn new( - name: &Token, + name: Option<&Token>, params: &Vec, body: &Vec, ) -> Rc> { let fun = Self { - name: name.clone(), + name: name.map(|t| t.clone()), params: params.clone(), body: body.clone(), }; @@ -66,6 +66,9 @@ impl Callable for Function { impl ToString for Function { fn to_string(&self) -> String { - format!("", self.name.lexeme) + match &self.name { + None => "".to_owned(), + Some(token) => format!("", token.lexeme), + } } }