#ifndef HELPERS_CONTAINERS_H_ #define HELPERS_CONTAINERS_H_ #include #include #include #include #include "tree_sitter/compiler.h" #include "compiler/rules/rule.h" using std::map; using std::vector; using std::string; using std::initializer_list; using std::pair; using tree_sitter::rules::rule_ptr; template class rule_map : public map { public: bool operator==(const map &other) const { if (this->size() != other.size()) return false; for (const auto &pair : *this) { auto other_pair = other.find(pair.first); if (other_pair == other.end()) return false; if (!pair.second->operator==(*other_pair->second)) return false; } return true; } rule_map(const initializer_list> &list) : map(list) {} }; class rule_list : public vector> { public: bool operator==(const vector> &other) const { if (this->size() != other.size()) return false; for (size_t i = 0; i < this->size(); i++) { auto pair = this->operator[](i); auto other_pair = other[i]; if (!pair.second->operator==(*other_pair.second)) return false; } return true; } rule_list(const initializer_list> &list) : vector>(list) {} }; class rule_vector : public vector { public: bool operator==(const vector &other) const { if (this->size() != other.size()) return false; for (size_t i = 0; i < this->size(); i++) { auto rule = this->operator[](i); auto other_rule = other[i]; if (!rule->operator==(*rule)) return false; } return true; } rule_vector(const initializer_list &list) : vector(list) {} }; #endif // HELPERS_CONTAINERS_H_