Use custom operators
This commit is contained in:
32
src/ast.rs
32
src/ast.rs
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user