Continue parsing formulas
This commit is contained in:
46
src/ast.rs
46
src/ast.rs
@@ -29,6 +29,15 @@ pub enum UnaryOperator
|
||||
Negative,
|
||||
}
|
||||
|
||||
// ImplicationDirection
|
||||
|
||||
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub enum ImplicationDirection
|
||||
{
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
}
|
||||
|
||||
// Primitives
|
||||
|
||||
#[derive(Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
@@ -291,38 +300,22 @@ impl ForAll
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct IfAndOnlyIf
|
||||
{
|
||||
pub left: Box<Formula>,
|
||||
pub right: Box<Formula>,
|
||||
}
|
||||
|
||||
impl IfAndOnlyIf
|
||||
{
|
||||
pub fn new(left: Box<Formula>, right: Box<Formula>) -> Self
|
||||
{
|
||||
Self
|
||||
{
|
||||
left,
|
||||
right,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct Implies
|
||||
{
|
||||
pub direction: ImplicationDirection,
|
||||
pub antecedent: Box<Formula>,
|
||||
pub implication: Box<Formula>,
|
||||
}
|
||||
|
||||
impl Implies
|
||||
{
|
||||
pub fn new(antecedent: Box<Formula>, implication: Box<Formula>) -> Self
|
||||
pub fn new(direction: ImplicationDirection, antecedent: Box<Formula>, implication: Box<Formula>)
|
||||
-> Self
|
||||
{
|
||||
Self
|
||||
{
|
||||
direction,
|
||||
antecedent,
|
||||
implication,
|
||||
}
|
||||
@@ -480,7 +473,7 @@ pub enum Formula
|
||||
Compare(Compare),
|
||||
Exists(Exists),
|
||||
ForAll(ForAll),
|
||||
IfAndOnlyIf(IfAndOnlyIf),
|
||||
IfAndOnlyIf(Formulas),
|
||||
Implies(Implies),
|
||||
Not(Box<Formula>),
|
||||
Or(Formulas),
|
||||
@@ -542,14 +535,17 @@ impl Formula
|
||||
Self::compare(ComparisonOperator::GreaterOrEqual, left, right)
|
||||
}
|
||||
|
||||
pub fn if_and_only_if(left: Box<Formula>, right: Box<Formula>) -> Self
|
||||
pub fn if_and_only_if(arguments: Formulas) -> Self
|
||||
{
|
||||
Self::IfAndOnlyIf(IfAndOnlyIf::new(left, right))
|
||||
assert!(!arguments.is_empty());
|
||||
|
||||
Self::IfAndOnlyIf(arguments)
|
||||
}
|
||||
|
||||
pub fn implies(antecedent: Box<Formula>, consequent: Box<Formula>) -> Self
|
||||
pub fn implies(direction: ImplicationDirection, antecedent: Box<Formula>,
|
||||
consequent: Box<Formula>) -> Self
|
||||
{
|
||||
Self::Implies(Implies::new(antecedent, consequent))
|
||||
Self::Implies(Implies::new(direction, antecedent, consequent))
|
||||
}
|
||||
|
||||
pub fn less(left: Box<Term>, right: Box<Term>) -> Self
|
||||
|
Reference in New Issue
Block a user