lang: ast: transparently ignore linefeeds if the current parse context doesn't handle them
This commit is contained in:
@@ -44,13 +44,18 @@ enum ivy_status ivy_parser_push_token(
|
|||||||
}
|
}
|
||||||
|
|
||||||
token_parse_function func = get_token_parser(state->s_node, tok);
|
token_parse_function func = get_token_parser(state->s_node, tok);
|
||||||
if (!func) {
|
if (func) {
|
||||||
parser->p_status = IVY_ERR_BAD_SYNTAX;
|
|
||||||
return IVY_ERR_BAD_SYNTAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
parser->p_status = func(parser, tok);
|
parser->p_status = func(parser, tok);
|
||||||
return parser->p_status;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct parser_state *parser_get_state_generic(struct ivy_parser *parser)
|
struct parser_state *parser_get_state_generic(struct ivy_parser *parser)
|
||||||
@@ -106,7 +111,7 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
|
|||||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||||
b_queue_pop_back(&parser->p_state);
|
b_queue_pop_back(&parser->p_state);
|
||||||
|
|
||||||
if (flags & STATE_ADD_NODE_TO_PARENT) {
|
if (state && (flags & STATE_ADD_NODE_TO_PARENT)) {
|
||||||
ast_node_add_child(state->s_parent, state->s_node);
|
ast_node_add_child(state->s_parent, state->s_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +127,7 @@ struct ivy_ast_node *ivy_parser_root_node(struct ivy_parser *parser)
|
|||||||
{
|
{
|
||||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||||
return state->s_node;
|
return state ? state->s_node : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
|
struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
|
||||||
@@ -130,6 +135,10 @@ struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
|
|||||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||||
|
|
||||||
|
if (!state) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (state->s_node->n_type != IVY_AST_UNIT) {
|
if (state->s_node->n_type != IVY_AST_UNIT) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user