Add stream operator for parse states
This commit is contained in:
parent
5d9dc71da1
commit
0877d01194
3 changed files with 34 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
using std::cout;
|
||||
|
||||
|
|
@ -21,6 +22,18 @@ namespace std {
|
|||
return stream << ">";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::vector<T> &vector) {
|
||||
stream << std::string("#<vector: ");
|
||||
bool started = false;
|
||||
for (auto item : vector) {
|
||||
if (started) stream << std::string(", ");
|
||||
stream << item;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::set<T> &set) {
|
||||
stream << std::string("#<set: ");
|
||||
|
|
|
|||
|
|
@ -59,6 +59,25 @@ namespace tree_sitter {
|
|||
return result;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &stream, const ParseState &state) {
|
||||
stream << string("#<parse_state ");
|
||||
bool started1 = false;
|
||||
for (auto pair : state.actions) {
|
||||
if (started1) stream << string(", ");
|
||||
stream << pair.first << string(" => #<set: ");
|
||||
bool started2 = false;
|
||||
for (auto action : pair.second) {
|
||||
if (started2) stream << string(", ");
|
||||
stream << action;
|
||||
started2 = true;
|
||||
}
|
||||
stream << string(">");
|
||||
started1 = true;
|
||||
}
|
||||
stream << string(">");
|
||||
return stream;
|
||||
}
|
||||
|
||||
// Table
|
||||
size_t ParseTable::add_state() {
|
||||
states.push_back(ParseState());
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ namespace tree_sitter {
|
|||
size_t lex_state_index;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream &stream, const ParseState &state);
|
||||
|
||||
class ParseTable {
|
||||
public:
|
||||
size_t add_state();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue