lang: ast: fix expr_finalise not consuming the right-paren of a parenthesised expression
This commit is contained in:
@@ -629,6 +629,7 @@ struct token_parse_result arith_parse_right_paren(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_RIGHT_PAREN;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
@@ -766,6 +767,11 @@ struct token_parse_result expr_finalise(
|
||||
flags = PARSE_REPEAT_TOKEN;
|
||||
}
|
||||
|
||||
if (state->s_paren_depth > 0 && state->s_prev_token == IVY_SYM_RIGHT_PAREN) {
|
||||
/* this is the ending right paren in a parenthesised expression, so we need to consume it. */
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_MSG) {
|
||||
/* this is the end of a unary message (probably in a cascade operation). */
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
@@ -776,7 +782,7 @@ struct token_parse_result expr_finalise(
|
||||
}
|
||||
|
||||
*result = expr;
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, PARSE_REPEAT_TOKEN);
|
||||
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_CASCADE) {
|
||||
@@ -817,11 +823,6 @@ struct token_parse_result expr_finalise(
|
||||
struct token_parse_result expr_finalise_and_return(
|
||||
struct ivy_parser *ctx, struct expr_parser_state *state)
|
||||
{
|
||||
int flags = 0;
|
||||
if (state->s_subexpr_depth > 0) {
|
||||
flags = PARSE_REPEAT_TOKEN;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *expr_node = NULL;
|
||||
struct token_parse_result result = expr_finalise(ctx, state, IVY_PRECEDENCE_ASSIGN, &expr_node);
|
||||
|
||||
@@ -849,6 +850,7 @@ struct token_parse_result arith_parse_dot(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_DOT;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user