lang: ast: implement ast iteration
iteration is implementing without recursion, instead using type-specific callbacks to construct a queue of nodes to iterate through. ast priting is implemented using this functionality.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <blue/object/string.h>
|
||||
#include <stdio.h>
|
||||
#include "unit-package.h"
|
||||
|
||||
#include "ctx.h"
|
||||
@@ -54,6 +56,22 @@ static enum ivy_status add_child(
|
||||
|
||||
static void print(struct ivy_ast_node *node)
|
||||
{
|
||||
struct ivy_ast_unit_package_node *unit_package = (struct ivy_ast_unit_package_node *)node;
|
||||
b_string *str = b_string_create();
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &unit_package->n_ident) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
|
||||
if (b_string_get_size(str, B_STRLEN_NORMAL) > 0) {
|
||||
b_string_append_cstr(str, ".");
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, tok->t_str);
|
||||
}
|
||||
|
||||
printf("%s(%s)\n", ivy_ast_node_type_to_string(node->n_type), b_string_ptr(str));
|
||||
b_string_release(str);
|
||||
}
|
||||
|
||||
static void init_state(struct parser_state *sp)
|
||||
|
||||
Reference in New Issue
Block a user