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 match_parser_state {
struct parser_state s_base;
@@ -16,14 +16,11 @@ struct match_parser_state {
static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg)
{
struct match_parser_state *state
= (struct match_parser_state *)sp;
struct match_parser_state *state = (struct match_parser_state *)sp;
state->s_prev_node = (struct ivy_ast_node *)arg;
}
struct token_parse_result parse_match(
struct ivy_parser *ctx,
struct ivy_token *tok)
struct token_parse_result parse_match(struct ivy_parser *ctx, struct ivy_token *tok)
{
struct match_parser_state *state
= parser_get_state(ctx, struct match_parser_state);
@@ -32,7 +29,8 @@ struct token_parse_result parse_match(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
state->s_cur_branch = (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
state->s_cur_branch
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
if (!state->s_cur_branch) {
return PARSE_RESULT(IVY_ERR_NO_MEMORY, 0);
}
@@ -53,12 +51,12 @@ static enum ivy_status flush_current_branch(struct match_parser_state *state)
if (!state->s_cur_branch) {
return IVY_ERR_INTERNAL_FAILURE;
}
b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
state->s_cur_branch
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
if (!state->s_cur_branch) {
return IVY_ERR_NO_MEMORY;
}
@@ -96,7 +94,7 @@ struct token_parse_result parse_in(struct ivy_parser *ctx, struct ivy_token *tok
return PARSE_RESULT(IVY_OK, 0);
}
static enum ivy_status finalise_match(struct match_parser_state* state)
static enum ivy_status finalise_match(struct match_parser_state *state)
{
struct ivy_ast_match_node *match
= (struct ivy_ast_match_node *)state->s_base.s_node;
@@ -119,7 +117,8 @@ static struct token_parse_result parse_arrow(
struct match_parser_state *state
= parser_get_state(ctx, struct match_parser_state);
if (state->s_prev_token != IVY_KW_IN && state->s_prev_token != IVY_SYM_COMMA) {
if (state->s_prev_token != IVY_KW_IN
&& state->s_prev_token != IVY_SYM_COMMA) {
/* this token can only appear after the `in` keyword and an expression. */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
@@ -171,7 +170,8 @@ static struct token_parse_result parse_comma(
return PARSE_RESULT(IVY_OK, 0);
}
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 match_parser_state *state
= parser_get_state(ctx, struct match_parser_state);
@@ -202,13 +202,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 match_parser_state *state
= (struct match_parser_state *)parent;
struct match_parser_state *state = (struct match_parser_state *)parent;
if (state->s_prev_node) {
return IVY_ERR_BAD_SYNTAX;
}
state->s_prev_node = child;
return IVY_OK;
}
@@ -216,14 +215,14 @@ static enum ivy_status add_child(
static void match_collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_match_node *match
= (struct ivy_ast_match_node *)node;
struct ivy_ast_match_node *match = (struct ivy_ast_match_node *)node;
ast_node_iterator_enqueue_node(iterator, node, match->n_cond);
b_queue_iterator it = {0};
b_queue_foreach (&it, &match->n_branches) {
struct ivy_ast_node *branch = b_unbox(struct ivy_ast_node, it.entry, n_entry);
struct ivy_ast_node *branch
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, branch);
}
}