Put rule classes in their own files
This commit is contained in:
parent
849f2ee195
commit
d830c7c255
17 changed files with 326 additions and 215 deletions
32
src/rules/seq.cpp
Normal file
32
src/rules/seq.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "seq.h"
|
||||
#include "blank.h"
|
||||
#include "transition_map.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
Seq::Seq(const Rule &left, const Rule &right) : left(left.copy()), right(right.copy()) {};
|
||||
Seq::Seq(rule_ptr left, rule_ptr right) : left(left), right(right) {};
|
||||
|
||||
TransitionMap<Rule> Seq::transitions() const {
|
||||
return left->transitions().map([&](rule_ptr left_rule) -> rule_ptr {
|
||||
if (typeid(*left_rule) == typeid(Blank))
|
||||
return right;
|
||||
else
|
||||
return rule_ptr(new Seq(left_rule, right));
|
||||
});
|
||||
}
|
||||
|
||||
bool Seq::operator==(const Rule &rule) const {
|
||||
const Seq *other = dynamic_cast<const Seq *>(&rule);
|
||||
return (other != NULL) && (*other->left == *left) && (*other->right == *right);
|
||||
}
|
||||
|
||||
Seq * Seq::copy() const {
|
||||
return new Seq(left, right);
|
||||
}
|
||||
|
||||
std::string Seq::to_string() const {
|
||||
return std::string("(seq ") + left->to_string() + " " + right->to_string() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue