update
This commit is contained in:
parent
d16b39091a
commit
ff1670e264
15 changed files with 435 additions and 243 deletions
|
|
@ -6,13 +6,14 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/19 14:51:28 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/29 16:39:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
#include "app/env.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
|
||||
void ts_parser_delete(t_first_parser *self);
|
||||
|
|
@ -20,7 +21,7 @@ void ts_parser_delete(t_first_parser *self);
|
|||
void ft_free(void *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
free(ptr);
|
||||
mem_free(ptr);
|
||||
}
|
||||
|
||||
void ft_free_strs(t_str *strs)
|
||||
|
|
@ -36,7 +37,7 @@ void ft_free_strs(t_str *strs)
|
|||
void ft_free_utils(t_utils *s)
|
||||
{
|
||||
if (s->str_input)
|
||||
free(s->str_input);
|
||||
mem_free(s->str_input);
|
||||
if (s->path)
|
||||
ft_free_strs(s->path);
|
||||
if (s->env)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/21 14:53:26 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/29 16:40:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,12 +18,13 @@
|
|||
#include "gmr/symbols.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "minishell.h"
|
||||
#include "parser/api.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "ast/from_node.h"
|
||||
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
|
|
@ -87,7 +88,6 @@ t_error handle_node_getstr(t_node *self, t_utils *shcat, t_str *out)
|
|||
*out = NULL;
|
||||
if (self->kind == sym_word)
|
||||
{
|
||||
printf("word!!!\n");
|
||||
*out = node_getstr(self);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -102,7 +102,11 @@ void print_node_data(t_node *t, t_usize depth)
|
|||
t_usize idx;
|
||||
|
||||
idx = 0;
|
||||
while (idx++ < depth)
|
||||
if (t->kind == 7)
|
||||
return;
|
||||
printf("\x1b[%im[%s](%lu)\x1b[0m", t->field_str == NULL ? 90 : 32,
|
||||
t->field_str == NULL ? "nil" : t->field_str, t->field);
|
||||
while (idx++ < depth + 1)
|
||||
printf("\t");
|
||||
idx = 0;
|
||||
printf("%s(%lu) = %s\n", t->kind_str, t->kind, node_getstr(t));
|
||||
|
|
@ -122,31 +126,12 @@ t_node parse_to_nodes(t_first_parser *parser, t_const_str input)
|
|||
ts_tree_delete(tree);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_node parse_str(t_parser *parser, t_const_str input)
|
||||
{
|
||||
return (parse_to_nodes(parser->parser, input));
|
||||
}
|
||||
|
||||
// void ft_check(t_utils *shcat, char **input)
|
||||
// {
|
||||
// t_usize i;
|
||||
// t_usize prev_i;
|
||||
//
|
||||
// i = 0;
|
||||
// prev_i = 0;
|
||||
// while (input[i] != NULL)
|
||||
// {
|
||||
// if (ft_strcmp(input[i], "exit") == 0)
|
||||
// ft_exit(shcat, 0);
|
||||
// else if (ft_strcmp(input[i], "pwd") == 0)
|
||||
// ft_pwd();
|
||||
// else
|
||||
// ft_other_cmd(shcat, i, prev_i);
|
||||
// prev_i = i;
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
|
||||
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret);
|
||||
|
||||
void print_node_concat(t_node *self)
|
||||
|
|
@ -171,7 +156,7 @@ void exec_shcat(t_utils *shcat)
|
|||
{
|
||||
t_i32 ret;
|
||||
|
||||
// print_node_data(&shcat->current_node, 0);
|
||||
print_node_data(&shcat->current_node, 0);
|
||||
handle_program(&shcat->current_node, shcat, &ret);
|
||||
free_node(shcat->current_node);
|
||||
(void)ret;
|
||||
|
|
@ -179,16 +164,20 @@ void exec_shcat(t_utils *shcat)
|
|||
|
||||
void ft_take_args(t_utils *shcat)
|
||||
{
|
||||
t_str cmd;
|
||||
|
||||
while (1)
|
||||
{
|
||||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
if (!shcat->str_input)
|
||||
shcat->str_input = NULL;
|
||||
cmd = readline((t_const_str)shcat->name_shell);
|
||||
if (cmd == NULL)
|
||||
ft_exit(shcat, 0);
|
||||
shcat->str_input = str_clone(cmd);
|
||||
free(cmd);
|
||||
shcat->current_node = parse_str(&shcat->parser, shcat->str_input);
|
||||
exec_shcat(shcat);
|
||||
add_history(shcat->str_input);
|
||||
free(shcat->str_input);
|
||||
mem_free(shcat->str_input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,4 +220,5 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
|||
"\001\x1B[0m\002"
|
||||
"$ ";
|
||||
ft_take_args(&utils);
|
||||
// (void)from_node(NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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"
|
||||
|
|
@ -6,13 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/28 18:36:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/18 16:14:55 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/29 14:52:46 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/node.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
|
@ -24,6 +23,11 @@ t_const_str ts_node_type(t_parse_node self);
|
|||
t_u32 ts_node_start_byte(t_parse_node self);
|
||||
t_u32 ts_node_end_byte(t_parse_node self);
|
||||
t_u32 ts_node_child_count(t_parse_node self);
|
||||
t_const_str ts_node_field_name_for_child(t_parse_node self, t_u32 child_index);
|
||||
t_u64 ts_language_field_id_for_name(t_language *lang, t_const_str name,
|
||||
t_u64 name_len);
|
||||
|
||||
t_language *tree_sitter_bash(void);
|
||||
|
||||
t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
|
||||
{
|
||||
|
|
@ -39,6 +43,10 @@ t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
|
|||
{
|
||||
child = ts_node_child(parent, idx);
|
||||
ret[idx] = build_node(child, input);
|
||||
ret[idx].field_str = ts_node_field_name_for_child(parent, idx);
|
||||
ret[idx].field = ts_language_field_id_for_name(
|
||||
tree_sitter_bash(), ret[idx].field_str,
|
||||
str_len(ret[idx].field_str));
|
||||
idx++;
|
||||
}
|
||||
return (ret);
|
||||
|
|
@ -54,6 +62,7 @@ t_node build_node(t_parse_node curr, t_const_str input)
|
|||
out.end = ts_node_end_byte(curr);
|
||||
out.input = input;
|
||||
out.single_str = NULL;
|
||||
out.field_str = NULL;
|
||||
out.childs_count = ts_node_child_count(curr);
|
||||
if (out.childs_count == 0)
|
||||
out.childs = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue