Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

View file

@ -0,0 +1,13 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 18:29:36 by maiboyer #+# #+# */
/* Updated: 2024/04/28 18:31:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser/api.h"

87
sources/node/node.c Normal file
View file

@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 18:36:40 by maiboyer #+# #+# */
/* Updated: 2024/04/28 18:53:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/string/str_l_copy.h"
#include "parser/api.h"
t_node build_node(TSNode curr, t_const_str input);
t_node *build_childs(TSNode parent, t_const_str input, t_usize count)
{
t_node *ret;
t_usize idx;
TSNode child;
ret = mem_alloc_array(sizeof(*ret), count);
if (ret == NULL)
return (NULL);
idx = 0;
while (idx < count)
{
child = ts_node_named_child(parent, idx);
ret[idx] = build_node(child, input);
idx++;
}
return (ret);
}
t_node build_node(TSNode curr, t_const_str input)
{
t_node out;
out.kind = ts_node_symbol(curr);
out.kind_str = ts_node_type(curr);
out.start = ts_node_start_byte(curr);
out.end = ts_node_end_byte(curr);
out.input = input;
out.single_str = NULL;
out.childs_count = ts_node_named_child_count(curr);
if (out.childs_count == 0)
out.childs = NULL;
else
out.childs = build_childs(curr, input, out.childs_count);
return (out);
}
t_str node_getstr(t_node *node)
{
t_usize start;
t_usize end;
t_str ret;
if (node->single_str == NULL)
{
start = node->start;
end = node->end;
if (start > end)
return (NULL);
ret = mem_alloc(end - start + 1);
str_l_copy(ret, node->input + start, end - start + 1);
node->single_str = ret;
}
return (node->single_str);
}
void free_node(t_node t)
{
t_usize idx;
idx = 0;
while (idx < t.childs_count)
free_node(t.childs[idx++]);
free(t.childs);
if (t.single_str != NULL)
free(t.single_str);
}