Last active
November 30, 2017 16:33
-
-
Save RReverser/afee1c9f23d475604710da657a4b646f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! err { | |
($i:expr, $kind: expr) => { | |
IResult::Error(error_position!($kind, $i)) | |
}; | |
} | |
macro_rules! alt_switch { | |
($i:expr, $($lhs_mac:ident ! ( $($lhs_arg:tt)* ) $(as $lhs_binding:pat)* => $rhs_mac:ident ! ( $($rhs_arg:tt)* ) |)+ _ => $def_mac:ident ! ( $($def_arg:tt)* )) => {{ | |
$(if let IResult::Done(i, $($lhs_binding,)* ..) = $lhs_mac ! ( $i, $($lhs_arg)* ) { | |
$rhs_mac ! ( i, $($rhs_arg)* ) | |
} else )+ { | |
$def_mac ! ( $i, $($def_arg)* ) | |
} | |
}}; | |
} | |
alt_switch!( | |
char!('(') => terminated!(sub_parse, char!(')') | | |
char!('!') => map!(sub_parse, Not) | | |
_ => err!(ErrorKind::Alt) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment