[][src]Macro nom::many0_count

macro_rules! many0_count {
    ($i:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $f:expr) => { ... };
}

many0_count!(I -> IResult<I,O>) => I -> IResult<I, usize> Applies the parser 0 or more times and returns the number of times the parser was applied.

many0_count will only return Error if the embedded parser does not consume any input (to avoid infinite loops).

#[macro_use] extern crate nom;
use nom::digit;

named!(number<&[u8], usize>, many0_count!(pair!(digit, tag!(","))));

fn main() {
    assert_eq!(number(&b"123,45,abc"[..]), Ok((&b"abc"[..], 2)));
}