lang: ast: add stub functions for retrieving, printing, interating, and destroying ast nodes

This commit is contained in:
2024-11-24 16:12:31 +00:00
parent f524899da4
commit fbef0b6743
3 changed files with 53 additions and 0 deletions

View File

@@ -112,3 +112,35 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
free(state);
}
bool ivy_parser_is_node_complete(struct ivy_parser *parser)
{
return (parser->p_state.q_first == parser->p_state.q_last);
}
struct ivy_ast_node *ivy_parser_root_node(struct ivy_parser *parser)
{
b_queue_entry *entry = b_queue_first(&parser->p_state);
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
return state->s_node;
}
struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
{
b_queue_entry *entry = b_queue_first(&parser->p_state);
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
if (state->s_node->n_type != IVY_AST_UNIT) {
return NULL;
}
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)state->s_node;
entry = b_queue_pop_front(&unit->n_children);
if (!entry) {
return NULL;
}
return b_unbox(struct ivy_ast_node, entry, n_entry);
}