cas_parser/parser/error/
mod.rs

1pub mod kind;
2
3use ariadne::Report;
4use cas_error::ErrorKind;
5use std::ops::Range;
6
7/// A general parsing error.
8#[derive(Debug)]
9pub struct Error {
10    /// The regions of the source code that this error originated from.
11    pub spans: Vec<Range<usize>>,
12
13    /// The kind of error that occurred.
14    pub kind: Box<dyn ErrorKind>,
15}
16
17impl Error {
18    /// Creates a new error with the given spans and kind.
19    pub fn new(spans: Vec<Range<usize>>, kind: impl ErrorKind + 'static) -> Self {
20        Self { spans, kind: Box::new(kind) }
21    }
22
23    /// Build a report from this error kind.
24    pub fn build_report(&self) -> Report<(&'static str, Range<usize>)> {
25        self.kind.build_report("input", &self.spans)
26    }
27}