Function chomp::combinators::skip_many1 [] [src]

pub fn skip_many1<I: Input, T, E, F>(i: I, f: F) -> ParseResult<I, (), E> where
    F: FnMut(I) -> ParseResult<I, T, E>, 

Runs the given parser until it fails, discarding matched input, expects at least one match.

Incomplete state will be propagated. Will propagate the error if it occurs during the first attempt.

This is more efficient compared to using many1 and then just discarding the result as many1 allocates a separate data structure to contain the data before proceeding.

use chomp::prelude::{Error, parse_only, skip_many1, token};

let p = |i| skip_many1(i, |i| token(i, b'a')).bind(|i, _| token(i, b'b'));

assert_eq!(parse_only(&p, b"aaaabc"), Ok(b'b'));
assert_eq!(parse_only(&p, b"abc"), Ok(b'b'));

assert_eq!(parse_only(&p, b"bc"), Err((&b"bc"[..], Error::expected(b'a'))));