Function winnow::sequence::separated_pair
source · pub fn separated_pair<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
first: F,
sep: G,
second: H
) -> impl Parser<I, (O1, O3), E>where
I: Stream,
F: Parser<I, O1, E>,
G: Parser<I, O2, E>,
H: Parser<I, O3, E>,Expand description
Apply three parsers, only returning the values of the first and third.
Arguments
firstThe first parser to apply.sepThe separator parser to apply.secondThe second parser to apply.
Example
use winnow::sequence::separated_pair;
use winnow::bytes::tag;
let mut parser = separated_pair("abc", "|", "efg");
assert_eq!(parser.parse_next("abc|efg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser.parse_next("abc|efghij"), Ok(("hij", ("abc", "efg"))));
assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));