Adds operators
This commit is contained in:
51
src/ast.rs
51
src/ast.rs
@ -27,7 +27,31 @@ pub enum Body
|
||||
pub enum Predicate
|
||||
{
|
||||
Variable(Variable), // Upercase variable like X
|
||||
Fixed(String, Vec<Predicate>),
|
||||
Fixed(Functor, Vec<Predicate>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Functor
|
||||
{
|
||||
Operator(Operator),
|
||||
Functor(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Operator
|
||||
{
|
||||
Plus,
|
||||
Minus,
|
||||
Cons,
|
||||
Custom(String, usize, OperatorType),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum OperatorType
|
||||
{
|
||||
Prefix,
|
||||
Postfix,
|
||||
Infix,
|
||||
}
|
||||
|
||||
impl Display for Body
|
||||
@ -110,3 +134,28 @@ impl Display for Module
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Functor
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
||||
{
|
||||
match self
|
||||
{
|
||||
Functor::Operator(op) => write!(f, "{}", op),
|
||||
Functor::Functor(name) => write!(f, "{}", name),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Display for Operator
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
||||
{
|
||||
match self
|
||||
{
|
||||
Operator::Plus => write!(f, "+"),
|
||||
Operator::Minus => write!(f, "-"),
|
||||
Operator::Cons => write!(f, "::"),
|
||||
Operator::Custom(string, _, _) => write!(f, "{}", string),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user