Shell: Rewrite 'FOR NAME do ... done' according to Dr.POSIX
Dr.POSIX says this form of the loop is supposed to iterate over exactly `"$@"`, this commit makes us support that.
This commit is contained in:
parent
764ea6104e
commit
0214e9b905
Notes:
sideshowbarker
2024-07-17 02:42:21 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/0214e9b905 Pull-request: https://github.com/SerenityOS/serenity/pull/21173 Reviewed-by: https://github.com/gmta ✅
1 changed files with 7 additions and 3 deletions
|
@ -1372,7 +1372,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_term()
|
|||
|
||||
ErrorOr<RefPtr<AST::Node>> Parser::parse_for_clause()
|
||||
{
|
||||
// FOR NAME newline+ do_group
|
||||
// FOR NAME newline+ do_group //-> FOR NAME IN "$@" newline+ do_group
|
||||
// FOR NAME newline+ IN separator do_group
|
||||
// FOR NAME IN separator do_group
|
||||
// FOR NAME IN wordlist separator do_group
|
||||
|
@ -1400,16 +1400,20 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_for_clause()
|
|||
|
||||
auto saw_in = false;
|
||||
Optional<AST::Position> in_kw_position;
|
||||
RefPtr<AST::Node> iterated_expression;
|
||||
|
||||
if (peek().type == Token::Type::In) {
|
||||
saw_in = true;
|
||||
in_kw_position = peek().position;
|
||||
skip();
|
||||
} else if (!saw_newline) {
|
||||
error(peek(), "Expected 'in' or a newline, not {}", peek().type_name());
|
||||
} else {
|
||||
// FOR NAME newline+ do_group //-> FOR NAME IN "$@" newline+ do_group
|
||||
iterated_expression = TRY(Parser { "\"$@\""_string }.parse_word());
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> iterated_expression;
|
||||
if (!saw_newline)
|
||||
if (saw_in && !saw_newline)
|
||||
iterated_expression = parse_word_list();
|
||||
|
||||
if (saw_in) {
|
||||
|
|
Loading…
Add table
Reference in a new issue