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

43 lines
1.1 KiB
C++
Raw Normal View History

2014-03-09 21:37:21 -07:00
#include "compiler/rules/symbol.h"
#include <map>
2014-03-09 22:45:33 -07:00
#include <string>
2014-03-09 21:37:21 -07:00
#include "compiler/rules/visitor.h"
2013-11-07 13:24:01 -08:00
namespace tree_sitter {
2014-03-09 21:37:21 -07:00
using std::string;
using std::hash;
2014-03-09 23:51:33 -07:00
2013-11-07 13:24:01 -08:00
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 && this->operator==(*other);
2013-11-07 13:24:01 -08:00
}
bool Symbol::operator==(const Symbol &other) const {
return other.name == name;
}
2013-12-30 23:52:38 -08:00
size_t Symbol::hash_code() const {
return hash<string>()(name);
2013-12-30 23:52:38 -08:00
}
2014-03-09 19:49:35 -07:00
2014-01-02 13:04:41 -08:00
rule_ptr Symbol::copy() const {
return std::make_shared<Symbol>(*this);
}
2014-03-09 19:49:35 -07:00
string Symbol::to_string() const {
return string("#<sym '") + name + "'>";
}
2014-03-09 19:49:35 -07:00
bool Symbol::operator<(const Symbol &other) const {
return name < other.name;
}
2014-03-09 19:49:35 -07:00
void Symbol::accept(Visitor *visitor) const {
visitor->visit(this);
2013-12-18 20:58:05 -08:00
}
2013-11-07 13:24:01 -08:00
}
2014-04-14 08:38:11 -07:00
}