lang: ast: initial implementation of msg handler and selector parsing
This commit is contained in:
@@ -14,6 +14,55 @@ struct class_parser_state {
|
||||
int s_prev_token;
|
||||
};
|
||||
|
||||
static enum ivy_status parse_dollar(struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct class_parser_state *state
|
||||
= parser_get_state(ctx, struct class_parser_state);
|
||||
|
||||
if (state->s_current_area != AREA_BODY) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
parser_push_state(ctx, IVY_AST_PROPERTY);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_plus(struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct class_parser_state *state
|
||||
= parser_get_state(ctx, struct class_parser_state);
|
||||
|
||||
if (state->s_current_area != AREA_BODY) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
parser_push_state(ctx, IVY_AST_MSGH);
|
||||
struct parser_state *msgh_state = parser_get_state_generic(ctx);
|
||||
struct ivy_ast_msgh_node *msgh
|
||||
= (struct ivy_ast_msgh_node *)msgh_state->s_node;
|
||||
msgh->n_recipient = IVY_AST_MSGH_CLASS;
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_hyphen(struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct class_parser_state *state
|
||||
= parser_get_state(ctx, struct class_parser_state);
|
||||
|
||||
if (state->s_current_area != AREA_BODY) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
parser_push_state(ctx, IVY_AST_MSGH);
|
||||
struct parser_state *msgh_state = parser_get_state_generic(ctx);
|
||||
struct ivy_ast_msgh_node *msgh
|
||||
= (struct ivy_ast_msgh_node *)msgh_state->s_node;
|
||||
msgh->n_recipient = IVY_AST_MSGH_OBJECT;
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static enum ivy_status parse_ident(struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct class_parser_state *state
|
||||
@@ -96,7 +145,7 @@ static void print(struct ivy_ast_node *node)
|
||||
c->n_ident->t_str);
|
||||
}
|
||||
|
||||
static void init_state(struct parser_state *sp)
|
||||
static void init_state(struct ivy_parser *ctx, struct parser_state *sp)
|
||||
{
|
||||
struct class_parser_state *state = (struct class_parser_state *)sp;
|
||||
state->s_prev_token = IVY_KW_CLASS;
|
||||
@@ -109,6 +158,11 @@ struct ast_node_type class_node_ops = {
|
||||
.n_init_state = init_state,
|
||||
.n_state_size = sizeof(struct class_parser_state),
|
||||
.n_node_size = sizeof(struct ivy_ast_class_node),
|
||||
.n_symbol_parsers = {
|
||||
[IVY_SYM_DOLLAR] = parse_dollar,
|
||||
[IVY_SYM_HYPHEN] = parse_hyphen,
|
||||
[IVY_SYM_PLUS] = parse_plus,
|
||||
},
|
||||
.n_token_parsers = {
|
||||
[IVY_TOK_IDENT] = parse_ident,
|
||||
[IVY_TOK_LINEFEED] = parse_linefeed,
|
||||
|
||||
Reference in New Issue
Block a user