Move shared rule pointer factories into individual rule files

This commit is contained in:
Max Brunsfeld 2013-11-14 12:55:02 -08:00
parent 8a0a442a24
commit 040ec86000
19 changed files with 102 additions and 76 deletions

View file

@ -7,10 +7,14 @@ namespace tree_sitter {
namespace rules {
String::String(std::string value) : value(value) {};
string_ptr str(const std::string &value) {
return std::make_shared<String>(value);
}
TransitionMap<Rule> String::transitions() const {
auto result = rule_ptr(new Char(value[0]));
rule_ptr result = character(value[0]);
for (int i = 1; i < value.length(); i++)
result = rule_ptr(new Seq(result, rule_ptr(new Char(value[i]))));
result = seq({ result, character(value[i]) });
return result->transitions();
}
@ -18,13 +22,10 @@ namespace tree_sitter {
const String *other = dynamic_cast<const String *>(&rule);
return (other != NULL) && (other->value == value);
}
String * String::copy() const {
return new String(value);
}
std::string String::to_string() const {
return std::string("(string '") + value + "')";
}
}
}