2021-12-16 20:30:28 +00:00
|
|
|
use crate::Tree;
|
2021-12-16 18:23:02 +00:00
|
|
|
|
|
|
|
grammar<'s>();
|
|
|
|
|
|
|
|
|
2021-12-16 20:30:28 +00:00
|
|
|
pub Tree: Tree = {
|
|
|
|
"(" "+" <Tree*> ")" => Tree::Add(<>),
|
|
|
|
"(" "-" <Tree+> ")" => Tree::Sub(<>),
|
|
|
|
"(" "*" <Tree*> ")" => Tree::Mul(<>),
|
|
|
|
"(" "/" <Tree+> ")" => Tree::Div(<>),
|
|
|
|
r"[0-9]+(\.[0-9]+)?" => Tree::Val(<>.parse().unwrap()),
|
2021-12-16 18:23:02 +00:00
|
|
|
}
|