Function fold
fn fold<I, E, F, G, H, J, R>(range: J, parser: F, init: H, fold: G) -> impl Parser<I, Output = R, Error = E>
where
I: Clone + Input,
F: Parser<I, Error = E>,
G: FnMut(R, <F as Parser<I>>::Output) -> R,
H: FnMut() -> R,
E: ParseError<I>,
J: NomRange<usize>
Applies a parser and accumulates the results using a given function and initial value. Fails if the amount of time the embedded parser is run is not within the specified range.
Arguments
rangeConstrains the number of iterations.- A range without an upper bound
a..allows the parser to run until it fails. - A single
usizevalue is equivalent tovalue..=value. - An empty range is invalid.
- A range without an upper bound
parseThe parser to apply.initA function returning the initial value.foldThe function that combines a result offwith the current accumulator.
# extern crate nom;
# use ;
use fold;
use tag;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;