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

31 lines
954 B
C++
Raw Normal View History

2013-11-07 18:30:00 -08:00
#include "string.h"
#include "transition_map.h"
#include "char.h"
#include "seq.h"
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);
}
2013-11-07 18:30:00 -08:00
TransitionMap<Rule> String::transitions() const {
rule_ptr result = character(value[0]);
for (int i = 1; i < value.length(); i++)
result = seq({ result, character(value[i]) });
2013-11-07 18:30:00 -08:00
return result->transitions();
}
bool String::operator==(const Rule &rule) const {
const String *other = dynamic_cast<const String *>(&rule);
return (other != NULL) && (other->value == value);
}
2013-11-07 18:30:00 -08:00
std::string String::to_string() const {
return std::string("(string '") + value + "')";
2013-11-07 18:30:00 -08:00
}
2013-11-07 18:30:00 -08:00
}
}