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
use combine::{
ParseError,
Parser,
ParseResult,
Stream,
};
#[derive(Clone)]
pub(crate) struct Log<P, T>(P, T)
where P: Parser,
T: ::std::fmt::Debug;
impl<I, P, T> Parser for Log<P, T>
where I: Stream,
I::Item: ::std::fmt::Debug,
P: Parser<Input = I>,
P::Output: ::std::fmt::Debug,
T: ::std::fmt::Debug,
{
type Input = I;
type Output = P::Output;
fn parse_stream(&mut self, input: I) -> ParseResult<Self::Output, I> {
let head = input.clone().uncons();
let result = self.0.parse_stream(input.clone());
match result {
Ok((ref value, _)) => eprintln!("{:?}: [{:?} ...] => Ok({:?})", self.1, head.ok(), value),
Err(_) => eprintln!("{:?}: [{:?} ...] => Err(_)", self.1, head.ok()),
}
result
}
fn add_error(&mut self, errors: &mut ParseError<Self::Input>) {
self.0.add_error(errors);
}
}
#[inline(always)]
pub(crate) fn log<P, T>(p: P, msg: T) -> Log<P, T>
where P: Parser,
T: ::std::fmt::Debug,
{
Log(p, msg)
}
pub(crate) trait LogParsing: Parser + Sized {
fn log<T>(self, msg: T) -> Log<Self, T>
where Self: Sized,
T: ::std::fmt::Debug;
}
impl<P> LogParsing for P
where P: Parser,
{
fn log<T>(self, msg: T) -> Log<Self, T>
where T: ::std::fmt::Debug,
{
log(self, msg)
}
}