about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-28T21·47+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-28T21·47+0000
commit1ec9f55741ae54f5e618e248ee49aff132017247 (patch)
tree8de1c8a0c1b6ae62065e4b4a37208a7cd6ff361e
parent1fca76870b7a96d1eb33abb8ad4e4cc5ba656253 (diff)
* In toString, deal with nested lists properly (i.e., flatten them).
-rw-r--r--src/libexpr/primops.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index b9f625e8bcbd..5496e945e31b 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -69,6 +69,26 @@ static Expr primImport(EvalState & state, const ATermVector & args)
 }
 
 
+static void flattenList(EvalState & state, Expr e, ATermList & result)
+{
+    ATermList es;
+    e = evalExpr(state, e);
+    if (matchList(e, es))
+        for (ATermIterator i(es); i; ++i)
+            flattenList(state, *i, result);
+    else
+        result = ATinsert(result, e);
+}
+
+
+ATermList flattenList(EvalState & state, Expr e)
+{
+    ATermList result = ATempty;
+    flattenList(state, e, result);
+    return ATreverse(result);
+}
+
+
 void toString(EvalState & state, Expr e,
     ATermList & context, string & result)
 {
@@ -135,6 +155,7 @@ void toString(EvalState & state, Expr e,
     }
     
     else if (matchList(e, es)) {
+        es = flattenList(state, e);
         bool first = true;
         for (ATermIterator i(es); i; ++i) {
             if (!first) result += " "; else first = false;