lang: add missing includes; misc formatting cleanup

This commit is contained in:
2024-12-06 09:53:09 +00:00
parent 5fe3231c9e
commit d1855afc05
9 changed files with 131 additions and 88 deletions

View File

@@ -1,6 +1,6 @@
#include "block.h"
#include "iterate.h"
#include "expr/expr.h"
#include "iterate.h"
struct while_parser_state {
struct parser_state s_base;
@@ -14,14 +14,11 @@ struct while_parser_state {
static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg)
{
struct while_parser_state *state
= (struct while_parser_state *)sp;
struct while_parser_state *state = (struct while_parser_state *)sp;
state->s_prev_node = (struct ivy_ast_node *)arg;
}
struct token_parse_result parse_while(
struct ivy_parser* ctx,
struct ivy_token* tok)
struct token_parse_result parse_while(struct ivy_parser *ctx, struct ivy_token *tok)
{
struct while_parser_state *state
= parser_get_state(ctx, struct while_parser_state);
@@ -41,11 +38,13 @@ struct token_parse_result parse_while(
state->s_prev_token = IVY_KW_WHILE;
expr->s_subexpr_depth = 1;
expr->s_terminator = IVY_KW_DO;
return PARSE_RESULT(IVY_OK, 0);
}
static struct token_parse_result parse_do(struct ivy_parser *ctx, struct ivy_token *tok)
static struct token_parse_result parse_do(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct while_parser_state *state
= parser_get_state(ctx, struct while_parser_state);
@@ -77,7 +76,8 @@ static struct token_parse_result parse_do(struct ivy_parser *ctx, struct ivy_tok
return PARSE_RESULT(IVY_OK, 0);
}
static struct token_parse_result parse_expr_begin(struct ivy_parser* ctx, struct ivy_token* tok)
static struct token_parse_result parse_expr_begin(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct while_parser_state *state
= parser_get_state(ctx, struct while_parser_state);
@@ -87,7 +87,9 @@ static struct token_parse_result parse_expr_begin(struct ivy_parser* ctx, struct
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
struct block_parser_state *block = (struct block_parser_state *)parser_push_state(ctx, IVY_AST_BLOCK, 0);
struct block_parser_state *block
= (struct block_parser_state *)parser_push_state(
ctx, IVY_AST_BLOCK, 0);
block->s_terminator = IVY_KW_END;
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
}
@@ -106,7 +108,7 @@ static enum ivy_status finalise_while_loop(struct while_parser_state *state)
/* the condition and body are parsed in reverse order for inline loops. */
loop->n_cond = state->s_prev_node;
loop->n_body = state->s_body;
loop->n_body = state->s_body;
state->s_prev_node = NULL;
return IVY_OK;
}
@@ -116,7 +118,6 @@ static enum ivy_status finalise_while_loop(struct while_parser_state *state)
return IVY_ERR_BAD_SYNTAX;
}
loop->n_cond = state->s_cond;
loop->n_body = state->s_prev_node;
@@ -146,7 +147,8 @@ static struct token_parse_result parse_punct_terminator(
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
}
static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_token *tok)
static struct token_parse_result parse_end(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct while_parser_state *state
= parser_get_state(ctx, struct while_parser_state);
@@ -168,13 +170,12 @@ static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_to
static enum ivy_status add_child(
struct parser_state *parent, struct ivy_ast_node *child)
{
struct while_parser_state *state
= (struct while_parser_state *)parent;
struct while_parser_state *state = (struct while_parser_state *)parent;
if (state->s_prev_node) {
return IVY_ERR_BAD_SYNTAX;
}
state->s_prev_node = child;
return IVY_OK;
}
@@ -182,7 +183,8 @@ static enum ivy_status add_child(
static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_while_loop_node *loop = (struct ivy_ast_while_loop_node *)node;
struct ivy_ast_while_loop_node *loop
= (struct ivy_ast_while_loop_node *)node;
if (loop->n_cond) {
ast_node_iterator_enqueue_node(iterator, node, loop->n_cond);
@@ -213,4 +215,4 @@ struct ast_node_type while_loop_node_ops = {
.n_expr_parser = {
.expr_begin = parse_expr_begin,
},
};
};