1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
use karlcommon::Condition;
pub fn indent(s: &str) -> String {
s.replace("\n", "\n ")
}
pub fn fmt_condition(c: &Condition) -> String {
match c {
Condition::From(_) => todo!(),
Condition::Or(cs) => cs
.iter()
.map(|e| format!("{{ {} }}", fmt_condition(e)))
.reduce(|a, b| format!("{} ∨ {}", a, b))
.unwrap_or("never".to_string()),
Condition::And(cs) => cs
.iter()
.map(|e| format!("{{ {} }}", fmt_condition(e)))
.reduce(|a, b| format!("{} ∧ {}", a, b))
.unwrap_or("never".to_string()),
Condition::Invert(_) => todo!(),
Condition::Equal {
prop,
value,
modulus,
} => {
if let Some(m) = modulus {
format!("{:?} ≡ {} (mod {})", prop, value, m)
} else {
format!("{:?} = {}", prop, value)
}
}
Condition::Range {
prop,
min,
max,
modulus,
} => {
if let Some(m) = modulus {
format!("{} < {:?} < {} (mod {})", min, prop, max, m)
} else {
format!("{} < {:?} < {}", min, prop, max)
}
}
}
}
|