Restore to a stage where it works and is easier to manage (#5)
Everything in the parser that needs to be normed is in a single .c + .h file (also there is the scanner.c file)
This commit is contained in:
parent
dc2358a320
commit
cc8567f434
61 changed files with 14052 additions and 15081 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/13 20:26:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/04/30 15:30:52 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/04/30 21:31:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,11 +28,9 @@ void ft_other_cmd(t_utils *shcat, t_usize i, t_usize prev_i)
|
|||
t_i32 options;
|
||||
t_str *args;
|
||||
t_usize k;
|
||||
t_usize tmp;
|
||||
// t_str cmd;
|
||||
|
||||
k = prev_i;
|
||||
tmp = prev_i;
|
||||
args = (t_str *)malloc(sizeof(t_str) * (i + 2));
|
||||
while (prev_i < i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/04/30 16:16:55 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/04/30 22:03:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
void ts_parser_delete(TSParser *self);
|
||||
|
||||
void ft_free(void *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
|
|
@ -37,6 +39,8 @@ void ft_free_utils(t_utils *s)
|
|||
(void)(s);
|
||||
if (s->str_input)
|
||||
free(s->str_input);
|
||||
if (s->path)
|
||||
ft_free_strs(s->path);
|
||||
ts_parser_delete(s->parser.parser);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/04/30 16:43:14 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/01 10:36:58 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -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));
|
||||
}
|
||||
|
|
@ -73,9 +81,7 @@ void exec_shcat(t_utils *shcat)
|
|||
|
||||
void ft_take_args(t_utils *shcat)
|
||||
{
|
||||
t_i32 i;
|
||||
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
|
|
@ -85,17 +91,14 @@ void ft_take_args(t_utils *shcat)
|
|||
exec_shcat(shcat);
|
||||
add_history(shcat->str_input);
|
||||
free(shcat->str_input);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_find_path(t_str arge[], t_utils *utils)
|
||||
{
|
||||
t_i32 i;
|
||||
t_u8 check;
|
||||
|
||||
i = 0;
|
||||
check = 0;
|
||||
while (arge[i] != NULL)
|
||||
{
|
||||
if (arge[i][0] == 'P' && arge[i][1] == 'A' && arge[i][2] == 'T' &&
|
||||
|
|
@ -109,32 +112,34 @@ 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);
|
||||
}
|
||||
|
||||
t_i32 main(t_i32 argc, t_str argv[], t_str arge[])
|
||||
t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
||||
{
|
||||
t_utils utils;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue