use std::error::Error;
use std::fmt::Display;
pub type Result<T, E = DimlError> = std::result::Result<T, E>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DimlError {
EmptyInput(
usize,
usize,
),
UnexpectedCharacter(
char,
usize,
usize,
),
MissingNewline(
usize,
usize,
),
InvalidIndentation(
usize,
usize,
usize,
usize,
),
SkippedIndentation(
usize,
usize,
usize,
usize,
),
}
impl Display for DimlError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::EmptyInput(line, column) => {
write!(f, "empty input at line {line}, column {column}")
}
Self::UnexpectedCharacter(ch, line, column) => {
write!(
f,
"unexpected character '{}' at line {line}, column {column}",
ch.escape_debug()
)
}
Self::MissingNewline(line, column) => {
write!(f, "missing newline at line {line}, column {column}")
}
Self::InvalidIndentation(indent, multiplier, line, column) => {
write!(
f,
"invalid indentation {indent}, expected a multiple of {multiplier} spaces at line {line}, column {column}"
)
}
Self::SkippedIndentation(previous, level, line, column) => {
write!(
f,
"skipped indentation level, jump from level {previous} to level {level} at line {line}, column {column}"
)
}
}
}
}
impl Error for DimlError {}