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-11-07 13:24:01 -08:00
|
|
|
namespace tree_sitter {
|
|
|
|
|
namespace rules {
|
|
|
|
|
Choice::Choice(rule_ptr left, rule_ptr right) : left(left), right(right) {};
|
|
|
|
|
|
|
|
|
|
bool Choice::operator==(const Rule &rule) const {
|
|
|
|
|
const Choice *other = dynamic_cast<const Choice *>(&rule);
|
2013-11-14 21:25:58 -08:00
|
|
|
return other && (*other->left == *left) && (*other->right == *right);
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
|
|
|
|
|
2013-12-30 23:52:38 -08:00
|
|
|
size_t Choice::hash_code() const {
|
2014-02-15 16:12:16 -08:00
|
|
|
return left->hash_code() ^ right->hash_code();
|
2013-12-30 23:52:38 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-02 13:04:41 -08:00
|
|
|
rule_ptr Choice::copy() const {
|
|
|
|
|
return std::make_shared<Choice>(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
string Choice::to_string() const {
|
2013-12-30 23:12:19 -08:00
|
|
|
return string("#<choice ") + left->to_string() + " " + right->to_string() + ">";
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
2013-12-18 20:58:05 -08:00
|
|
|
|
2013-12-19 23:16:13 -08:00
|
|
|
void Choice::accept(Visitor &visitor) const {
|
2013-12-18 20:58:05 -08:00
|
|
|
visitor.visit(this);
|
|
|
|
|
}
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
|
|
|
|
}
|