Macro nom::many0_count[][src]

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

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::character::streaming::digit1;

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

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