Skip to content

Instantly share code, notes, and snippets.

@RReverser RReverser/alt_switch.rs
Last active Nov 30, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.