lang: ast: implement parsing of lambdas
This commit is contained in:
@@ -81,8 +81,7 @@ enum ivy_status arith_push_operand(
|
||||
}
|
||||
case IVY_TOK_ATOM: {
|
||||
struct ivy_ast_atom_node *v
|
||||
= (struct ivy_ast_atom_node *)ast_node_create(
|
||||
IVY_AST_ATOM);
|
||||
= (struct ivy_ast_atom_node *)ast_node_create(IVY_AST_ATOM);
|
||||
v->n_content = tok;
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
@@ -646,7 +645,6 @@ struct token_parse_result arith_parse_left_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_right_brace(
|
||||
@@ -655,14 +653,29 @@ struct token_parse_result arith_parse_right_brace(
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_SYM_RIGHT_BRACE) {
|
||||
state->s_prev_token = IVY_SYM_RIGHT_BRACE;
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
state->s_prev_token = IVY_SYM_RIGHT_BRACE;
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
struct token_parse_result arith_parse_left_bracket(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
parser_push_state(ctx, IVY_AST_LAMBDA, 0);
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_right_bracket(
|
||||
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_RIGHT_BRACKET;
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *labels)
|
||||
@@ -1088,7 +1101,8 @@ struct token_parse_result arith_parse_comma(
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_SYM_COMMA) {
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
struct token_parse_result result
|
||||
= expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ struct ast_node_type expr_node_ops = {
|
||||
SYM_PARSER(RIGHT_PAREN, arith_parse_right_paren),
|
||||
SYM_PARSER(LEFT_BRACE, arith_parse_left_brace),
|
||||
SYM_PARSER(RIGHT_BRACE, arith_parse_right_brace),
|
||||
SYM_PARSER(LEFT_BRACKET, arith_parse_left_bracket),
|
||||
SYM_PARSER(RIGHT_BRACKET, arith_parse_right_bracket),
|
||||
SYM_PARSER(SEMICOLON, arith_parse_semicolon),
|
||||
SYM_PARSER(UNDERSCORE, arith_parse_operand),
|
||||
SYM_PARSER(CARET, arith_parse_caret),
|
||||
|
||||
@@ -122,6 +122,10 @@ extern struct token_parse_result arith_parse_left_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_right_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_left_bracket(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_right_bracket(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_semicolon(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_dot(
|
||||
|
||||
Reference in New Issue
Block a user