-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgrammar-operators.js
35 lines (33 loc) · 1.32 KB
/
grammar-operators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module.exports = {
// TODO: array, map, anonymous struct, range
// array: ($) => "null",
operator: ($) => choice($._binaryOperator, $._unaryOperator),
// From: https://haxe.org/manual/expression-operators-unops.html
_unaryOperator: ($) => prec.right(choice($._prefixUnaryOperator, $._postfixUnaryOperator)),
_prefixUnaryOperator: ($) => choice('~', '!', '-', '++', '--'),
_postfixUnaryOperator: ($) => choice('++', '--'),
// From: https://haxe.org/manual/expression-operators-binops.html
_binaryOperator: ($) =>
prec.left(
choice(
$._arithmeticOperator,
$._bitwiseOperator,
$._logicalOperator,
$._comparisonOperator,
$._miscOperator,
$._assignmentOperator,
$._compoundAssignmentOperator,
$._rangeOperator,
),
),
_arithmeticOperator: ($) => choice('%', '*', '/', '+', '-'),
_bitwiseOperator: ($) => choice('<<', '>>', '>>>', '&', '|', '^'),
_logicalOperator: ($) => choice('&&', '||'),
_comparisonOperator: ($) => choice('==', '!=', '<', '<=', '>', '>='),
_miscOperator: ($) => choice('=>', '??'),
// _miscOperator: ($) => choice('...', '=>'),
_assignmentOperator: ($) => '=',
_compoundAssignmentOperator: ($) =>
seq(choice($._arithmeticOperator, $._bitwiseOperator), $._assignmentOperator),
_rangeOperator: ($) => '...',
};