pub fn call<'a, I, O, F>(parser_factory: F) -> Parser<'a, I, O>Expand description
Call a parser factory, can be used to create recursive parsers.
Examples found in repository?
More examples
examples/whitespace.rs (line 36)
34fn subcontainer<'a>() -> Parser<'a, u8, (Vec<Container>, Vec<String>)> {
35 (
36 call(container).map(|ctr| TmpContainerOrContent::Container(ctr)) |
37 content().map(|ctn| TmpContainerOrContent::Content(ctn))
38 ).repeat(1..).map(
39 |tmp| {
40 tmp.into_iter().fold(
41 (vec![], vec![]),
42 |acc, x| match x {
43 TmpContainerOrContent::Container(ct) => (
44 acc.0.into_iter().chain(vec![ct].into_iter()).collect(),
45 acc.1,
46 ),
47 TmpContainerOrContent::Content(cn) => (
48 acc.0,
49 acc.1.into_iter().chain(vec![cn].into_iter()).collect(),
50 ),
51 }
52 )
53 }
54 )
55}
56
57fn container<'a>() -> Parser<'a, u8, Container> {
58 seq(b"Container\n") *
59 (
60 indented() |
61 empty().map(|()| vec![])
62 ).repeat(1..).map(
63 |lines| lines.into_iter().filter(
64 |line| line.len() > 0
65 ).fold(
66 vec![],
67 |accum, line| accum.into_iter().chain(
68 line.into_iter().chain(vec![b'\n'].into_iter())
69 ).collect()
70 )
71 ).map(|deden| {
72 subcontainer().parse(&deden).expect("subcont")
73 }).map(|(containers, contents)| Container { containers, contents })
74}
75
76fn mylang<'a>() -> Parser<'a, u8, Vec<Container>> {
77 (
78 whitespace() *
79 list(
80 call(container),
81 whitespace()
82 )
83 )
84}