lang: ast: add stub functions for retrieving, printing, interating, and destroying ast nodes
This commit is contained in:
@@ -112,3 +112,35 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
|
|||||||
|
|
||||||
free(state);
|
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);
|
||||||
|
}
|
||||||
@@ -78,3 +78,11 @@ enum ivy_status ast_node_add_child(
|
|||||||
|
|
||||||
return add_child(parent, child);
|
return add_child(parent, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ivy_ast_node_print(struct ivy_ast_node *node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -59,9 +59,17 @@ enum ivy_ast_msgh_recipient_type {
|
|||||||
IVY_AST_MSGH_CLASS,
|
IVY_AST_MSGH_CLASS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ivy_ast_node_iterable {
|
||||||
|
b_queue_entry it_entry;
|
||||||
|
unsigned int it_depth;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum ivy_status(*ivy_ast_node_iteration_callback)(struct ivy_ast_node *, unsigned int);
|
||||||
|
|
||||||
struct ivy_ast_node {
|
struct ivy_ast_node {
|
||||||
enum ivy_ast_node_type n_type;
|
enum ivy_ast_node_type n_type;
|
||||||
b_queue_entry n_entry;
|
b_queue_entry n_entry;
|
||||||
|
struct ivy_ast_node_iterable n_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ivy_ast_unit_node {
|
struct ivy_ast_unit_node {
|
||||||
@@ -230,10 +238,15 @@ IVY_API enum ivy_status ivy_parser_create(struct ivy_parser **parser);
|
|||||||
IVY_API void ivy_parser_destroy(struct ivy_parser *parser);
|
IVY_API void ivy_parser_destroy(struct ivy_parser *parser);
|
||||||
|
|
||||||
IVY_API enum ivy_status ivy_parser_get_status(struct ivy_parser *parser);
|
IVY_API enum ivy_status ivy_parser_get_status(struct ivy_parser *parser);
|
||||||
|
IVY_API bool ivy_parser_is_node_complete(struct ivy_parser *parser);
|
||||||
|
IVY_API struct ivy_ast_node *ivy_parser_root_node(struct ivy_parser *parser);
|
||||||
|
IVY_API struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser);
|
||||||
|
|
||||||
IVY_API enum ivy_status ivy_parser_push_token(
|
IVY_API enum ivy_status ivy_parser_push_token(
|
||||||
struct ivy_parser *parser, struct ivy_token *tok);
|
struct ivy_parser *parser, struct ivy_token *tok);
|
||||||
|
|
||||||
|
IVY_API void ivy_ast_node_iterate(struct ivy_ast_node *node);
|
||||||
|
IVY_API void ivy_ast_node_print(struct ivy_ast_node *node);
|
||||||
IVY_API void ivy_ast_node_destroy(struct ivy_ast_node *node);
|
IVY_API void ivy_ast_node_destroy(struct ivy_ast_node *node);
|
||||||
|
|
||||||
IVY_API const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v);
|
IVY_API const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v);
|
||||||
|
|||||||
Reference in New Issue
Block a user