[−][src]Macro syn::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 ofTHING1
andFUNC(THING2)
and ...
Example
#[macro_use] extern crate syn; use syn::Ident; // Parse any identifier token, or the `!` token in which case the // identifier is treated as `"BANG"`. named!(ident_or_bang -> Ident, alt!( syn!(Ident) | punct!(!) => { |_| "BANG".into() } ));
The alt!
macro is most commonly seen when parsing a syntax tree enum such
as the Item
enum.
impl Synom for Item { named!(parse -> Self, alt!( syn!(ItemExternCrate) => { Item::ExternCrate } | syn!(ItemUse) => { Item::Use } | syn!(ItemStatic) => { Item::Static } | syn!(ItemConst) => { Item::Const } | /* ... */ )); }
This macro is available if Syn is built with the "parsing"
feature.