AST - Logical binary expressions

This commit is contained in:
Emmanuel BENOîT 2023-01-01 11:13:41 +01:00
parent 9a84283245
commit 0637e52c83

View file

@ -33,6 +33,13 @@ pub enum ExprNode {
/// Assignment to a variable. /// Assignment to a variable.
Assignment { name: Token, value: Box<ExprNode> }, Assignment { name: Token, value: Box<ExprNode> },
/// Logical binary expression.
Logical {
left: Box<ExprNode>,
operator: Token,
right: Box<ExprNode>,
},
/// Binary expression. /// Binary expression.
Binary { Binary {
left: Box<ExprNode>, left: Box<ExprNode>,
@ -111,6 +118,11 @@ impl AstDumper for ExprNode {
fn dump(&self) -> String { fn dump(&self) -> String {
match self { match self {
Self::Assignment { name, value } => format!("( = {} {} )", name.lexeme, value.dump()), Self::Assignment { name, value } => format!("( = {} {} )", name.lexeme, value.dump()),
Self::Logical {
left,
operator,
right,
} => format!("( {} {} {} )", operator.lexeme, left.dump(), right.dump()),
Self::Binary { Self::Binary {
left, left,
operator, operator,