lisp-take-1/value/list/prettyprint.c

62 lines
1.1 KiB
C

#include <assert.h>
#include <debug.h>
#include <stringtree/new.h>
#include <stringtree/append.h>
#include <stringtree/free.h>
#include "../struct.h"
#include "../prettyprint.h"
#include "struct.h"
#include "prettyprint.h"
struct stringtree* list_value_prettyprint(
const struct value* super)
{
ENTER;
assert(super->kind == vk_list);
// const struct list_value* this = &super->subclass.list;
struct stringtree* tree = new_stringtree();
stringtree_append_string_const(tree, "(");
bool first = true;
for (const struct value* link = super;
link && link->kind == vk_list;
link = link->subclass.list.rest)
{
struct stringtree* element = value_prettyprint(
/* element: */ link->subclass.list.first);
if (first)
first = false;
else
stringtree_append_string_const(tree, " ");
stringtree_append_stringtree(tree, element);
free_stringtree(element);
}
stringtree_append_string_const(tree, ")");
EXIT;
return tree;
}