[][src]Function gchemol_parser::parsers::many_till

pub fn many_till<I, O, P, E, F, G>(f: F, g: G) -> impl Fn(I) where
    E: ParseError<I>,
    F: Fn(I) -> Result<(I, O), Err<E>>,
    G: Fn(I) -> Result<(I, P), Err<E>>,
    I: Clone + PartialEq<I>, 

Applies the parser f until the parser g produces a result. Returns a pair consisting of the results of f in a Vec and the result of g.

use nom::multi::many_till;
use nom::bytes::complete::tag;

fn parser(s: &str) -> IResult<&str, (Vec<&str>, &str)> {
  many_till(tag("abc"), tag("end"))(s)
};

assert_eq!(parser("abcabcend"), Ok(("", (vec!["abc", "abc"], "end"))));
assert_eq!(parser("abc123end"), Err(Err::Error(("123end", ErrorKind::Tag))));
assert_eq!(parser("123123end"), Err(Err::Error(("123123end", ErrorKind::Tag))));
assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser("abcendefg"), Ok(("efg", (vec!["abc"], "end"))));