use thiserror::Error;
use crate::{core::parse::Span, ArenaPtr, OpObj};
#[derive(Debug, Error)]
#[error("parse error: {error} at {span}")]
pub struct ParseError {
pub span: Span,
pub error: Box<dyn std::error::Error>,
}
pub type ParseResult<T> = Result<T, ParseError>;
#[macro_export]
macro_rules! parse_error {
($span:expr, $error:expr) => {
$crate::ParseError {
span: $span,
error: Box::new($error),
}
};
}
impl<T> From<ParseError> for ParseResult<T> {
fn from(error: ParseError) -> ParseResult<T> { Err(error) }
}
#[derive(Debug, Error)]
#[error("verification error: {error}")]
pub struct VerifyError {
pub error: Box<dyn std::error::Error>,
}
impl VerifyError {
pub fn new(error: impl std::error::Error + 'static) -> Self {
Self {
error: Box::new(error),
}
}
}
pub type VerifyResult<T> = Result<T, VerifyError>;
#[macro_export]
macro_rules! verify_error {
($error:expr) => {
$crate::VerifyError::new($error)
};
}
impl<T> From<VerifyError> for VerifyResult<T> {
fn from(error: VerifyError) -> VerifyResult<T> { Err(error) }
}
#[derive(Debug, Error)]
#[error("print error: {error}")]
pub struct PrintError {
pub error: Box<dyn std::error::Error>,
}
impl PrintError {
pub fn new(error: impl std::error::Error + 'static) -> Self {
Self {
error: Box::new(error),
}
}
}
pub type PrintResult<T> = Result<T, PrintError>;
#[macro_export]
macro_rules! print_error {
($error:expr) => {
$crate::PrintError::new($error)
};
}
impl From<std::fmt::Error> for PrintError {
fn from(error: std::fmt::Error) -> PrintError { PrintError::new(error) }
}
impl<T> From<PrintError> for PrintResult<T> {
fn from(error: PrintError) -> PrintResult<T> { Err(error) }
}
#[derive(Debug, Error)]
#[error("rewrite error: {error}")]
pub struct RewriteError {
pub op: ArenaPtr<OpObj>,
pub error: Box<dyn std::error::Error>,
}
impl RewriteError {
pub fn new(op: ArenaPtr<OpObj>, error: impl std::error::Error + 'static) -> Self {
Self {
op,
error: Box::new(error),
}
}
}
pub type RewriteResult<T> = Result<T, RewriteError>;
#[macro_export]
macro_rules! rewrite_error {
($op:expr, $error:expr) => {
$crate::RewriteError::new($op, $error)
};
}
impl<T> From<RewriteError> for RewriteResult<T> {
fn from(error: RewriteError) -> RewriteResult<T> { Err(error) }
}