Adds operators

This commit is contained in:
2026-02-10 15:41:56 +01:00
parent 0f721e34c4
commit 21414f75db
10 changed files with 329 additions and 61 deletions

View File

@ -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),
}
}
}