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)
{

View File

@@ -36,6 +36,7 @@ struct ast_node_type expr_node_ops = {
SYM_PARSER(CARET, arith_parse_caret),
SYM_PARSER(COMMA, arith_parse_comma),
SYM_PARSER(DOT, arith_parse_dot),
SYM_PARSER(BANG, arith_parse_bang),
SYM_PARSER(EQUAL_RIGHT_ANGLE, arith_parse_equal_right_angle),
},
.n_keyword_parsers = {

View File

@@ -120,6 +120,8 @@ extern struct token_parse_result arith_parse_semicolon(
struct ivy_parser *ctx, struct ivy_token *tok);
extern struct token_parse_result arith_parse_dot(
struct ivy_parser *ctx, struct ivy_token *tok);
extern struct token_parse_result arith_parse_bang(
struct ivy_parser *ctx, struct ivy_token *tok);
extern struct token_parse_result arith_parse_caret(
struct ivy_parser *ctx, struct ivy_token *tok);
extern struct token_parse_result arith_parse_comma(