[][src]Function nom::multi::many_till

pub fn many_till<I, O, P, E, F, G>(
    f: F,
    g: G
) -> impl Fn(I) -> IResult<I, (Vec<O>, P), E> where
    I: Clone + PartialEq,
    F: Fn(I) -> IResult<I, O, E>,
    G: Fn(I) -> IResult<I, P, E>,
    E: ParseError<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"))));