2020-01-09 06:40:04 -05:00
|
|
|
// Implement debug to allow .unwrap().
|
|
|
|
#[derive(Debug)]
|
2019-12-25 07:29:18 -05:00
|
|
|
pub enum ErrorType {
|
2020-01-10 02:30:49 -05:00
|
|
|
ClosingTagMismatch,
|
2019-12-25 07:29:18 -05:00
|
|
|
NotFound(&'static str),
|
2019-12-23 06:48:41 -05:00
|
|
|
UnexpectedEnd,
|
|
|
|
}
|
|
|
|
|
2019-12-30 02:16:33 -05:00
|
|
|
impl ErrorType {
|
|
|
|
pub fn message(self) -> String {
|
|
|
|
match self {
|
2020-01-10 02:30:49 -05:00
|
|
|
ErrorType::ClosingTagMismatch => {
|
2020-01-12 06:49:41 -05:00
|
|
|
format!("Closing tag name does not match opening tag.")
|
2020-01-10 02:30:49 -05:00
|
|
|
}
|
2019-12-30 02:16:33 -05:00
|
|
|
ErrorType::NotFound(exp) => {
|
|
|
|
format!("Expected {}.", exp)
|
|
|
|
}
|
|
|
|
ErrorType::UnexpectedEnd => {
|
|
|
|
format!("Unexpected end of source code.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 03:57:39 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
pub error_type: ErrorType,
|
|
|
|
pub position: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct FriendlyError {
|
|
|
|
pub position: usize,
|
|
|
|
pub message: String,
|
|
|
|
pub code_context: String,
|
|
|
|
}
|
|
|
|
|
2019-12-25 21:47:18 -05:00
|
|
|
pub type ProcessingResult<T> = Result<T, ErrorType>;
|