#pragma once #include #include #include #include "ast/ast_base.hpp" #include "ast/ast_component.hpp" #include "ast/ast_token.hpp" #include "lexer.hpp" #include "util/text.hpp" namespace fsh { class CommandNode : public ExecutableNode { using ArgumentVec = std::vector >; public: static std::shared_ptr build(std::list::iterator& it); virtual void print(int indent) override; virtual void execute(std::istream& in, std::ostream& out) override; protected: CommandNode(TokenNode::shared cmd_name, TokenNode::shared flag, ArgumentVec args, std::shared_ptr redirects) : ExecutableNode(NodeType::COMMAND, "CommandNode"), cmd_name(cmd_name->gvalue()), flag(util::mk_optional(flag)), redirects(redirects), args(args) {} private: std::string cmd_name; std::optional flag; std::shared_ptr redirects; ArgumentVec args; }; class PipeLineNode : public ExecutableNode { public: static std::shared_ptr build(std::list::iterator& it); virtual void print(int indent) override; virtual void execute(std::istream& in, std::ostream& out) override; protected: PipeLineNode(std::shared_ptr l, std::shared_ptr r) : ExecutableNode(NodeType::PIPELINE_COMMAND, "PipeLine"), l_command(l), r_command(r) {} private: std::shared_ptr l_command; std::shared_ptr r_command; }; class CommandLineNode : public ExecutableNode { public: static std::shared_ptr build(std::list::iterator& it); virtual void print(int indent) override; virtual void execute(std::istream& in, std::ostream& out) override; protected: CommandLineNode(std::shared_ptr command, std::shared_ptr pipe = nullptr) : ExecutableNode(NodeType::COMMAND_LINE, "CommandLine"), command(command), pipe(pipe) {} private: std::shared_ptr command; std::shared_ptr pipe; }; }