From 82b96abd62d80d53a8968d6261aca1047ada3c78 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 16 Jan 2017 16:40:36 -0800 Subject: [PATCH] Implement Error::new() --- src/parser/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 11c79cc..e879f93 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -57,7 +57,7 @@ impl Parser { match next.token { Token::Boolean(value) => Ok(Expression::Literal(Box::new(value))), Token::Character(value) => Ok(Expression::Literal(Box::new(value))), - _ => Err(Error { lex: next, desc: "Invalid token".to_string() }) + _ => Err(Error::new(next, "Invalid token")) } } else { @@ -71,6 +71,12 @@ pub struct Error { desc: String, } +impl Error { + pub fn new(lex: Lex, desc: &str) -> Error { + Error { lex: lex, desc: desc.to_string() } + } +} + impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "PARSE ERROR: {}\n token = {:?}", self.desc, self.lex)