lang: ast: re-write expression parser to support keyword messages
also adjust some parser state callbackss to better support sub-parsers returning results to their parents.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
|
||||
struct parser_state;
|
||||
|
||||
#define PARSE_RESULT(status, flags) \
|
||||
((struct token_parse_result) {.r_status = (status), .r_flags = (flags)})
|
||||
#define PARSE_RESULT(status, flags) \
|
||||
((struct token_parse_result) { .r_status = (status), .r_flags = (flags) })
|
||||
|
||||
#define __TOK_PARSER_INDEX(x) ((x) - __IVY_TOK_INDEX_BASE)
|
||||
#define __SYM_PARSER_INDEX(x) ((x) - __IVY_SYM_INDEX_BASE)
|
||||
@@ -26,51 +26,51 @@ struct parser_state;
|
||||
#define KW_PARSER_FALLBACK(func) [__KW_PARSER_FALLBACK_INDEX] = func
|
||||
|
||||
enum token_parse_flags {
|
||||
PARSE_REPEAT_TOKEN = 0x01u,
|
||||
PARSE_REPEAT_TOKEN = 0x01u,
|
||||
};
|
||||
|
||||
enum token_expr_type {
|
||||
TOK_EXPR_NONE = 0,
|
||||
TOK_EXPR_BEGIN,
|
||||
TOK_EXPR_ANY,
|
||||
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;
|
||||
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 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 *);
|
||||
enum ivy_status (*n_add_child)(
|
||||
struct parser_state*, 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;
|
||||
size_t n_state_size;
|
||||
size_t n_node_size;
|
||||
|
||||
token_parse_function n_token_parsers[__TOK_PARSER_INDEX(__IVY_TOK_INDEX_LIMIT)];
|
||||
token_parse_function n_keyword_parsers[__KW_PARSER_INDEX(__IVY_KW_INDEX_LIMIT)];
|
||||
token_parse_function n_symbol_parsers[__SYM_PARSER_INDEX(__IVY_SYM_INDEX_LIMIT)];
|
||||
token_parse_function n_token_parsers[__TOK_PARSER_INDEX(__IVY_TOK_INDEX_LIMIT)];
|
||||
token_parse_function n_keyword_parsers[__KW_PARSER_INDEX(__IVY_KW_INDEX_LIMIT)];
|
||||
token_parse_function n_symbol_parsers[__SYM_PARSER_INDEX(__IVY_SYM_INDEX_LIMIT)];
|
||||
|
||||
struct {
|
||||
token_parse_function expr_begin;
|
||||
token_parse_function expr_other;
|
||||
token_parse_function expr_all;
|
||||
} n_expr_parser;
|
||||
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 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 token_expr_type get_token_expr_type(struct ivy_token *tok);
|
||||
extern struct ivy_ast_node *ast_node_create(enum ivy_ast_node_type type);
|
||||
struct ivy_ast_node* context, struct ivy_token* tok);
|
||||
extern enum token_expr_type get_token_expr_type(struct ivy_token* tok);
|
||||
extern struct ivy_ast_node* ast_node_create(enum ivy_ast_node_type type);
|
||||
extern enum ivy_status ast_node_add_child(
|
||||
struct ivy_ast_node *parent, struct ivy_ast_node *child);
|
||||
struct ivy_ast_node* parent, struct ivy_ast_node* child);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user