about summary refs log tree commit diff stats
path: root/010vm.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-20 08:39:10 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-20 08:39:10 -0800
commitd75103c0c4fb52f09411b79843ab42586c6835ea (patch)
tree364d794d3efd862d664cbfb14bfd6971f3cdc880 /010vm.cc
parent96db34759717072fa600f2c4f4e27b2aa808859c (diff)
downloadmu-d75103c0c4fb52f09411b79843ab42586c6835ea.tar.gz
2675 - undo 2674
Diffstat (limited to '010vm.cc')
-rw-r--r--010vm.cc40
1 files changed, 19 insertions, 21 deletions
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<string, string_tree*>(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;
 }