diff --git a/rust-calc/src/main.rs b/rust-calc/src/main.rs index 141c593..046e786 100644 --- a/rust-calc/src/main.rs +++ b/rust-calc/src/main.rs @@ -145,6 +145,30 @@ fn parse(pattern: String) -> (Vec, Vec) { numbers.push(tmp_result); // Change the position in the list i = i2; + + // Check the symbol after the closing bracket + let c3 = pattern.chars().nth(i2 + 1).expect("some char"); + if !c3.is_numeric() { + let s2 = match c3 { + '-' => Some(Symbol::Minus), + '+' => Some(Symbol::Plus), + '*' => Some(Symbol::Multiply), + '/' => Some(Symbol::Divide), + + _ => None, + }; + match s2 { + Some(s2) => { + symbols.push(s2); + i += 1; + } + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // This will be used in case of bracket directly followed by number. + None => { + symbols.push(Symbol::Multiply); + } + } + } } } } @@ -286,7 +310,12 @@ fn main() { // println!("{:?}", numbers); if symbols.len() < 1 || symbols.len() + 1 != numbers.len() { - println!("The input is malformed"); + println!( + "The input is malformed {} {} {}", + symbols.len() < 1, + symbols.len() + 1 != numbers.len(), + symbols.len() + ); process::exit(2); }