Macro 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 syn::parse::{ident, ty}; #[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!(keyword!("struct") | keyword!("enum")) >> id: ident >> item: switch!(value!(which), "struct" => map!( punct!(";"), move |_| UnitType::Struct { name: id, } ) | "enum" => map!( delimited!(punct!("{"), ident, punct!("}")), move |variant| UnitType::Enum { name: id, variant: variant, } ) ) >> (item) )); fn main() { let input = "struct S;"; let parsed = unit_type(input).expect("unit struct or enum"); println!("{:?}", parsed); let input = "enum E { V }"; let parsed = unit_type(input).expect("unit struct or enum"); println!("{:?}", parsed); }