lang: ast: implement support for multiple expression terminator tokens
This commit is contained in:
@@ -504,7 +504,7 @@ struct token_parse_result arith_parse_in(
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_KW_IN) {
|
||||
if (expr_terminates_at_token(state, IVY_KW_IN)) {
|
||||
/* treat this as a statement terminator. */
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
result.r_flags |= PARSE_REPEAT_TOKEN;
|
||||
@@ -521,7 +521,7 @@ struct token_parse_result arith_parse_do(
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
bool terminator = false;
|
||||
if (state->s_terminator == IVY_KW_DO) {
|
||||
if (expr_terminates_at_token(state, IVY_KW_DO)) {
|
||||
terminator = true;
|
||||
}
|
||||
|
||||
@@ -1132,7 +1132,7 @@ struct token_parse_result arith_parse_comma(
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_SYM_COMMA) {
|
||||
if (expr_terminates_at_token(state, IVY_SYM_COMMA)) {
|
||||
struct token_parse_result result
|
||||
= expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
@@ -1177,21 +1177,23 @@ struct token_parse_result arith_parse_label(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_terminator == IVY_TOK_LABEL) {
|
||||
if (expr_terminates_at_token(state, IVY_TOK_LABEL)) {
|
||||
/* we are currently parsing a keyword or complex message
|
||||
* argument, and have just encountered the label denoting the
|
||||
* next argument. terminate here and propagate this label to the
|
||||
* parent keyword-message parser context. */
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
enum ivy_status status = expr_finalise_arith(
|
||||
state, &expr, IVY_PRECEDENCE_ASSIGN);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
struct token_parse_result result = expr_finalise(ctx,
|
||||
state, IVY_PRECEDENCE_ASSIGN, &expr);
|
||||
if (result.r_status != IVY_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.r_flags |= PARSE_REPEAT_TOKEN;
|
||||
|
||||
parser_replace_current_node(ctx, expr);
|
||||
parser_pop_state(ctx, STATE_ADD_NODE_TO_PARENT);
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, PARSE_REPEAT_TOKEN);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (state->s_sub_type != EXPR_SUBTYPE_KEYWORD_MSG
|
||||
@@ -1208,6 +1210,7 @@ struct token_parse_result arith_parse_label(
|
||||
if (new_parser) {
|
||||
msg_expr = (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_copy_terminators(state, msg_expr);
|
||||
} else {
|
||||
msg_expr = state;
|
||||
}
|
||||
@@ -1248,7 +1251,8 @@ struct token_parse_result arith_parse_label(
|
||||
struct expr_parser_state *arg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
arg_expr->s_terminator = IVY_TOK_LABEL;
|
||||
expr_copy_terminators(state, arg_expr);
|
||||
expr_add_terminator(arg_expr, IVY_TOK_LABEL);
|
||||
arg_expr->s_sub_type = EXPR_SUBTYPE_KEYWORD_ARG;
|
||||
arg_expr->s_subexpr_depth = state->s_subexpr_depth + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user