1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:05:07 +00:00

Shell: Add the (now) free subshell support

This commit is contained in:
AnotherTest 2020-09-08 15:59:07 +04:30 committed by Andreas Kling
parent 0fd8d5ad3d
commit b194d79c53
4 changed files with 92 additions and 0 deletions

View file

@ -366,6 +366,9 @@ RefPtr<AST::Node> Parser::parse_control_structure()
if (auto if_expr = parse_if_expr())
return if_expr;
if (auto subshell = parse_subshell())
return subshell;
return nullptr;
}
@ -510,6 +513,29 @@ RefPtr<AST::Node> Parser::parse_if_expr()
return create<AST::IfCond>(else_position, move(condition), move(true_branch), nullptr); // If expr true_branch
}
RefPtr<AST::Node> Parser::parse_subshell()
{
auto rule_start = push_start();
if (!expect('{'))
return nullptr;
auto body = parse_toplevel();
{
auto cbrace_error_start = push_start();
if (!expect('}')) {
auto error_start = push_start();
RefPtr<AST::SyntaxError> syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end a subshell");
if (body)
body->set_is_syntax_error(*syntax_error);
else
body = syntax_error;
}
}
return create<AST::Subshell>(move(body));
}
RefPtr<AST::Node> Parser::parse_redirection()
{
auto rule_start = push_start();