mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 12:47:41 +00:00
Shell: Actually execute loop/case bodies when running them
This commit is contained in:
parent
7b031138fc
commit
bbfedf17b7
1 changed files with 26 additions and 21 deletions
|
@ -780,7 +780,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_command()
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
if (auto node = TRY(parse_simple_command()))
|
if (auto node = TRY(parse_simple_command()))
|
||||||
return node;
|
return make_ref_counted<AST::CastToCommand>(node->position(), *node);
|
||||||
|
|
||||||
auto node = TRY(parse_compound_command());
|
auto node = TRY(parse_compound_command());
|
||||||
if (!node)
|
if (!node)
|
||||||
|
@ -800,7 +800,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_command()
|
||||||
if (!node)
|
if (!node)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return make_ref_counted<AST::CastToCommand>(node->position(), *node);
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<RefPtr<AST::Node>> Parser::parse_function_definition()
|
ErrorOr<RefPtr<AST::Node>> Parser::parse_function_definition()
|
||||||
|
@ -929,19 +929,21 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_while_clause()
|
||||||
"Expected 'do' after 'while'"_string.release_value_but_fixme_should_propagate_errors());
|
"Expected 'do' after 'while'"_string.release_value_but_fixme_should_propagate_errors());
|
||||||
|
|
||||||
// while foo; bar -> loop { if foo { bar } else { break } }
|
// while foo; bar -> loop { if foo { bar } else { break } }
|
||||||
|
auto position = start_position.with_end(peek().position.value_or(empty_position()));
|
||||||
return make_ref_counted<AST::ForLoop>(
|
return make_ref_counted<AST::ForLoop>(
|
||||||
start_position.with_end(peek().position.value_or(empty_position())),
|
position,
|
||||||
Optional<AST::NameWithPosition> {},
|
Optional<AST::NameWithPosition> {},
|
||||||
Optional<AST::NameWithPosition> {},
|
Optional<AST::NameWithPosition> {},
|
||||||
nullptr,
|
nullptr,
|
||||||
make_ref_counted<AST::IfCond>(
|
make_ref_counted<AST::Execute>(position,
|
||||||
start_position.with_end(peek().position.value_or(empty_position())),
|
make_ref_counted<AST::IfCond>(
|
||||||
Optional<AST::Position> {},
|
position,
|
||||||
condition.release_nonnull(),
|
Optional<AST::Position> {},
|
||||||
do_group.release_nonnull(),
|
condition.release_nonnull(),
|
||||||
make_ref_counted<AST::ContinuationControl>(
|
do_group.release_nonnull(),
|
||||||
start_position,
|
make_ref_counted<AST::ContinuationControl>(
|
||||||
AST::ContinuationControl::ContinuationKind::Break)));
|
start_position,
|
||||||
|
AST::ContinuationControl::ContinuationKind::Break))));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<RefPtr<AST::Node>> Parser::parse_until_clause()
|
ErrorOr<RefPtr<AST::Node>> Parser::parse_until_clause()
|
||||||
|
@ -963,19 +965,21 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_until_clause()
|
||||||
"Expected 'do' after 'until'"_string.release_value_but_fixme_should_propagate_errors());
|
"Expected 'do' after 'until'"_string.release_value_but_fixme_should_propagate_errors());
|
||||||
|
|
||||||
// until foo; bar -> loop { if foo { break } else { bar } }
|
// until foo; bar -> loop { if foo { break } else { bar } }
|
||||||
|
auto position = start_position.with_end(peek().position.value_or(empty_position()));
|
||||||
return make_ref_counted<AST::ForLoop>(
|
return make_ref_counted<AST::ForLoop>(
|
||||||
start_position.with_end(peek().position.value_or(empty_position())),
|
position,
|
||||||
Optional<AST::NameWithPosition> {},
|
Optional<AST::NameWithPosition> {},
|
||||||
Optional<AST::NameWithPosition> {},
|
Optional<AST::NameWithPosition> {},
|
||||||
nullptr,
|
nullptr,
|
||||||
make_ref_counted<AST::IfCond>(
|
make_ref_counted<AST::Execute>(position,
|
||||||
start_position.with_end(peek().position.value_or(empty_position())),
|
make_ref_counted<AST::IfCond>(
|
||||||
Optional<AST::Position> {},
|
position,
|
||||||
condition.release_nonnull(),
|
Optional<AST::Position> {},
|
||||||
make_ref_counted<AST::ContinuationControl>(
|
condition.release_nonnull(),
|
||||||
start_position,
|
make_ref_counted<AST::ContinuationControl>(
|
||||||
AST::ContinuationControl::ContinuationKind::Break),
|
start_position,
|
||||||
do_group.release_nonnull()));
|
AST::ContinuationControl::ContinuationKind::Break),
|
||||||
|
do_group.release_nonnull())));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<RefPtr<AST::Node>> Parser::parse_brace_group()
|
ErrorOr<RefPtr<AST::Node>> Parser::parse_brace_group()
|
||||||
|
@ -1084,12 +1088,13 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_case_clause()
|
||||||
syntax_error = nullptr;
|
syntax_error = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto position = compound_list->position();
|
||||||
entries.append(AST::MatchEntry {
|
entries.append(AST::MatchEntry {
|
||||||
.options = move(result.nodes),
|
.options = move(result.nodes),
|
||||||
.match_names = {},
|
.match_names = {},
|
||||||
.match_as_position = {},
|
.match_as_position = {},
|
||||||
.pipe_positions = move(result.pipe_positions),
|
.pipe_positions = move(result.pipe_positions),
|
||||||
.body = move(compound_list),
|
.body = make_ref_counted<AST::Execute>(position, compound_list.release_nonnull()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue