Function combine::parser::repeat::sep_by [−][src]
pub fn sep_by<F, Input, P, S>(parser: P, separator: S) -> SepBy<F, P, S> where
Input: Stream,
F: Extend<P::Output> + Default,
P: Parser<Input>,
S: Parser<Input>,
Expand description
Parses parser
zero or more time separated by separator
, returning a collection with the
values from p
.
If the returned collection cannot be inferred type annotations must be supplied, either by
annotating the resulting type binding let collection: Vec<_> = ...
or by specializing when
calling sep_by
, sep_by::<Vec<_>, _, _>(...)
.
let mut parser = sep_by(digit(), token(',')); let result_ok = parser.parse("1,2,3"); assert_eq!(result_ok, Ok((vec!['1', '2', '3'], ""))); let result_ok2 = parser.parse(""); assert_eq!(result_ok2, Ok((vec![], "")));