Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 693b73d

Browse files
committed
[Bug 15435] Lower constructor precedence
Since there's some uncertainty about the correct precedence of function & constructor chunks, leave them approximately the same as they before.
1 parent a7a4343 commit 693b73d

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

docs/lcb/notes/feature-precedence.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ defined set of 23 named precedence classes. This is to ensure
77
predictable and consistent interactions when multiple LCB operators
88
are used in a single expression.
99

10-
There are two changes which are likely to significantly affect
11-
pre-existing LCB code:
12-
13-
* "property", "subscript chunk", "function chunk" and "constructor
14-
chunk" syntax classes now always have higher precedence than
15-
arithmetic operators. In particular, this change is likely to
16-
require additional parentheses `(...)` around arithmetic operations
17-
when using the LCB canvas API.
18-
19-
* the precedence of the logical `not` operator has been reduced to
20-
below that of comparison operators. This may allow removal of
21-
parentheses in the condition clauses of `if` statements.
10+
There only change that is likely to significantly affect pre-existing
11+
LCB code is the reduction in precedence of the logical `not` operator
12+
to below that of comparison operators. This may allow removal of
13+
parentheses in the condition clauses of `if` statements.

docs/specs/lcb-precedence.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ Lower precedence numbers are more tightly-binding.
3131
| | subscript | `tList[1]`, `tArray["key"]` |
3232
| 3 | property | `the paint of this canvas` |
3333
| | subscript chunk | `char 2 of tString` |
34-
| | function chunk | `the length of tList` |
35-
| | constructor | `rectangle tList` |
3634
| 4 | conversion | `tString parsed as number` |
35+
| | function chunk | `the offset of "o" in "foo"` |
3736
| 5 | modifier | `-tNum`, `bitwise not` |
3837
| 6 | exponentiation | `^` |
3938
| 7 | multiplication | `/`,`*`,`mod`, `div` |
@@ -43,9 +42,10 @@ Lower precedence numbers are more tightly-binding.
4342
| 10 | bitwise and | `7 bitwise and 1` |
4443
| 11 | bitwise xor | `7 bitwise xor 5` |
4544
| 12 | bitwise or | `2 bitwise or 4` |
46-
| 13 | comparison | `<=`, `<`, `is` |
45+
| 13 | constructor | `rectangle tList` |
46+
| 14 | comparison | `<=`, `<`, `is` |
4747
| | classification | `is a` |
48-
| 14 | logical not | `not tBoolean` |
49-
| 15 | logical and | `Foo() and Bar()` |
50-
| 16 | logical or | `Foo() or Bar()` |
51-
| 17 | sequence | `,` |
48+
| 15 | logical not | `not tBoolean` |
49+
| 16 | logical and | `Foo() and Bar()` |
50+
| 17 | logical or | `Foo() or Bar()` |
51+
| 18 | sequence | `,` |

toolchain/lc-compile/src/syntax.g

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@
281281

282282
'rule' MapSyntaxPrecedence(property -> 3)
283283
'rule' MapSyntaxPrecedence(subscriptchunk -> 3)
284-
'rule' MapSyntaxPrecedence(functionchunk -> 3)
285-
'rule' MapSyntaxPrecedence(constructor -> 3)
286284

287285
'rule' MapSyntaxPrecedence(conversion -> 4)
286+
'rule' MapSyntaxPrecedence(functionchunk -> 3)
288287

289288
'rule' MapSyntaxPrecedence(modifier -> 5)
290289

@@ -303,13 +302,15 @@
303302

304303
'rule' MapSyntaxPrecedence(bitwiseor -> 12)
305304

306-
'rule' MapSyntaxPrecedence(comparison -> 13)
307-
'rule' MapSyntaxPrecedence(classification -> 13)
305+
'rule' MapSyntaxPrecedence(constructor -> 13)
306+
307+
'rule' MapSyntaxPrecedence(comparison -> 14)
308+
'rule' MapSyntaxPrecedence(classification -> 14)
308309

309-
'rule' MapSyntaxPrecedence(logicalnot -> 14)
310+
'rule' MapSyntaxPrecedence(logicalnot -> 15)
310311

311-
'rule' MapSyntaxPrecedence(logicaland -> 15)
312+
'rule' MapSyntaxPrecedence(logicaland -> 16)
312313

313-
'rule' MapSyntaxPrecedence(logicalor -> 16)
314+
'rule' MapSyntaxPrecedence(logicalor -> 17)
314315

315-
'rule' MapSyntaxPrecedence(sequence -> 17)
316+
'rule' MapSyntaxPrecedence(sequence -> 18)

toolchain/lc-compile/src/types.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@
340340
property, -- the paint of tCanvas
341341
subscriptchunk, -- char 5 of tString
342342
conversion, -- tString parsed as number
343+
functionchunk, -- the length of tList
343344
modifier, -- -tNumber, bitwise not tNumber
344345
exponentiation, -- 2 ^ 10
345346
multiplication, -- /, *, div, mod
@@ -349,7 +350,6 @@
349350
bitwiseand, -- 5 bitwise and 1
350351
bitwisexor, -- 5 bitwise xor 1
351352
bitwiseor, -- 5 bitwise or 1
352-
functionchunk, -- the length of tList
353353
constructor, -- rectangle tList
354354
comparison, -- <=, <, is, =
355355
classification, -- 5 is a number

0 commit comments

Comments
 (0)