Tweak format for pretty printing some classes
This commit is contained in:
parent
2963b08f79
commit
6f374fddff
14 changed files with 27 additions and 29 deletions
|
|
@ -14,43 +14,43 @@ namespace std {
|
|||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::vector<T> &vector) {
|
||||
stream << std::string("#<vector: ");
|
||||
stream << std::string("(vector: ");
|
||||
bool started = false;
|
||||
for (auto item : vector) {
|
||||
if (started) stream << std::string(", ");
|
||||
stream << item;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
return stream << ")";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::set<T> &set) {
|
||||
stream << std::string("#<set: ");
|
||||
stream << std::string("(set: ");
|
||||
bool started = false;
|
||||
for (auto item : set) {
|
||||
if (started) stream << std::string(", ");
|
||||
stream << item;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
return stream << ")";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::unordered_set<T> &set) {
|
||||
stream << std::string("#<set: ");
|
||||
stream << std::string("(set: ");
|
||||
bool started = false;
|
||||
for (auto item : set) {
|
||||
if (started) stream << std::string(", ");
|
||||
stream << item;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
return stream << ")";
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
inline std::ostream& operator<<(std::ostream &stream, const std::map<TKey, TValue> &map) {
|
||||
stream << std::string("#<map: ");
|
||||
stream << std::string("(map: ");
|
||||
bool started = false;
|
||||
for (auto pair : map) {
|
||||
if (started) stream << std::string(", ");
|
||||
|
|
@ -59,12 +59,12 @@ inline std::ostream& operator<<(std::ostream &stream, const std::map<TKey, TValu
|
|||
stream << pair.second;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
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: ");
|
||||
stream << std::string("(map: ");
|
||||
bool started = false;
|
||||
for (auto pair : map) {
|
||||
if (started) stream << std::string(", ");
|
||||
|
|
@ -73,7 +73,7 @@ inline std::ostream& operator<<(std::ostream &stream, const std::unordered_map<T
|
|||
stream << pair.second;
|
||||
started = true;
|
||||
}
|
||||
return stream << ">";
|
||||
return stream << ")";
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ bool LexItem::is_token_start() const {
|
|||
}
|
||||
|
||||
ostream &operator<<(ostream &stream, const LexItem &item) {
|
||||
return stream << string("#<item ") << item.lhs << string(" ") << *item.rule
|
||||
<< string(">");
|
||||
return stream << string("(item ") << item.lhs << string(" ") << *item.rule
|
||||
<< string(")");
|
||||
}
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ bool ParseItem::operator==(const ParseItem &other) const {
|
|||
}
|
||||
|
||||
ostream &operator<<(ostream &stream, const ParseItem &item) {
|
||||
return stream << string("#<item ") << item.lhs << string(" ") << *item.rule
|
||||
<< string(">");
|
||||
return stream << string("(item ") << item.lhs << string(" ") << *item.rule
|
||||
<< string(")");
|
||||
}
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ size_t Blank::hash_code() const { return 0; }
|
|||
|
||||
rule_ptr Blank::copy() const { return std::make_shared<Blank>(); }
|
||||
|
||||
std::string Blank::to_string() const { return "#<blank>"; }
|
||||
std::string Blank::to_string() const { return "(blank)"; }
|
||||
|
||||
void Blank::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ rule_ptr CharacterSet::copy() const {
|
|||
}
|
||||
|
||||
string CharacterSet::to_string() const {
|
||||
string result("#<char {");
|
||||
string result("(char");
|
||||
for (auto &range : ranges)
|
||||
result += " " + range.to_string();
|
||||
return result + " }>";
|
||||
return result + ")";
|
||||
}
|
||||
|
||||
CharacterSet CharacterSet::complement() const {
|
||||
|
|
|
|||
|
|
@ -60,10 +60,10 @@ size_t Choice::hash_code() const {
|
|||
rule_ptr Choice::copy() const { return std::make_shared<Choice>(*this); }
|
||||
|
||||
string Choice::to_string() const {
|
||||
string result = "#<choice";
|
||||
string result = "(choice";
|
||||
for (const auto &element : elements)
|
||||
result += " " + element->to_string();
|
||||
return result + ">";
|
||||
return result + ")";
|
||||
}
|
||||
|
||||
void Choice::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ int Metadata::value_for(MetadataKey key) const {
|
|||
}
|
||||
|
||||
std::string Metadata::to_string() const {
|
||||
return "#<metadata " + rule->to_string() + ">";
|
||||
return "(metadata " + rule->to_string() + ")";
|
||||
}
|
||||
|
||||
void Metadata::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ rule_ptr NamedSymbol::copy() const {
|
|||
return std::make_shared<NamedSymbol>(*this);
|
||||
}
|
||||
|
||||
string NamedSymbol::to_string() const {
|
||||
return string("#<sym '") + name + "'>";
|
||||
}
|
||||
string NamedSymbol::to_string() const { return string("(sym '") + name + "')"; }
|
||||
|
||||
void NamedSymbol::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ size_t Pattern::hash_code() const { return hash<string>()(value); }
|
|||
rule_ptr Pattern::copy() const { return std::make_shared<Pattern>(*this); }
|
||||
|
||||
string Pattern::to_string() const {
|
||||
return string("#<pattern '") + util::escape_string(value) + "'>";
|
||||
return string("(pattern '") + util::escape_string(value) + "')";
|
||||
}
|
||||
|
||||
void Pattern::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ size_t Repeat::hash_code() const { return content->hash_code(); }
|
|||
rule_ptr Repeat::copy() const { return std::make_shared<Repeat>(*this); }
|
||||
|
||||
string Repeat::to_string() const {
|
||||
return string("#<repeat ") + content->to_string() + ">";
|
||||
return string("(repeat ") + content->to_string() + ")";
|
||||
}
|
||||
|
||||
void Repeat::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ ostream &operator<<(ostream &stream, const rule_ptr &rule) {
|
|||
if (rule.get())
|
||||
stream << *rule;
|
||||
else
|
||||
stream << string("#<null-rule>");
|
||||
stream << string("(null-rule)");
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ size_t Seq::hash_code() const { return left->hash_code() ^ right->hash_code(); }
|
|||
rule_ptr Seq::copy() const { return std::make_shared<Seq>(*this); }
|
||||
|
||||
string Seq::to_string() const {
|
||||
return string("#<seq ") + left->to_string() + " " + right->to_string() + ">";
|
||||
return string("(seq ") + left->to_string() + " " + right->to_string() + ")";
|
||||
}
|
||||
|
||||
void Seq::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ size_t String::hash_code() const { return hash<string>()(value); }
|
|||
|
||||
rule_ptr String::copy() const { return std::make_shared<String>(*this); }
|
||||
|
||||
string String::to_string() const { return string("#<string '") + value + "'>"; }
|
||||
string String::to_string() const { return string("(string '") + value + "')"; }
|
||||
|
||||
void String::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ rule_ptr Symbol::copy() const { return std::make_shared<Symbol>(*this); }
|
|||
string Symbol::to_string() const {
|
||||
string name = (options & SymbolOptionAuxiliary) ? "aux_" : "";
|
||||
name += (options & SymbolOptionToken) ? "token" : "sym";
|
||||
return "#<" + name + " " + std::to_string(index) + ">";
|
||||
return "(" + name + " " + std::to_string(index) + ")";
|
||||
}
|
||||
|
||||
bool Symbol::operator<(const Symbol &other) const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue