pub fn chainl1<Input, P, Op>(parser: P, op: Op) -> Chainl1<P, Op> where
Input: Stream,
P: Parser<Input>,
Op: Parser<Input>,
Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
Expand description
Parses p
1 or more times separated by op
. The value returned is the one produced by the
left associative application of the function returned by the parser op
.
let number = digit().map(|c: char| c.to_digit(10).unwrap());
let sub = token('-').map(|_| |l: u32, r: u32| l - r);
let mut parser = chainl1(number, sub);
assert_eq!(parser.parse("9-3-5"), Ok((1, "")));