use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Undefined(String),
Type(String),
NoNextState(String),
NotGround(String),
Unbounded(String),
Malformed(String),
Syntax(tla_syntax::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Undefined(name) => write!(f, "`{name}` is not defined"),
Error::Type(m)
| Error::NoNextState(m)
| Error::NotGround(m)
| Error::Unbounded(m)
| Error::Malformed(m) => f.write_str(m),
Error::Syntax(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for Error {}
impl From<tla_syntax::Error> for Error {
fn from(e: tla_syntax::Error) -> Self {
Error::Syntax(e)
}
}
pub(crate) fn type_error<T>(msg: impl Into<String>) -> Result<T> {
Err(Error::Type(msg.into()))
}