64 lines
1.8 KiB
C
64 lines
1.8 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,
|
|
};
|
|
|
|
enum tok_expr_type {
|
|
TOK_EXPR_NONE = 0,
|
|
TOK_EXPR_BEGIN,
|
|
TOK_EXPR_ANY,
|
|
};
|
|
|
|
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];
|
|
struct {
|
|
token_parse_function expr_begin;
|
|
token_parse_function expr_other;
|
|
token_parse_function expr_all;
|
|
} n_expr_parser;
|
|
};
|
|
|
|
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 enum tok_expr_type get_tok_expr_type(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
|