use thiserror::Error;
use crate::parser::Error as ParseError;
pub trait LocatedError {
fn location(&self) -> (usize, usize);
}
#[derive(Debug, PartialEq, Eq, Error)]
pub enum Error<'a, GE> {
#[error("parse failed: {0}")]
Parse(ParseError<'a>),
#[error("generator failed: {0}")]
Gen(GE),
}
impl<'a, GE: LocatedError> LocatedError for Error<'a, GE> {
fn location(&self) -> (usize, usize) {
match self {
Self::Parse(e) => e.location(),
Self::Gen(e) => e.location(),
}
}
}
impl<'a, GE> From<ParseError<'a>> for Error<'a, GE> {
fn from(e: ParseError<'a>) -> Self {
Self::Parse(e)
}
}