Implement Error::new()

This commit is contained in:
Eryn Wells 2017-01-16 16:40:36 -08:00
parent ba911741ab
commit 82b96abd62

View file

@ -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)