lambda-calculus/expression/application/prettyprint.c
2025-01-13 20:36:07 -06:00

72 lines
1.2 KiB
C

#include <sys/param.h>
#include <debug.h>
/*#include <color_factory/struct.h>*/
#include <stringtree/new.h>
#include <stringtree/prepend.h>
#include <stringtree/append.h>
#include <stringtree/free.h>
#include <expression/prettyprint.h>
#include "struct.h"
#include "prettyprint.h"
struct stringtree* application_expression_prettyprint(
int *out_chosen_color,
struct expression* super,
struct color_factory* cfactory,
bool with_color)
{
ENTER;
struct application_expression* const this = (void*) super;
int left_color, right_color;
struct stringtree* left = expression_prettyprint(
&left_color,
this->left,
cfactory,
with_color);
struct stringtree* right = expression_prettyprint(
&right_color,
this->right,
cfactory,
with_color);
if (with_color && out_chosen_color)
{
*out_chosen_color = MAX(left_color, right_color);
}
struct stringtree* tree = new_stringtree();
stringtree_append_stringtree(tree, left);
stringtree_append_cstr(tree, L" ");
stringtree_append_stringtree(tree, right);
free_stringtree(left);
free_stringtree(right);
EXIT;
return tree;
}