Function chomp::combinators::many1
[−]
[src]
pub fn many1<'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 at least one instance of f
and continues 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, many1, take_while1}; let p1 = Input::new(b"a "); let p2 = Input::new(b"a, "); fn parse(i: Input<u8>) -> ParseResult<u8, Vec<&[u8]>, Error<u8>> { many1(i, |i| take_while1(i, |c| c != b',' && c != b' ').bind(|i, c| token(i, b',').bind(|i, _| i.ret(c)))) } assert_eq!(parse(p1).unwrap_err(), Error::Expected(b',')); assert_eq!(parse(p2).unwrap(), &[b"a"]);