Function winnow::combinator::delimited

source ·
pub fn delimited<I, O1, O2, O3, E: ParserError<I>, F, G, H>(
    first: F,
    second: G,
    third: H,
) -> impl Parser<I, O2, E>
where I: Stream, F: Parser<I, O1, E>, G: Parser<I, O2, E>, H: Parser<I, O3, E>,
Expand description

Sequence three parsers, only returning the output of the second.

§Arguments

  • first The first parser to apply and discard.
  • second The second parser to apply.
  • third The third parser to apply and discard.

§Example

use winnow::combinator::delimited;
use winnow::token::tag;

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

assert_eq!(parser.parse_peek("(abc)"), Ok(("", "abc")));
assert_eq!(parser.parse_peek("(abc)def"), Ok(("def", "abc")));
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))));