From 4e7b383fe2c1ccea7871c708ff1b281451feddd0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 10 Jun 2022 18:12:57 +0200 Subject: blub --- karlc/src/pretty.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 karlc/src/pretty.rs (limited to 'karlc/src/pretty.rs') 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!(), + } +} -- cgit v1.2.3-70-g09d2