1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

Shell: Add 'if' expressions

```sh
if foo bar baz {
    quux
} else if foobar || whatever {
    echo I ran out of example words
} else {
    exit 2
}
```
This commit is contained in:
AnotherTest 2020-08-11 12:05:46 +04:30 committed by Andreas Kling
parent c2be38e50f
commit b90eb5c9ba
4 changed files with 210 additions and 2 deletions

View file

@ -675,6 +675,26 @@ private:
bool m_capture_stdout { false };
};
class IfCond final : public Node {
public:
IfCond(Position, Optional<Position> else_position, RefPtr<AST::Node> cond_expr, RefPtr<AST::Node> true_branch, RefPtr<AST::Node> false_branch);
virtual ~IfCond();
private:
virtual void dump(int level) const override;
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 String class_name() const override { return "IfCond"; }
virtual bool would_execute() const override { return true; }
RefPtr<AST::Node> m_condition;
RefPtr<AST::Node> m_true_branch;
RefPtr<AST::Node> m_false_branch;
Optional<Position> m_else_position;
};
class Join final : public Node {
public:
Join(Position, RefPtr<Node>, RefPtr<Node>);