tree-sitter/spec/compiler/spec_helper.cpp

38 lines
1.3 KiB
C++
Raw Normal View History

#include "spec_helper.h"
2013-12-15 14:41:51 -08:00
namespace tree_sitter {
namespace lr {
2013-12-27 17:31:08 -08:00
template<typename TKey, typename TValue>
std::ostream & stream_map_of_sets(std::ostream &stream, const unordered_map<TKey, unordered_set<TValue>> &map) {
2013-12-15 14:41:51 -08:00
stream << string("{");
bool started = false;
for (auto pair : map) {
if (started) stream << string(", ");
2013-12-27 17:31:08 -08:00
stream << pair.first;
stream << string(" => [");
2013-12-15 14:41:51 -08:00
bool started_set = false;
2013-12-27 17:31:08 -08:00
for (TValue action : pair.second) {
2013-12-15 14:41:51 -08:00
if (started_set) stream << ", ";
stream << action;
started_set = true;
}
stream << string("]}");
started = true;
}
return stream;
}
2013-12-27 17:31:08 -08:00
std::ostream& operator<<(std::ostream &stream, const unordered_map<string, unordered_set<ParseAction>> &map) {
return stream_map_of_sets(stream, map);
}
std::ostream& operator<<(std::ostream &stream, const unordered_map<CharMatch, unordered_set<LexAction>> &map) {
return stream_map_of_sets(stream, map);
}
2013-12-15 14:41:51 -08:00
}
}
2013-12-15 19:33:34 -08:00
string src_dir() {
return string(getenv("TREESITTER_SRC_DIR"));
}