Macro synom::do_parse
[−]
[src]
macro_rules! do_parse { ($i:expr, ( $($rest:expr),* )) => { ... }; ($i:expr, $e:ident >> $($rest:tt)*) => { ... }; ($i:expr, $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => { ... }; ($i:expr, $field:ident : $e:ident >> $($rest:tt)*) => { ... }; ($i:expr, $field:ident : $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => { ... }; ($i:expr, mut $field:ident : $e:ident >> $($rest:tt)*) => { ... }; ($i:expr, mut $field:ident : $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => { ... }; }
Run a series of parsers, one after another, optionally assigning the results a name. Fail if any of the parsers fails.
Produces the result of evaluating the final expression in parentheses with all of the previously named results bound.
- Syntax:
do_parse!(name: THING1 >> THING2 >> (RESULT))
- Output:
RESULT
extern crate syn; #[macro_use] extern crate synom; use syn::{Ident, TokenTree}; use syn::parse::{ident, tt}; // Parse a macro invocation like `stringify!($args)`. named!(simple_mac -> (Ident, TokenTree), do_parse!( name: ident >> punct!("!") >> body: tt >> (name, body) )); fn main() { let input = "stringify!($args)"; let (name, body) = simple_mac(input).expect("macro invocation"); println!("{:?}", name); println!("{:?}", body); }