Implement Error::new()
This commit is contained in:
parent
ba911741ab
commit
82b96abd62
1 changed files with 7 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue