pub fn separated_foldr1<Input, Output, Sep, Error, ParseNext, SepParser, Op>(
parser: ParseNext,
sep: SepParser,
op: Op,
) -> impl Parser<Input, Output, Error>where
Input: Stream,
ParseNext: Parser<Input, Output, Error>,
SepParser: Parser<Input, Sep, Error>,
Error: ParserError<Input>,
Op: FnMut(Output, Sep, Output) -> Output,
Expand description
Alternates between two parsers, merging the results (right associative)
This stops when either parser returns ErrMode::Backtrack
. To instead chain an error up, see
cut_err
.
§Example
use winnow::combinator::separated_foldr1;
use winnow::ascii::dec_uint;
fn parser(s: &mut &str) -> ModalResult<u32> {
separated_foldr1(dec_uint, "^", |l: u32, _, r: u32| l.pow(r)).parse_next(s)
}
assert_eq!(parser.parse_peek("2^3^2"), Ok(("", 512)));
assert_eq!(parser.parse_peek("2"), Ok(("", 2)));
assert!(parser.parse_peek("").is_err());
assert!(parser.parse_peek("def|abc").is_err());