nom::fold_many_m_n!
[−]
[src]
macro_rules! fold_many_m_n { ($i:expr, $m:expr, $n: expr, $submac:ident!( $($args:tt)* ), $init:expr, $f:expr) => { ... }; ($i:expr, $m:expr, $n: expr, $f:expr, $init:expr, $fold_f:expr) => { ... }; }
fold_many_m_n!(usize, usize, I -> IResult<I,O>, R, Fn(R, O) -> R) => I -> IResult<I, R>
Applies the parser between m and n times (n included) and folds the list of return value
the embedded parser may return Incomplete
named!(multi<&[u8], Vec<&[u8]> >, fold_many_m_n!(2, 4, tag!( "abcd" ), Vec::new(), |mut acc: Vec<_>, item| { acc.push(item); acc })); let a = b"abcdefgh"; let b = b"abcdabcdefgh"; let c = b"abcdabcdabcdabcdabcdefgh"; assert_eq!(multi(&a[..]),Error(Position(ErrorKind::ManyMN,&a[..]))); let res = vec![&b"abcd"[..], &b"abcd"[..]]; assert_eq!(multi(&b[..]), Done(&b"efgh"[..], res)); let res2 = vec![&b"abcd"[..], &b"abcd"[..], &b"abcd"[..], &b"abcd"[..]]; assert_eq!(multi(&c[..]), Done(&b"abcdefgh"[..], res2));