Remove ChildPosition enum
This commit is contained in:
parent
1968ed83ee
commit
c8ca7ba337
@ -29,15 +29,7 @@ impl super::Precedence for crate::Formula
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
fn requires_parentheses<'formula>(formula: &'formula crate::Formula,
|
||||||
enum ChildPosition
|
|
||||||
{
|
|
||||||
Any,
|
|
||||||
Antecedent,
|
|
||||||
Implication,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_parentheses<'formula>(formula: &'formula crate::Formula, position: ChildPosition,
|
|
||||||
parent_formula: &'formula crate::Formula)
|
parent_formula: &'formula crate::Formula)
|
||||||
-> bool
|
-> bool
|
||||||
{
|
{
|
||||||
@ -140,18 +132,16 @@ struct FormulaDisplay<'formula>
|
|||||||
{
|
{
|
||||||
formula: &'formula crate::Formula,
|
formula: &'formula crate::Formula,
|
||||||
parent_formula: Option<&'formula crate::Formula>,
|
parent_formula: Option<&'formula crate::Formula>,
|
||||||
position: ChildPosition,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_formula<'formula>(formula: &'formula crate::Formula,
|
fn display_formula<'formula>(formula: &'formula crate::Formula,
|
||||||
parent_formula: Option<&'formula crate::Formula>, position: ChildPosition)
|
parent_formula: Option<&'formula crate::Formula>)
|
||||||
-> FormulaDisplay<'formula>
|
-> FormulaDisplay<'formula>
|
||||||
{
|
{
|
||||||
FormulaDisplay
|
FormulaDisplay
|
||||||
{
|
{
|
||||||
formula,
|
formula,
|
||||||
parent_formula,
|
parent_formula,
|
||||||
position,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +152,7 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
let precedence_level = self.formula.precedence_level();
|
let precedence_level = self.formula.precedence_level();
|
||||||
let requires_parentheses = match self.parent_formula
|
let requires_parentheses = match self.parent_formula
|
||||||
{
|
{
|
||||||
Some(ref parent_formula) => requires_parentheses(self.formula, self.position, parent_formula),
|
Some(ref parent_formula) => requires_parentheses(self.formula, parent_formula),
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,7 +178,7 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
separator = ", "
|
separator = ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(format, " {:?}", display_formula(&exists.argument, Some(self.formula), ChildPosition::Any))?;
|
write!(format, " {:?}", display_formula(&exists.argument, Some(self.formula)))?;
|
||||||
},
|
},
|
||||||
crate::Formula::ForAll(for_all) =>
|
crate::Formula::ForAll(for_all) =>
|
||||||
{
|
{
|
||||||
@ -205,10 +195,10 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
separator = ", "
|
separator = ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(format, " {:?}", display_formula(&for_all.argument, Some(self.formula), ChildPosition::Any))?;
|
write!(format, " {:?}", display_formula(&for_all.argument, Some(self.formula)))?;
|
||||||
},
|
},
|
||||||
crate::Formula::Not(argument) => write!(format, "not {:?}",
|
crate::Formula::Not(argument) => write!(format, "not {:?}",
|
||||||
display_formula(argument, Some(self.formula), ChildPosition::Any))?,
|
display_formula(argument, Some(self.formula)))?,
|
||||||
crate::Formula::And(arguments) =>
|
crate::Formula::And(arguments) =>
|
||||||
{
|
{
|
||||||
let mut separator = "";
|
let mut separator = "";
|
||||||
@ -223,7 +213,7 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
|
|
||||||
for argument in arguments
|
for argument in arguments
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator, display_formula(argument, parent_formula, ChildPosition::Any))?;
|
write!(format, "{}{:?}", separator, display_formula(argument, parent_formula))?;
|
||||||
|
|
||||||
separator = " and "
|
separator = " and "
|
||||||
}
|
}
|
||||||
@ -242,7 +232,7 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
|
|
||||||
for argument in arguments
|
for argument in arguments
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator, display_formula(argument, parent_formula, ChildPosition::Any))?;
|
write!(format, "{}{:?}", separator, display_formula(argument, parent_formula))?;
|
||||||
|
|
||||||
separator = " or "
|
separator = " or "
|
||||||
}
|
}
|
||||||
@ -251,12 +241,12 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
{
|
{
|
||||||
let format_antecedent = |format: &mut std::fmt::Formatter| -> Result<_, _>
|
let format_antecedent = |format: &mut std::fmt::Formatter| -> Result<_, _>
|
||||||
{
|
{
|
||||||
write!(format, "{:?}", display_formula(antecedent, Some(self.formula), ChildPosition::Antecedent))
|
write!(format, "{:?}", display_formula(antecedent, Some(self.formula)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let format_implication = |format: &mut std::fmt::Formatter| -> Result<_, _>
|
let format_implication = |format: &mut std::fmt::Formatter| -> Result<_, _>
|
||||||
{
|
{
|
||||||
write!(format, "{:?}", display_formula(implication, Some(self.formula), ChildPosition::Implication))
|
write!(format, "{:?}", display_formula(implication, Some(self.formula)))
|
||||||
};
|
};
|
||||||
|
|
||||||
match direction
|
match direction
|
||||||
@ -281,7 +271,7 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
|
|
||||||
for argument in arguments
|
for argument in arguments
|
||||||
{
|
{
|
||||||
write!(format, "{}{:?}", separator, display_formula(argument, Some(self.formula), ChildPosition::Any))?;
|
write!(format, "{}{:?}", separator, display_formula(argument, Some(self.formula)))?;
|
||||||
|
|
||||||
separator = " <-> ";
|
separator = " <-> ";
|
||||||
}
|
}
|
||||||
@ -356,7 +346,7 @@ impl std::fmt::Debug for crate::Formula
|
|||||||
{
|
{
|
||||||
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
|
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
|
||||||
{
|
{
|
||||||
write!(format, "{:?}", display_formula(&self, None, ChildPosition::Any))
|
write!(format, "{:?}", display_formula(&self, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +354,7 @@ impl std::fmt::Display for crate::Formula
|
|||||||
{
|
{
|
||||||
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
|
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
|
||||||
{
|
{
|
||||||
write!(format, "{}", display_formula(&self, None, ChildPosition::Any))
|
write!(format, "{}", display_formula(&self, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user