lang: ast: treat bang (!) as an unconsumed expression terminator
This commit is contained in:
@@ -985,6 +985,27 @@ struct token_parse_result arith_parse_dot(
|
|||||||
return expr_finalise_and_return(ctx, state);
|
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 token_parse_result arith_parse_caret(
|
||||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct ast_node_type expr_node_ops = {
|
|||||||
SYM_PARSER(CARET, arith_parse_caret),
|
SYM_PARSER(CARET, arith_parse_caret),
|
||||||
SYM_PARSER(COMMA, arith_parse_comma),
|
SYM_PARSER(COMMA, arith_parse_comma),
|
||||||
SYM_PARSER(DOT, arith_parse_dot),
|
SYM_PARSER(DOT, arith_parse_dot),
|
||||||
|
SYM_PARSER(BANG, arith_parse_bang),
|
||||||
SYM_PARSER(EQUAL_RIGHT_ANGLE, arith_parse_equal_right_angle),
|
SYM_PARSER(EQUAL_RIGHT_ANGLE, arith_parse_equal_right_angle),
|
||||||
},
|
},
|
||||||
.n_keyword_parsers = {
|
.n_keyword_parsers = {
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ extern struct token_parse_result arith_parse_semicolon(
|
|||||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||||
extern struct token_parse_result arith_parse_dot(
|
extern struct token_parse_result arith_parse_dot(
|
||||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
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(
|
extern struct token_parse_result arith_parse_caret(
|
||||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||||
extern struct token_parse_result arith_parse_comma(
|
extern struct token_parse_result arith_parse_comma(
|
||||||
|
|||||||
Reference in New Issue
Block a user