#[derive(Debug)]
pub enum LexError {
UnclosedTag,
InvalidTag(String),
UnclosedValue,
InvalidArgumentCount { expected: usize, got: usize },
InvalidValue(String),
InvalidResetTarget,
UnknownStyle(String),
}
impl std::fmt::Display for LexError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LexError::UnclosedTag => write!(f, "unclosed tag"),
LexError::InvalidTag(tag) => write!(f, "invalid tag: {tag}"),
LexError::UnclosedValue => write!(f, "unclosed parentheses for color value"),
LexError::InvalidArgumentCount { expected, got } => {
write!(f, "expected {expected} arguments, got {got}")
}
LexError::InvalidValue(s) => write!(f, "invalid value '{s}'"),
LexError::InvalidResetTarget => {
write!(f, "reset target must be a color or emphasis tag")
}
LexError::UnknownStyle(name) => {
write!(f, "no style named '{name}' in the registry")
}
}
}
}
impl std::error::Error for LexError {}