mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 07:36:50 +00:00
Shell: Add the (now) free subshell support
This commit is contained in:
committed by
Andreas Kling
parent
0fd8d5ad3d
commit
b194d79c53
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user