Rename types for consistency
This commit is contained in:
parent
242435c698
commit
f0958b100e
30
src/ast.rs
30
src/ast.rs
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
pub enum BinaryOperator
|
pub enum BinaryOperator
|
||||||
{
|
{
|
||||||
Addition,
|
Add,
|
||||||
Subtraction,
|
Subtract,
|
||||||
Multiplication,
|
Multiply,
|
||||||
Division,
|
Divide,
|
||||||
Modulo,
|
Modulo,
|
||||||
Exponentiation,
|
Exponentiate,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ComparisonOperator
|
pub enum ComparisonOperator
|
||||||
@ -23,7 +23,7 @@ pub enum ComparisonOperator
|
|||||||
pub enum UnaryOperator
|
pub enum UnaryOperator
|
||||||
{
|
{
|
||||||
AbsoluteValue,
|
AbsoluteValue,
|
||||||
Negation,
|
Negative,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
@ -153,13 +153,7 @@ pub struct Variable
|
|||||||
|
|
||||||
// Formulas
|
// Formulas
|
||||||
|
|
||||||
pub struct Biconditional
|
pub struct Compare
|
||||||
{
|
|
||||||
pub left: Box<Formula>,
|
|
||||||
pub right: Box<Formula>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Comparison
|
|
||||||
{
|
{
|
||||||
pub operator: ComparisonOperator,
|
pub operator: ComparisonOperator,
|
||||||
pub left: Box<Term>,
|
pub left: Box<Term>,
|
||||||
@ -178,6 +172,12 @@ pub struct ForAll
|
|||||||
pub argument: Box<Formula>,
|
pub argument: Box<Formula>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct IfAndOnlyIf
|
||||||
|
{
|
||||||
|
pub left: Box<Formula>,
|
||||||
|
pub right: Box<Formula>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Implies
|
pub struct Implies
|
||||||
{
|
{
|
||||||
pub antecedent: Box<Formula>,
|
pub antecedent: Box<Formula>,
|
||||||
@ -210,11 +210,11 @@ pub type Terms = Vec<Box<Term>>;
|
|||||||
pub enum Formula
|
pub enum Formula
|
||||||
{
|
{
|
||||||
And(Formulas),
|
And(Formulas),
|
||||||
Biconditional(Biconditional),
|
|
||||||
Boolean(bool),
|
Boolean(bool),
|
||||||
Comparison(Comparison),
|
Compare(Compare),
|
||||||
Exists(Exists),
|
Exists(Exists),
|
||||||
ForAll(ForAll),
|
ForAll(ForAll),
|
||||||
|
IfAndOnlyIf(IfAndOnlyIf),
|
||||||
Implies(Implies),
|
Implies(Implies),
|
||||||
Not(Box<Formula>),
|
Not(Box<Formula>),
|
||||||
Or(Formulas),
|
Or(Formulas),
|
||||||
|
@ -48,16 +48,16 @@ impl Precedence for crate::Term
|
|||||||
| Self::String(_)
|
| Self::String(_)
|
||||||
| Self::Variable(_)
|
| Self::Variable(_)
|
||||||
=> 0,
|
=> 0,
|
||||||
Self::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::Negation, ..})
|
Self::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::Negative, ..})
|
||||||
=> 1,
|
=> 1,
|
||||||
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Exponentiation, ..})
|
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Exponentiate, ..})
|
||||||
=> 2,
|
=> 2,
|
||||||
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Multiplication, ..})
|
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Multiply, ..})
|
||||||
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Division, ..})
|
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Divide, ..})
|
||||||
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Modulo, ..})
|
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Modulo, ..})
|
||||||
=> 3,
|
=> 3,
|
||||||
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Addition, ..})
|
Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Add, ..})
|
||||||
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Subtraction, ..})
|
| Self::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Subtract, ..})
|
||||||
=> 4,
|
=> 4,
|
||||||
Self::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::AbsoluteValue, ..})
|
Self::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::AbsoluteValue, ..})
|
||||||
=> 5,
|
=> 5,
|
||||||
@ -73,7 +73,7 @@ impl Precedence for crate::Formula
|
|||||||
{
|
{
|
||||||
Self::Predicate(_)
|
Self::Predicate(_)
|
||||||
| Self::Boolean(_)
|
| Self::Boolean(_)
|
||||||
| Self::Comparison(_)
|
| Self::Compare(_)
|
||||||
=> 0,
|
=> 0,
|
||||||
Self::Exists(_)
|
Self::Exists(_)
|
||||||
| Self::ForAll(_)
|
| Self::ForAll(_)
|
||||||
@ -86,7 +86,7 @@ impl Precedence for crate::Formula
|
|||||||
=> 4,
|
=> 4,
|
||||||
Self::Implies(_)
|
Self::Implies(_)
|
||||||
=> 5,
|
=> 5,
|
||||||
Self::Biconditional(_)
|
Self::IfAndOnlyIf(_)
|
||||||
=> 6,
|
=> 6,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,19 +156,19 @@ impl<'term> std::fmt::Debug for TermDisplay<'term>
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Addition, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Add, left, right})
|
||||||
=> write!(format, "{:?} + {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} + {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Subtraction, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Subtract, left, right})
|
||||||
=> write!(format, "{:?} - {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} - {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Multiplication, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Multiply, left, right})
|
||||||
=> write!(format, "{:?} * {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} * {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Division, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Divide, left, right})
|
||||||
=> write!(format, "{:?} / {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} / {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Modulo, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Modulo, left, right})
|
||||||
=> write!(format, "{:?} % {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} % {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Exponentiation, left, right})
|
crate::Term::BinaryOperation(crate::BinaryOperation{operator: crate::BinaryOperator::Exponentiate, left, right})
|
||||||
=> write!(format, "{:?} ** {:?}", display_term(left, precedence), display_term(right, precedence)),
|
=> write!(format, "{:?} ** {:?}", display_term(left, precedence), display_term(right, precedence)),
|
||||||
crate::Term::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::Negation, argument})
|
crate::Term::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::Negative, argument})
|
||||||
=> write!(format, "-{:?}", display_term(argument, precedence)),
|
=> write!(format, "-{:?}", display_term(argument, precedence)),
|
||||||
crate::Term::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::AbsoluteValue, argument})
|
crate::Term::UnaryOperation(crate::UnaryOperation{operator: crate::UnaryOperator::AbsoluteValue, argument})
|
||||||
=> write!(format, "|{:?}|", display_term(argument, precedence)),
|
=> write!(format, "|{:?}|", display_term(argument, precedence)),
|
||||||
@ -260,19 +260,19 @@ impl<'formula> std::fmt::Debug for FormulaDisplay<'formula>
|
|||||||
},
|
},
|
||||||
crate::Formula::Implies(crate::Implies{antecedent, implication})
|
crate::Formula::Implies(crate::Implies{antecedent, implication})
|
||||||
=> write!(format, "{:?} -> {:?}", display_formula(antecedent, precedence), display_formula(implication, precedence))?,
|
=> write!(format, "{:?} -> {:?}", display_formula(antecedent, precedence), display_formula(implication, precedence))?,
|
||||||
crate::Formula::Biconditional(crate::Biconditional{left, right})
|
crate::Formula::IfAndOnlyIf(crate::IfAndOnlyIf{left, right})
|
||||||
=> write!(format, "{:?} <-> {:?}", display_formula(left, precedence), display_formula(right, precedence))?,
|
=> write!(format, "{:?} <-> {:?}", display_formula(left, precedence), display_formula(right, precedence))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::Less, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::Less, left, right})
|
||||||
=> write!(format, "{:?} < {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} < {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::LessOrEqual, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::LessOrEqual, left, right})
|
||||||
=> write!(format, "{:?} <= {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} <= {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::Greater, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::Greater, left, right})
|
||||||
=> write!(format, "{:?} > {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} > {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::GreaterOrEqual, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::GreaterOrEqual, left, right})
|
||||||
=> write!(format, "{:?} >= {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} >= {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::Equal, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::Equal, left, right})
|
||||||
=> write!(format, "{:?} = {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} = {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Comparison(crate::Comparison{operator: crate::ComparisonOperator::NotEqual, left, right})
|
crate::Formula::Compare(crate::Compare{operator: crate::ComparisonOperator::NotEqual, left, right})
|
||||||
=> write!(format, "{:?} != {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
=> write!(format, "{:?} != {:?}", display_term(left, 1000), display_term(right, 1000))?,
|
||||||
crate::Formula::Boolean(true) => write!(format, "#true")?,
|
crate::Formula::Boolean(true) => write!(format, "#true")?,
|
||||||
crate::Formula::Boolean(false) => write!(format, "#false")?,
|
crate::Formula::Boolean(false) => write!(format, "#false")?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user