From a7e07380ffebc1b89aac108915d55566c9073a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 30 Mar 2020 05:30:29 +0200 Subject: [PATCH] Support formatting special integers separately This adds Debug and Display trait implementations for the SpecialInteger enum to make it possible to format its values without having to wrap it in a Term variant. --- src/format.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/format.rs b/src/format.rs index a12a54d..02c7cce 100644 --- a/src/format.rs +++ b/src/format.rs @@ -67,6 +67,26 @@ impl Precedence for crate::Formula } } +impl std::fmt::Debug for crate::SpecialInteger +{ + fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result + { + match &self + { + crate::SpecialInteger::Infimum => write!(format, "#inf"), + crate::SpecialInteger::Supremum => write!(format, "#sup"), + } + } +} + +impl std::fmt::Display for crate::SpecialInteger +{ + fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result + { + write!(format, "{:?}", &self) + } +} + impl std::fmt::Debug for crate::FunctionDeclaration { fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result @@ -151,8 +171,7 @@ impl<'term> std::fmt::Debug for TermDisplay<'term> { crate::Term::Boolean(true) => write!(format, "true"), crate::Term::Boolean(false) => write!(format, "false"), - crate::Term::SpecialInteger(crate::SpecialInteger::Infimum) => write!(format, "#inf"), - crate::Term::SpecialInteger(crate::SpecialInteger::Supremum) => write!(format, "#sup"), + crate::Term::SpecialInteger(value) => write!(format, "{:?}", value), crate::Term::Integer(value) => write!(format, "{}", value), crate::Term::String(value) => write!(format, "\"{}\"", value), crate::Term::Variable(variable) => write!(format, "{:?}", variable.declaration),