75 lines
1.6 KiB
C
75 lines
1.6 KiB
C
#include "unit-package.h"
|
|
|
|
#include "ctx.h"
|
|
#include "node.h"
|
|
|
|
static enum ivy_status parse_dot(struct ivy_parser *ctx, struct ivy_token *tok)
|
|
{
|
|
struct unit_package_parser_state *state
|
|
= parser_get_state(ctx, struct unit_package_parser_state);
|
|
|
|
if (state->s_prev_token != IVY_TOK_IDENT) {
|
|
return IVY_ERR_BAD_SYNTAX;
|
|
}
|
|
|
|
state->s_prev_token = IVY_SYM_DOT;
|
|
return IVY_OK;
|
|
}
|
|
|
|
static enum ivy_status parse_ident(struct ivy_parser *ctx, struct ivy_token *tok)
|
|
{
|
|
struct unit_package_parser_state *state
|
|
= parser_get_state(ctx, struct unit_package_parser_state);
|
|
|
|
if (state->s_prev_token == IVY_TOK_IDENT) {
|
|
return IVY_ERR_BAD_SYNTAX;
|
|
}
|
|
|
|
state->s_prev_token = IVY_TOK_IDENT;
|
|
return IVY_OK;
|
|
}
|
|
|
|
static enum ivy_status parse_linefeed(struct ivy_parser *ctx, struct ivy_token *tok)
|
|
{
|
|
struct unit_package_parser_state *state
|
|
= parser_get_state(ctx, struct unit_package_parser_state);
|
|
|
|
if (state->s_prev_token != IVY_TOK_IDENT) {
|
|
return IVY_ERR_BAD_SYNTAX;
|
|
}
|
|
|
|
return IVY_ERR_IO_FAILURE;
|
|
}
|
|
|
|
static enum ivy_status add_child(
|
|
struct ivy_ast_node *parent, struct ivy_ast_node *child)
|
|
{
|
|
return IVY_OK;
|
|
}
|
|
|
|
static void print(struct ivy_ast_node *node)
|
|
{
|
|
}
|
|
|
|
static void init_state(struct parser_state *sp)
|
|
{
|
|
struct unit_package_parser_state *state
|
|
= (struct unit_package_parser_state *)sp;
|
|
state->s_prev_token = IVY_KW_PACKAGE;
|
|
}
|
|
|
|
struct ast_node_type unit_package_node_ops = {
|
|
.n_add_child = add_child,
|
|
.n_print = print,
|
|
.n_init_state = init_state,
|
|
.n_state_size = sizeof(struct unit_package_parser_state),
|
|
.n_symbol_parsers = {
|
|
[IVY_SYM_DOT] = parse_dot,
|
|
},
|
|
.n_token_parsers = {
|
|
[IVY_TOK_IDENT] = parse_ident,
|
|
[IVY_TOK_LINEFEED] = parse_linefeed,
|
|
}
|
|
|
|
};
|