* In toString, deal with nested lists properly (i.e., flatten them).

This commit is contained in:
Eelco Dolstra 2006-08-28 21:47:42 +00:00
parent 1fca76870b
commit 1ec9f55741

View file

@ -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, void toString(EvalState & state, Expr e,
ATermList & context, string & result) ATermList & context, string & result)
{ {
@ -135,6 +155,7 @@ void toString(EvalState & state, Expr e,
} }
else if (matchList(e, es)) { else if (matchList(e, es)) {
es = flattenList(state, e);
bool first = true; bool first = true;
for (ATermIterator i(es); i; ++i) { for (ATermIterator i(es); i; ++i) {
if (!first) result += " "; else first = false; if (!first) result += " "; else first = false;