Remove BinOpType::Not from ast
- Impl. Display for BinOpType & UnOpType - Impl. scuffed Display for Ast that just uses Debug pretty print
This commit is contained in:
parent
1712dac6d6
commit
12e95ed822
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::token::Literal;
|
use crate::token::Literal;
|
||||||
|
|
||||||
/// Binary Operator Types. For operations that have two operands
|
/// Binary Operator Types. For operations that have two operands
|
||||||
@ -35,8 +37,6 @@ pub enum BinOpType {
|
|||||||
And,
|
And,
|
||||||
/// Boolean Or "||"
|
/// Boolean Or "||"
|
||||||
Or,
|
Or,
|
||||||
/// Boolean Not "!"
|
|
||||||
Not,
|
|
||||||
/// Boolean Xor "^^"
|
/// Boolean Xor "^^"
|
||||||
Xor,
|
Xor,
|
||||||
}
|
}
|
||||||
@ -108,3 +108,47 @@ impl Ast {
|
|||||||
Self { prog }
|
Self { prog }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Ast {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
writeln!(f, "Ast[")?;
|
||||||
|
for stmt in &self.prog {
|
||||||
|
writeln!(f, "{:#?},", stmt)?;
|
||||||
|
}
|
||||||
|
writeln!(f, "]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for BinOpType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let sop = match self {
|
||||||
|
BinOpType::Add => "+",
|
||||||
|
BinOpType::Sub => "-",
|
||||||
|
BinOpType::Mul => "*",
|
||||||
|
BinOpType::Div => "/",
|
||||||
|
BinOpType::Mod => "%",
|
||||||
|
BinOpType::Eq => "==",
|
||||||
|
BinOpType::Neq => "!=",
|
||||||
|
BinOpType::Gt => ">",
|
||||||
|
BinOpType::Lt => "<",
|
||||||
|
BinOpType::Ge => ">=",
|
||||||
|
BinOpType::Le => "<=",
|
||||||
|
BinOpType::And => "&&",
|
||||||
|
BinOpType::Or => "||",
|
||||||
|
BinOpType::Xor => "^^",
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "{}", sop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for UnOpType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let sop = match self {
|
||||||
|
UnOpType::Neg => "-",
|
||||||
|
UnOpType::Not => "!",
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "{}", sop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -83,7 +83,6 @@ impl Interpreter {
|
|||||||
|
|
||||||
BinOpType::And => todo!(),
|
BinOpType::And => todo!(),
|
||||||
BinOpType::Or => todo!(),
|
BinOpType::Or => todo!(),
|
||||||
BinOpType::Not => todo!(),
|
|
||||||
BinOpType::Xor => todo!(),
|
BinOpType::Xor => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user