Operator only needs to be a tuple struct

This commit is contained in:
greg 2017-01-01 18:29:09 -08:00
parent e5ee072b00
commit 297003c0b0
2 changed files with 4 additions and 6 deletions

View File

@ -111,7 +111,7 @@ impl Parser {
} }
fn get_precedence(&self, op: &Op) -> Precedence { fn get_precedence(&self, op: &Op) -> Precedence {
match &op.repr[..] { match &op.0[..] {
"+" => 10, "+" => 10,
"-" => 10, "-" => 10,
"*" => 20, "*" => 20,
@ -297,7 +297,7 @@ impl Parser {
} }
} }
lhs = Expression::BinExp(op.repr, Box::new(lhs), Box::new(rhs)); lhs = Expression::BinExp(op.0, Box::new(lhs), Box::new(rhs));
} }
Ok(lhs) Ok(lhs)

View File

@ -15,9 +15,7 @@ pub enum Token {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct Op { pub struct Op(pub String);
pub repr: String,
}
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Kw { pub enum Kw {
@ -100,7 +98,7 @@ pub fn tokenize(input: &str) -> TokenizeResult {
break; break;
} }
} }
Operator(Op { repr: buffer }) Operator(Op(buffer))
} }
c => { c => {
if c == '.' && !iter.peek().map_or(false, |x| is_digit(x)) { if c == '.' && !iter.peek().map_or(false, |x| is_digit(x)) {