diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-15 15:59:32 -0500 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-15 15:59:32 -0500 |
| commit | c8d8714db00d3e4b0aa149482b04343e9e8af89c (patch) | |
| tree | 7e770b0c095a2e22c7c021848f188d158378aa8b | |
| parent | 932673c0026c33c41e969e109a0ca7a1fd6abba8 (diff) | |
| download | sloth-c8d8714db00d3e4b0aa149482b04343e9e8af89c.tar.gz | |
Fixed expressions
| -rw-r--r-- | sloth/src/parser/expr.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/sloth/src/parser/expr.rs b/sloth/src/parser/expr.rs index aaf76a9..4783fc3 100644 --- a/sloth/src/parser/expr.rs +++ b/sloth/src/parser/expr.rs @@ -97,30 +97,30 @@ mod tests { let lexer = Lexer::new("3 + 5 * 4 - 9 / 3"); let tokens = lexer.collect_vec(); - // let expected_ast = Ok(ExprKind::BinaryOp { - // op: BinaryOp::Sub, - // lhs: Box::new(ExprKind::BinaryOp { - // op: BinaryOp::Add, - // lhs: Box::new(ExprKind::Literal(Literal::Integer(3))), - // rhs: Box::new(ExprKind::BinaryOp { - // op: BinaryOp::Mul, - // lhs: Box::new(ExprKind::Literal(Literal::Integer(5))), - // rhs: Box::new(ExprKind::Literal(Literal::Integer(4))), - // }), - // }), - // rhs: Box::new(ExprKind::BinaryOp { - // op: BinaryOp::Div, - // lhs: Box::new(ExprKind::Literal(Literal::Integer(9))), - // rhs: Box::new(ExprKind::Literal(Literal::Integer(3))), - // }), - // }); + let expected_ast = Ok(Expr::new(8, ExprKind::BinaryOp { + op: BinaryOp::Sub, + lhs: Box::new(Expr::new(4, ExprKind::BinaryOp { + op: BinaryOp::Add, + lhs: Box::new(Expr::new(0, ExprKind::Literal(Literal::Integer(3)))), + rhs: Box::new(Expr::new(3, ExprKind::BinaryOp { + op: BinaryOp::Mul, + lhs: Box::new(Expr::new(1, ExprKind::Literal(Literal::Integer(5)))), + rhs: Box::new(Expr::new(2, ExprKind::Literal(Literal::Integer(4)))), + })), + })), + rhs: Box::new(Expr::new(7, ExprKind::BinaryOp { + op: BinaryOp::Div, + lhs: Box::new(Expr::new(5, ExprKind::Literal(Literal::Integer(9)))), + rhs: Box::new(Expr::new(6, ExprKind::Literal(Literal::Integer(3)))), + })), + })); let mut parser = AstParser::new(tokens); let generated_ast = parser.expression(); - // println!("Expected AST:\n{expected_ast:#?}\n\n"); + println!("Expected AST:\n{expected_ast:#?}\n\n"); println!("Generated AST:\n{generated_ast:#?}\n\n"); - assert_eq!(Ok(Expr::new(0, Literal::Integer(0).into())), generated_ast); + assert_eq!(expected_ast, generated_ast); } } |
