aboutsummaryrefslogtreecommitdiff
path: root/karlc/src/pretty.rs
blob: bf9cf205be20b9b9e1e7f38207204445f1cfd85c (plain)
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
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(_) => todo!(),
        Condition::And(cs) => cs
            .iter()
            .map(|e| 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: _,
        } => todo!(),
    }
}