[−][src]Function gchemol_parser::parsers::delimited
pub fn delimited<I, O1, O2, O3, E, F, G, H>(
first: F,
sep: G,
second: H
) -> impl Fn(I) where
E: ParseError<I>,
F: Fn(I) -> Result<(I, O1), Err<E>>,
G: Fn(I) -> Result<(I, O2), Err<E>>,
H: Fn(I) -> Result<(I, O3), Err<E>>,
Matches an object from the first parser, then gets an object from the sep_parser, then matches another object from the second parser.
Arguments
first
The first parser to apply.sep
The separator parser to apply.second
The second parser to apply.
use nom::sequence::delimited; use nom::bytes::complete::tag; let parser = delimited(tag("abc"), tag("|"), tag("efg")); assert_eq!(parser("abc|efg"), Ok(("", "|"))); assert_eq!(parser("abc|efghij"), Ok(("hij", "|"))); assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag)))); assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));