mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
Shell: Add support for functions
This implementation does not have support for 'return' yet.
This commit is contained in:
parent
519aa2048a
commit
d1550ea64f
6 changed files with 264 additions and 5 deletions
22
Shell/AST.h
22
Shell/AST.h
|
@ -636,6 +636,28 @@ private:
|
|||
int dest_fd { -1 };
|
||||
};
|
||||
|
||||
class FunctionDeclaration final : public Node {
|
||||
public:
|
||||
struct NameWithPosition {
|
||||
String name;
|
||||
Position position;
|
||||
};
|
||||
FunctionDeclaration(Position, NameWithPosition name, Vector<NameWithPosition> argument_names, RefPtr<AST::Node> body);
|
||||
virtual ~FunctionDeclaration();
|
||||
|
||||
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 "FunctionDeclaration"; }
|
||||
virtual bool would_execute() const override { return true; }
|
||||
|
||||
NameWithPosition m_name;
|
||||
Vector<NameWithPosition> m_arguments;
|
||||
RefPtr<AST::Node> m_block;
|
||||
};
|
||||
|
||||
class ForLoop final : public Node {
|
||||
public:
|
||||
ForLoop(Position, String variable_name, RefPtr<AST::Node> iterated_expr, RefPtr<AST::Node> block, Optional<size_t> in_kw_position = {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue