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 {
|
2019-12-30 00:52:59 -05:00
|
|
|
EntityFollowingMalformedEntity,
|
2020-01-10 02:30:49 -05:00
|
|
|
ClosingTagMismatch,
|
2019-12-25 21:47:18 -05:00
|
|
|
NoSpaceBeforeAttr,
|
2019-12-25 07:29:18 -05:00
|
|
|
CharNotFound { need: u8, got: u8 },
|
|
|
|
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 {
|
|
|
|
ErrorType::EntityFollowingMalformedEntity => {
|
|
|
|
format!("Entity cannot follow malformed entity.")
|
|
|
|
}
|
2020-01-10 02:30:49 -05:00
|
|
|
ErrorType::ClosingTagMismatch => {
|
|
|
|
format!("Opening tag name does not match closing tag.")
|
|
|
|
}
|
2019-12-30 02:16:33 -05:00
|
|
|
ErrorType::NoSpaceBeforeAttr => {
|
|
|
|
format!("Space required before attribute.")
|
|
|
|
}
|
|
|
|
ErrorType::CharNotFound { need, got } => {
|
|
|
|
format!("Expected {} (U+{:X}), got {} (U+{:X}).", need as char, need, got as char, got)
|
|
|
|
}
|
|
|
|
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>;
|