method calls are left associative.
This commit is contained in:
parent
78f7593520
commit
ba04a202c6
2 changed files with 18 additions and 24 deletions
|
@ -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]
|
||||
|
|
|
@ -12,34 +12,23 @@ lazy_static! {
|
|||
|
||||
fn build_precedence_climber() -> PrecClimber<Rule> {
|
||||
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),
|
||||
])
|
||||
}
|
||||
|
|
Reference in a new issue