use std::str::FromStr; use ast::{self, WithLocation}; grammar; pub Program: ast::Program = { Expression => ast::Program(<>), }; Expression: Box> = { "+" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Add, Box::new(v1), Box::new(v2)) })), "-" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Sub, Box::new(v1), Box::new(v2)) })), => <>, }; ExpressionMul: Box> = { "*" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Mul, Box::new(v1), Box::new(v2)) })), "/" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Div, Box::new(v1), Box::new(v2)) })), "//" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::FloorDiv, Box::new(v1), Box::new(v2)) })), => <>, }; ExpressionBase: Box> = { Num => Box::new(<>.map(|v| ast::Expression::Number(v))), Spanned => Box::new(<>.map(|v| ast::Expression::Nil)), "(" ")" => <>, }; Num: WithLocation = > => e.map(|v| u64::from_str(v).unwrap()); Spanned: WithLocation = { => WithLocation::new(v, l, r) };