winnow::combinator

Function delimited

Source
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;

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))));