lang: ast: implement simple identifier and operator expression parsing

This commit is contained in:
2024-11-27 22:29:29 +00:00
parent 31de937a21
commit 101d87e09d
4 changed files with 503 additions and 50 deletions

View File

@@ -13,8 +13,8 @@ struct msgh_parser_state {
unsigned int s_prev;
};
static struct token_parse_result parse_ident(
struct ivy_parser *ctx, struct ivy_token *tok)
static struct token_parse_result parse_expr(
struct ivy_parser* ctx, struct ivy_token* tok)
{
struct msgh_parser_state *state
= parser_get_state(ctx, struct msgh_parser_state);
@@ -22,17 +22,12 @@ static struct token_parse_result parse_ident(
struct ivy_ast_msgh_node *msgh
= (struct ivy_ast_msgh_node *)state->s_base.s_node;
if (msgh->n_sel) {
/* TODO expression parsing */
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
if (!msgh->n_sel) {
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (state->s_prev == IVY_SYM_HYPHEN) {
/* message name */
return PARSE_RESULT(IVY_OK, 0);
}
return PARSE_RESULT(IVY_OK, 0);
parser_push_state(ctx, IVY_AST_EXPR);
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
}
static enum ivy_status add_child(
@@ -64,7 +59,7 @@ struct ast_node_type msgh_node_ops = {
.n_init_state = init_state,
.n_state_size = sizeof(struct msgh_parser_state),
.n_node_size = sizeof(struct ivy_ast_msgh_node),
.n_token_parsers = {
[IVY_TOK_IDENT] = parse_ident,
},
.n_expr_parser = {
.expr_begin = parse_expr,
}
};