Files
ivy/lang/ast/string.c
T

36 lines
1003 B
C

#include "iterate.h"
#include "node.h"
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_string_node *s = (struct ivy_ast_string_node *)node;
fx_string_append_cstrf(
str, "%s (\"%s\")", ivy_ast_node_type_to_string(node->n_type),
s->n_value->t_str);
}
static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_fstring_node *str = (struct ivy_ast_fstring_node *)node;
fx_queue_entry *entry = fx_queue_first(&str->n_value);
while (entry) {
struct ivy_ast_node *child
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, child);
entry = fx_queue_next(entry);
}
}
struct ast_node_type string_node_ops = {
.n_to_string = to_string,
.n_node_size = sizeof(struct ivy_ast_string_node),
};
struct ast_node_type fstring_node_ops = {
.n_collect_children = collect_children,
.n_node_size = sizeof(struct ivy_ast_fstring_node),
};