[−][src]Macro synom::alt
Run a series of parsers, returning the result of the first one which succeeds.
Optionally allows for the result to be transformed.
- Syntax:
alt!(THING1 | THING2 => { FUNC } | ...) - Output:
T, the return type ofTHING1andFUNC(THING2)and ...
extern crate syn; #[macro_use] extern crate synom; use syn::Ident; use syn::parse::ident; named!(ident_or_bang -> Ident, alt!( ident | punct!("!") => { |_| "BANG".into() } ) ); fn main() { let input = "foo"; let parsed = ident_or_bang(input).expect("identifier or `!`"); assert_eq!(parsed, "foo"); let input = "!"; let parsed = ident_or_bang(input).expect("identifier or `!`"); assert_eq!(parsed, "BANG"); }