This commit is contained in:
Maieul BOYER 2024-05-01 17:26:08 +02:00
parent 39c1c5026a
commit 509b551ce4
No known key found for this signature in database
17 changed files with 37 additions and 1891 deletions

View file

@ -12,6 +12,8 @@
#include "../includes/minishell.h"
void ts_parser_delete(TSParser *self);
void ft_free(void *ptr)
{
if (!ptr)

View file

@ -15,6 +15,14 @@
#include "me/string/str_len.h"
#include "parser/api.h"
TSParser *ts_parser_new();
void ts_tree_delete(TSTree *);
TSNode ts_tree_root_node(TSTree *);
TSTree *ts_parser_parse_string(TSParser *, TSTree *oldtree, t_const_str input,
t_usize len);
void ts_parser_delete(TSParser *self);
void ts_parser_set_language(TSParser *self, TSLanguage *lang);
void print_node_data(t_node *t, t_usize depth)
{
t_usize idx;
@ -28,10 +36,10 @@ void print_node_data(t_node *t, t_usize depth)
print_node_data(&t->childs[idx++], depth + 1);
}
t_node parse_to_nodes(t_parser *parser, t_const_str input)
t_node parse_to_nodes(TSParser *parser, t_const_str input)
{
t_parse_tree *tree;
t_parse_node node;
TSTree *tree;
TSNode node;
t_node ret;
tree = ts_parser_parse_string(parser, NULL, input, str_len(input));
@ -40,7 +48,7 @@ t_node parse_to_nodes(t_parser *parser, t_const_str input)
ts_tree_delete(tree);
return (ret);
}
t_node parse_str(t_myparser *parser, t_const_str input)
t_node parse_str(t_parser *parser, t_const_str input)
{
return (parse_to_nodes(parser->parser, input));
}
@ -104,20 +112,20 @@ void ft_find_path(t_str arge[], t_utils *utils)
utils->path = ft_split(PATH_FILES, ':');
}
t_language *tree_sitter_bash(void);
TSLanguage *tree_sitter_bash(void);
t_myparser create_myparser(void)
t_parser create_myparser(void)
{
t_language *lang;
t_parser *parser;
TSLanguage *lang;
TSParser *parser;
lang = tree_sitter_bash();
parser = ts_parser_new();
ts_parser_set_language(parser, lang);
return ((t_myparser){.parser = parser});
return ((t_parser){.parser = parser});
}
void free_myparser(t_myparser self)
void free_myparser(t_parser self)
{
ts_parser_delete(self.parser);
}
@ -131,7 +139,7 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
(void)envp;
utils = (t_utils){};
utils.parser = create_myparser();
//ft_find_path(arge, &utils);
// ft_find_path(arge, &utils);
utils.name_shell = "42sh > ";
ft_take_args(&utils);
}

View file

@ -16,13 +16,19 @@
#include "me/string/str_l_copy.h"
#include "parser/api.h"
t_node build_node(t_parse_node curr, t_const_str input);
t_node build_node(TSNode current, t_const_str input);
TSNode ts_node_child(TSNode parent, t_usize idx);
TSSymbol ts_node_symbol(TSNode self);
t_const_str ts_node_type(TSNode self);
t_u32 ts_node_start_byte(TSNode self);
t_u32 ts_node_end_byte(TSNode self);
t_u32 ts_node_child_count(TSNode self);
t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
t_node *build_childs(TSNode parent, t_const_str input, t_usize count)
{
t_node *ret;
t_usize idx;
t_parse_node child;
TSNode child;
ret = mem_alloc_array(sizeof(*ret), count);
if (ret == NULL)
@ -37,7 +43,7 @@ t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
return (ret);
}
t_node build_node(t_parse_node curr, t_const_str input)
t_node build_node(TSNode curr, t_const_str input)
{
t_node out;