prism_parser/error/
empty_error.rs

1use crate::core::pos::Pos;
2use crate::core::span::Span;
3use crate::error::error_printer::ErrorLabel;
4use crate::error::ParseError;
5use ariadne::{Report, ReportKind};
6use std::marker::PhantomData;
7
8/// Empty error is an error type that keeps track of no data, meant to be performant.
9#[derive(Clone)]
10pub struct EmptyError<'grm>(PhantomData<&'grm str>);
11
12impl<'grm> ParseError for EmptyError<'grm> {
13    type L = ErrorLabel<'grm>;
14
15    fn new(_: Span) -> Self {
16        Self(PhantomData)
17    }
18
19    fn add_label_explicit(&mut self, _: Self::L) {}
20
21    fn add_label_implicit(&mut self, _: Self::L) {}
22
23    fn merge(self, _: Self) -> Self {
24        Self(PhantomData)
25    }
26
27    fn set_end(&mut self, _: Pos) {}
28
29    fn report(&self, _enable_debug: bool) -> Report<'static, Span> {
30        Report::build(ReportKind::Error, (), 0)
31            .with_message("Parsing error in this file")
32            .with_help(
33                "Parsing was run in fast-mode, rerun without fast-mode to get more error details",
34            )
35            .finish()
36    }
37}