Fixed unary "+" bug

pull/2/head
Mark 2023-04-07 09:27:15 -07:00
parent aeacd8746d
commit 88078fea5a
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 9 additions and 7 deletions

View File

@ -34,7 +34,7 @@ fn lookback_signs(
match (&a, &b) { match (&a, &b) {
(PreToken::PreOperator(_, sa), PreToken::PreOperator(l,sb)) (PreToken::PreOperator(_, sa), PreToken::PreOperator(l,sb))
=> { => {
if sb == "-" && { if {
let o = Operator::from_string(sa); let o = Operator::from_string(sa);
o.is_some() && o.is_some() &&
@ -43,6 +43,7 @@ fn lookback_signs(
!o.as_ref().unwrap().is_left_associative() !o.as_ref().unwrap().is_left_associative()
) )
} { } {
if sb == "-" {
g.insert(i-1, PreToken::PreOperator(*l, String::from("neg"))); g.insert(i-1, PreToken::PreOperator(*l, String::from("neg")));
g.insert(i-1, a); g.insert(i-1, a);
} else if sb == "+" { } else if sb == "+" {
@ -50,6 +51,7 @@ fn lookback_signs(
i -= 1; // g is now shorter, we don't need to advance i. i -= 1; // g is now shorter, we don't need to advance i.
// This nullifies the i += 1 at the end of the loop. // This nullifies the i += 1 at the end of the loop.
} else { g.insert(i-1, b); g.insert(i-1, a); } } else { g.insert(i-1, b); g.insert(i-1, a); }
} else { g.insert(i-1, b); g.insert(i-1, a); }
}, },
_ => { g.insert(i-1, b); g.insert(i-1, a); } _ => { g.insert(i-1, b); g.insert(i-1, a); }