2013-12-18 20:58:05 -08:00
|
|
|
#include "rules.h"
|
2013-11-07 13:24:01 -08:00
|
|
|
#include "transition_map.h"
|
|
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
|
|
|
|
namespace rules {
|
|
|
|
|
Choice::Choice(rule_ptr left, rule_ptr right) : left(left), right(right) {};
|
|
|
|
|
|
2013-11-14 12:55:02 -08:00
|
|
|
rule_ptr choice(const std::initializer_list<rule_ptr> &rules) {
|
2013-11-20 19:00:20 -08:00
|
|
|
rule_ptr result;
|
|
|
|
|
for (auto rule : rules)
|
|
|
|
|
result = result.get() ? std::make_shared<Choice>(result, rule) : rule;
|
|
|
|
|
return result;
|
2013-11-14 12:55:02 -08:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Choice::to_string() const {
|
|
|
|
|
return std::string("(choice ") + left->to_string() + " " + right->to_string() + ")";
|
|
|
|
|
}
|
2013-12-18 20:58:05 -08:00
|
|
|
|
|
|
|
|
void Choice::accept(RuleVisitor &visitor) const {
|
|
|
|
|
visitor.visit(this);
|
|
|
|
|
}
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
|
|
|
|
}
|