Macro exclude

Source
macro_rules! exclude {
    ($input:expr, $submacro1:ident!($($arguments1:tt)*), $submacro2:ident!($($arguments2:tt)*)) => { ... };
    ($input:expr, $submacro1:ident!($($arguments1:tt)*), $g:expr) => { ... };
    ($input:expr, $f:expr, $submacro2:ident!($($arguments2:tt)*)) => { ... };
    ($input:expr, $f:expr, $g:expr) => { ... };
}
Expand description

exclude!(I -> Result<I, O>, I -> Result<I, P>) => I -> Result<I, 0> returns the result of the first parser if the second fails. Both parsers run on the same input.

This is handy when the first parser accepts general values and the second parser denies a particular subset of values.

ยงExamples

use tagua_parser::{
    Error,
    ErrorKind,
    Result
};
use tagua_parser::macros::ErrorKindCustom;

named!(
    test,
    exclude!(
        is_a!("abcdef"),
        alt!(
            tag!("abc")
          | tag!("ace")
        )
    )
);

assert_eq!(test(&b"fedabc"[..]), Result::Done(&b""[..], &b"fedabc"[..]));
assert_eq!(test(&b"abcabc"[..]), Result::Error(Error::Position(ErrorKind::Custom(ErrorKindCustom::Exclude as u32), &b"abcabc"[..])));