Nicen up precedence-testing
This commit is contained in:
parent
077ab8ddb8
commit
1981b74d89
@ -476,7 +476,7 @@ impl Operation {
|
|||||||
i32::min_value()
|
i32::min_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_precedence(op: Rc<String>) -> i32 {
|
fn get_precedence(op: &str) -> i32 {
|
||||||
let c: char = op.chars().next().unwrap();
|
let c: char = op.chars().next().unwrap();
|
||||||
match c {
|
match c {
|
||||||
'+' | '-' => 10,
|
'+' | '-' => 10,
|
||||||
@ -582,12 +582,12 @@ impl Parser {
|
|||||||
//TODO clean this up
|
//TODO clean this up
|
||||||
let mut lhs = self.primary()?;
|
let mut lhs = self.primary()?;
|
||||||
loop {
|
loop {
|
||||||
let op_str = match self.peek() {
|
let new_precedence = match self.peek() {
|
||||||
Operator(op) => op,
|
Operator(op) => Operation::get_precedence(&*op),
|
||||||
Period => Rc::new(".".to_string()),
|
Period => Operation::get_precedence("."),
|
||||||
_ => break,
|
_ => break,
|
||||||
};
|
};
|
||||||
let new_precedence = Operation::get_precedence(op_str);
|
|
||||||
if precedence >= new_precedence {
|
if precedence >= new_precedence {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user