2019-12-25 07:29:18 -05:00
|
|
|
pub enum ErrorType {
|
2019-12-30 00:52:59 -05:00
|
|
|
EntityFollowingMalformedEntity,
|
2019-12-25 21:47:18 -05:00
|
|
|
NoSpaceBeforeAttr,
|
|
|
|
UnterminatedCssString,
|
|
|
|
UnterminatedJsString,
|
2019-12-25 07:29:18 -05:00
|
|
|
CharNotFound { need: u8, got: u8 },
|
|
|
|
MatchNotFound(&'static [u8]),
|
|
|
|
NotFound(&'static str),
|
|
|
|
UnexpectedChar(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.")
|
|
|
|
}
|
|
|
|
ErrorType::NoSpaceBeforeAttr => {
|
|
|
|
format!("Space required before attribute.")
|
|
|
|
}
|
|
|
|
ErrorType::UnterminatedCssString => {
|
|
|
|
format!("Unterminated CSS string.")
|
|
|
|
}
|
|
|
|
ErrorType::UnterminatedJsString => {
|
|
|
|
format!("Unterminated JavaScript string.")
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
ErrorType::UnexpectedChar(unexp) => {
|
|
|
|
format!("Unexpected {} (U+{:X}).", unexp as char, unexp)
|
|
|
|
}
|
|
|
|
ErrorType::UnexpectedEnd => {
|
|
|
|
format!("Unexpected end of source code.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-25 21:47:18 -05:00
|
|
|
pub type ProcessingResult<T> = Result<T, ErrorType>;
|