lang: ast: treat bang (!) as an unconsumed expression terminator

This commit is contained in:
2024-12-06 13:22:33 +00:00
parent 363b13534d
commit d3813dc514
3 changed files with 24 additions and 0 deletions

View File

@@ -985,6 +985,27 @@ struct token_parse_result arith_parse_dot(
return expr_finalise_and_return(ctx, state);
}
struct token_parse_result arith_parse_bang(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct expr_parser_state *state
= parser_get_state(ctx, struct expr_parser_state);
if (state->s_type != EXPR_TYPE_ARITH) {
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (state->s_paren_depth > 0) {
/* end-of-expression with mismatched parentheses */
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
state->s_prev_token = IVY_SYM_BANG;
struct token_parse_result result = expr_finalise_and_return(ctx, state);
result.r_flags = PARSE_REPEAT_TOKEN;
return result;
}
struct token_parse_result arith_parse_caret(
struct ivy_parser *ctx, struct ivy_token *tok)
{