1
0
dust/src/error.rs

83 lines
1.8 KiB
Rust
Raw Normal View History

2024-02-25 18:49:26 +00:00
use std::sync::PoisonError;
use chumsky::prelude::Rich;
2024-03-06 17:15:03 +00:00
use crate::{abstract_tree::Type, lexer::Token};
2024-02-25 18:49:26 +00:00
#[derive(Debug, PartialEq)]
pub enum Error<'src> {
Parse(Vec<Rich<'src, Token<'src>>>),
Lex(Vec<Rich<'src, char>>),
Runtime(RuntimeError),
}
impl<'src> From<Vec<Rich<'src, Token<'src>>>> for Error<'src> {
fn from(errors: Vec<Rich<'src, Token<'src>>>) -> Self {
Error::Parse(errors)
}
}
impl<'src> From<Vec<Rich<'src, char>>> for Error<'src> {
fn from(errors: Vec<Rich<'src, char>>) -> Self {
Error::Lex(errors)
}
}
impl<'src> From<RuntimeError> for Error<'src> {
fn from(error: RuntimeError) -> Self {
Error::Runtime(error)
}
}
#[derive(Debug, PartialEq)]
pub enum RuntimeError {
RwLockPoison(RwLockPoisonError),
ValidationFailure(ValidationError),
2024-02-25 18:49:26 +00:00
}
impl From<RwLockPoisonError> for RuntimeError {
fn from(error: RwLockPoisonError) -> Self {
RuntimeError::RwLockPoison(error)
}
}
impl From<ValidationError> for RuntimeError {
fn from(error: ValidationError) -> Self {
RuntimeError::ValidationFailure(error)
}
}
#[derive(Debug, PartialEq)]
pub enum ValidationError {
ExpectedBoolean,
2024-03-06 17:15:03 +00:00
RwLockPoison(RwLockPoisonError),
TypeCheck(TypeCheckError),
}
impl From<RwLockPoisonError> for ValidationError {
fn from(error: RwLockPoisonError) -> Self {
ValidationError::RwLockPoison(error)
}
}
2024-03-06 17:15:03 +00:00
impl From<TypeCheckError> for ValidationError {
fn from(error: TypeCheckError) -> Self {
ValidationError::TypeCheck(error)
}
}
2024-02-25 18:49:26 +00:00
#[derive(Debug, PartialEq)]
pub struct RwLockPoisonError;
impl<T> From<PoisonError<T>> for RwLockPoisonError {
fn from(_: PoisonError<T>) -> Self {
RwLockPoisonError
}
}
2024-03-06 17:15:03 +00:00
#[derive(Debug, PartialEq)]
pub struct TypeCheckError {
pub actual: Type,
pub expected: Type,
}