This branch had diverged considerably, so merging it required changing a lot of code. Conflicts: project.gyp spec/compiler/build_tables/action_takes_precedence_spec.cc spec/compiler/build_tables/build_conflict_spec.cc spec/compiler/build_tables/build_parse_table_spec.cc spec/compiler/build_tables/first_symbols_spec.cc spec/compiler/build_tables/item_set_closure_spec.cc spec/compiler/build_tables/item_set_transitions_spec.cc spec/compiler/build_tables/rule_can_be_blank_spec.cc spec/compiler/helpers/containers.h spec/compiler/prepare_grammar/expand_repeats_spec.cc spec/compiler/prepare_grammar/extract_tokens_spec.cc src/compiler/build_tables/action_takes_precedence.h src/compiler/build_tables/build_parse_table.cc src/compiler/build_tables/first_symbols.cc src/compiler/build_tables/first_symbols.h src/compiler/build_tables/item_set_closure.cc src/compiler/build_tables/item_set_transitions.cc src/compiler/build_tables/parse_item.cc src/compiler/build_tables/parse_item.h src/compiler/build_tables/rule_can_be_blank.cc src/compiler/build_tables/rule_can_be_blank.h src/compiler/prepare_grammar/expand_repeats.cc src/compiler/prepare_grammar/extract_tokens.cc src/compiler/prepare_grammar/extract_tokens.h src/compiler/prepare_grammar/prepare_grammar.cc src/compiler/rules/built_in_symbols.cc src/compiler/rules/built_in_symbols.h src/compiler/syntax_grammar.cc src/compiler/syntax_grammar.h
123 lines
3.2 KiB
C++
123 lines
3.2 KiB
C++
#ifndef tree_sitter_stream_methods_h
|
|
#define tree_sitter_stream_methods_h
|
|
|
|
#include <iostream>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
#include <map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
#include "tree_sitter/compiler.h"
|
|
|
|
using std::cout;
|
|
|
|
namespace std {
|
|
|
|
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: ");
|
|
bool started = false;
|
|
for (auto item : set) {
|
|
if (started) stream << std::string(", ");
|
|
stream << item;
|
|
started = true;
|
|
}
|
|
return stream << ")";
|
|
}
|
|
|
|
template<typename T, typename H, typename E>
|
|
inline std::ostream& operator<<(std::ostream &stream, const std::unordered_set<T, H, E> &set) {
|
|
stream << std::string("(set: ");
|
|
bool started = false;
|
|
for (auto item : set) {
|
|
if (started) stream << std::string(", ");
|
|
stream << item;
|
|
started = true;
|
|
}
|
|
return stream << ")";
|
|
}
|
|
|
|
template<typename TKey, typename TValue>
|
|
inline std::ostream& operator<<(std::ostream &stream, const std::map<TKey, TValue> &map) {
|
|
stream << std::string("(map: ");
|
|
bool started = false;
|
|
for (auto pair : map) {
|
|
if (started) stream << std::string(", ");
|
|
stream << pair.first;
|
|
stream << std::string(" => ");
|
|
stream << pair.second;
|
|
started = true;
|
|
}
|
|
return stream << ")";
|
|
}
|
|
|
|
template<typename TKey, typename TValue>
|
|
inline std::ostream& operator<<(std::ostream &stream, const std::unordered_map<TKey, TValue> &map) {
|
|
stream << std::string("(map: ");
|
|
bool started = false;
|
|
for (auto pair : map) {
|
|
if (started) stream << std::string(", ");
|
|
stream << pair.first;
|
|
stream << std::string(" => ");
|
|
stream << pair.second;
|
|
started = true;
|
|
}
|
|
return stream << ")";
|
|
}
|
|
|
|
template<typename T1, typename T2>
|
|
inline std::ostream& operator<<(std::ostream &stream, const std::pair<T1, T2> &pair) {
|
|
return stream << "{" << pair.first << ", " << pair.second << "}";
|
|
}
|
|
|
|
} // namespace std
|
|
|
|
namespace tree_sitter {
|
|
|
|
using std::ostream;
|
|
using std::string;
|
|
using std::to_string;
|
|
struct Variable;
|
|
struct SyntaxVariable;
|
|
class LexAction;
|
|
class ParseAction;
|
|
class ParseState;
|
|
struct ProductionStep;
|
|
|
|
ostream &operator<<(ostream &, const Grammar &);
|
|
ostream &operator<<(ostream &, const GrammarError &);
|
|
ostream &operator<<(ostream &, const Rule &);
|
|
ostream &operator<<(ostream &, const rule_ptr &);
|
|
ostream &operator<<(ostream &, const Variable &);
|
|
ostream &operator<<(ostream &, const SyntaxVariable &);
|
|
ostream &operator<<(ostream &, const LexAction &);
|
|
ostream &operator<<(ostream &, const ParseAction &);
|
|
ostream &operator<<(ostream &, const ParseState &);
|
|
ostream &operator<<(ostream &, const ProductionStep &);
|
|
|
|
namespace build_tables {
|
|
|
|
struct MetadataRange;
|
|
class LexItem;
|
|
class ParseItem;
|
|
|
|
ostream &operator<<(ostream &, const MetadataRange &);
|
|
ostream &operator<<(ostream &, const LexItem &);
|
|
ostream &operator<<(ostream &, const ParseItem &);
|
|
|
|
} // namespace build_tables
|
|
} // namespace tree_sitter
|
|
|
|
#endif
|