Normed parser/src/node.c into multiple files

This commit is contained in:
Maieul BOYER 2024-08-31 17:30:30 +00:00
parent 009be4a4b4
commit 36d9d411ba
10 changed files with 242 additions and 165 deletions

View file

@ -6,50 +6,52 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 17:16:18 by maiboyer #+# #+# */
/* Updated: 2024/08/31 17:16:34 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 17:23:14 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser/_inner/node.h"
TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
{
TSNode result = self;
bool did_descend = true;
TSNode result;
bool did_descend;
TSNode child;
t_u32 index;
NodeChildIterator iterator;
t_u32 grandchild_index;
t_u32 grandchild_count;
result = self;
did_descend = true;
while (did_descend)
{
did_descend = false;
TSNode child;
t_u32 index = 0;
NodeChildIterator iterator = ts_node_iterate_children(&result);
index = 0;
iterator = ts_node_iterate_children(&result);
while (ts_node_child_iterator_next(&iterator, &child))
{
if (ts_node__is_relevant(child, include_anonymous))
{
if (index == child_index)
{
return child;
}
return (child);
index++;
}
else
{
t_u32 grandchild_index = child_index - index;
t_u32 grandchild_count = ts_node__relevant_child_count(child, include_anonymous);
grandchild_index = child_index - index;
grandchild_count = ts_node__relevant_child_count(child,
include_anonymous);
if (grandchild_index < grandchild_count)
{
printf("did_descend\n");
did_descend = true;
result = child;
child_index = grandchild_index;
break;
break ;
}
index += grandchild_count;
}
}
}
return ts_node__null();
return (ts_node__null());
}