2014-03-09 21:37:21 -07:00
|
|
|
#include "compiler/rules/repeat.h"
|
2015-01-14 21:09:39 -08:00
|
|
|
#include <memory>
|
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-15 08:46:45 -08:00
|
|
|
namespace tree_sitter {
|
2014-07-20 21:43:27 -07:00
|
|
|
namespace rules {
|
2014-03-09 23:51:33 -07:00
|
|
|
|
2015-01-14 21:09:39 -08:00
|
|
|
using std::make_shared;
|
2014-07-20 21:43:27 -07:00
|
|
|
using std::string;
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2014-07-20 21:43:27 -07:00
|
|
|
Repeat::Repeat(const rule_ptr content) : content(content) {}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2015-01-14 21:09:39 -08:00
|
|
|
rule_ptr Repeat::build(const rule_ptr &rule) {
|
2015-10-12 15:26:50 -07:00
|
|
|
auto inner_repeat = rule->as<Repeat>();
|
|
|
|
|
if (inner_repeat)
|
|
|
|
|
return rule;
|
2015-01-14 21:09:39 -08:00
|
|
|
else
|
|
|
|
|
return make_shared<Repeat>(rule);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-20 21:43:27 -07:00
|
|
|
bool Repeat::operator==(const Rule &rule) const {
|
2015-10-12 15:26:50 -07:00
|
|
|
auto other = rule.as<Repeat>();
|
2014-07-20 21:43:27 -07:00
|
|
|
return other && (*other->content == *content);
|
|
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2015-07-31 16:32:24 -07:00
|
|
|
size_t Repeat::hash_code() const {
|
|
|
|
|
return content->hash_code();
|
|
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2015-07-31 16:32:24 -07:00
|
|
|
rule_ptr Repeat::copy() const {
|
|
|
|
|
return make_shared<Repeat>(*this);
|
|
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2014-07-20 21:43:27 -07:00
|
|
|
string Repeat::to_string() const {
|
2014-08-23 13:52:00 -07:00
|
|
|
return string("(repeat ") + content->to_string() + ")";
|
2013-11-15 08:46:45 -08:00
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2015-07-31 16:32:24 -07:00
|
|
|
void Repeat::accept(Visitor *visitor) const {
|
|
|
|
|
visitor->visit(this);
|
|
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
|
|
|
|
} // namespace rules
|
|
|
|
|
} // namespace tree_sitter
|