Function combine::parser::repeat::chainr1 [−][src]
pub fn chainr1<Input, P, Op>(parser: P, op: Op) -> Chainr1<P, Op> where
Input: Stream,
P: Parser<Input>,
Op: Parser<Input>,
Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
Expand description
Parses p
one or more times separated by op
. The value returned is the one produced by the
right associative application of the function returned by op
.
let number = digit().map(|c: char| c.to_digit(10).unwrap()); let pow = token('^').map(|_| |l: u32, r: u32| l.pow(r)); let mut parser = chainr1(number, pow); assert_eq!(parser.parse("2^3^2"), Ok((512, ""))); }