use super::ast::ConditionExpr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum StatusKind {
Kann,
Soll,
Muss,
}
impl StatusKind {
pub fn of(line: &str) -> Option<Self> {
let line = line.trim_start();
if line.starts_with("Muss") || line.starts_with('X') {
Some(Self::Muss)
} else if line.starts_with("Soll") {
Some(Self::Soll)
} else if line.starts_with("Kann") {
Some(Self::Kann)
} else {
None
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct StatusBranch {
pub kind: Option<StatusKind>,
pub condition: Option<ConditionExpr>,
}
pub(crate) fn status_lines(input: &str) -> Vec<&str> {
let mut out = Vec::new();
for line in input.lines() {
let mut rest = line.trim();
while !rest.is_empty() {
let mut depth = 0usize;
let split = rest
.char_indices()
.find(|&(i, c)| {
match c {
'(' => depth += 1,
')' => depth = depth.saturating_sub(1),
_ => {}
}
i > 0
&& depth == 0
&& rest[..i].ends_with(char::is_whitespace)
&& ["Muss", "Soll", "Kann"]
.iter()
.any(|w| rest[i..].starts_with(w))
})
.map_or(rest.len(), |(i, _)| i);
out.push(rest[..split].trim());
rest = rest[split..].trim_start();
}
}
out
}