Function chomp::combinators::many [] [src]

pub fn many<'a, I, T, E, F, U>(i: Input<'a, I>, f: F) -> ParseResult<'a, I, T, E> where I: Copy, U: 'a, F: FnMut(Input<'a, I>) -> ParseResult<'a, I, U, E>, T: FromIterator<U>

Parses many instances of f until it does no longer match, returning all matches.

Note: If the last parser succeeds on the last input item then this parser is still considered incomplete as there might be more data to fill.

Note: Allocates data.

use chomp::{ParseResult, Error, Input, token, many, take_while1};

let p = Input::new(b"a,bc,cd ");

let r: ParseResult<_, Vec<&[u8]>, Error<u8>> =
    many(p, |i| take_while1(i, |c| c != b',' && c != b' ').bind(|i, c|
        token(i, b',').bind(|i, _| i.ret(c))));
let v = r.unwrap();

assert_eq!(v.len(), 2);
assert_eq!(v[0], b"a");
assert_eq!(v[1], b"bc");