Skip to content

Commit

Permalink
unary: Unary operations
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Oct 1, 2024
1 parent 91bbeea commit 13036fc
Show file tree
Hide file tree
Showing 4 changed files with 5,330 additions and 4,718 deletions.
6 changes: 5 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ module.exports = grammar({
assert: $ => seq("assert", field("test", $.expression)),
return: $ => seq("return", optional(field("rv", $.expression))),

// TODO Should we make expression a hidden node?

expression: $ =>
choice(
$.identifier,
Expand All @@ -108,6 +110,7 @@ module.exports = grammar({
$.parenthesized_expression,
$.vec,
// $.map,
$.unary_expression,
$.binary_expression,
$.index,
$.slice,
Expand Down Expand Up @@ -139,7 +142,8 @@ module.exports = grammar({
),
assignment: $ => seq(field("left", choice($.access, $.identifier)), "=", field("right", $.expression)),

unary_expression: $ => choice(seq("-", $.expression), seq("!", $.expression)),
unary_operator: _ => choice("-", "!"),
unary_expression: $ => seq(field("operator", $.unary_operator), field("expression", $.expression)),

power_operator: _ => "**",
multiplicative_operator: _ => choice("*", "/", "%"),
Expand Down
53 changes: 30 additions & 23 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 13036fc

Please sign in to comment.