OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library precedence; | 5 library precedence; |
6 | 6 |
7 const EXPRESSION = 0; | 7 const EXPRESSION = 0; |
8 const SPREAD = EXPRESSION + 1; | 8 const SPREAD = EXPRESSION + 1; |
9 const YIELD = SPREAD + 1; | 9 const YIELD = SPREAD + 1; |
| 10 |
| 11 // Note that some primary expressions (in the parser) must be emitted with lower |
| 12 // precedence, because it's not normally legal for them to be followed by |
| 13 // other postfix expressions, like ACCESS and CALL. For example: |
| 14 // `function foo(){}` needs parens to call or access properties or |
| 15 // compare with equality. Same thing with `class Foo {}` and `(x) => x`. |
| 16 // However, prefix unary expressions will work in these cases. Unfortunately our |
| 17 // current precedence tracking doesn't capture this distinction. |
| 18 const PRIMARY_LOW_PRECEDENCE = ASSIGNMENT; |
| 19 |
10 const ASSIGNMENT = YIELD + 1; | 20 const ASSIGNMENT = YIELD + 1; |
11 const LOGICAL_OR = ASSIGNMENT + 1; | 21 const LOGICAL_OR = ASSIGNMENT + 1; |
12 const LOGICAL_AND = LOGICAL_OR + 1; | 22 const LOGICAL_AND = LOGICAL_OR + 1; |
13 const BIT_OR = LOGICAL_AND + 1; | 23 const BIT_OR = LOGICAL_AND + 1; |
14 const BIT_XOR = BIT_OR + 1; | 24 const BIT_XOR = BIT_OR + 1; |
15 const BIT_AND = BIT_XOR + 1; | 25 const BIT_AND = BIT_XOR + 1; |
16 const EQUALITY = BIT_AND + 1; | 26 const EQUALITY = BIT_AND + 1; |
17 const RELATIONAL = EQUALITY + 1; | 27 const RELATIONAL = EQUALITY + 1; |
18 const SHIFT = RELATIONAL + 1; | 28 const SHIFT = RELATIONAL + 1; |
19 const ADDITIVE = SHIFT + 1; | 29 const ADDITIVE = SHIFT + 1; |
20 const MULTIPLICATIVE = ADDITIVE + 1; | 30 const MULTIPLICATIVE = ADDITIVE + 1; |
21 const UNARY = MULTIPLICATIVE + 1; | 31 const UNARY = MULTIPLICATIVE + 1; |
22 const LEFT_HAND_SIDE = UNARY + 1; | 32 const LEFT_HAND_SIDE = UNARY + 1; |
23 const CALL = LEFT_HAND_SIDE; | 33 const CALL = LEFT_HAND_SIDE; |
24 // We always emit `new` with parenthesis, so it uses ACCESS as its precedence. | 34 // We always emit `new` with parenthesis, so it uses ACCESS as its precedence. |
25 const ACCESS = CALL + 1; | 35 const ACCESS = CALL + 1; |
26 const PRIMARY = ACCESS + 1; | 36 const PRIMARY = ACCESS + 1; |
OLD | NEW |