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

@ -92,6 +92,10 @@ cat a b > /dev/null
echo "foobar" >&2
[ ! command -v go &>/dev/null ] && return
if [ ]; then
>aa >bb
fi
---
(program
@ -113,7 +117,12 @@ echo "foobar" >&2
(negated_command
(command (command_name (word)) (word) (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)