2014-02-16 22:13:08 -08:00
|
|
|
#include "seq.h"
|
|
|
|
|
#include "visitor.h"
|
|
|
|
|
#include "blank.h"
|
2013-12-19 23:05:54 -08:00
|
|
|
|
2013-11-10 14:24:25 -08:00
|
|
|
namespace tree_sitter {
|
2014-02-16 22:13:08 -08:00
|
|
|
using std::make_shared;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
namespace rules {
|
|
|
|
|
Seq::Seq(rule_ptr left, rule_ptr right) : left(left), right(right) {};
|
2013-11-10 14:24:25 -08:00
|
|
|
|
2014-02-16 22:13:08 -08:00
|
|
|
rule_ptr Seq::Build(const std::vector<rule_ptr> &rules) {
|
|
|
|
|
rule_ptr result = make_shared<Blank>();
|
|
|
|
|
for (auto &rule : rules)
|
|
|
|
|
result = (typeid(*result) != typeid(Blank)) ? make_shared<Seq>(result, rule) : rule;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
bool Seq::operator==(const Rule &rule) const {
|
|
|
|
|
const Seq *other = dynamic_cast<const Seq *>(&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
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2013-12-30 23:52:38 -08:00
|
|
|
size_t Seq::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-03-09 19:49:35 -07:00
|
|
|
|
2014-01-02 13:04:41 -08:00
|
|
|
rule_ptr Seq::copy() const {
|
|
|
|
|
return std::make_shared<Seq>(*this);
|
|
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
string Seq::to_string() const {
|
2013-12-30 23:12:19 -08:00
|
|
|
return string("#<seq ") + left->to_string() + " " + right->to_string() + ">";
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
2014-03-09 19:49:35 -07:00
|
|
|
|
2013-12-19 23:16:13 -08:00
|
|
|
void Seq::accept(Visitor &visitor) const {
|
2013-12-18 20:58:05 -08:00
|
|
|
visitor.visit(this);
|
|
|
|
|
}
|
2013-11-07 13:24:01 -08:00
|
|
|
}
|
2013-11-10 14:24:25 -08:00
|
|
|
}
|