lang: ast: add a BLOCK ast node to hold lists of expressions
This commit is contained in:
@@ -30,6 +30,24 @@ static struct token_parse_result parse_expr(
|
||||
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
|
||||
}
|
||||
|
||||
|
||||
static struct token_parse_result parse_bang(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct msgh_parser_state *state
|
||||
= parser_get_state(ctx, struct msgh_parser_state);
|
||||
|
||||
struct ivy_ast_msgh_node *msgh
|
||||
= (struct ivy_ast_msgh_node *)state->s_base.s_node;
|
||||
|
||||
if (!msgh->n_sel || state->s_oneline) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
parser_pop_state(ctx, STATE_ADD_NODE_TO_PARENT);
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
static enum ivy_status add_child(
|
||||
struct ivy_ast_node *parent, struct ivy_ast_node *child)
|
||||
{
|
||||
@@ -40,7 +58,11 @@ static enum ivy_status add_child(
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
b_queue_push_back(&msgh->n_body, &child->n_entry);
|
||||
if (child->n_type == IVY_AST_BLOCK && !msgh->n_body) {
|
||||
msgh->n_body = child;
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -61,5 +83,8 @@ struct ast_node_type msgh_node_ops = {
|
||||
.n_node_size = sizeof(struct ivy_ast_msgh_node),
|
||||
.n_expr_parser = {
|
||||
.expr_begin = parse_expr,
|
||||
}
|
||||
},
|
||||
.n_symbol_parsers = {
|
||||
[IVY_SYM_BANG] = parse_bang,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user