Function nom::multi::separated_nonempty_list[][src]

pub fn separated_nonempty_list<I, O, O2, E, F, G>(
    sep: G,
    f: F
) -> impl Fn(I) -> IResult<I, Vec<O>, E> where
    I: Clone + PartialEq,
    F: Fn(I) -> IResult<I, O, E>,
    G: Fn(I) -> IResult<I, O2, E>,
    E: ParseError<I>, 

Alternates between two parsers to produce a list of elements. Fails if the element parser does not produce at least one element.

Arguments

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

fn parser(s: &str) -> IResult<&str, Vec<&str>> {
  separated_nonempty_list(tag("|"), tag("abc"))(s)
}

assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser("def|abc"), Err(Err::Error(("def|abc", ErrorKind::Tag))));