fix: raise precedence of is above equality operators in parser

The `is` operator was placed at `PREC_IS` which had lower precedence than `PREC_EQUALITY`, causing expressions like `true == 10 is Num` to parse incorrectly. Moved `PREC_IS` above `PREC_EQUALITY` in the precedence enum to give `is` higher binding power than `==` and `!=`. Added precedence tests in new `test/precedence.wren` file and removed TODO comments about precedence from `test/is/is.wren`.
This commit is contained in:
Bob Nystrom
2015-01-18 18:20:13 +00:00
parent 48c3f540df
commit 850d6d1b5d
3 changed files with 5 additions and 4 deletions
+41
View File
@@ -0,0 +1,41 @@
// * has higher precedence than +.
IO.print(2 + 3 * 4) // expect: 14
// * has higher precedence than -.
IO.print(20 - 3 * 4) // expect: 8
// / has higher precedence than +.
IO.print(2 + 6 / 3) // expect: 4
// / has higher precedence than -.
IO.print(2 - 6 / 3) // expect: 0
// < has higher precedence than ==.
IO.print(false == 2 < 1) // expect: true
// > has higher precedence than ==.
IO.print(false == 1 > 2) // expect: true
// <= has higher precedence than ==.
IO.print(false == 2 <= 1) // expect: true
// >= has higher precedence than ==.
IO.print(false == 1 >= 2) // expect: true
// is has higher precedence than ==.
IO.print(true == 10 is Num) // expect: true
IO.print(10 is Num == false) // expect: false
// Unary - has lower precedence than ..
IO.print(-"abc".count) // expect: -3
// 1 - 1 is not space-sensitive.
IO.print(1 - 1) // expect: 0
IO.print(1 -1) // expect: 0
IO.print(1- 1) // expect: 0
IO.print(1-1) // expect: 0
// TODO: %, associativity.
// Using () for grouping.
IO.print((2 * (6 - (2 + 2)))) // expect: 4