rowan_nom/
error.rs

1use std::ops::Range;
2
3pub trait RowanNomError<Lang: super::Language> {
4    /// Generic error, should probably be ultimately removed
5    fn from_message(message: &str) -> Self;
6
7    fn from_expected(position: usize, message: &str) -> Self;
8
9    fn from_expected_eof(range: Range<usize>) -> Self;
10
11    /// Creates error: Attempted to read a token when there are none remaining
12    fn from_unexpected_eof(position: usize) -> Self;
13
14    fn from_unexpected_token(span: Range<usize>, expected: Lang::Kind, found: Lang::Kind) -> Self;
15
16    fn with_context(self, ctx: &'static str) -> Self;
17
18    // TODO add much more errors, include location information in constructors
19}
20
21/// A ZST that implements [`RowanNomError`] when details or context don't matter
22#[derive(Debug, Default, Clone, Copy, thiserror::Error)]
23#[error("dummy error used, can't provide further information")]
24pub struct DummyError;
25
26impl<Lang: super::Language> RowanNomError<Lang> for DummyError {
27    fn from_message(_message: &str) -> Self {
28        Self
29    }
30
31    fn from_expected(_position: usize, _message: &str) -> Self {
32        Self
33    }
34
35    fn from_expected_eof(_range: Range<usize>) -> Self {
36        Self
37    }
38
39    fn from_unexpected_eof(_position: usize) -> Self {
40        Self
41    }
42
43    fn from_unexpected_token(
44        _span: Range<usize>,
45        _expected: Lang::Kind,
46        _found: Lang::Kind,
47    ) -> Self {
48        Self
49    }
50
51    fn with_context(self, _ctx: &'static str) -> Self {
52        Self
53    }
54}