Compare commits

...

5 Commits

Author SHA1 Message Date
Patrick Lühne ae3925c72b
Fix function formatting
By mistake, a function’s name was printed two consecutive times if the
function had more than one argument.
2020-03-30 05:39:20 +02:00
Patrick Lühne 6183ae22b5
Minor refactoring for clarity 2020-03-30 05:38:42 +02:00
Patrick Lühne a7e07380ff
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.
2020-03-30 05:32:26 +02:00
Patrick Lühne 14abd73110
Remove unneeded lifetime specifiers 2020-03-30 05:19:01 +02:00
Patrick Lühne 3a5788bd24
Remove redundant release badge
Provided that the latest version of this crate is always published on
crates.io and tagged as a release on GitHub.com, the crates.io and the
GitHub.com release badges will always show the same version.
Consequently, remove the GitHub.com release badge to avoid redundancy.
2020-02-25 15:27:24 +01:00
2 changed files with 26 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# foliage [![GitHub release](https://img.shields.io/github/release/potassco/foliage.svg?maxAge=3600)](https://github.com/potassco/foliage/releases) [![crates.io](https://img.shields.io/crates/v/foliage.svg?maxAge=3600)](https://crates.io/crates/foliage)
# foliage [![crates.io](https://img.shields.io/crates/v/foliage.svg?maxAge=3600)](https://crates.io/crates/foliage)
> First-order logic with integer arithmetics in Rust

View File

@ -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
@ -121,8 +141,7 @@ struct TermDisplay<'term>
term: &'term crate::Term,
}
fn display_term<'term>(term: &'term crate::Term, parent_precedence: Option<i32>)
-> TermDisplay<'term>
fn display_term(term: &crate::Term, parent_precedence: Option<i32>) -> TermDisplay
{
TermDisplay
{
@ -152,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),
@ -165,9 +183,9 @@ impl<'term> std::fmt::Debug for TermDisplay<'term>
"number of function arguments differs from declaration (expected {}, got {})",
function.declaration.arity, function.arguments.len());
if function.arguments.len() > 0
if !function.arguments.is_empty()
{
write!(format, "{}(", function.declaration.name)?;
write!(format, "(")?;
let mut separator = "";
@ -238,8 +256,7 @@ struct FormulaDisplay<'formula>
formula: &'formula crate::Formula,
}
fn display_formula<'formula>(formula: &'formula crate::Formula, parent_precedence: Option<i32>)
-> FormulaDisplay<'formula>
fn display_formula(formula: &crate::Formula, parent_precedence: Option<i32>) -> FormulaDisplay
{
FormulaDisplay
{