128 lines
3.1 KiB
C
128 lines
3.1 KiB
C
|
|
#include <sys/param.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <defines/N.h>
|
|
|
|
#include <stringtree/new.h>
|
|
#include <stringtree/append.h>
|
|
#include <stringtree/prepend.h>
|
|
#include <stringtree/free.h>
|
|
|
|
#include <globals/terminalcolors.h>
|
|
|
|
#include <value/prettyprint.h>
|
|
|
|
#include "struct.h"
|
|
#include "inheritance.h"
|
|
#include "prettyprint.h"
|
|
|
|
struct stringtree* builtin_lambda_value_prettyprint(
|
|
int *out_chosen_color,
|
|
struct value* super,
|
|
bool with_color)
|
|
{
|
|
ENTER;
|
|
|
|
struct stringtree* helper(
|
|
int* out,
|
|
struct builtin_lambda_value* this,
|
|
bool initial_call)
|
|
{
|
|
ENTER;
|
|
|
|
struct stringtree* tree = new_stringtree();
|
|
|
|
if (this->prev)
|
|
{
|
|
int left_color, right_color;
|
|
|
|
struct stringtree* left = helper(&left_color, this->prev, false);
|
|
|
|
struct stringtree* right = value_prettyprint(&right_color,
|
|
this->value, with_color);
|
|
|
|
stringtree_append_stringtree(tree, left);
|
|
stringtree_append_cstr(tree, L" ");
|
|
stringtree_append_stringtree(tree, right);
|
|
|
|
if (initial_call)
|
|
{
|
|
if (with_color)
|
|
{
|
|
int my_color =
|
|
(MAX(left_color, right_color) + 1)
|
|
% (int) N(terminalcolors.precedences);
|
|
|
|
stringtree_prepend_cstr(tree, terminalcolors.reset);
|
|
stringtree_prepend_cstr(tree, L"(");
|
|
stringtree_prepend_cstr(tree, terminalcolors.precedences[my_color]);
|
|
|
|
stringtree_append_cstr(tree, terminalcolors.precedences[my_color]);
|
|
stringtree_append_cstr(tree, L")");
|
|
stringtree_append_cstr(tree, terminalcolors.reset);
|
|
|
|
if (out)
|
|
{
|
|
*out = my_color;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stringtree_prepend_cstr(tree, L"(");
|
|
stringtree_append_cstr(tree, L")");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (with_color && out)
|
|
{
|
|
*out = MAX(left_color, right_color);
|
|
}
|
|
}
|
|
|
|
free_stringtree(left);
|
|
|
|
free_stringtree(right);
|
|
}
|
|
else
|
|
{
|
|
stringtree_append_string(tree, this->name);
|
|
|
|
if (with_color)
|
|
{
|
|
stringtree_prepend_cstr(tree, terminalcolors.variable);
|
|
|
|
stringtree_append_cstr(tree, terminalcolors.reset);
|
|
|
|
if (out)
|
|
*out = -1;
|
|
}
|
|
}
|
|
|
|
EXIT;
|
|
return tree;
|
|
}
|
|
|
|
struct builtin_lambda_value* this = (void*) super;
|
|
|
|
struct stringtree* tree = helper(
|
|
/* out color: */ out_chosen_color,
|
|
/* this: */ this,
|
|
/* initial call?: */ true);
|
|
|
|
EXIT;
|
|
return tree;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|