From 6f374fddff27b957e16e101cedc593fa41576935 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sat, 23 Aug 2014 13:52:00 -0700 Subject: [PATCH] Tweak format for pretty printing some classes --- spec/compiler/helpers/stream_methods.h | 20 ++++++++++---------- src/compiler/build_tables/lex_item.cc | 4 ++-- src/compiler/build_tables/parse_item.cc | 4 ++-- src/compiler/rules/blank.cc | 2 +- src/compiler/rules/character_set.cc | 4 ++-- src/compiler/rules/choice.cc | 4 ++-- src/compiler/rules/metadata.cc | 2 +- src/compiler/rules/named_symbol.cc | 4 +--- src/compiler/rules/pattern.cc | 2 +- src/compiler/rules/repeat.cc | 2 +- src/compiler/rules/rule.cc | 2 +- src/compiler/rules/seq.cc | 2 +- src/compiler/rules/string.cc | 2 +- src/compiler/rules/symbol.cc | 2 +- 14 files changed, 27 insertions(+), 29 deletions(-) diff --git a/spec/compiler/helpers/stream_methods.h b/spec/compiler/helpers/stream_methods.h index 01284035..5d3fc663 100644 --- a/spec/compiler/helpers/stream_methods.h +++ b/spec/compiler/helpers/stream_methods.h @@ -14,43 +14,43 @@ namespace std { template inline std::ostream& operator<<(std::ostream &stream, const std::vector &vector) { - stream << std::string("#"; + return stream << ")"; } template inline std::ostream& operator<<(std::ostream &stream, const std::set &set) { - stream << std::string("#"; + return stream << ")"; } template inline std::ostream& operator<<(std::ostream &stream, const std::unordered_set &set) { - stream << std::string("#"; + return stream << ")"; } template inline std::ostream& operator<<(std::ostream &stream, const std::map &map) { - stream << std::string("#"; + return stream << ")"; } template inline std::ostream& operator<<(std::ostream &stream, const std::unordered_map &map) { - stream << std::string("#"; + return stream << ")"; } template diff --git a/src/compiler/build_tables/lex_item.cc b/src/compiler/build_tables/lex_item.cc index d19a0814..8db92401 100644 --- a/src/compiler/build_tables/lex_item.cc +++ b/src/compiler/build_tables/lex_item.cc @@ -39,8 +39,8 @@ bool LexItem::is_token_start() const { } ostream &operator<<(ostream &stream, const LexItem &item) { - return stream << string("#"); + return stream << string("(item ") << item.lhs << string(" ") << *item.rule + << string(")"); } } // namespace build_tables diff --git a/src/compiler/build_tables/parse_item.cc b/src/compiler/build_tables/parse_item.cc index e436bd54..4deda6fb 100644 --- a/src/compiler/build_tables/parse_item.cc +++ b/src/compiler/build_tables/parse_item.cc @@ -22,8 +22,8 @@ bool ParseItem::operator==(const ParseItem &other) const { } ostream &operator<<(ostream &stream, const ParseItem &item) { - return stream << string("#"); + return stream << string("(item ") << item.lhs << string(" ") << *item.rule + << string(")"); } } // namespace build_tables diff --git a/src/compiler/rules/blank.cc b/src/compiler/rules/blank.cc index 497ba34e..64a5d891 100644 --- a/src/compiler/rules/blank.cc +++ b/src/compiler/rules/blank.cc @@ -15,7 +15,7 @@ size_t Blank::hash_code() const { return 0; } rule_ptr Blank::copy() const { return std::make_shared(); } -std::string Blank::to_string() const { return "#"; } +std::string Blank::to_string() const { return "(blank)"; } void Blank::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/character_set.cc b/src/compiler/rules/character_set.cc index 93bbee02..602d9325 100644 --- a/src/compiler/rules/character_set.cc +++ b/src/compiler/rules/character_set.cc @@ -43,10 +43,10 @@ rule_ptr CharacterSet::copy() const { } string CharacterSet::to_string() const { - string result("#"; + return result + ")"; } CharacterSet CharacterSet::complement() const { diff --git a/src/compiler/rules/choice.cc b/src/compiler/rules/choice.cc index bc6ff0ff..1e1580be 100644 --- a/src/compiler/rules/choice.cc +++ b/src/compiler/rules/choice.cc @@ -60,10 +60,10 @@ size_t Choice::hash_code() const { rule_ptr Choice::copy() const { return std::make_shared(*this); } string Choice::to_string() const { - string result = "#to_string(); - return result + ">"; + return result + ")"; } void Choice::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/metadata.cc b/src/compiler/rules/metadata.cc index 8828607a..17f61a7b 100644 --- a/src/compiler/rules/metadata.cc +++ b/src/compiler/rules/metadata.cc @@ -37,7 +37,7 @@ int Metadata::value_for(MetadataKey key) const { } std::string Metadata::to_string() const { - return "#to_string() + ">"; + return "(metadata " + rule->to_string() + ")"; } void Metadata::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/named_symbol.cc b/src/compiler/rules/named_symbol.cc index 2281bbf6..8423fc9a 100644 --- a/src/compiler/rules/named_symbol.cc +++ b/src/compiler/rules/named_symbol.cc @@ -21,9 +21,7 @@ rule_ptr NamedSymbol::copy() const { return std::make_shared(*this); } -string NamedSymbol::to_string() const { - return string("#"; -} +string NamedSymbol::to_string() const { return string("(sym '") + name + "')"; } void NamedSymbol::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/pattern.cc b/src/compiler/rules/pattern.cc index 645fcad8..536391c9 100644 --- a/src/compiler/rules/pattern.cc +++ b/src/compiler/rules/pattern.cc @@ -21,7 +21,7 @@ size_t Pattern::hash_code() const { return hash()(value); } rule_ptr Pattern::copy() const { return std::make_shared(*this); } string Pattern::to_string() const { - return string("#"; + return string("(pattern '") + util::escape_string(value) + "')"; } void Pattern::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/repeat.cc b/src/compiler/rules/repeat.cc index bcf1807f..cf833ac6 100644 --- a/src/compiler/rules/repeat.cc +++ b/src/compiler/rules/repeat.cc @@ -19,7 +19,7 @@ size_t Repeat::hash_code() const { return content->hash_code(); } rule_ptr Repeat::copy() const { return std::make_shared(*this); } string Repeat::to_string() const { - return string("#to_string() + ">"; + return string("(repeat ") + content->to_string() + ")"; } void Repeat::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/rule.cc b/src/compiler/rules/rule.cc index 1ce1aa2e..99282985 100644 --- a/src/compiler/rules/rule.cc +++ b/src/compiler/rules/rule.cc @@ -19,7 +19,7 @@ ostream &operator<<(ostream &stream, const rule_ptr &rule) { if (rule.get()) stream << *rule; else - stream << string("#"); + stream << string("(null-rule)"); return stream; } diff --git a/src/compiler/rules/seq.cc b/src/compiler/rules/seq.cc index cc34621a..d83ee0a1 100644 --- a/src/compiler/rules/seq.cc +++ b/src/compiler/rules/seq.cc @@ -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(*this); } string Seq::to_string() const { - return string("#to_string() + " " + right->to_string() + ">"; + return string("(seq ") + left->to_string() + " " + right->to_string() + ")"; } void Seq::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/string.cc b/src/compiler/rules/string.cc index 4576a2ac..250b70cb 100644 --- a/src/compiler/rules/string.cc +++ b/src/compiler/rules/string.cc @@ -19,7 +19,7 @@ size_t String::hash_code() const { return hash()(value); } rule_ptr String::copy() const { return std::make_shared(*this); } -string String::to_string() const { return string("#"; } +string String::to_string() const { return string("(string '") + value + "')"; } void String::accept(Visitor *visitor) const { visitor->visit(this); } diff --git a/src/compiler/rules/symbol.cc b/src/compiler/rules/symbol.cc index 7a9cd462..7f155953 100644 --- a/src/compiler/rules/symbol.cc +++ b/src/compiler/rules/symbol.cc @@ -33,7 +33,7 @@ rule_ptr Symbol::copy() const { return std::make_shared(*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 {