Massive reformating and cleanup
This commit is contained in:
@ -1,67 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "lexer.hpp"
|
||||
#include "util/text.hpp"
|
||||
|
||||
namespace fsh {
|
||||
|
||||
enum NodeType {
|
||||
COMMAND_LINE,
|
||||
COMMAND,
|
||||
PIPELINE_COMMAND,
|
||||
LREDIRECTS,
|
||||
RREDIRECTS,
|
||||
REDIRECTS,
|
||||
STRING_LITERAL,
|
||||
COMMAND_ARGUMENT,
|
||||
TOKEN
|
||||
};
|
||||
enum NodeType {
|
||||
COMMAND_LINE,
|
||||
COMMAND,
|
||||
PIPELINE_COMMAND,
|
||||
LREDIRECTS,
|
||||
RREDIRECTS,
|
||||
REDIRECTS,
|
||||
STRING_LITERAL,
|
||||
COMMAND_ARGUMENT,
|
||||
TOKEN
|
||||
};
|
||||
|
||||
class AstNode {
|
||||
friend class std::shared_ptr<AstNode>;
|
||||
public:
|
||||
NodeType gtype() {return type;}
|
||||
const std::string& gname() {return name;};
|
||||
class AstNode {
|
||||
friend class std::shared_ptr<AstNode>;
|
||||
|
||||
protected:
|
||||
using TokenType = Lexer::TokenType;
|
||||
AstNode(NodeType type, std::string name) : type(type), name(name) {}
|
||||
public:
|
||||
NodeType gtype() { return type; }
|
||||
const std::string& gname() { return name; };
|
||||
|
||||
protected:
|
||||
using TokenType = Lexer::TokenType;
|
||||
AstNode(NodeType type, std::string name) : type(type), name(name) {}
|
||||
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Optional(std::list<Token>::iterator& it, std::shared_ptr<T>& node_ptr);
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Optional(std::list<Token>::iterator& it) {
|
||||
std::shared_ptr<T> node_ptr;
|
||||
return Optional<T>(it, node_ptr);
|
||||
}
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Mandatory(std::list<Token>::iterator& it) {return T::build(it);}
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Optional(std::list<Token>::iterator& it, std::shared_ptr<T>& node_ptr);
|
||||
|
||||
private:
|
||||
AstNode();
|
||||
AstNode(const AstNode&);
|
||||
NodeType type;
|
||||
const std::string name;
|
||||
};
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Optional(std::list<Token>::iterator& it) {
|
||||
std::shared_ptr<T> node_ptr;
|
||||
return Optional<T>(it, node_ptr);
|
||||
}
|
||||
|
||||
class ExecutableNode : public AstNode {
|
||||
public:
|
||||
virtual void print(int indent) {};
|
||||
virtual void execute(std::istream &in, std::ostream &out) {}
|
||||
protected:
|
||||
ExecutableNode(NodeType type, std::string Name) : AstNode(type, Name) {}
|
||||
private:
|
||||
};
|
||||
template <class T>
|
||||
static std::shared_ptr<T> Mandatory(std::list<Token>::iterator& it) {
|
||||
return T::build(it);
|
||||
}
|
||||
|
||||
class AstBuildError : public std::runtime_error {
|
||||
public:
|
||||
AstBuildError(std::string err) : std::runtime_error(err) {}
|
||||
};
|
||||
private:
|
||||
AstNode();
|
||||
AstNode(const AstNode&);
|
||||
NodeType type;
|
||||
const std::string name;
|
||||
};
|
||||
|
||||
}
|
||||
class ExecutableNode : public AstNode {
|
||||
public:
|
||||
virtual void print(int indent) {};
|
||||
virtual void execute(std::istream& in, std::ostream& out) {}
|
||||
|
||||
protected:
|
||||
ExecutableNode(NodeType type, std::string Name) : AstNode(type, Name) {}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class AstBuildError : public std::runtime_error {
|
||||
public:
|
||||
AstBuildError(std::string err) : std::runtime_error(err) {}
|
||||
};
|
||||
|
||||
} // namespace fsh
|
||||
Reference in New Issue
Block a user