lang: update bluelib api usage

This commit is contained in:
2025-11-06 10:38:32 +00:00
parent b26c37c349
commit 4386965cd9
40 changed files with 351 additions and 271 deletions

View File

@@ -4,8 +4,8 @@
#include "iterate.h"
#include "node.h"
#include <blue/ds/string.h>
#include <ivy/lang/lex.h>
#include <blue/object/string.h>
enum package_type {
PACKAGE_NONE = 0,
@@ -34,9 +34,13 @@ struct package_parser_state {
struct ivy_ast_node *s_cond;
};
static enum ivy_status add_package_item(struct package_parser_state *state, struct ivy_ast_node *index, struct ivy_ast_node *value)
static enum ivy_status add_package_item(
struct package_parser_state *state, struct ivy_ast_node *index,
struct ivy_ast_node *value)
{
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)ast_node_create(IVY_AST_PKG_ITEM);
struct ivy_ast_pkg_static_item_node *item
= (struct ivy_ast_pkg_static_item_node *)ast_node_create(
IVY_AST_PKG_ITEM);
if (!item) {
return IVY_ERR_NO_MEMORY;
}
@@ -64,7 +68,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
switch (state->s_type) {
case PACKAGE_STATIC:
s = (struct ivy_ast_pkg_static_node *)ast_node_create(IVY_AST_PKG_STATIC);
s = (struct ivy_ast_pkg_static_node *)ast_node_create(
IVY_AST_PKG_STATIC);
if (!s) {
return NULL;
@@ -74,7 +79,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
state->s_items = B_QUEUE_INIT;
return (struct ivy_ast_node *)s;
case PACKAGE_DYNAMIC:
d = (struct ivy_ast_pkg_dynamic_node *)ast_node_create(IVY_AST_PKG_DYNAMIC);
d = (struct ivy_ast_pkg_dynamic_node *)ast_node_create(
IVY_AST_PKG_DYNAMIC);
if (!d) {
return NULL;
}
@@ -98,7 +104,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
static struct token_parse_result parse_equal_right_angle(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type == PACKAGE_NONE) {
state->s_type = PACKAGE_STATIC;
@@ -123,7 +130,9 @@ static struct token_parse_result parse_equal_right_angle(
state->s_next_index = state->s_prev_node;
state->s_prev_node = NULL;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_SYM_COMMA);
expr->s_subexpr_depth = 1;
@@ -133,7 +142,8 @@ static struct token_parse_result parse_equal_right_angle(
static struct token_parse_result parse_comma(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type == PACKAGE_NONE) {
state->s_type = PACKAGE_STATIC;
@@ -144,7 +154,8 @@ static struct token_parse_result parse_comma(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA && state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA
&& state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
/* token unexpected at this time. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
@@ -154,14 +165,17 @@ static struct token_parse_result parse_comma(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
enum ivy_status status = add_package_item(state, state->s_next_index, state->s_prev_node);
enum ivy_status status = add_package_item(
state, state->s_next_index, state->s_prev_node);
if (status != IVY_OK) {
return PARSE_RESULT(status, 0);
}
state->s_prev = IVY_SYM_COMMA;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_SYM_EQUAL_RIGHT_ANGLE);
expr->s_subexpr_depth = 1;
@@ -171,7 +185,8 @@ static struct token_parse_result parse_comma(
static struct token_parse_result parse_right_brace(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type == PACKAGE_NONE) {
state->s_type = PACKAGE_STATIC;
@@ -181,13 +196,15 @@ static struct token_parse_result parse_right_brace(
switch (state->s_type) {
case PACKAGE_STATIC:
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA && state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA
&& state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
/* token unexpected at this time. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (state->s_prev_node) {
status = add_package_item(state, state->s_next_index, state->s_prev_node);
status = add_package_item(
state, state->s_next_index, state->s_prev_node);
}
break;
@@ -235,7 +252,8 @@ static struct token_parse_result parse_right_brace(
static struct token_parse_result parse_for(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type == PACKAGE_NONE) {
state->s_type = PACKAGE_DYNAMIC;
@@ -260,7 +278,9 @@ static struct token_parse_result parse_for(
state->s_transform = state->s_prev_node;
state->s_prev_node = NULL;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_KW_IN);
expr->s_subexpr_depth = 1;
@@ -270,7 +290,8 @@ static struct token_parse_result parse_for(
static struct token_parse_result parse_in(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type != PACKAGE_DYNAMIC) {
/* this token cannot be used in this context. */
@@ -291,7 +312,9 @@ static struct token_parse_result parse_in(
state->s_item = state->s_prev_node;
state->s_prev_node = NULL;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_KW_IF);
expr->s_subexpr_depth = 1;
@@ -301,7 +324,8 @@ static struct token_parse_result parse_in(
static struct token_parse_result parse_if(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
struct package_parser_state *state
= parser_get_state(ctx, struct package_parser_state);
if (state->s_type != PACKAGE_DYNAMIC) {
/* this token cannot be used in this context. */
@@ -322,7 +346,9 @@ static struct token_parse_result parse_if(
state->s_source = state->s_prev_node;
state->s_prev_node = NULL;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_SYM_RIGHT_BRACE);
expr->s_subexpr_depth = 1;
@@ -332,8 +358,7 @@ static struct token_parse_result parse_if(
static enum ivy_status add_child(
struct parser_state *parent, struct ivy_ast_node *child)
{
struct package_parser_state *state
= (struct package_parser_state *)parent;
struct package_parser_state *state = (struct package_parser_state *)parent;
if (state->s_prev_node) {
return IVY_ERR_BAD_SYNTAX;
@@ -346,19 +371,22 @@ static enum ivy_status add_child(
static void pkg_static_collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_pkg_static_node *pkg = (struct ivy_ast_pkg_static_node *)node;
b_queue_iterator it = {0};
b_queue_foreach (&it, &pkg->n_items) {
struct ivy_ast_node *item = b_unbox(struct ivy_ast_node, it.entry, n_entry);
struct ivy_ast_pkg_static_node *pkg
= (struct ivy_ast_pkg_static_node *)node;
b_queue_entry *entry = b_queue_first(&pkg->n_items);
while (entry) {
struct ivy_ast_node *item
= b_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, item);
entry = b_queue_next(entry);
}
}
static void pkg_static_item_to_string(struct ivy_ast_node *node, b_string *str)
{
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)node;
struct ivy_ast_pkg_static_item_node *item
= (struct ivy_ast_pkg_static_item_node *)node;
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
@@ -370,7 +398,8 @@ static void pkg_static_item_to_string(struct ivy_ast_node *node, b_string *str)
static void pkg_static_item_collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)node;
struct ivy_ast_pkg_static_item_node *item
= (struct ivy_ast_pkg_static_item_node *)node;
if (item->n_index) {
ast_node_iterator_enqueue_node(iterator, node, item->n_index);
@@ -384,7 +413,8 @@ static void pkg_static_item_collect_children(
static void pkg_dynamic_collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_pkg_dynamic_node *pkg = (struct ivy_ast_pkg_dynamic_node *)node;
struct ivy_ast_pkg_dynamic_node *pkg
= (struct ivy_ast_pkg_dynamic_node *)node;
if (pkg->n_transform) {
ast_node_iterator_enqueue_node(iterator, node, pkg->n_transform);
@@ -410,7 +440,9 @@ static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_
state->s_prev = IVY_SYM_LEFT_BRACE;
state->s_next_implicit_index = 0;
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
struct expr_parser_state *expr
= (struct expr_parser_state *)parser_push_state(
ctx, IVY_AST_EXPR, 0);
expr_add_terminator(expr, IVY_KW_FOR);
expr->s_subexpr_depth = 1;
}