fix: arithmetic expansions

pull/504/merge
Amaan Qureshi 2023-08-23 05:11:13 +07:00
parent a1fead6eb7
commit d22ee263e6
4 changed files with 87 additions and 25 deletions

@ -562,7 +562,7 @@ module.exports = grammar({
$.brace_expression,
),
arithmetic_expansion: $ => seq('$((', $._arithmetic_expression, '))'),
arithmetic_expansion: $ => seq(choice('$((', '(('), commaSep1($._arithmetic_expression), '))'),
brace_expression: $ => seq(
alias($._brace_start, '{'),
@ -583,10 +583,12 @@ module.exports = grammar({
_arithmetic_literal: $ => prec(1, choice(
$.number,
$.test_operator,
$.subscript,
$.simple_expansion,
$.expansion,
$._simple_variable_name,
$.variable_name,
)),
_arithmetic_binary_expression: $ => prec.left(2, choice(
@ -619,12 +621,12 @@ module.exports = grammar({
),
_arithmetic_unary_expression: $ => choice(
prec(1, seq(
prec(3, seq(
token(prec(1, choice('-', '+', '~', '++', '--'))),
$._arithmetic_expression,
)),
prec.right(1, seq(
choice('!', $.test_operator),
prec.right(3, seq(
'!',
$._arithmetic_expression,
)),
),

@ -469,15 +469,13 @@ ${array[((number+1))]}
(expansion
(subscript
(variable_name)
(parenthesized_expression
(parenthesized_expression
(concatenation (simple_expansion (variable_name)) (word))))))))
(arithmetic_expansion (binary_expression (simple_expansion (variable_name)) (number)))))))
(command
(command_name
(expansion
(subscript
(variable_name)
(parenthesized_expression (parenthesized_expression (word))))))))
(arithmetic_expansion (binary_expression (variable_name) (number))))))))
==========================================
Bare $

@ -843,6 +843,11 @@ Arithmetic expansions
echo $((1 + 2 - 3 * 4 / 5))
a=$((6 % 7 ** 8 << 9 >> 10 & 11 | 12 ^ 13))
$(((${1:-${SECONDS}} % 12) + 144))
((foo=0))
echo $((bar=1))
echo $((-1, 1))
echo $((! -a || ~ +b || ++c || --d))
echo $((foo-- || bar++))
--------------------------------------------------------------------------------
@ -889,7 +894,52 @@ $(((${1:-${SECONDS}} % 12) + 144))
(expansion
(variable_name)))
(number)))
(number))))))
(number)))))
(command
(command_name
(arithmetic_expansion
(binary_expression
(variable_name)
(number)))))
(command
(command_name
(word))
(arithmetic_expansion
(binary_expression
(variable_name)
(number))))
(command
(command_name
(word))
(arithmetic_expansion
(unary_expression
(number))
(number)))
(command
(command_name
(word))
(arithmetic_expansion
(binary_expression
(binary_expression
(binary_expression
(unary_expression
(test_operator))
(unary_expression
(unary_expression
(variable_name))))
(unary_expression
(variable_name)))
(unary_expression
(variable_name)))))
(command
(command_name
(word))
(arithmetic_expansion
(postfix_expression
(binary_expression
(postfix_expression
(variable_name))
(variable_name))))))
================================================================================
Concatenation with double backticks

@ -393,11 +393,13 @@ done )
(simple_expansion
(variable_name)))
(if_statement
(test_command
(binary_expression
(simple_expansion
(variable_name))
(regex)))
(command
(command_name
(arithmetic_expansion
(binary_expression
(simple_expansion
(variable_name))
(number)))))
(command
(command_name
(word))))))
@ -421,8 +423,12 @@ done )
(command_substitution
(redirected_statement
(list
(test_command
(word))
(command
(command_name
(arithmetic_expansion
(binary_expression
(variable_name)
(number)))))
(command
(command_name
(word))
@ -470,8 +476,12 @@ done )
(command_substitution
(redirected_statement
(list
(test_command
(word))
(command
(command_name
(arithmetic_expansion
(binary_expression
(variable_name)
(number)))))
(command
(command_name
(word))
@ -935,13 +945,15 @@ fi
(program
(if_statement
(test_command
(ternary_expression
(binary_expression
(number)
(number))
(number)
(number)))
(command
(command_name
(arithmetic_expansion
(ternary_expression
(binary_expression
(number)
(number))
(number)
(number)))))
(command
(command_name
(word))