Macro unrest_tmp_synom::alt [] [src]

macro_rules! alt {
    ($i:expr, $e:ident | $($rest:tt)*) => { ... };
    ($i:expr, $subrule:ident!( $($args:tt)*) | $($rest:tt)*) => { ... };
    ($i:expr, $subrule:ident!( $($args:tt)* ) => { $gen:expr } | $($rest:tt)+) => { ... };
    ($i:expr, $e:ident => { $gen:expr } | $($rest:tt)*) => { ... };
    ($i:expr, $e:ident => { $gen:expr }) => { ... };
    ($i:expr, $subrule:ident!( $($args:tt)* ) => { $gen:expr }) => { ... };
    ($i:expr, $e:ident) => { ... };
    ($i:expr, $subrule:ident!( $($args:tt)*)) => { ... };
}

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 of THING1 and FUNC(THING2) and ...
extern crate syn;
#[macro_use] extern crate synom;

use syn::Ident;
use synom::tokens::Bang;

named!(ident_or_bang -> Ident,
    alt!(
        syn!(Ident)
        |
        syn!(Bang) => { |_| "BANG".into() }
    )
);