Macro synom::option [] [src]

macro_rules! option {
    ($i:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $f:expr) => { ... };
}

Turn a failed parse into None and a successful parse into Some.

extern crate syn;
#[macro_use] extern crate synom;

named!(maybe_bang -> Option<&str>, option!(punct!("!")));

fn main() {
    let input = "!";
    let parsed = maybe_bang(input).expect("maybe bang");
    assert_eq!(parsed, Some("!"));

    let input = "";
    let parsed = maybe_bang(input).expect("maybe bang");
    assert_eq!(parsed, None);
}