fix: disallow ';;' as a terminator for C-style for loops

pull/504/merge
Amaan Qureshi 2023-08-21 21:36:41 +07:00
parent 9ed07205a7
commit 8a26c9bc29
2 changed files with 28 additions and 4 deletions

@ -154,7 +154,7 @@ module.exports = grammar({
c_style_for_statement: $ => seq( c_style_for_statement: $ => seq(
'for', 'for',
'((', '((',
choice($._for_body, ';;'), choice($._for_body),
'))', '))',
optional(';'), optional(';'),
field('body', choice( field('body', choice(
@ -164,9 +164,9 @@ module.exports = grammar({
), ),
_for_body: $ => seq( _for_body: $ => seq(
field('initializer', commaSep($._c_expression)), field('initializer', commaSep($._c_expression)),
$._terminator, $._c_terminator,
field('condition', commaSep($._c_expression)), field('condition', commaSep($._c_expression)),
$._terminator, $._c_terminator,
field('update', commaSep($._c_expression)), field('update', commaSep($._c_expression)),
), ),
@ -684,6 +684,7 @@ module.exports = grammar({
test_operator: _ => token(prec(1, seq('-', /[a-zA-Z]+/))), test_operator: _ => token(prec(1, seq('-', /[a-zA-Z]+/))),
_c_terminator: _ => choice(';', '\n', '&'),
_terminator: _ => choice(';', ';;', '\n', '&'), _terminator: _ => choice(';', ';;', '\n', '&'),
}, },
}); });

@ -301,6 +301,8 @@ for ((cx = 0; c = $cx / $pf, c < $wc - $k; )); do
echo "$cx" echo "$cx"
done done
for (( i = 4;;i--)) ; do echo $i; if (( $i == 0 )); then break; fi; done
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(program (program
@ -364,7 +366,28 @@ done
(word)) (word))
(string (string
(simple_expansion (simple_expansion
(variable_name))))))) (variable_name))))))
(c_style_for_statement
(variable_assignment
(variable_name)
(number))
(postfix_expression
(word))
(do_group
(command
(command_name
(word))
(simple_expansion
(variable_name)))
(if_statement
(test_command
(binary_expression
(simple_expansion
(variable_name))
(regex)))
(command
(command_name
(word)))))))
================================================================================ ================================================================================
If statements If statements