Add arithmetic expressions
This commit is contained in:
@@ -2,6 +2,9 @@ const PREC = {
|
||||
DEFAULT: 1,
|
||||
PATCH: 2,
|
||||
AND: 3,
|
||||
ADD: 4,
|
||||
MUL: 5,
|
||||
UNARY: 6,
|
||||
CALL: 7,
|
||||
PATH: 8,
|
||||
};
|
||||
@@ -52,6 +55,7 @@ module.exports = grammar({
|
||||
$.parenthesized_expression,
|
||||
$.call_expression,
|
||||
$.path_expression,
|
||||
$.unary_expression,
|
||||
$.binary_expression,
|
||||
$.default_expression,
|
||||
),
|
||||
@@ -161,10 +165,25 @@ module.exports = grammar({
|
||||
|
||||
comparison_constraint: $ => prec(6, seq(
|
||||
field('operator', choice('>', '>=', '<', '<=')),
|
||||
field('value', choice($.integer, $.float)),
|
||||
field('value', $._expression),
|
||||
)),
|
||||
|
||||
unary_expression: $ => prec(PREC.UNARY, seq(
|
||||
field('operator', '-'),
|
||||
field('operand', $._expression),
|
||||
)),
|
||||
|
||||
binary_expression: $ => choice(
|
||||
prec.left(PREC.ADD, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', choice('+', '-')),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.MUL, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', choice('*', '/')),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.AND, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', '&'),
|
||||
|
||||
Reference in New Issue
Block a user