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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::parser::Parser;
use lark_debug_with::DebugWith;
use lark_error::ErrorReported;
pub mod delimited;
pub mod entity;
pub mod expression;
pub mod fn_body;
pub mod fn_signature;
pub mod guard;
pub mod identifier;
pub mod list;
pub mod matched;
pub mod member;
pub mod sigil;
pub mod skip_newline;
pub mod type_reference;
pub trait Syntax<'parse>: DebugWith {
type Data;
fn test(&mut self, parser: &Parser<'parse>) -> bool;
fn expect(&mut self, parser: &mut Parser<'parse>) -> Result<Self::Data, ErrorReported>;
}
pub trait NonEmptySyntax<'parse>: Syntax<'parse> {}
pub trait Delimiter<'parse>: DebugWith {
type Open: NonEmptySyntax<'parse>;
type Close: NonEmptySyntax<'parse>;
fn open_syntax(&self) -> Self::Open;
fn close_syntax(&self) -> Self::Close;
}
impl<T> Syntax<'parse> for &mut T
where
T: Syntax<'parse>,
{
type Data = T::Data;
fn test(&mut self, parser: &Parser<'parse>) -> bool {
T::test(self, parser)
}
fn expect(&mut self, parser: &mut Parser<'parse>) -> Result<Self::Data, ErrorReported> {
T::expect(self, parser)
}
}