alt

Macro alt 

Source
macro_rules! alt {
    () => { ... };
    ($($a:ident $($b:expr)?,)+) => { ... };
    ($($a:ident $($b:expr)?),*) => { ... };
    (#$f:literal, $($a:ident $($b:expr)?,)+) => { ... };
    (#$f:literal, $($a:ident $($b:expr)?),*) => { ... };
    ($(#$f:ident,)? $(%($v:expr, $id:expr),)? $($a:ident $($b:expr)?,)+) => { ... };
    ($(#$f:ident,)? $(%($v:expr, $id:expr),)? $($a:ident $($b:expr)?),*) => { ... };
    (#($f:expr, $o:expr), $(%($v:expr, $id:expr),)? $($a:ident $($b:expr)?,)+) => { ... };
    (#($f:expr, $o:expr), $(%($v:expr, $id:expr),)? $($a:ident $($b:expr)?),*) => { ... };
    (%($v:expr, $id:expr), $($a:ident $($b:expr)?,)+) => { ... };
    (%($v:expr, $id:expr), $($a:ident $($b:expr)?),*) => { ... };
}
Expand description

Generates a production rule alternative. An alternative is made up of symbols separated by a comma. Each symbol is either

  • a non-terminal: nt {integer}
  • a terminal: t {integer}
  • the empty symbol: e

Preceding an alternative with # {integer} sets a flag value on that alternative. The values are:

  • 128: L-form (low-latency parsing of that alternative)
  • 256: R-assoc (right-associative - by default, ambiguous alternatives like ‘E * E’ are left-associative)

§Example

assert_eq!(alt!(nt 1, t 2, e), Alternative::new(vec![sym!(nt 1), sym!(t 2), sym!(e)]));
assert_eq!(alt!(#128, nt 1, t 2, e), Alternative::new(vec![sym!(nt 1), sym!(t 2), sym!(e)]).with_flags(128));
assert_eq!(alt!(#L, nt 1, t 2, e), Alternative::new(vec![sym!(nt 1), sym!(t 2), sym!(e)]).with_flags(128));
let x = 256;
let o_id = 4;
assert_eq!(alt!(#(x, o_id), nt 0, t 1, e), Alternative::new(vec![sym!(nt 0), sym!(t 1), sym!(e)]).with_flags(256).with_ambig_alt_id(4));