1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::ops::Range;
use ariadne::{Report, ReportKind};
use crate::{parsing::ParseError, DuplicateError, FileID, RuntimeError};
pub mod display;
pub type ValkyrieReport = Report<(FileID, Range<usize>)>;
pub type ValkyrieResult<T = ()> = Result<T, ValkyrieError>;
#[derive(Clone)]
pub struct ValkyrieError {
pub kind: ValkyrieErrorKind,
pub level: ReportKind,
}
#[derive(Clone)]
pub enum ValkyrieErrorKind {
Duplicate(Box<DuplicateError>),
Runtime(Box<RuntimeError>),
Parsing(Box<ParseError>),
}
impl ValkyrieError {
pub fn as_report(&self) -> ValkyrieReport {
match &self.kind {
ValkyrieErrorKind::Duplicate(e) => e.as_report(self.level),
ValkyrieErrorKind::Runtime(e) => e.as_report(self.level),
ValkyrieErrorKind::Parsing(e) => e.as_report(self.level),
}
}
}