Function winnow::combinator::separated0
source · pub fn separated0<I, O, C, O2, E, P, S>(
parser: P,
sep: S,
) -> impl Parser<I, C, E>
Expand description
Accumulate
the output of a parser, interleaed with sep
This stops when either parser returns ErrMode::Backtrack
. To instead chain an error up, see
cut_err
.
§Arguments
parser
Parses the elements of the list.sep
Parses the separator between list elements.
§Example
use winnow::combinator::separated0;
use winnow::token::tag;
fn parser(s: &str) -> IResult<&str, Vec<&str>> {
separated0("abc", "|").parse_peek(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![])));