Function nom::multi::separated_list [−][src]
pub fn separated_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.
Arguments
sep
Parses the separator between list elements.f
Parses the elements of the list.
use nom::multi::separated_list; use nom::bytes::complete::tag; fn parser(s: &str) -> IResult<&str, Vec<&str>> { separated_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(""), Ok(("", vec![]))); assert_eq!(parser("def|abc"), Ok(("def|abc", vec![])));