#[derive(Debug, Clone, Default)]
pub struct CaseTracker {
depth: usize,
in_pattern: bool,
}
impl CaseTracker {
pub fn check_word(&mut self, word: &str) {
match word {
"case" => self.depth += 1,
"in" if self.depth > 0 => self.in_pattern = true,
"esac" if self.depth > 0 => {
self.depth -= 1;
if self.depth == 0 {
self.in_pattern = false;
}
}
_ => {}
}
}
pub const fn is_pattern_close(&self) -> bool {
self.depth > 0 && self.in_pattern
}
pub const fn close_pattern(&mut self) {
self.in_pattern = false;
}
pub const fn resume_pattern(&mut self) {
if self.depth > 0 {
self.in_pattern = true;
}
}
pub const fn is_pattern_open(&self) -> bool {
self.depth > 0 && self.in_pattern
}
}