make Operation a tuple-style struct

This commit is contained in:
greg 2017-09-17 17:53:21 -07:00
parent fc350cd03e
commit f51e1a3c47
1 changed files with 4 additions and 6 deletions

View File

@ -481,9 +481,7 @@ pub enum Expression {
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Operation { pub struct Operation(Rc<String>);
op: Rc<String>
}
impl Operation { impl Operation {
fn min_precedence() -> i32 { fn min_precedence() -> i32 {
@ -630,7 +628,7 @@ impl Parser {
_ => unreachable!(), _ => unreachable!(),
}; };
let rhs = self.precedence_expr(new_precedence)?; let rhs = self.precedence_expr(new_precedence)?;
let operation = Operation { op: op_str }; let operation = Operation(op_str);
lhs = BinExp(operation, Box::new(lhs), Box::new(rhs)); lhs = BinExp(operation, Box::new(lhs), Box::new(rhs));
} }
Ok(lhs) Ok(lhs)
@ -644,7 +642,7 @@ impl Parser {
_ => unreachable!(), _ => unreachable!(),
}; };
let expr = self.primary()?; let expr = self.primary()?;
Ok(Expression::PrefixExp(Operation { op: op_str }, Box::new(expr))) Ok(Expression::PrefixExp(Operation(op_str), Box::new(expr)))
}, },
_ => self.primary() _ => self.primary()
} }
@ -841,7 +839,7 @@ mod parse_tests {
($op:expr, $lhs:expr) => { PrefixExp($op, Box::new($lhs)) } ($op:expr, $lhs:expr) => { PrefixExp($op, Box::new($lhs)) }
} }
macro_rules! op { macro_rules! op {
($op:expr) => { Operation { op: Rc::new($op.to_string()) } } ($op:expr) => { Operation(Rc::new($op.to_string())) }
} }
macro_rules! var { macro_rules! var {
($var:expr) => { Variable(Rc::new($var.to_string())) } ($var:expr) => { Variable(Rc::new($var.to_string())) }