about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--017parse_tree.cc9
-rw-r--r--html/017parse_tree.cc.html9
2 files changed, 16 insertions, 2 deletions
diff --git a/017parse_tree.cc b/017parse_tree.cc
index eb1fb85d..50499a7c 100644
--- a/017parse_tree.cc
+++ b/017parse_tree.cc
@@ -79,10 +79,11 @@ string_tree* parse_string_tree(istream& in) {
   }
   in.get();  // skip ')'
   assert(*curr == NULL);
+  if (result->right == NULL) return result;
   // standardize the final element to always be on the right if it's an atom
   // (a b c) => (a b . c) in s-expression parlance
   string_tree* tmp = result;
-  while (tmp->right && tmp->right->right) tmp = tmp->right;
+  while (tmp->right->right) tmp = tmp->right;
   assert(!tmp->right->atom);
   if (!tmp->right->left->atom) return result;
   string_tree* tmp2 = tmp->right;
@@ -104,3 +105,9 @@ container foo [
 container bar [
 ]
 +parse:   product: {1: ("foo" ("address" "array" "character") ("bar" "number"))}
+
+:(scenario dilated_singleton_tree)
+def main [
+  {1: number, foo: (bar)} <- copy 34
+]
++parse:   product: {1: "number", "foo": ("bar")}
diff --git a/html/017parse_tree.cc.html b/html/017parse_tree.cc.html
index 98f55374..f700033e 100644
--- a/html/017parse_tree.cc.html
+++ b/html/017parse_tree.cc.html
@@ -115,10 +115,11 @@ string_tree* parse_string_tree<span class="Delimiter">(</span>istream&amp; in<sp
   <span class="Delimiter">}</span>
   in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>  <span class="Comment">// skip ')'</span>
   assert<span class="Delimiter">(</span>*curr == <span class="Constant">NULL</span><span class="Delimiter">);</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">-&gt;</span>right == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span>
   <span class="Comment">// standardize the final element to always be on the right if it's an atom</span>
   <span class="Comment">// (a b c) =&gt; (a b . c) in s-expression parlance</span>
   string_tree* tmp = result<span class="Delimiter">;</span>
-  <span class="Normal">while</span> <span class="Delimiter">(</span>tmp<span class="Delimiter">-&gt;</span>right &amp;&amp; tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span> tmp = tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>
+  <span class="Normal">while</span> <span class="Delimiter">(</span>tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span> tmp = tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>
   assert<span class="Delimiter">(</span>!tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">);</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>!tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span>
   string_tree* tmp2 = tmp<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>
@@ -140,6 +141,12 @@ string_tree* parse_string_tree<span class="Delimiter">(</span>istream&amp; in<sp
 <span class="muData">container</span> bar [
 ]
 <span class="traceContains">+parse:   product: {1: (&quot;foo&quot; (&quot;address&quot; &quot;array&quot; &quot;character&quot;) (&quot;bar&quot; &quot;number&quot;))}</span>
+
+<span class="Delimiter">:(scenario dilated_singleton_tree)</span>
+<span class="muRecipe">def</span> main [
+  <span class="Delimiter">{</span><span class="Constant">1</span>: number<span class="Delimiter">,</span> foo: <span class="Delimiter">(</span>bar<span class="Delimiter">)}</span><span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
+]
+<span class="traceContains">+parse:   product: {1: &quot;number&quot;, &quot;foo&quot;: (&quot;bar&quot;)}</span>
 </pre>
 </body>
 </html>