From 1981b74d89b61f9d6858242cd47c90d39bf72f9b Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 17 Sep 2017 05:12:20 -0700 Subject: [PATCH] Nicen up precedence-testing --- src/schala_lang/parsing.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index aebfec0..29da57f 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -476,7 +476,7 @@ impl Operation { i32::min_value() } - fn get_precedence(op: Rc) -> i32 { + fn get_precedence(op: &str) -> i32 { let c: char = op.chars().next().unwrap(); match c { '+' | '-' => 10, @@ -582,12 +582,12 @@ impl Parser { //TODO clean this up let mut lhs = self.primary()?; loop { - let op_str = match self.peek() { - Operator(op) => op, - Period => Rc::new(".".to_string()), + let new_precedence = match self.peek() { + Operator(op) => Operation::get_precedence(&*op), + Period => Operation::get_precedence("."), _ => break, }; - let new_precedence = Operation::get_precedence(op_str); + if precedence >= new_precedence { break; }