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>Expand description
Sequence three parsers, only returning the output of the second.
§Arguments
firstThe first parser to apply and discard.secondThe second parser to apply.thirdThe 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))));