nom::peek! [] [src]

macro_rules! peek(
  ($i:expr, $submac:ident!( $($args:tt)* )) => (
    {
      match $submac!($i, $($args)*) {
        $crate::IResult::Done(_,o)     => $crate::IResult::Done($i, o),
        $crate::IResult::Error(a)      => $crate::IResult::Error(a),
        $crate::IResult::Incomplete(i) => $crate::IResult::Incomplete(i)
      }
    }
  );
  ($i:expr, $f:expr) => (
    peek!($i, call!(f));
  );
);

peek!(I -> IResult<I,O>) => I -> IResult<I, O> returns a result without consuming the input

the embedded parser may return Incomplete

 named!(ptag, peek!( tag!( "abcd" ) ) );

 let r = ptag(&b"abcdefgh"[..]);
 assert_eq!(r, Done(&b"abcdefgh"[..], &b"abcd"[..]));