Skip to content

Commit

Permalink
Fix priority of application vs unary (Wilfred#11)
Browse files Browse the repository at this point in the history
test plan:
make test
  • Loading branch information
Yoann Padioleau authored Dec 20, 2022
1 parent 768a384 commit 505f5bd
Show file tree
Hide file tree
Showing 4 changed files with 5,571 additions and 5,200 deletions.
32 changes: 17 additions & 15 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const PREC = {
// The order is reversed though: In the spec, '1' means high priority
// but with tree-sitter it means low priority.
application_indexing: 13,
//TODO:
unary: 12,
multiplicative: 11,
additive: 10,
Expand Down Expand Up @@ -60,8 +59,11 @@ module.exports = grammar({
optional($.compspec),
"]"
),
prec(PREC.application_indexing, seq($.expr, ".", $.id)),
seq(
prec(PREC.application_indexing,
seq($.expr, ".", $.id)),
seq($.super, ".", $.id),
prec(PREC.application_indexing,
seq(
$.expr,
"[",
optional($.expr),
Expand All @@ -73,10 +75,10 @@ module.exports = grammar({
)
),
"]"
),
seq($.super, ".", $.id),
)),
seq($.super, "[", $.expr, "]"),
seq($.expr, "(", optional($.args), ")", optional($.tailstrict)),
prec(PREC.application_indexing,
seq($.expr, "(", optional($.args), ")", optional($.tailstrict))),
$.id,
$.local_bind,
prec.right(seq(
Expand All @@ -87,7 +89,7 @@ module.exports = grammar({
optional(seq("else", field("alternative", $.expr)))
)),
$._binary_expr,
prec.left(
prec(PREC.unary,
seq(
field("operator", $.unaryop),
field("argument", $.expr)
Expand All @@ -108,20 +110,20 @@ module.exports = grammar({
true: () => "true",
false: () => "false",

// Keywords
// Keywords
self: () => "self",
dollar: () => "$",
super: () => "super",
local: () => "local",
tailstrict: () => "tailstrict",
_binary_expr: ($) => {
tailstrict: () => "tailstrict",

_binary_expr: ($) => {
const table = [
[PREC.multiplicative, choice("*", "/", "%")],
[PREC.additive, choice("+", "-")],
[PREC.bitshift, choice("<<", ">>")],
[PREC.comparison, choice("<", "<=", ">", ">=")],
[PREC.equality, choice("==", "!=")],
[PREC.equality, choice("==", "!=")],
[PREC.bitand, '&'],
[PREC.bitxor, '^'],
[PREC.bitor, '|'],
Expand All @@ -138,7 +140,7 @@ module.exports = grammar({
},

unaryop: () => choice("-", "+", "!", "~"),

local_bind: ($) =>
prec.right(seq($.local, commaSep1($.bind, false), ";", $.expr)),

Expand Down Expand Up @@ -191,9 +193,9 @@ module.exports = grammar({

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

// assert in objects
// assert in objects
assert: ($) => seq("assert", $.expr, optional(seq(":", $.expr))),

objlocal: ($) => seq($.local, $.bind),

compspec: ($) => repeat1(choice($.forspec, $.ifspec)),
Expand Down
264 changes: 136 additions & 128 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,93 +237,6 @@
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
Expand All @@ -341,6 +254,97 @@
}
]
},
{
"type": "PREC",
"value": 13,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
}
},
{
"type": "SEQ",
"members": [
Expand All @@ -363,45 +367,49 @@
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "args"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "tailstrict"
},
{
"type": "BLANK"
}
]
}
]
"type": "PREC",
"value": 13,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expr"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "args"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "tailstrict"
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -474,8 +482,8 @@
"name": "_binary_expr"
},
{
"type": "PREC_LEFT",
"value": 0,
"type": "PREC",
"value": 12,
"content": {
"type": "SEQ",
"members": [
Expand Down
Loading

0 comments on commit 505f5bd

Please sign in to comment.