Files
ivy/lang/ast/string.c
T

36 lines
1003 B
C
Raw Normal View History

#include "iterate.h"
#include "node.h"
2026-03-16 14:07:33 +00:00
#include <fx/ds/string.h>
2026-03-16 14:07:33 +00:00
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_string_node *s = (struct ivy_ast_string_node *)node;
2026-03-16 14:07:33 +00:00
fx_string_append_cstrf(
str, "%s (\"%s\")", ivy_ast_node_type_to_string(node->n_type),
s->n_value->t_str);
}
2024-12-06 13:46:58 +00:00
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;
2026-03-16 14:07:33 +00:00
fx_queue_entry *entry = fx_queue_first(&str->n_value);
2025-11-06 10:38:32 +00:00
while (entry) {
2024-12-06 13:46:58 +00:00
struct ivy_ast_node *child
2026-03-16 14:07:33 +00:00
= fx_unbox(struct ivy_ast_node, entry, n_entry);
2024-12-06 13:46:58 +00:00
ast_node_iterator_enqueue_node(iterator, node, child);
2026-03-16 14:07:33 +00:00
entry = fx_queue_next(entry);
2024-12-06 13:46:58 +00:00
}
}
struct ast_node_type string_node_ops = {
.n_to_string = to_string,
2024-11-29 12:06:06 +00:00
.n_node_size = sizeof(struct ivy_ast_string_node),
};
2024-12-06 13:46:58 +00:00
struct ast_node_type fstring_node_ops = {
.n_collect_children = collect_children,
.n_node_size = sizeof(struct ivy_ast_fstring_node),
};