use std::fmt; // TODO: global error #[derive(Debug, Clone, PartialEq)] pub struct ParseError { pub line: usize, pub message: String, } impl std::error::Error for ParseError {} impl From for ParseError { fn from(err: std::io::Error) -> Self { // TODO ParseError { line: 0, message: err.to_string(), } } } impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "parser (line {}): {}.", self.line + 1, self.message) } }