[−][src]Function nom::sequence::separated_pair
pub fn separated_pair<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
first: F,
sep: G,
second: H
) -> impl Fn(I) -> IResult<I, (O1, O3), E> where
F: Fn(I) -> IResult<I, O1, E>,
G: Fn(I) -> IResult<I, O2, E>,
H: Fn(I) -> IResult<I, O3, E>,
Gets an object from the first parser, then matches an object from the sep_parser and discards it, then gets another object from the second parser.
Arguments
firstThe first parser to apply.sepThe separator parser to apply.secondThe second parser to apply.
use nom::sequence::separated_pair; use nom::bytes::complete::tag; let parser = separated_pair(tag("abc"), tag("|"), tag("efg")); assert_eq!(parser("abc|efg"), Ok(("", ("abc", "efg")))); assert_eq!(parser("abc|efghij"), Ok(("hij", ("abc", "efg")))); assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag)))); assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));