cooler kid syntax
This commit is contained in:
parent
43457aae9f
commit
c338f55094
@ -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 {
|
||||
'&' | '^' | '|' => {
|
||||
self.stack.push(value.to_string());
|
||||
true
|
||||
},
|
||||
'>' | '<' => {
|
||||
if let Some(last) = self.stack.last_mut() {
|
||||
match last.as_str() {
|
||||
match self.stack.last_mut() {
|
||||
None => self.stack.push(value.to_string()),
|
||||
Some(last) => match last.as_str() {
|
||||
">" => *last = ">>".to_owned(),
|
||||
"<" => *last = "<<".to_owned(),
|
||||
_ => self.stack.push(value.to_string())
|
||||
}
|
||||
} else {
|
||||
self.stack.push(value.to_string())
|
||||
};
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false
|
||||
@ -40,7 +39,7 @@ impl ShuntingYard {
|
||||
self.output = self.input.chars()
|
||||
.collect::<Vec<char>>()
|
||||
.into_iter()
|
||||
.filter(|char| self.is_operator(*char))
|
||||
.filter(|char| self.is_shift_operator(*char))
|
||||
.map(|char_num| char_num.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user