Macro synom::map [] [src]

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

Transform the result of a parser by applying a function or closure.

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

use syn::{Item, Ident};
use syn::parse::item;

fn get_item_ident(item: Item) -> Ident {
    item.ident
}

// Parses an item and returns the name (identifier) of the item only.
named!(item_ident -> Ident,
    map!(item, get_item_ident)
);

// Or equivalently:
named!(item_ident2 -> Ident,
    map!(item, |i: Item| i.ident)
);

fn main() {
    let input = "fn foo() {}";

    let parsed = item_ident(input).expect("item");

    assert_eq!(parsed, "foo");
}