lambda-calc-1/statement/assignment/prettyprint.c

64 lines
1.3 KiB
C

#include <debug.h>
#include <defines/N.h>
#include <stringtree/new.h>
#include <stringtree/prepend.h>
#include <stringtree/append.h>
#include <stringtree/free.h>
#include <globals/terminalcolors.h>
#include <expression/prettyprint.h>
#include "struct.h"
#include "prettyprint.h"
struct stringtree* assignment_statement_prettyprint(
int *out_chosen_color,
struct statement* super,
bool with_color)
{
ENTER;
struct assignment_statement* const this = (void*) super;
int inner_color;
struct stringtree* header = new_stringtree();
stringtree_append_string(header, this->variable_name);
stringtree_append_cstr(header, L" <- ");
struct stringtree* tree = expression_prettyprint(
&inner_color,
this->expression,
with_color);
if (with_color)
{
int my_color = (inner_color + 1) % (int) N(terminalcolors.precedences);
stringtree_prepend_cstr(header, terminalcolors.precedences[my_color]);
stringtree_append_cstr(header, terminalcolors.reset);
if (out_chosen_color)
*out_chosen_color = my_color;
}
stringtree_prepend_stringtree(tree, header);
free_stringtree(header);
EXIT;
return tree;
}