use std::fmt;
use std::num::ParseIntError;
#[derive(Clone, Debug, PartialEq)]
pub enum ParamParseError {
Empty,
TypeDef {
name: String,
},
MissingDef,
InvalidFlag,
InvalidGeneric,
NotImplemented,
}
impl fmt::Display for ParamParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Empty => write!(f, "empty token"),
Self::TypeDef { name } => write!(f, "generic type definition: {name}"),
Self::MissingDef => write!(f, "unknown generic or flag definition"),
Self::InvalidFlag => write!(f, "invalid flag expression"),
Self::InvalidGeneric => write!(f, "invalid generic argument (unclosed `<`)"),
Self::NotImplemented => write!(f, "parameter without `:type` is not supported"),
}
}
}
impl std::error::Error for ParamParseError {}
#[derive(Debug, PartialEq)]
pub enum ParseError {
Empty,
MissingType,
MissingName,
InvalidId(ParseIntError),
InvalidParam(ParamParseError),
NotImplemented,
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Empty => write!(f, "empty definition"),
Self::MissingType => write!(f, "missing `= Type`"),
Self::MissingName => write!(f, "missing or malformed name"),
Self::InvalidId(e) => write!(f, "invalid constructor ID: {e}"),
Self::InvalidParam(e) => write!(f, "invalid parameter: {e}"),
Self::NotImplemented => write!(f, "unsupported TL syntax"),
}
}
}
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidId(e) => Some(e),
Self::InvalidParam(e) => Some(e),
_ => None,
}
}
}