Macro unrest_tmp_synom::value
[−]
[src]
macro_rules! value { ($i:expr, $res:expr) => { ... }; }
Produce the given value without parsing anything. Useful as an argument to
switch!
.
- Syntax:
value!(VALUE)
- Output:
VALUE
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) ));