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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
mod stream;
pub use self::stream::Stream;
mod scanner;
pub use self::scanner::Scanner;
pub mod adapters;
pub use Either::{Left, Right};
pub(crate) use self::adapters::*;
mod error;
pub(crate) use self::error::Res;
pub use self::error::{Error, Expected};
pub type Result<O, I> = std::result::Result<O, Error<I>>;
#[macro_export]
macro_rules! or {
($x:expr) => {
$x
};
($x:expr, $($xs:tt)+) => {
$x.or(or!($($xs)+))
}
}
pub fn scan_with<F, A, B>(f: F) -> ScanWith<F, A, B>
where
F: Fn(&mut Stream<A>) -> Result<B, A>,
{
ScanWith::new(f)
}
pub fn any<T>() -> Any<T>
where
T: Clone,
{
Any::new()
}
pub fn value<T, I>(x: T) -> Value<T, I>
where
T: Clone,
{
Value::new(x)
}
pub fn end<T>() -> End<T>
where
T: Clone,
{
End::new()
}
pub fn expect<T, F>(f: F) -> Expect<T, F>
where
T: Clone,
F: Fn(&T) -> bool,
{
Expect::new(f)
}
pub fn fail<A: Clone, B>() -> Fail<A, B> {
Fail::new()
}
pub fn token<A>(a: A) -> Token<A>
where
A: Clone + PartialEq,
{
Token::new(a)
}
pub fn tokens<I, A>(iter: I) -> Tokens<A>
where
I: IntoIterator<Item = A>,
A: Clone + PartialEq,
{
Tokens::new(iter.into_iter().collect())
}