Function winnow::combinator::separated_pair
source · pub fn separated_pair<I, O1, O2, O3, E: ParserError<I>, F, G, H>(
first: F,
sep: G,
second: H,
) -> impl Parser<I, (O1, O3), E>
Expand description
Sequence three parsers, only returning the values of the first and third.
§Arguments
first
The first parser to apply.sep
The separator parser to apply.second
The second parser to apply.
§Example
use winnow::combinator::separated_pair;
use winnow::token::tag;
let mut parser = separated_pair("abc", "|", "efg");
assert_eq!(parser.parse_peek("abc|efg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser.parse_peek("abc|efghij"), Ok(("hij", ("abc", "efg"))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));