2013-12-18 20:58:05 -08:00
|
|
|
#include "rules.h"
|
2013-11-07 13:24:01 -08:00
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
using std::string;
|
2013-12-30 23:52:38 -08:00
|
|
|
using std::hash;
|
2013-12-19 23:05:54 -08:00
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
namespace tree_sitter {
|
|
|
|
|
namespace rules {
|
2014-01-28 13:27:30 -08:00
|
|
|
Symbol::Symbol(const std::string &name) : name(name), is_auxiliary(false) {};
|
|
|
|
|
Symbol::Symbol(const std::string &name, bool is_auxiliary) : name(name), is_auxiliary(is_auxiliary) {};
|
2013-11-14 12:55:02 -08:00
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
bool Symbol::operator==(const Rule &rule) const {
|
|
|
|
|
const Symbol *other = dynamic_cast<const Symbol *>(&rule);
|
2014-01-28 13:27:30 -08:00
|
|
|
return other && (other->name == name) && (other->is_auxiliary == is_auxiliary);
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
|
|
|
|
|
2013-12-30 23:52:38 -08:00
|
|
|
size_t Symbol::hash_code() const {
|
2014-01-28 13:27:30 -08:00
|
|
|
return typeid(this).hash_code() ^ hash<string>()(name) ^ hash<bool>()(is_auxiliary);
|
2013-12-30 23:52:38 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-02 13:04:41 -08:00
|
|
|
rule_ptr Symbol::copy() const {
|
|
|
|
|
return std::make_shared<Symbol>(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
string Symbol::to_string() const {
|
2014-01-28 13:27:30 -08:00
|
|
|
return is_auxiliary ?
|
|
|
|
|
string("#<aux_sym '") + name + "'>" :
|
|
|
|
|
string("#<sym '") + name + "'>";
|
2013-11-10 14:24:25 -08:00
|
|
|
}
|
2013-12-18 20:58:05 -08:00
|
|
|
|
2014-01-04 15:01:06 -08:00
|
|
|
bool Symbol::operator<(const Symbol &other) const {
|
2014-01-28 13:27:30 -08:00
|
|
|
if (name < other.name) return true;
|
|
|
|
|
if (other.name < name) return false;
|
|
|
|
|
return is_auxiliary < other.is_auxiliary;
|
2014-01-04 15:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|