Yerbacon/src/headers/parsing/ParseComponents.hpp
2021-03-18 21:22:41 +01:00

33 lines
1.2 KiB
C++

#ifndef YERBACON_PARSECOMPONENTS_HPP
#define YERBACON_PARSECOMPONENTS_HPP
#include <iostream>
#include <vector>
using namespace std;
#include "../lex.hpp"
class ParseComponent {};
struct ParseTree: public ParseComponent {
private:
mutable unsigned int compCount = 0;
inline void addComp(const auto& comp) const {
subComponents.push_back(comp); ++compCount;
}; inline void addAllComps(const auto& comps) const { for (const auto& comp: comps) addComp(comp); }
protected:
mutable vector<ParseComponent> subComponents;
public:
unsigned int& getCompCount() const { return compCount; }
auto& getComponents() const { return subComponents; }
void add(const ParseComponent& component) { addComp(component); };
void addAll(const vector<ParseComponent>& components) { addAllComps(components); }
void operator<<(const ParseComponent& component) { this->addComp(component); }
explicit ParseTree(const ParseComponent& element): subComponents() { addComp(element); }
ParseTree(const initializer_list<ParseComponent>& elements): subComponents() { addAllComps(elements); }
ParseTree(): subComponents() {};
~ParseTree() = default;
};
#endif //YERBACON_PARSECOMPONENTS_HPP