Add support for automatic bracket simbol in progress

This commit is contained in:
Alexandre Stein 2022-11-14 16:42:12 +01:00
parent fbe8e2c1c1
commit a033d3b647
1 changed files with 30 additions and 1 deletions

View File

@ -145,6 +145,30 @@ fn parse(pattern: String) -> (Vec<Symbol>, Vec<f64>) {
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);
}