pub fn delimited<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
    first: F,
    second: G,
    third: H
) -> impl FnMut(I) -> IResult<I, O2, E> where
    F: Parser<I, O1, E>,
    G: Parser<I, O2, E>,
    H: Parser<I, O3, E>, 
Expand description

Matches an object from the first parser and discards it, then gets an object from the second parser, and finally matches an object from the third parser and discards it.

Arguments

  • first The first parser to apply and discard.
  • second The second parser to apply.
  • third The third parser to apply and discard.
use nom::sequence::delimited;
use nom::bytes::complete::tag;

let mut parser = delimited(tag("("), tag("abc"), tag(")"));

assert_eq!(parser("(abc)"), Ok(("", "abc")));
assert_eq!(parser("(abc)def"), Ok(("def", "abc")));
assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));