mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
Shell: Allow control structures to appear in pipe sequences
This makes commands like the following to be possible: ```sh $ ls && for $(seq 10) { echo $it } $ ls | for $(seq 1) { cat > foobar } ```
This commit is contained in:
parent
7b5ead64a5
commit
aa2df9277d
Notes:
sideshowbarker
2024-07-19 02:48:51 +09:00
Author: https://github.com/alimpfard
Commit: aa2df9277d
Pull-request: https://github.com/SerenityOS/serenity/pull/3372
Reviewed-by: https://github.com/tomuta
5 changed files with 73 additions and 41 deletions
|
@ -167,12 +167,7 @@ RefPtr<AST::Node> Parser::parse_sequence()
|
|||
break;
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> first = nullptr;
|
||||
if (auto control_structure = parse_control_structure())
|
||||
first = control_structure;
|
||||
|
||||
if (!first)
|
||||
first = parse_or_logical_sequence();
|
||||
auto first = parse_or_logical_sequence();
|
||||
|
||||
if (!first)
|
||||
return var_decls;
|
||||
|
@ -311,23 +306,27 @@ RefPtr<AST::Node> Parser::parse_and_logical_sequence()
|
|||
RefPtr<AST::Node> Parser::parse_pipe_sequence()
|
||||
{
|
||||
auto rule_start = push_start();
|
||||
auto command = parse_command();
|
||||
if (!command)
|
||||
return nullptr;
|
||||
auto left = parse_control_structure();
|
||||
if (!left) {
|
||||
if (auto cmd = parse_command())
|
||||
left = cmd;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
consume_while(is_whitespace);
|
||||
|
||||
if (peek() != '|')
|
||||
return command;
|
||||
return left;
|
||||
|
||||
consume();
|
||||
|
||||
if (auto pipe_seq = parse_pipe_sequence()) {
|
||||
return create<AST::Pipe>(move(command), move(pipe_seq)); // Pipe
|
||||
return create<AST::Pipe>(move(left), move(pipe_seq)); // Pipe
|
||||
}
|
||||
|
||||
putback();
|
||||
return command;
|
||||
return left;
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Parser::parse_command()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue