Skip to content

Commit

Permalink
fix: re-add some unary ops
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jan 24, 2024
1 parent 121d749 commit eaabb02
Show file tree
Hide file tree
Showing 4 changed files with 10,404 additions and 9,903 deletions.
8 changes: 7 additions & 1 deletion grammar.js
Expand Up @@ -25,6 +25,7 @@ const PREC = {
PLUS: 9, // + -
MULTI: 10, // * / // %
CAST: 11, // ::
UNARY: 12, // not # -
POWER: 13, // ^
};

Expand Down Expand Up @@ -207,7 +208,7 @@ module.exports = grammar(lua, {
literal_type: $ => choice($.string, $.true, $.false),

expression: ($, original) => choice(
...original.members.filter(member => member.name !== 'unary_expression'),
original,
$.cast_expression,
$.if_expression,
),
Expand Down Expand Up @@ -256,6 +257,11 @@ module.exports = grammar(lua, {
),
),

unary_expression: ($) => prec.left(
PREC.UNARY,
seq(choice('not', '#', '-'), field('operand', $.expression)),
),

cast_expression: $ => prec(PREC.CAST, seq(
$.expression,
'::',
Expand Down
107 changes: 56 additions & 51 deletions src/grammar.json
Expand Up @@ -1151,52 +1151,61 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "nil"
},
{
"type": "SYMBOL",
"name": "false"
},
{
"type": "SYMBOL",
"name": "true"
},
{
"type": "SYMBOL",
"name": "number"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "vararg_expression"
},
{
"type": "SYMBOL",
"name": "function_definition"
},
{
"type": "SYMBOL",
"name": "variable"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "parenthesized_expression"
},
{
"type": "SYMBOL",
"name": "table_constructor"
},
{
"type": "SYMBOL",
"name": "binary_expression"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "nil"
},
{
"type": "SYMBOL",
"name": "false"
},
{
"type": "SYMBOL",
"name": "true"
},
{
"type": "SYMBOL",
"name": "number"
},
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "vararg_expression"
},
{
"type": "SYMBOL",
"name": "function_definition"
},
{
"type": "SYMBOL",
"name": "variable"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "parenthesized_expression"
},
{
"type": "SYMBOL",
"name": "table_constructor"
},
{
"type": "SYMBOL",
"name": "binary_expression"
},
{
"type": "SYMBOL",
"name": "unary_expression"
}
]
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -2844,7 +2853,7 @@
},
"unary_expression": {
"type": "PREC_LEFT",
"value": 11,
"value": 12,
"content": {
"type": "SEQ",
"members": [
Expand All @@ -2862,10 +2871,6 @@
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "~"
}
]
},
Expand Down
24 changes: 20 additions & 4 deletions src/node-types.json
Expand Up @@ -65,6 +65,10 @@
"type": "true",
"named": true
},
{
"type": "unary_expression",
"named": true
},
{
"type": "vararg_expression",
"named": true
Expand Down Expand Up @@ -1365,6 +1369,22 @@
]
}
},
{
"type": "unary_expression",
"named": true,
"fields": {
"operand": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
}
},
{
"type": "union_type",
"named": true,
Expand Down Expand Up @@ -1824,10 +1844,6 @@
"type": "}",
"named": false
},
{
"type": "~",
"named": false
},
{
"type": "~=",
"named": false
Expand Down

0 comments on commit eaabb02

Please sign in to comment.