tree-sitter/spec/runtime/helpers/tree_helpers.cc

30 lines
979 B
C++
Raw Normal View History

2014-06-23 18:50:03 -07:00
#include "runtime/helpers/tree_helpers.h"
2015-06-03 09:44:13 -07:00
const char *symbol_names[12] = {
"ERROR", "END", "DOCUMENT", "AMBIGUITY",
"zero", "one", "two", "three", "four", "five", "six", "seven",
};
2014-06-28 18:45:22 -07:00
TSTree ** tree_array(std::vector<TSTree *> trees) {
2014-08-06 13:00:35 -07:00
TSTree ** result = (TSTree **)calloc(trees.size(), sizeof(TSTree *));
for (size_t i = 0; i < trees.size(); i++)
result[i] = trees[i];
return result;
}
2015-05-25 20:44:23 -07:00
EqualsTree::EqualsTree(const TSTree *expected, const char **symbol_names)
: expected(expected), symbol_names(symbol_names) {}
bool EqualsTree::Matches(const TSTree *actual) const {
return ts_tree_eq(actual, expected);
}
std::ostream &operator<<(std::ostream &stream, const EqualsTree &matcher) {
stream << std::string("equals tree: ") << std::string(ts_tree_string(matcher.expected, matcher.symbol_names));
return stream;
}
2015-06-03 09:44:13 -07:00
std::ostream &operator<<(std::ostream &stream, const TSTree *tree) {
return stream << std::string(ts_tree_string(tree, symbol_names));;
}