pub fn delimited<Input, Ignored1, Output, Ignored2, Error, IgnoredParser1, ParseNext, IgnoredParser2>(
ignored1: IgnoredParser1,
parser: ParseNext,
ignored2: IgnoredParser2,
) -> impl Parser<Input, Output, Error>where
Input: Stream,
Error: ParserError<Input>,
IgnoredParser1: Parser<Input, Ignored1, Error>,
ParseNext: Parser<Input, Output, Error>,
IgnoredParser2: Parser<Input, Ignored2, Error>,
Expand description
Sequence three parsers, only returning the output of the second.
See also seq
to generalize this across any number of fields.
§Example
use winnow::combinator::delimited;
fn parser<'i>(input: &mut &'i str) -> ModalResult<&'i str> {
delimited("(", "abc", ")").parse_next(input)
}
assert_eq!(parser.parse_peek("(abc)"), Ok(("", "abc")));
assert_eq!(parser.parse_peek("(abc)def"), Ok(("def", "abc")));
assert!(parser.parse_peek("").is_err());
assert!(parser.parse_peek("123").is_err());