Separate auxiliary rules from user-specified rules

This commit is contained in:
Max Brunsfeld 2014-01-28 13:27:30 -08:00
parent 19e5b2a563
commit fd0d77ef8b
16 changed files with 741 additions and 412 deletions

View file

@ -5,15 +5,16 @@ using std::hash;
namespace tree_sitter {
namespace rules {
Symbol::Symbol(const std::string &name) : name(name) {};
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) {};
bool Symbol::operator==(const Rule &rule) const {
const Symbol *other = dynamic_cast<const Symbol *>(&rule);
return other && (other->name == name);
return other && (other->name == name) && (other->is_auxiliary == is_auxiliary);
}
size_t Symbol::hash_code() const {
return typeid(this).hash_code() ^ hash<string>()(name);
return typeid(this).hash_code() ^ hash<string>()(name) ^ hash<bool>()(is_auxiliary);
}
rule_ptr Symbol::copy() const {
@ -21,11 +22,15 @@ namespace tree_sitter {
}
string Symbol::to_string() const {
return string("#<sym '") + name + "'>";
return is_auxiliary ?
string("#<aux_sym '") + name + "'>" :
string("#<sym '") + name + "'>";
}
bool Symbol::operator<(const Symbol &other) const {
return name < other.name;
if (name < other.name) return true;
if (other.name < name) return false;
return is_auxiliary < other.is_auxiliary;
}
void Symbol::accept(Visitor &visitor) const {