lang: ast: fix some source formatting

This commit is contained in:
2025-09-08 16:01:02 +01:00
parent d95a544ff2
commit 6e65349d70
2 changed files with 20 additions and 10 deletions

View File

@@ -637,9 +637,11 @@ struct token_parse_result arith_parse_do(
struct block_parser_state *block struct block_parser_state *block
= (struct block_parser_state *)parser_push_state( = (struct block_parser_state *)parser_push_state(
ctx, IVY_AST_BLOCK, 0); ctx, IVY_AST_BLOCK, 0);
/* set the sub-expression depth to be non-zero so the expression parser doesn't consume the expression separator. */ /* set the sub-expression depth to be non-zero so the expression parser
* doesn't consume the expression separator. */
state->s_prev_token = IVY_KW_DO; state->s_prev_token = IVY_KW_DO;
return PARSE_RESULT(IVY_OK, 0); return PARSE_RESULT(IVY_OK, 0);
} }

View File

@@ -19,7 +19,8 @@ struct tuple_parser_state {
static void finalise_tuple(struct tuple_parser_state *state) static void finalise_tuple(struct tuple_parser_state *state)
{ {
struct ivy_ast_tuple_node *tuple = (struct ivy_ast_tuple_node *)state->s_base.s_node; struct ivy_ast_tuple_node *tuple
= (struct ivy_ast_tuple_node *)state->s_base.s_node;
tuple->n_members = state->s_items; tuple->n_members = state->s_items;
state->s_items = B_QUEUE_INIT; state->s_items = B_QUEUE_INIT;
@@ -27,7 +28,8 @@ static void finalise_tuple(struct tuple_parser_state *state)
struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *tok) struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *tok)
{ {
struct tuple_parser_state *state = parser_get_state(ctx, struct tuple_parser_state); struct tuple_parser_state *state
= parser_get_state(ctx, struct tuple_parser_state);
if (state->s_prev != IVY_SYM_LEFT_PAREN && state->s_prev != IVY_SYM_COMMA) { if (state->s_prev != IVY_SYM_LEFT_PAREN && state->s_prev != IVY_SYM_COMMA) {
/* token not expected at this time. */ /* token not expected at this time. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
@@ -42,7 +44,9 @@ struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *
state->s_prev_node = NULL; state->s_prev_node = NULL;
state->s_prev = IVY_SYM_COMMA; 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_COMMA); expr_add_terminator(expr, IVY_SYM_COMMA);
expr_add_terminator(expr, IVY_SYM_RIGHT_PAREN); expr_add_terminator(expr, IVY_SYM_RIGHT_PAREN);
expr->s_subexpr_depth = 1; expr->s_subexpr_depth = 1;
@@ -50,9 +54,11 @@ struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *
return PARSE_RESULT(IVY_OK, 0); return PARSE_RESULT(IVY_OK, 0);
} }
struct token_parse_result parse_right_paren(struct ivy_parser *ctx, struct ivy_token *tok) struct token_parse_result parse_right_paren(
struct ivy_parser *ctx, struct ivy_token *tok)
{ {
struct tuple_parser_state *state = parser_get_state(ctx, struct tuple_parser_state); struct tuple_parser_state *state
= parser_get_state(ctx, struct tuple_parser_state);
if (state->s_prev != IVY_SYM_COMMA) { if (state->s_prev != IVY_SYM_COMMA) {
/* token not expected at this time. */ /* token not expected at this time. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
@@ -76,8 +82,7 @@ struct token_parse_result parse_right_paren(struct ivy_parser *ctx, struct ivy_t
static enum ivy_status add_child( static enum ivy_status add_child(
struct parser_state *parent, struct ivy_ast_node *child) struct parser_state *parent, struct ivy_ast_node *child)
{ {
struct tuple_parser_state *state struct tuple_parser_state *state = (struct tuple_parser_state *)parent;
= (struct tuple_parser_state *)parent;
if (state->s_prev_node) { if (state->s_prev_node) {
return IVY_ERR_BAD_SYNTAX; return IVY_ERR_BAD_SYNTAX;
@@ -99,7 +104,9 @@ static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_
state->s_prev = IVY_SYM_COMMA; 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_COMMA); expr_add_terminator(expr, IVY_SYM_COMMA);
expr_add_terminator(expr, IVY_SYM_RIGHT_PAREN); expr_add_terminator(expr, IVY_SYM_RIGHT_PAREN);
expr->s_subexpr_depth = 1; expr->s_subexpr_depth = 1;
@@ -112,7 +119,8 @@ static void collect_children(
b_queue_iterator it = {0}; b_queue_iterator it = {0};
b_queue_foreach (&it, &tuple->n_members) { b_queue_foreach (&it, &tuple->n_members) {
struct ivy_ast_node *item = b_unbox(struct ivy_ast_node, it.entry, n_entry); struct ivy_ast_node *item
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, item); ast_node_iterator_enqueue_node(iterator, node, item);
} }
} }