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, collecting all matches into the type T: FromIterator.

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

Note: Allocates data.

use chomp::{parse_only, token, many, take_while1};

let r: Result<Vec<_>, _> = parse_only(|i| many(i,
    |i| take_while1(i, |c| c != b',' && c != b' ')
        .bind(|i, c| token(i, b',')
                     .map(|_| c))),
    b"a,bc,cd ");

assert_eq!(r, Ok(vec![&b"a"[..], &b"bc"[..]]));