Files
ivy/lang/ast/node.h

53 lines
1.6 KiB
C

#ifndef _AST_NODE_H_
#define _AST_NODE_H_
#include <ivy/lang/ast.h>
#include <ivy/lang/lex.h>
#define ast_node_create(type_id, type_struct) \
((type_struct *)ast_node_create_with_size(type_id, sizeof(type_struct)))
struct parser_state;
#define PARSE_RESULT(status, flags) \
((struct token_parse_result) {.r_status = (status), .r_flags = (flags) })
enum token_parse_flags {
PARSE_REPEAT_TOKEN = 0x01u,
};
struct token_parse_result {
enum ivy_status r_status;
enum token_parse_flags r_flags;
};
typedef struct token_parse_result (*token_parse_function)(
struct ivy_parser *, struct ivy_token *);
struct ast_node_type {
enum ivy_status (*n_add_child)(
struct ivy_ast_node *, struct ivy_ast_node *);
void (*n_print)(struct ivy_ast_node *);
void (*n_init_state)(struct ivy_parser *, struct parser_state *);
void (*n_collect_children)(
struct ivy_ast_node *, struct ivy_ast_node_iterator *);
size_t n_state_size;
size_t n_node_size;
token_parse_function n_token_parsers[IVY_TOK_TYPE_COUNT];
token_parse_function n_keyword_parsers[IVY_KW_TYPE_COUNT];
token_parse_function n_symbol_parsers[IVY_SYM_TYPE_COUNT];
};
extern const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type);
extern token_parse_function get_token_parser(
struct ivy_ast_node *context, struct ivy_token *tok);
extern struct ivy_ast_node *ast_node_create_with_size(
enum ivy_ast_node_type type, size_t size);
extern enum ivy_status ast_node_add_child(
struct ivy_ast_node *parent, struct ivy_ast_node *child);
#endif