2013-11-07 13:24:01 -08:00
|
|
|
#include "seq.h"
|
|
|
|
|
#include "blank.h"
|
|
|
|
|
#include "transition_map.h"
|
|
|
|
|
|
2013-11-10 14:24:25 -08:00
|
|
|
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) {};
|
2013-11-10 14:24:25 -08:00
|
|
|
|
2013-11-14 12:55:02 -08:00
|
|
|
rule_ptr seq(const std::initializer_list<rule_ptr> &rules) {
|
|
|
|
|
return build_binary_rule_tree<Seq>(rules);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 13:24:01 -08:00
|
|
|
TransitionMap<Rule> Seq::transitions() const {
|
2013-11-10 14:24:25 -08:00
|
|
|
return left->transitions().map<Rule>([&](rule_ptr left_rule) -> rule_ptr {
|
2013-11-07 13:24:01 -08:00
|
|
|
if (typeid(*left_rule) == typeid(Blank))
|
|
|
|
|
return right;
|
|
|
|
|
else
|
2013-11-14 12:55:02 -08:00
|
|
|
return seq({ left_rule, right });
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Seq::to_string() const {
|
|
|
|
|
return std::string("(seq ") + left->to_string() + " " + right->to_string() + ")";
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-10 14:24:25 -08:00
|
|
|
}
|