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:
parent
0fd8d5ad3d
commit
b194d79c53
4 changed files with 92 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue