cooler kid syntax

This commit is contained in:
rhpidfyre 2025-04-12 19:14:29 -04:00
parent 43457aae9f
commit c338f55094

View File

@ -14,22 +14,21 @@ impl ShuntingYard {
} }
} }
fn is_operator(&mut self, value: char) -> bool { fn is_shift_operator(&mut self, value: char) -> bool {
match value { match value {
'&' | '^' | '|' => { '&' | '^' | '|' => {
self.stack.push(value.to_string()); self.stack.push(value.to_string());
true true
}, },
'>' | '<' => { '>' | '<' => {
if let Some(last) = self.stack.last_mut() { match self.stack.last_mut() {
match last.as_str() { None => self.stack.push(value.to_string()),
Some(last) => match last.as_str() {
">" => *last = ">>".to_owned(), ">" => *last = ">>".to_owned(),
"<" => *last = "<<".to_owned(), "<" => *last = "<<".to_owned(),
_ => self.stack.push(value.to_string()) _ => self.stack.push(value.to_string())
} }
} else { }
self.stack.push(value.to_string())
};
true true
} }
_ => false _ => false
@ -40,7 +39,7 @@ impl ShuntingYard {
self.output = self.input.chars() self.output = self.input.chars()
.collect::<Vec<char>>() .collect::<Vec<char>>()
.into_iter() .into_iter()
.filter(|char| self.is_operator(*char)) .filter(|char| self.is_shift_operator(*char))
.map(|char_num| char_num.to_string()) .map(|char_num| char_num.to_string())
.collect::<Vec<String>>(); .collect::<Vec<String>>();