Macro futures_await_synom::switch
[−]
[src]
macro_rules! switch { ($i:expr, $submac:ident!( $($args:tt)* ), $($p:pat => $subrule:ident!( $($args2:tt)* ))|* ) => { ... }; }
Pattern-match the result of a parser to select which other parser to run.
- Syntax:
switch!(TARGET, PAT1 => THEN1 | PAT2 => THEN2 | ...)
- Output:
T
, the return type ofTHEN1
andTHEN2
and ...
extern crate syn; #[macro_use] extern crate synom; use syn::{Ident, Ty}; use synom::tokens::*; #[derive(Debug)] enum UnitType { Struct { name: Ident, }, Enum { name: Ident, variant: Ident, }, } // Parse a unit struct or enum: either `struct S;` or `enum E { V }`. named!(unit_type -> UnitType, do_parse!( which: alt!( syn!(Struct) => { |_| 0 } | syn!(Enum) => { |_| 1 } ) >> id: syn!(Ident) >> item: switch!(value!(which), 0 => map!( syn!(Semi), move |_| UnitType::Struct { name: id, } ) | 1 => map!( braces!(syn!(Ident)), move |(variant, _)| UnitType::Enum { name: id, variant: variant, } ) ) >> (item) ));