diff options
Diffstat (limited to 'karlc/src/pretty.rs')
-rw-r--r-- | karlc/src/pretty.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/karlc/src/pretty.rs b/karlc/src/pretty.rs new file mode 100644 index 0000000..bf9cf20 --- /dev/null +++ b/karlc/src/pretty.rs @@ -0,0 +1,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!(), + } +} |