lang: ast: implement parsing of match statements
This commit is contained in:
@@ -50,7 +50,7 @@ static void print_operand(struct ivy_ast_node *node)
|
||||
}
|
||||
}
|
||||
|
||||
void arith_push_operand(struct expr_parser_state *state, struct ivy_token *tok)
|
||||
enum ivy_status arith_push_operand(struct expr_parser_state *state, struct ivy_token *tok)
|
||||
{
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_IDENT: {
|
||||
@@ -84,9 +84,20 @@ void arith_push_operand(struct expr_parser_state *state, struct ivy_token *tok)
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case IVY_TOK_SYMBOL: {
|
||||
if (tok->t_symbol != IVY_SYM_UNDERSCORE) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *v = ast_node_create(IVY_AST_DISCARD);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_entry);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static const struct ivy_operator *get_operator_from_token(struct ivy_token *tok)
|
||||
@@ -448,6 +459,20 @@ struct token_parse_result arith_parse_operator(
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_in(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_KW_IN) {
|
||||
state->s_prev_token = IVY_KW_IN;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_ident(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
@@ -790,21 +815,21 @@ struct token_parse_result expr_finalise(
|
||||
struct ivy_ast_cascade_node *cascade
|
||||
= expr_finalise_cascade(state);
|
||||
|
||||
*result = cascade;
|
||||
*result = (struct ivy_ast_node *)cascade;
|
||||
return PARSE_RESULT(IVY_OK, flags);
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
|
||||
/* this is the end of a keyword-message */
|
||||
struct ivy_ast_msg_node *msg = expr_finalise_complex_msg(state);
|
||||
*result = msg;
|
||||
*result = (struct ivy_ast_node *)msg;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG) {
|
||||
/* this is the end of a keyword-message */
|
||||
struct ivy_ast_msg_node *msg = expr_finalise_keyword_msg(state);
|
||||
*result = msg;
|
||||
*result = (struct ivy_ast_node *)msg;
|
||||
return PARSE_RESULT(IVY_OK, flags);
|
||||
}
|
||||
|
||||
@@ -854,6 +879,38 @@ struct token_parse_result arith_parse_dot(
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_comma(
|
||||
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 && (state->s_prev_component == EXPR_CMP_OPERAND || state->s_prev_component == EXPR_CMP_MSG)) {
|
||||
/* tuple. */
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_DOT;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
extern struct token_parse_result arith_parse_equal_right_angle(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
state->s_prev_token = IVY_SYM_EQUAL_RIGHT_ANGLE;
|
||||
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_label(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user