2014-03-09 21:37:21 -07:00
|
|
|
#include "compiler/rules/symbol.h"
|
2014-02-19 13:05:54 -08:00
|
|
|
#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-12-19 23:05:54 -08:00
|
|
|
|
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 {
|
2014-04-22 23:38:26 -07:00
|
|
|
Symbol::Symbol(const std::string &name) : name(name) {}
|
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-31 00:13:05 -08:00
|
|
|
return other && this->operator==(*other);
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
2014-01-31 00:13:05 -08:00
|
|
|
|
|
|
|
|
bool Symbol::operator==(const Symbol &other) const {
|
2014-04-22 23:38:26 -07:00
|
|
|
return other.name == name;
|
2014-01-31 00:13:05 -08:00
|
|
|
}
|
|
|
|
|
|
2013-12-30 23:52:38 -08:00
|
|
|
size_t Symbol::hash_code() const {
|
2014-04-22 23:38:26 -07:00
|
|
|
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
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
string Symbol::to_string() const {
|
2014-04-22 23:38:26 -07:00
|
|
|
return string("#<sym '") + name + "'>";
|
2013-11-10 14:24:25 -08:00
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2014-01-04 15:01:06 -08:00
|
|
|
bool Symbol::operator<(const Symbol &other) const {
|
2014-04-22 23:38:26 -07:00
|
|
|
return name < other.name;
|
2014-02-19 13:05:54 -08:00
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2014-03-09 22:21:58 -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
|
|
|
}
|