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
|
|
|
MatchNotFound(&'static [u8]),
|
|
|
|
NotFound(&'static str),
|
2020-01-08 08:49:17 -05:00
|
|
|
ExpectedChar(u8),
|
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::MatchNotFound(seq) => {
|
|
|
|
format!("Expected `{}`.", unsafe { std::str::from_utf8_unchecked(seq) })
|
|
|
|
}
|
|
|
|
ErrorType::NotFound(exp) => {
|
|
|
|
format!("Expected {}.", exp)
|
|
|
|
}
|
2020-01-08 08:49:17 -05:00
|
|
|
ErrorType::ExpectedChar(unexp) => {
|
|
|
|
format!("Expected {} (U+{:X}).", unexp as char, unexp)
|
2019-12-30 02:16:33 -05:00
|
|
|
}
|
|
|
|
ErrorType::UnexpectedEnd => {
|
|
|
|
format!("Unexpected end of source code.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-25 21:47:18 -05:00
|
|
|
pub type ProcessingResult<T> = Result<T, ErrorType>;
|