Initial commit

This commit is contained in:
2024-12-02 06:30:40 +00:00
commit fd62fb822d
33 changed files with 1972 additions and 0 deletions

View File

@ -0,0 +1,78 @@
#pragma once
#include <memory>
#include <stdexcept>
#include <optional>
#include "ast/ast_base.hpp"
#include "ast/ast_token.hpp"
#include "ast/ast_component.hpp"
#include "lexer.hpp"
#include "util/text.hpp"
namespace fsh {
class CommandNode : public ExecutableNode {
using ArgumentVec = std::vector<std::shared_ptr<CommandArgumentNode> >;
public:
static std::shared_ptr<CommandNode> build(std::list<Token>::iterator& it);
virtual void print(int indent) override;
virtual void execute(std::istream &in, std::ostream &out) override;
protected:
CommandNode(
TokenNode<TokenType::WORD>::shared cmd_name,
TokenNode<TokenType::FLAG>::shared flag,
ArgumentVec args,
std::shared_ptr<RedirectsNode> 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<std::string> flag;
std::shared_ptr<RedirectsNode> redirects;
ArgumentVec args;
};
class PipeLineNode : public ExecutableNode {
public:
static std::shared_ptr<PipeLineNode> build(std::list<Token>::iterator& it);
virtual void print(int indent) override;
virtual void execute(std::istream &in, std::ostream &out) override;
protected:
PipeLineNode(std::shared_ptr<CommandNode> l, std::shared_ptr<ExecutableNode> r)
: ExecutableNode(NodeType::PIPELINE_COMMAND, "PipeLine"),
l_command(l),
r_command(r) {}
private:
std::shared_ptr<ExecutableNode> l_command;
std::shared_ptr<ExecutableNode> r_command;
};
class CommandLineNode : public ExecutableNode {
public:
static std::shared_ptr<CommandLineNode> build(std::list<Token>::iterator& it);
virtual void print(int indent) override;
virtual void execute(std::istream &in, std::ostream &out) override;
protected:
CommandLineNode(std::shared_ptr<ExecutableNode> command, std::shared_ptr<ExecutableNode> pipe = nullptr)
: ExecutableNode(NodeType::COMMAND_LINE, "CommandLine"),
command(command),
pipe(pipe) {}
private:
std::shared_ptr<ExecutableNode> command;
std::shared_ptr<ExecutableNode> pipe;
};
}