lang: ast: fix parsing of inline-if expressions that immediately precede an end keyword
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user