From ba04a202c66ec5ea4df07a02e711144f1c026c81 Mon Sep 17 00:00:00 2001 From: James Harton Date: Thu, 7 Mar 2019 18:36:29 +1300 Subject: [PATCH] method calls are left associative. --- huia-parser/src/ast/term.rs | 25 +++++++++++++++---------- huia-parser/src/precedence.rs | 17 +++-------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/huia-parser/src/ast/term.rs b/huia-parser/src/ast/term.rs index faa58d7..69daec7 100644 --- a/huia-parser/src/ast/term.rs +++ b/huia-parser/src/ast/term.rs @@ -777,24 +777,29 @@ mod test { fn test_method_call_multi() { let terms = Term::input("delorean.target_year(1985).accellerate(88)").unwrap(); + println!("terms = {:#?}", terms); + let (op0, lhs0, rhs0) = terms[0].binary().unwrap(); assert_eq!(op0.value_ref(), &binary::Operator::Method); - assert_eq!(lhs0.node_type(), NodeType::Local); - assert_eq!(lhs0.local().unwrap().value_ref(), "delorean"); - assert_eq!(rhs0.node_type(), NodeType::Binary); + assert_eq!(lhs0.node_type(), NodeType::Binary); + assert_eq!(rhs0.node_type(), NodeType::Call); - let (op1, lhs1, rhs1) = rhs0.binary().unwrap(); + let (method_name0, arguments0) = rhs0.call().unwrap(); + assert_eq!(method_name0.value_ref(), "accellerate"); + assert_eq!(*arguments0[0].integer().unwrap().value_ref(), 88); + + let (op1, lhs1, rhs1) = lhs0.binary().unwrap(); assert_eq!(op1.value_ref(), &binary::Operator::Method); - assert_eq!(lhs1.node_type(), NodeType::Call); - let (method_name0, arguments0) = lhs1.call().unwrap(); - assert_eq!(method_name0.value_ref(), "target_year"); - assert_eq!(*arguments0[0].integer().unwrap().value_ref(), 1985); + assert_eq!(lhs1.node_type(), NodeType::Local); + assert_eq!(rhs1.node_type(), NodeType::Call); + + assert_eq!(lhs1.local().unwrap().value_ref(), "delorean"); let (method_name1, arguments1) = rhs1.call().unwrap(); - assert_eq!(method_name1.value_ref(), "accellerate"); - assert_eq!(*arguments1[0].integer().unwrap().value_ref(), 88); + assert_eq!(method_name1.value_ref(), "target_year"); + assert_eq!(*arguments1[0].integer().unwrap().value_ref(), 1985); } #[test] diff --git a/huia-parser/src/precedence.rs b/huia-parser/src/precedence.rs index 32c62c1..147c54a 100644 --- a/huia-parser/src/precedence.rs +++ b/huia-parser/src/precedence.rs @@ -12,34 +12,23 @@ lazy_static! { fn build_precedence_climber() -> PrecClimber { PrecClimber::new(vec![ - Operator::new(Rule::method, Assoc::Right), - + Operator::new(Rule::method, Assoc::Left), Operator::new(Rule::logical_or, Assoc::Left), Operator::new(Rule::logical_and, Assoc::Left), - - Operator::new(Rule::equal, Assoc::Right) - | Operator::new(Rule::not_equal, Assoc::Right), - + Operator::new(Rule::equal, Assoc::Right) | Operator::new(Rule::not_equal, Assoc::Right), Operator::new(Rule::greater_than_or_equal, Assoc::Left) | Operator::new(Rule::less_than_or_equal, Assoc::Left) | Operator::new(Rule::greater_than, Assoc::Left) | Operator::new(Rule::less_than, Assoc::Left), - Operator::new(Rule::bitwise_xor, Assoc::Left) | Operator::new(Rule::bitwise_or, Assoc::Left), - Operator::new(Rule::bitwise_and, Assoc::Left), - Operator::new(Rule::shift_right, Assoc::Left) | Operator::new(Rule::shift_left, Assoc::Left), - - Operator::new(Rule::plus, Assoc::Left) - | Operator::new(Rule::minus, Assoc::Left), - + Operator::new(Rule::plus, Assoc::Left) | Operator::new(Rule::minus, Assoc::Left), Operator::new(Rule::modulus, Assoc::Left) | Operator::new(Rule::divide, Assoc::Left) | Operator::new(Rule::multiply, Assoc::Left), - Operator::new(Rule::exponent, Assoc::Right), ]) }