Add helper functions for making shared pointers to rules

- start work on item set class
This commit is contained in:
Max Brunsfeld 2013-11-10 14:24:25 -08:00
parent ec8b7ccf20
commit 11e3980319
33 changed files with 486 additions and 150 deletions

View file

@ -2,13 +2,12 @@
#include "blank.h"
#include "transition_map.h"
namespace tree_sitter {
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 {
return left->transitions().map<Rule>([&](rule_ptr left_rule) -> rule_ptr {
if (typeid(*left_rule) == typeid(Blank))
return right;
else
@ -21,12 +20,8 @@ namespace tree_sitter {
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() + ")";
}
}
}
}