about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-27 16:34:58 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-27 16:37:57 -0700
commit6808ff7d6df42aa8a8abe63041254b40b76ba8db (patch)
tree1c5db69f17e3da1fb1241c24a3a288a42b3fc35c
parent9e30dba08d6475e9c26f95630b9595bea73fb705 (diff)
downloadmu-6808ff7d6df42aa8a8abe63041254b40b76ba8db.tar.gz
2293
-rw-r--r--010vm.cc20
-rw-r--r--011load.cc6
-rw-r--r--013literal_string.cc2
-rw-r--r--030container.cc2
-rw-r--r--032array.cc2
-rw-r--r--055parse_tree.cc33
6 files changed, 43 insertions, 22 deletions
diff --git a/010vm.cc b/010vm.cc
index da5725fe..47a2d01c 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -353,18 +353,23 @@ void dump_property(const string_tree* property, ostream& out) {
     out << "<>";
     return;
   }
+  // abbreviate a single-node tree to just its contents
   if (!property->left && !property->right) {
     out << '"' << property->value << '"';
     return;
   }
+  dump_property_tree(property, out);
+}
+
+void dump_property_tree(const string_tree* property, ostream& out) {
   out << "<";
   if (property->left)
-    dump_property(property->left, out);
+    dump_property_tree(property->left, out);
   else
     out << '"' << property->value << '"';
   out << " : ";
   if (property->right)
-    dump_property(property->right, out);
+    dump_property_tree(property->right, out);
   else
     out << "<>";
   out << ">";
@@ -377,20 +382,25 @@ string dump_types(const reagent& x) {
 }
 
 void dump_types(type_tree* type, ostream& out) {
+  // abbreviate a single-node tree to just its contents
   if (!type->left && !type->right) {
     out << Type[type->value].name;
     return;
   }
+  dump_types_tree(type, out);
+}
+
+void dump_types_tree(type_tree* type, ostream& out) {
   out << "<";
   if (type->left)
-    dump_types(type->left, out);
+    dump_types_tree(type->left, out);
   else
     out << Type[type->value].name;
   out << " : ";
   if (type->right)
-    dump_types(type->right, out);
+    dump_types_tree(type->right, out);
   else
-    out << " : <>";
+    out << "<>";
   out << ">";
 }
 
diff --git a/011load.cc b/011load.cc
index 47829b04..7c7bded0 100644
--- a/011load.cc
+++ b/011load.cc
@@ -320,7 +320,7 @@ recipe main [
   1:number <- copy 23/foo:bar:baz
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal", "foo": <"bar" : "baz">}
++parse:   ingredient: {"23": "literal", "foo": <"bar" : <"baz" : <>>>}
 +parse:   product: {"1": "number"}
 
 :(scenario parse_multiple_products)
@@ -350,13 +350,13 @@ recipe main [
 +parse:   ingredient: {"23": "literal"}
 +parse:   ingredient: {"4": "number"}
 +parse:   product: {"1": "number"}
-+parse:   product: {"2": <"address" : "number">}
++parse:   product: {"2": <"address" : <"number" : <>>>}
 
 :(scenario parse_properties)
 recipe main [
   1:number:address/lookup <- copy 23
 ]
-+parse:   product: {"1": <"number" : "address">, "lookup": <>}
++parse:   product: {"1": <"number" : <"address" : <>>>, "lookup": <>}
 
 //: this test we can't represent with a scenario
 :(code)
diff --git a/013literal_string.cc b/013literal_string.cc
index 3bbd4940..032eb438 100644
--- a/013literal_string.cc
+++ b/013literal_string.cc
@@ -171,7 +171,7 @@ recipe main [
 ]
 +parse: instruction: copy
 +parse:   ingredient: {"abc": "literal-string"}
-+parse:   product: {"1": <"address" : <"array" : "character">>}
++parse:   product: {"1": <"address" : <"array" : <"character" : <>>>>}
 # no other ingredients
 $parse: 3
 
diff --git a/030container.cc b/030container.cc
index da12ef8d..de83c739 100644
--- a/030container.cc
+++ b/030container.cc
@@ -337,7 +337,7 @@ recipe main [
   14:number <- copy 36
   15:number <- get-address 12:point-number/raw, 1:offset
 ]
-+error: main: 'get-address' 1:offset (1) on point-number can't be saved in 15:number; type should be <address : number>
++error: main: 'get-address' 1:offset (1) on point-number can't be saved in 15:number; type should be <address : <number : <>>>
 
 //:: Allow containers to be defined in mu code.
 
diff --git a/032array.cc b/032array.cc
index b544df38..32a8f544 100644
--- a/032array.cc
+++ b/032array.cc
@@ -360,7 +360,7 @@ recipe main [
   8:address:array:point <- copy 1/raw
   9:address:number <- index-address *8:address:array:point, 0
 ]
-+error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be <address : point>
++error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be <address : <point : <>>>
 
 //:: compute the length of an array
 
diff --git a/055parse_tree.cc b/055parse_tree.cc
index 3c6c2302..16b5309a 100644
--- a/055parse_tree.cc
+++ b/055parse_tree.cc
@@ -30,18 +30,29 @@ string_tree* parse_string_tree(istream& in) {
     return NULL;
   }
   if (in.peek() != '(') {
-    return new string_tree(next_word(in));
+    string_tree* result = new string_tree(next_word(in));
+    return result;
   }
   in.get();  // skip '('
-  if (in.peek() == '(') {
-    string_tree* left = parse_string_tree(in);
-    string_tree* right = parse_string_tree(in);
-    return new string_tree(left, right);
-  }
-  else {
-    string value = next_word(in);
-    string_tree* right = parse_string_tree(in);
-    string_tree* rest = parse_string_tree(in);
-    return new string_tree(value, new string_tree(right, rest));
+  string_tree* result = NULL;
+  string_tree** curr = &result;
+  while (in.peek() != ')') {
+    assert(!in.eof());
+    *curr = new string_tree("");
+    skip_whitespace(in);
+    skip_ignored_characters(in);
+    if (in.peek() == '(')
+      (*curr)->left = parse_string_tree(in);
+    else
+      (*curr)->value = next_word(in);
+    curr = &(*curr)->right;
   }
+  in.get();  // skip ')'
+  return result;
 }
+
+:(scenario dilated_reagent_with_type_tree)
+recipe main [
+  {1: (map (address array character) (list number))} <- copy 34
+]
++parse:   product: {"1": <"map" : <<"address" : <"array" : <"character" : <>>>> : <<"list" : <"number" : <>>> : <>>>>}