Skip to content

Commit 505f5bd

Browse files
authored
Fix priority of application vs unary (#11)
test plan: make test
1 parent 768a384 commit 505f5bd

File tree

4 files changed

+5571
-5200
lines changed

4 files changed

+5571
-5200
lines changed

grammar.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const PREC = {
44
// The order is reversed though: In the spec, '1' means high priority
55
// but with tree-sitter it means low priority.
66
application_indexing: 13,
7-
//TODO:
87
unary: 12,
98
multiplicative: 11,
109
additive: 10,
@@ -60,8 +59,11 @@ module.exports = grammar({
6059
optional($.compspec),
6160
"]"
6261
),
63-
prec(PREC.application_indexing, seq($.expr, ".", $.id)),
64-
seq(
62+
prec(PREC.application_indexing,
63+
seq($.expr, ".", $.id)),
64+
seq($.super, ".", $.id),
65+
prec(PREC.application_indexing,
66+
seq(
6567
$.expr,
6668
"[",
6769
optional($.expr),
@@ -73,10 +75,10 @@ module.exports = grammar({
7375
)
7476
),
7577
"]"
76-
),
77-
seq($.super, ".", $.id),
78+
)),
7879
seq($.super, "[", $.expr, "]"),
79-
seq($.expr, "(", optional($.args), ")", optional($.tailstrict)),
80+
prec(PREC.application_indexing,
81+
seq($.expr, "(", optional($.args), ")", optional($.tailstrict))),
8082
$.id,
8183
$.local_bind,
8284
prec.right(seq(
@@ -87,7 +89,7 @@ module.exports = grammar({
8789
optional(seq("else", field("alternative", $.expr)))
8890
)),
8991
$._binary_expr,
90-
prec.left(
92+
prec(PREC.unary,
9193
seq(
9294
field("operator", $.unaryop),
9395
field("argument", $.expr)
@@ -108,20 +110,20 @@ module.exports = grammar({
108110
true: () => "true",
109111
false: () => "false",
110112

111-
// Keywords
113+
// Keywords
112114
self: () => "self",
113115
dollar: () => "$",
114116
super: () => "super",
115117
local: () => "local",
116-
tailstrict: () => "tailstrict",
117-
118-
_binary_expr: ($) => {
118+
tailstrict: () => "tailstrict",
119+
120+
_binary_expr: ($) => {
119121
const table = [
120122
[PREC.multiplicative, choice("*", "/", "%")],
121123
[PREC.additive, choice("+", "-")],
122124
[PREC.bitshift, choice("<<", ">>")],
123125
[PREC.comparison, choice("<", "<=", ">", ">=")],
124-
[PREC.equality, choice("==", "!=")],
126+
[PREC.equality, choice("==", "!=")],
125127
[PREC.bitand, '&'],
126128
[PREC.bitxor, '^'],
127129
[PREC.bitor, '|'],
@@ -138,7 +140,7 @@ module.exports = grammar({
138140
},
139141

140142
unaryop: () => choice("-", "+", "!", "~"),
141-
143+
142144
local_bind: ($) =>
143145
prec.right(seq($.local, commaSep1($.bind, false), ";", $.expr)),
144146

@@ -191,9 +193,9 @@ module.exports = grammar({
191193

192194
h: () => choice(":", "::", ":::"),
193195

194-
// assert in objects
196+
// assert in objects
195197
assert: ($) => seq("assert", $.expr, optional(seq(":", $.expr))),
196-
198+
197199
objlocal: ($) => seq($.local, $.bind),
198200

199201
compspec: ($) => repeat1(choice($.forspec, $.ifspec)),

src/grammar.json

Lines changed: 136 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -237,93 +237,6 @@
237237
]
238238
}
239239
},
240-
{
241-
"type": "SEQ",
242-
"members": [
243-
{
244-
"type": "SYMBOL",
245-
"name": "expr"
246-
},
247-
{
248-
"type": "STRING",
249-
"value": "["
250-
},
251-
{
252-
"type": "CHOICE",
253-
"members": [
254-
{
255-
"type": "SYMBOL",
256-
"name": "expr"
257-
},
258-
{
259-
"type": "BLANK"
260-
}
261-
]
262-
},
263-
{
264-
"type": "CHOICE",
265-
"members": [
266-
{
267-
"type": "SEQ",
268-
"members": [
269-
{
270-
"type": "STRING",
271-
"value": ":"
272-
},
273-
{
274-
"type": "CHOICE",
275-
"members": [
276-
{
277-
"type": "SYMBOL",
278-
"name": "expr"
279-
},
280-
{
281-
"type": "BLANK"
282-
}
283-
]
284-
},
285-
{
286-
"type": "CHOICE",
287-
"members": [
288-
{
289-
"type": "SEQ",
290-
"members": [
291-
{
292-
"type": "STRING",
293-
"value": ":"
294-
},
295-
{
296-
"type": "CHOICE",
297-
"members": [
298-
{
299-
"type": "SYMBOL",
300-
"name": "expr"
301-
},
302-
{
303-
"type": "BLANK"
304-
}
305-
]
306-
}
307-
]
308-
},
309-
{
310-
"type": "BLANK"
311-
}
312-
]
313-
}
314-
]
315-
},
316-
{
317-
"type": "BLANK"
318-
}
319-
]
320-
},
321-
{
322-
"type": "STRING",
323-
"value": "]"
324-
}
325-
]
326-
},
327240
{
328241
"type": "SEQ",
329242
"members": [
@@ -341,6 +254,97 @@
341254
}
342255
]
343256
},
257+
{
258+
"type": "PREC",
259+
"value": 13,
260+
"content": {
261+
"type": "SEQ",
262+
"members": [
263+
{
264+
"type": "SYMBOL",
265+
"name": "expr"
266+
},
267+
{
268+
"type": "STRING",
269+
"value": "["
270+
},
271+
{
272+
"type": "CHOICE",
273+
"members": [
274+
{
275+
"type": "SYMBOL",
276+
"name": "expr"
277+
},
278+
{
279+
"type": "BLANK"
280+
}
281+
]
282+
},
283+
{
284+
"type": "CHOICE",
285+
"members": [
286+
{
287+
"type": "SEQ",
288+
"members": [
289+
{
290+
"type": "STRING",
291+
"value": ":"
292+
},
293+
{
294+
"type": "CHOICE",
295+
"members": [
296+
{
297+
"type": "SYMBOL",
298+
"name": "expr"
299+
},
300+
{
301+
"type": "BLANK"
302+
}
303+
]
304+
},
305+
{
306+
"type": "CHOICE",
307+
"members": [
308+
{
309+
"type": "SEQ",
310+
"members": [
311+
{
312+
"type": "STRING",
313+
"value": ":"
314+
},
315+
{
316+
"type": "CHOICE",
317+
"members": [
318+
{
319+
"type": "SYMBOL",
320+
"name": "expr"
321+
},
322+
{
323+
"type": "BLANK"
324+
}
325+
]
326+
}
327+
]
328+
},
329+
{
330+
"type": "BLANK"
331+
}
332+
]
333+
}
334+
]
335+
},
336+
{
337+
"type": "BLANK"
338+
}
339+
]
340+
},
341+
{
342+
"type": "STRING",
343+
"value": "]"
344+
}
345+
]
346+
}
347+
},
344348
{
345349
"type": "SEQ",
346350
"members": [
@@ -363,45 +367,49 @@
363367
]
364368
},
365369
{
366-
"type": "SEQ",
367-
"members": [
368-
{
369-
"type": "SYMBOL",
370-
"name": "expr"
371-
},
372-
{
373-
"type": "STRING",
374-
"value": "("
375-
},
376-
{
377-
"type": "CHOICE",
378-
"members": [
379-
{
380-
"type": "SYMBOL",
381-
"name": "args"
382-
},
383-
{
384-
"type": "BLANK"
385-
}
386-
]
387-
},
388-
{
389-
"type": "STRING",
390-
"value": ")"
391-
},
392-
{
393-
"type": "CHOICE",
394-
"members": [
395-
{
396-
"type": "SYMBOL",
397-
"name": "tailstrict"
398-
},
399-
{
400-
"type": "BLANK"
401-
}
402-
]
403-
}
404-
]
370+
"type": "PREC",
371+
"value": 13,
372+
"content": {
373+
"type": "SEQ",
374+
"members": [
375+
{
376+
"type": "SYMBOL",
377+
"name": "expr"
378+
},
379+
{
380+
"type": "STRING",
381+
"value": "("
382+
},
383+
{
384+
"type": "CHOICE",
385+
"members": [
386+
{
387+
"type": "SYMBOL",
388+
"name": "args"
389+
},
390+
{
391+
"type": "BLANK"
392+
}
393+
]
394+
},
395+
{
396+
"type": "STRING",
397+
"value": ")"
398+
},
399+
{
400+
"type": "CHOICE",
401+
"members": [
402+
{
403+
"type": "SYMBOL",
404+
"name": "tailstrict"
405+
},
406+
{
407+
"type": "BLANK"
408+
}
409+
]
410+
}
411+
]
412+
}
405413
},
406414
{
407415
"type": "SYMBOL",
@@ -474,8 +482,8 @@
474482
"name": "_binary_expr"
475483
},
476484
{
477-
"type": "PREC_LEFT",
478-
"value": 0,
485+
"type": "PREC",
486+
"value": 12,
479487
"content": {
480488
"type": "SEQ",
481489
"members": [

0 commit comments

Comments
 (0)