1use crate::*;
2
3pub trait Parser<T = Node> {
4 fn parse(&self, state: &mut State) -> T;
5
6 fn map<F>(self, f: F) -> Map<Self, F, T>
7 where
8 Self: Sized,
9 {
10 Map::new(self, f)
11 }
12
13 fn boxed<'a>(self) -> Box<dyn Parser<T> + 'a>
14 where
15 Self: 'a + Sized,
16 {
17 Box::new(self)
18 }
19
20 fn arc<'a>(self) -> std::sync::Arc<dyn Parser<T> + 'a>
21 where
22 Self: 'a + Sized,
23 {
24 std::sync::Arc::new(self)
25 }
26}
27
28impl<F, T> Parser<T> for F
29where
30 F: Fn(&mut State) -> T,
31{
32 fn parse(&self, state: &mut State) -> T {
33 self(state)
34 }
35}