From d75103c0c4fb52f09411b79843ab42586c6835ea Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 20 Feb 2016 08:39:10 -0800 Subject: 2675 - undo 2674 --- 010vm.cc | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to '010vm.cc') diff --git a/010vm.cc b/010vm.cc index af4bd1b2..f4f3cb11 100644 --- a/010vm.cc +++ b/010vm.cc @@ -87,16 +87,17 @@ struct type_tree { }; struct string_tree { - bool is_leaf; - string value; // only if is_leaf is true - string_tree* left; // only if is_leaf is false - string_tree* right; // only if is_leaf is false + string value; + string_tree* left; + string_tree* right; ~string_tree(); string_tree(const string_tree& old); // simple: flat string - explicit string_tree(string v) :is_leaf(true), value(v), left(NULL), right(NULL) {} + explicit string_tree(string v) :value(v), left(NULL), right(NULL) {} + // intermediate: list of strings + string_tree(string v, string_tree* r) :value(v), left(NULL), right(r) {} // advanced: tree containing strings - string_tree(string_tree* l, string_tree* r) :is_leaf(false), value(""), left(l), right(r) {} + string_tree(string_tree* l, string_tree* r) :left(l), right(r) {} }; :(before "End Globals") @@ -236,7 +237,6 @@ reagent::reagent(string s) :original_string(s), value(0), initialized(false), ty row >> std::noskipws; string key = slurp_until(row, ':'); string_tree* value = parse_property_list(row); - cerr << "bb: " << to_string(value) << '\n'; properties.push_back(pair(key, value)); } // structures for the first row of properties: name and list of types @@ -258,14 +258,9 @@ reagent::reagent(string s) :original_string(s), value(0), initialized(false), ty string_tree* parse_property_list(istream& in) { skip_whitespace_but_not_newline(in); if (!has_data(in)) return NULL; - string next = slurp_until(in, ':'); - if (!has_data(in)) { - string_tree* result = new string_tree(next); - cerr << "aa: " << to_string(result) << '\n'; - return result; - } - return new string_tree(new string_tree(next), - parse_property_list(in)); + string_tree* result = new string_tree(slurp_until(in, ':')); + result->right = parse_property_list(in); + return result; } type_tree* new_type_tree(const string_tree* properties) { @@ -476,7 +471,7 @@ string inspect(const string_tree* x) { } void dump_inspect(const string_tree* x, ostream& out) { - if (x->is_leaf) { + if (!x->left && !x->right) { out << x->value; return; } @@ -494,14 +489,17 @@ void dump_inspect(const string_tree* x, ostream& out) { string to_string(const string_tree* property) { if (!property) return "()"; ostringstream out; - cerr << "AAA " << property->is_leaf << " " << property->value << '\n'; - dump(property, out); + if (!property->left && !property->right) + // abbreviate a single-node tree to just its contents + out << '"' << property->value << '"'; + else + dump(property, out); return out.str(); } void dump(const string_tree* x, ostream& out) { - if (x->is_leaf) { - out << '"' + x->value + '"'; + if (!x->left && !x->right) { + out << x->value; return; } out << '('; @@ -542,7 +540,7 @@ void dump(const type_tree* type, ostream& out) { void dump(type_ordinal type, ostream& out) { if (contains_key(Type, type)) - out << get(Type, type).name << '(' << type << ") "; + out << get(Type, type).name; else out << "?" << type; } -- cgit 1.4.1-2-gfad0