use gobble::*;
mod scoper{
use gobble::*;
#[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]);