prism_parser/error/
mod.rs1pub mod aggregate_error;
2pub mod empty_error;
3pub mod error_printer;
4pub mod set_error;
5pub mod tree_error;
6
7use crate::core::pos::Pos;
8use crate::core::span::Span;
9use ariadne::Report;
10use std::cmp::Ordering;
11
12pub trait ParseError: Sized + Clone {
13 type L;
14
15 fn new(span: Span) -> Self;
16 fn add_label_explicit(&mut self, label: Self::L);
17 fn add_label_implicit(&mut self, label: Self::L);
18 fn merge(self, other: Self) -> Self;
19 fn set_end(&mut self, end: Pos);
20 fn report(&self, enable_debug: bool) -> Report<'static, Span>;
21}
22
23pub fn err_combine<E: ParseError>((xe, xs): (E, Pos), (ye, ys): (E, Pos)) -> (E, Pos) {
24 match xs.cmp(&ys) {
25 Ordering::Less => (ye, ys),
26 Ordering::Equal => (xe.merge(ye), xs),
27 Ordering::Greater => (xe, xs),
28 }
29}
30
31pub fn err_combine_opt<E: ParseError>(
32 x: Option<(E, Pos)>,
33 y: Option<(E, Pos)>,
34) -> Option<(E, Pos)> {
35 match (x, y) {
36 (Some(x), Some(y)) => Some(err_combine(x, y)),
37 (Some(x), None) => Some(x),
38 (None, Some(y)) => Some(y),
39 (None, None) => None,
40 }
41}