mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
Shell: Make 'if' expressions return the unevaluated value of blocks
This makes it possible to actually put them in a sequence and cast them to commands.
This commit is contained in:
parent
50473003be
commit
5ec139e728
Notes:
sideshowbarker
2024-07-18 23:03:40 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5ec139e7280 Pull-request: https://github.com/SerenityOS/serenity/pull/4996
3 changed files with 14 additions and 4 deletions
|
@ -1690,12 +1690,18 @@ IfCond::IfCond(Position position, Optional<Position> else_position, NonnullRefPt
|
|||
|
||||
if (m_true_branch) {
|
||||
auto true_branch = m_true_branch.release_nonnull();
|
||||
m_true_branch = create<AST::Execute>(true_branch->position(), true_branch);
|
||||
if (true_branch->is_execute())
|
||||
m_true_branch = static_ptr_cast<AST::Execute>(true_branch)->command();
|
||||
else
|
||||
m_true_branch = move(true_branch);
|
||||
}
|
||||
|
||||
if (m_false_branch) {
|
||||
auto false_branch = m_false_branch.release_nonnull();
|
||||
m_false_branch = create<AST::Execute>(false_branch->position(), false_branch);
|
||||
if (false_branch->is_execute())
|
||||
m_false_branch = static_ptr_cast<AST::Execute>(false_branch)->command();
|
||||
else
|
||||
m_false_branch = move(false_branch);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -984,7 +984,6 @@ private:
|
|||
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
||||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual bool would_execute() const override { return true; }
|
||||
virtual bool should_override_execution_in_current_process() const override { return true; }
|
||||
|
||||
NonnullRefPtr<AST::Node> m_condition;
|
||||
|
|
|
@ -730,7 +730,12 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
|||
}
|
||||
}
|
||||
|
||||
if (command.argv.is_empty() && !command.next_chain.is_empty() && command.should_immediately_execute_next && command.next_chain.first().node->should_override_execution_in_current_process()) {
|
||||
if (command.argv.is_empty()
|
||||
&& !command.next_chain.is_empty()
|
||||
&& command.should_immediately_execute_next
|
||||
&& command.redirections.is_empty()
|
||||
&& command.next_chain.first().node->should_override_execution_in_current_process()) {
|
||||
|
||||
for (auto& next_in_chain : command.next_chain)
|
||||
run_tail(command, next_in_chain, last_return_code);
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue