Skip to content

Commit

Permalink
feat: support new grammar falsy operator
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Apr 23, 2023
1 parent cd63bd2 commit 27f1905
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ const ENCODING = [
];

const PREC = {
TERNARY: 1, //=> expr ? expr : expr
OR: 2, //=> or
AND: 3, //=> and
COMPARE: 4, //=> < <= == ~= >= > and all
PLUS: 5, //=> + -
CONCAT: 5, //=> .. .
MULTI: 6, //=> * / %
UNARY: 7, //=> ! - +
CALL: 8, //expr[n] expr[n:m] expr.name expr(...)
FALSY: 1, //=> expr ?? expr
TERNARY: 2, //=> expr ? expr : expr
OR: 3, //=> or
AND: 4, //=> and
COMPARE: 5, //=> < <= == ~= >= > and all
PLUS: 6, //=> + -
CONCAT: 6, //=> .. .
MULTI: 7, //=> * / %
UNARY: 8, //=> ! - +
CALL: 9, //expr[n] expr[n:m] expr.name expr(...)
};

module.exports = grammar({
Expand Down Expand Up @@ -924,6 +925,7 @@ module.exports = grammar({
choice(
$._variable,
$.ternary_expression,
$.falsy_expression,
$.index_expression,
$.slice_expression,
$.binary_operation,
Expand All @@ -946,6 +948,16 @@ module.exports = grammar({
)
),

falsy_expression: ($) =>
prec.left(
PREC.FALSY,
seq(
field("left", $._expression),
"??",
field("right", $._expression),
)
),

// Shamelessly stolen from tree-sitter-lua
match_case: ($) => choice("#", "?"),

Expand Down

0 comments on commit 27f1905

Please sign in to comment.