tree-sitter/src/compiler/rules/symbol.cpp

35 lines
945 B
C++
Raw Normal View History

2013-12-18 20:58:05 -08:00
#include "rules.h"
2013-11-07 13:24:01 -08:00
using std::string;
2013-12-30 23:52:38 -08:00
using std::hash;
2013-11-07 13:24:01 -08:00
namespace tree_sitter {
namespace rules {
Symbol::Symbol(const std::string &name) : name(name) {};
2013-11-07 13:24:01 -08:00
bool Symbol::operator==(const Rule &rule) const {
const Symbol *other = dynamic_cast<const Symbol *>(&rule);
return other && (other->name == name);
2013-11-07 13:24:01 -08:00
}
2013-12-30 23:52:38 -08:00
size_t Symbol::hash_code() const {
return typeid(this).hash_code() ^ hash<string>()(name);
}
2014-01-02 13:04:41 -08:00
rule_ptr Symbol::copy() const {
return std::make_shared<Symbol>(*this);
}
string Symbol::to_string() const {
2013-12-30 23:12:19 -08:00
return string("#<sym '") + name + "'>";
}
2013-12-18 20:58:05 -08:00
bool Symbol::operator<(const Symbol &other) const {
return name < other.name;
}
2013-12-19 23:16:13 -08:00
void Symbol::accept(Visitor &visitor) const {
2013-12-18 20:58:05 -08:00
visitor.visit(this);
}
2013-11-07 13:24:01 -08:00
}
}