macro_rules! parse_by_kind { ( $self:ident, $expr_id:expr, $expr_name:pat, $expected:literal, $( @call($name:ident, $args:ident) => $call_expr:expr, )* $( @variant($adt:ident, $variant:ident) => $variant_expr:expr, )* $( $pat:pat $(if $guard:expr)? => $expr:expr, )* ) => { ... }; }
Expand description
Helper macro for parsing custom MIR.
Example usage looks something like:
ⓘ
parse_by_kind!(
self, // : &ParseCtxt
expr_id, // what you're matching against
"assignment", // the thing you're trying to parse
@call("mir_assign", args) => { args[0] }, // match invocations of the `mir_assign` special function
ExprKind::Assign { lhs, .. } => { lhs }, // match thir assignment expressions
// no need for fallthrough case - reasonable error is automatically generated
)