fix: file_redirects can be a statement alone, test_command can be empty

pull/504/merge
Amaan Qureshi 2023-08-23 01:00:07 +07:00
parent ef162f7402
commit a8e6579ec3
2 changed files with 24 additions and 10 deletions

@ -29,6 +29,8 @@ module.exports = grammar({
[$._expression, $.command_name], [$._expression, $.command_name],
[$.command, $.variable_assignments], [$.command, $.variable_assignments],
[$.compound_statement], [$.compound_statement],
[$.redirected_statement, $.command],
[$.redirected_statement, $.command_substitution],
], ],
inline: $ => [ inline: $ => [
@ -132,14 +134,17 @@ module.exports = grammar({
$.function_definition, $.function_definition,
), ),
redirected_statement: $ => prec(-1, seq( redirected_statement: $ => prec.dynamic(-1, prec(-1, choice(
field('body', $._statement), seq(
field('redirect', repeat1(choice( field('body', $._statement),
$.file_redirect, field('redirect', repeat1(choice(
$.heredoc_redirect, $.file_redirect,
$.herestring_redirect, $.heredoc_redirect,
))), $.herestring_redirect,
)), ))),
),
repeat1($.file_redirect),
))),
for_statement: $ => seq( for_statement: $ => seq(
choice('for', 'select'), choice('for', 'select'),
@ -352,7 +357,7 @@ module.exports = grammar({
test_command: $ => seq( test_command: $ => seq(
choice( choice(
seq('[', choice($._expression, $.redirected_statement), ']'), seq('[', optional(choice($._expression, $.redirected_statement)), ']'),
seq('[[', $._expression, ']]'), seq('[[', $._expression, ']]'),
seq('(', '(', optional($._expression), '))'), seq('(', '(', optional($._expression), '))'),
), ),

@ -92,6 +92,10 @@ cat a b > /dev/null
echo "foobar" >&2 echo "foobar" >&2
[ ! command -v go &>/dev/null ] && return [ ! command -v go &>/dev/null ] && return
if [ ]; then
>aa >bb
fi
--- ---
(program (program
@ -113,7 +117,12 @@ echo "foobar" >&2
(negated_command (negated_command
(command (command_name (word)) (word) (word))) (command (command_name (word)) (word) (word)))
(file_redirect (word)))) (file_redirect (word))))
(command (command_name (word))))) (command (command_name (word))))
(if_statement
(test_command)
(redirected_statement
(file_redirect (word))
(file_redirect (word)))))
=============================== ===============================
File redirects (noclobber override) File redirects (noclobber override)