#include "compiler/rules/metadata.h" #include #include #include "compiler/rules/visitor.h" namespace tree_sitter { using std::hash; using std::make_shared; using std::map; namespace rules { Metadata::Metadata(rule_ptr rule, map values) : rule(rule), value(values) {} bool Metadata::operator==(const Rule &rule) const { auto other = dynamic_cast(&rule); return other && other->value == value && other->rule->operator==(*this->rule); } size_t Metadata::hash_code() const { size_t result = hash()(value.size()); for (auto &pair : value) { result ^= hash()(pair.first); result ^= hash()(pair.second); } return result; } rule_ptr Metadata::copy() const { return make_shared(rule->copy(), value); } int Metadata::value_for(MetadataKey key) const { auto pair = value.find(key); return (pair != value.end()) ? pair->second : 0; } std::string Metadata::to_string() const { return "#to_string() + ">"; } void Metadata::accept(Visitor *visitor) const { visitor->visit(this); } } }