lang: ast: add diag support to parser
This commit is contained in:
@@ -250,6 +250,39 @@ void ivy_ast_node_to_string(struct ivy_ast_node *node, struct b_string *out)
|
||||
}
|
||||
}
|
||||
|
||||
void ivy_ast_node_set_bounds_from_token(
|
||||
struct ivy_ast_node *parent, const struct ivy_token *tok)
|
||||
{
|
||||
parent->n_start = tok->t_start;
|
||||
parent->n_end = tok->t_end;
|
||||
}
|
||||
|
||||
void ivy_ast_node_extend_bounds(
|
||||
struct ivy_ast_node *parent, const struct ivy_ast_node *child)
|
||||
{
|
||||
if (child->n_start.c_row < parent->n_start.c_row) {
|
||||
parent->n_start = child->n_start;
|
||||
} else if (child->n_start.c_col < parent->n_start.c_col) {
|
||||
parent->n_start.c_col = child->n_start.c_col;
|
||||
}
|
||||
|
||||
if (child->n_end.c_row > parent->n_end.c_row) {
|
||||
parent->n_end = child->n_end;
|
||||
} else if (child->n_end.c_col > parent->n_end.c_col) {
|
||||
parent->n_end.c_col = child->n_end.c_col;
|
||||
}
|
||||
}
|
||||
|
||||
void ivy_ast_node_extend_bounds_recursive(
|
||||
struct ivy_ast_node *parent, const struct ivy_ast_node *child)
|
||||
{
|
||||
while (parent) {
|
||||
ivy_ast_node_extend_bounds(parent, child);
|
||||
child = parent;
|
||||
parent = parent->n_parent;
|
||||
}
|
||||
}
|
||||
|
||||
void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
{
|
||||
struct ivy_ast_node_iterator it = {};
|
||||
|
||||
Reference in New Issue
Block a user