lang: ast: implement control flags returned by parser functions
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "ctx.h"
|
||||
|
||||
#include "node.h"
|
||||
#include "parse.h"
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
@@ -37,25 +36,36 @@ enum ivy_status ivy_parser_get_status(struct ivy_parser *parser)
|
||||
enum ivy_status ivy_parser_push_token(
|
||||
struct ivy_parser *parser, struct ivy_token *tok)
|
||||
{
|
||||
struct parser_state *state = parser_get_state_generic(parser);
|
||||
if (!state) {
|
||||
parser->p_status = IVY_ERR_INTERNAL_FAILURE;
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
while (true) {
|
||||
struct parser_state *state = parser_get_state_generic(parser);
|
||||
if (!state) {
|
||||
parser->p_status = IVY_ERR_INTERNAL_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
token_parse_function func = get_token_parser(state->s_node, tok);
|
||||
if (func) {
|
||||
struct token_parse_result result = func(parser, tok);
|
||||
parser->p_status = result.r_status;
|
||||
|
||||
if (result.r_flags & PARSE_REPEAT_TOKEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok->t_type == IVY_TOK_LINEFEED) {
|
||||
ivy_token_destroy(tok);
|
||||
parser->p_status = IVY_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
parser->p_status = IVY_ERR_BAD_SYNTAX;
|
||||
break;
|
||||
}
|
||||
|
||||
token_parse_function func = get_token_parser(state->s_node, tok);
|
||||
if (func) {
|
||||
parser->p_status = func(parser, tok);
|
||||
return parser->p_status;
|
||||
}
|
||||
|
||||
if (tok->t_type == IVY_TOK_LINEFEED) {
|
||||
ivy_token_destroy(tok);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
parser->p_status = IVY_ERR_BAD_SYNTAX;
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
return parser->p_status;
|
||||
}
|
||||
|
||||
struct parser_state *parser_get_state_generic(struct ivy_parser *parser)
|
||||
@@ -92,12 +102,12 @@ struct parser_state *parser_push_state(
|
||||
}
|
||||
|
||||
state->s_node = ast_node_create_with_size(type, node_type->n_node_size);
|
||||
b_queue_push_back(&parser->p_state, &state->s_entry);
|
||||
|
||||
if (node_type->n_init_state) {
|
||||
node_type->n_init_state(parser, state);
|
||||
}
|
||||
|
||||
b_queue_push_back(&parser->p_state, &state->s_entry);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user