[][src]Macro gobble::enum_parser

macro_rules! enum_parser {
    ( ($name:ident,$mod:ident,$ot:ty)=>$($mbit:tt),* $(,)?) => { ... };
}

use gobble::*;
mod scoper{
    // had to make a new scope for the doc test but it shouldn't be needed
    // from outer crates
    use gobble::*;
    //declare the enum
    #[derive(Clone, PartialEq, Debug)]
    pub enum Oper {
        Add,
        Sub,
        Div,
        Mul,
        Var(String),
    }
     
    enum_parser! { (OPER,oper,Oper) =>
        ((ADD->Oper::Add) '+'),
        ((SUB->Oper::Sub) '-'),
        ((DIV->Oper::Div) '/'),
        ((MUL->Oper::Mul) '*'),
        (VAR , Alpha.plus().map(|s|Oper::Var(s))),
    }
}
use scoper::*;

let v = star(scoper::OPER).parse_s("-cat").unwrap();
assert_eq!( v, vec![ Oper::Sub, Oper::Var("cat".to_string()) ]);

let v2 = star(or!(oper::ADD, oper::SUB)).parse_s("-+-hello").unwrap();
assert_eq!(v2, vec![Oper::Sub, Oper::Add, Oper::Sub]);