From 3c72527204d0b41f0fc18ef268cfd369c3e3aaf2 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 8 Sep 2025 15:57:04 +0100 Subject: [PATCH] lang: ast: fix parsing of inline-if expressions that immediately precede an end keyword --- lang/ast/cond.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lang/ast/cond.c b/lang/ast/cond.c index 28c154a..72628b6 100644 --- a/lang/ast/cond.c +++ b/lang/ast/cond.c @@ -97,12 +97,6 @@ struct token_parse_result parse_elif(struct ivy_parser *ctx, struct ivy_token *t return PARSE_RESULT(status, 0); } - 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); - } - struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state( ctx, IVY_AST_EXPR, 0); @@ -204,7 +198,8 @@ static struct token_parse_result parse_else( struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state( ctx, IVY_AST_EXPR, 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. */ expr->s_subexpr_depth = 1; } @@ -310,18 +305,18 @@ static struct token_parse_result parse_end( struct cond_group_parser_state *state = parser_get_state(ctx, struct cond_group_parser_state); - if (state->s_inline) { - /* inline if-else must be terminated with punctuation. */ - return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); - } - enum ivy_status status = finalise_cond_group(state); if (status != IVY_OK) { return PARSE_RESULT(status, 0); } + int flags = 0; + if (state->s_inline) { + flags = PARSE_REPEAT_TOKEN; + } + parser_pop_state(ctx, STATE_ADD_NODE_TO_PARENT); - return PARSE_RESULT(IVY_OK, 0); + return PARSE_RESULT(IVY_OK, flags); } static enum ivy_status add_child(