83 lines
2.7 KiB
C++
83 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
#include "ast/ast_base.hpp"
|
|
#include "ast_token.hpp"
|
|
|
|
#include "lexer.hpp"
|
|
#include "util/text.hpp"
|
|
|
|
namespace fsh {
|
|
|
|
class CommandArgumentNode : public AstNode {
|
|
public:
|
|
static std::shared_ptr<CommandArgumentNode> build(std::list<Token>::iterator& it);
|
|
|
|
Lexer::TokenType gtoken_type() { return type; }
|
|
std::string& gvalue() { return value; }
|
|
|
|
protected:
|
|
CommandArgumentNode(TokenNode<TokenType::WORD>::shared word) :
|
|
AstNode(NodeType::COMMAND_ARGUMENT, "StringArgument"), type(word->gtoken_type()), value(word->gvalue()) {}
|
|
|
|
CommandArgumentNode(TokenNode<TokenType::STRING_LITERAL>::shared word) :
|
|
AstNode(NodeType::COMMAND_ARGUMENT, "StringArgument"), type(word->gtoken_type()), value(word->gvalue()) {}
|
|
|
|
private:
|
|
Lexer::TokenType type;
|
|
std::string value;
|
|
};
|
|
|
|
class LRedirectNode : public AstNode {
|
|
public:
|
|
static std::shared_ptr<LRedirectNode> build(std::list<Token>::iterator& it);
|
|
|
|
std::string gvalue() { return input; }
|
|
|
|
protected:
|
|
LRedirectNode(TokenNode<TokenType::LREDIRECTION>::shared, TokenNode<TokenType::WORD>::shared in) :
|
|
AstNode(NodeType::LREDIRECTS, "LRedirectNode"), input(in->gvalue()) {}
|
|
|
|
private:
|
|
std::string input;
|
|
};
|
|
|
|
class RRedirectNode : public AstNode {
|
|
public:
|
|
static std::shared_ptr<RRedirectNode> build(std::list<Token>::iterator& it);
|
|
|
|
std::string gvalue() { return output; }
|
|
bool gappend() { return append; }
|
|
|
|
protected:
|
|
RRedirectNode(TokenNode<TokenType::RREDIRECTION>::shared rr, TokenNode<TokenType::WORD>::shared out) :
|
|
AstNode(NodeType::RREDIRECTS, "LRedirectNode"), output(out->gvalue()), append(rr->gvalue().size() > 1) {}
|
|
|
|
private:
|
|
std::string output;
|
|
bool append;
|
|
};
|
|
|
|
class RedirectsNode : public AstNode {
|
|
public:
|
|
static std::shared_ptr<RedirectsNode> build(std::list<Token>::iterator& it);
|
|
|
|
std::optional<std::string> ginput() { return input; }
|
|
std::optional<std::string> goutput() { return output; }
|
|
bool gappend() { return append; }
|
|
|
|
protected:
|
|
RedirectsNode(std::shared_ptr<LRedirectNode> in, std::shared_ptr<RRedirectNode> out) :
|
|
AstNode(NodeType::REDIRECTS, "RedirectNode"), input(util::mk_optional(in)), output(util::mk_optional(out)) {
|
|
if (out) append = out->gappend();
|
|
}
|
|
|
|
private:
|
|
std::optional<std::string> input;
|
|
std::optional<std::string> output;
|
|
bool append = false;
|
|
};
|
|
|
|
} // namespace fsh
|