tree-sitter/src/compiler/rules/seq.cpp

31 lines
993 B
C++
Raw Normal View History

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 {
2013-11-07 13:24:01 -08:00
namespace rules {
Seq::Seq(rule_ptr left, rule_ptr right) : left(left), right(right) {};
rule_ptr seq(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() && typeid(*result) != typeid(Blank)) ?
std::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);
return other && (*other->left == *left) && (*other->right == *right);
2013-11-07 13:24:01 -08:00
}
std::string Seq::to_string() const {
return std::string("(seq ") + left->to_string() + " " + right->to_string() + ")";
}
2013-12-18 20:58:05 -08:00
void Seq::accept(RuleVisitor &visitor) const {
visitor.visit(this);
}
2013-11-07 13:24:01 -08:00
}
}