nom::many1! [] [src]

macro_rules! many1(
  ($i:expr, $submac:ident!( $($args:tt)* )) => (
    {
      let mut begin = 0;
      let mut remaining = $i.len();
      let mut res = Vec::new();
      loop {
        match $submac!(&$i[begin..], $($args)*) {
          $crate::IResult::Done(i,o) => {
            if i.len() == $i[begin..].len() {
              break;
            }
            res.push(o);
            begin += remaining - i.len();
            remaining = i.len();
          },
          _                  => {
            break;
          }
        }
      }
      if res.len() == 0 {
        $crate::IResult::Error($crate::Err::Position($crate::ErrorCode::Many1 as u32,$i))
      } else {
        $crate::IResult::Done(&$i[begin..], res)
      }
    }
  );
  ($i:expr, $f:expr) => (
    many1!($i, call!($f));
  );
);

many1!(I -> IResult<I,O>) => I -> IResult<I, Vec<O>> Applies the parser 1 or more times and returns the list of results in a Vec

the embedded parser may return Incomplete

 named!(multi<&[u8], Vec<&[u8]> >, many1!( tag!( "abcd" ) ) );

 let a = b"abcdabcdef";
 let b = b"azerty";

 let res = vec![&b"abcd"[..], &b"abcd"[..]];
 assert_eq!(multi(&a[..]), Done(&b"ef"[..], res));
 assert_eq!(multi(&b[..]), Error(Position(ErrorCode::Many1 as u32,&b[..])));