Use custom operators

This commit is contained in:
2026-02-10 22:18:51 +01:00
parent 21414f75db
commit c82384764c
3 changed files with 72 additions and 63 deletions

View File

@ -38,12 +38,23 @@ pub enum Functor
}
#[derive(Clone, Debug, PartialEq)]
pub enum Operator
pub struct Operator
{
Plus,
Minus,
Cons,
Custom(String, usize, OperatorType),
pub op: String,
pub precedence: usize,
pub op_type: OperatorType,
}
impl Operator
{
pub fn new(op: String, precedence: usize, op_type: OperatorType) -> Self
{
Self {
op,
precedence,
op_type,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
@ -51,7 +62,8 @@ pub enum OperatorType
{
Prefix,
Postfix,
Infix,
LeftInfix,
RightInfix,
}
impl Display for Body
@ -150,12 +162,6 @@ 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),
}
write!(f, "{}", self.op)
}
}