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
mod parser1;
mod parser2;
mod parser3;
mod parser4;
use std::fmt;
use self::prelude::*;
pub mod prelude {
pub use ::Peel;
pub use parser::{Parser, ParserNode, ParserArena, ParserState};
pub use super::{ParserResult, ParserVariant};
pub use nom::IResult;
pub type ExampleArena = ParserArena<ParserResult, ParserVariant>;
pub type ExampleNode = ParserNode<ParserResult, ParserVariant>;
pub use example::parser1::*;
pub use example::parser2::*;
pub use example::parser3::*;
pub use example::parser4::*;
}
pub enum ParserVariant {
Variant1(Parser1),
Variant2(Parser2),
Variant3(Parser3),
Variant4(Parser4),
}
#[derive(PartialEq, Debug)]
pub enum ParserResult {
Result1(bool),
Result2(bool),
Result3(bool),
Result4(bool),
}
pub fn peel_example() -> Peel<ParserResult, ParserVariant> {
let mut p = Peel::new();
let parser_1 = p.new_parser(Parser1);
p.link_new_parser(parser_1, Parser2);
let parser_3 = p.link_new_parser(parser_1, Parser3);
p.link_new_parser(parser_3, Parser4);
p
}
impl fmt::Display for ParserVariant {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ParserVariant::Variant1(_) => write!(f, "Parser 1"),
ParserVariant::Variant2(_) => write!(f, "Parser 2"),
ParserVariant::Variant3(_) => write!(f, "Parser 3"),
ParserVariant::Variant4(_) => write!(f, "Parser 4"),
}
}
}