Function combine::sep_by1 [] [src]

pub fn sep_by1<F, P, S>(parser: P, separator: S) -> SepBy1<F, P, S> where F: FromIterator<P::Output>, P: Parser, S: Parser<Input=P::Input>

Parses parser one 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_by1::<Vec<_>, _, _>(...).

let mut parser = sep_by1(digit(), token(','));
let result_ok = parser.parse(State::new("1,2,3"))
                      .map(|(vec, state)| (vec, state.input));
assert_eq!(result_ok, Ok((vec!['1', '2', '3'], "")));
let result_err = parser.parse(State::new(""));
assert_eq!(result_err, Err(ParseError {
    position: <char as Positioner>::start(),
    errors: vec![
        Error::end_of_input(),
        Error::Expected("digit".into())
    ]
}));