Massive reformating and cleanup

This commit is contained in:
2024-12-06 21:07:54 +01:00
parent 79390b94b7
commit d2cbdc2910
33 changed files with 1030 additions and 1100 deletions

View File

@ -1,78 +1,69 @@
#pragma once
#include <memory>
#include <stdexcept>
#include <optional>
#include <stdexcept>
#include "ast/ast_base.hpp"
#include "ast/ast_token.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<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;
class CommandNode : public ExecutableNode {
using ArgumentVec = std::vector<std::shared_ptr<CommandArgumentNode> >;
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;
};
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;
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:
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) {}
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;
};
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;
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:
PipeLineNode(std::shared_ptr<CommandNode> l, std::shared_ptr<ExecutableNode> r) :
ExecutableNode(NodeType::PIPELINE_COMMAND, "PipeLine"), l_command(l), r_command(r) {}
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;
};
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;
};
} // namespace fsh