Remove cmp comparison

This commit is contained in:
Pyther99 2021-07-14 07:50:20 +02:00
parent 634dff682b
commit 07bf7b48e1

View File

@ -12,7 +12,6 @@ use crate::FunctionIdentifier::{Cbrt, Ceil, Cos, Exp, Abs, Floor, Ln, Log, Round
use crate::units::Unit;
use crate::units::Unit::*;
use unicode_segmentation::{Graphemes, UnicodeSegmentation};
use std::cmp::Ordering;
fn is_word_char_str(input: &str) -> bool {
matches!(input, "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L"
@ -625,19 +624,15 @@ pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) ->
}
let tokens = &mut lexer.tokens;
// auto insert missing parentheses in first and last position
match lexer.left_paren_count.cmp(&lexer.right_paren_count) {
Ordering::Less => {
let missing_left_parens = lexer.right_paren_count - lexer.left_paren_count;
for _ in 0..missing_left_parens {
tokens.insert(0, Token::Operator(LeftParen));
}
if lexer.left_paren_count > lexer.right_paren_count {
let missing_right_parens = lexer.left_paren_count - lexer.right_paren_count;
for _ in 0..missing_right_parens {
tokens.push(Token::Operator(RightParen));
}
Ordering::Equal => {}
Ordering::Greater => {
let missing_right_parens = lexer.left_paren_count - lexer.right_paren_count;
for _ in 0..missing_right_parens {
tokens.push(Token::Operator(RightParen));
}
} else if lexer.left_paren_count < lexer.right_paren_count {
let missing_left_parens = lexer.right_paren_count - lexer.left_paren_count;
for _ in 0..missing_left_parens {
tokens.insert(0, Token::Operator(LeftParen));
}
}