diff --git a/src/compiler/parser/mod.rs b/src/compiler/parser/mod.rs index f272d80..9b41ef7 100644 --- a/src/compiler/parser/mod.rs +++ b/src/compiler/parser/mod.rs @@ -27,7 +27,14 @@ fn parse_expression<'source>( pos: &mut usize, tokens: &[Token<'source>], ) -> Expression<'source> { - const LEFT_ASSOC_BIN_OPS: [&[&str]; 2] = [&["+", "-"], &["*", "/"]]; + const LEFT_ASSOC_BIN_OPS: [&[&str]; 6] = [ + &["or"], + &["and"], + &["==", "!="], + &["<", "<=", "=>", ">"], + &["+", "-"], + &["*", "/", "%"], + ]; if level == LEFT_ASSOC_BIN_OPS.len() { parse_term(pos, tokens) diff --git a/src/compiler/parser/tests.rs b/src/compiler/parser/tests.rs index b74f83d..e675a5f 100644 --- a/src/compiler/parser/tests.rs +++ b/src/compiler/parser/tests.rs @@ -64,6 +64,31 @@ fn test_binary_op_basic() { assert_eq!(result, BinaryOp(int_ast!(1), "/", int_ast!(2))); } +#[test] +fn test_binary_op_all_levels() { + let result = parse(&tokenize("1 * 2 + 3 < 4 == 5 and 6 or 7")); + assert_eq!( + result, + BinaryOp( + bin_ast!( + bin_ast!( + bin_ast!( + bin_ast!(bin_ast!(int_ast!(1), "*", int_ast!(2)), "+", int_ast!(3)), + "<", + int_ast!(4) + ), + "==", + int_ast!(5) + ), + "and", + int_ast!(6) + ), + "or", + int_ast!(7) + ) + ); +} + #[test] fn test_binary_op_identifier() { let result = parse(&tokenize("a + 1"));