update: normed lots of stuff
This commit is contained in:
parent
978636b6ef
commit
50a2f3d4be
118 changed files with 1145 additions and 1330 deletions
|
|
@ -6,13 +6,13 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 18:15:08 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:32:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/colors.h"
|
||||
#include "app/env.h"
|
||||
#include "app/node.h"
|
||||
//#include "app/node.h"
|
||||
#include "app/signal_handler.h"
|
||||
#include "app/state.h"
|
||||
#include "ast/ast.h"
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
void ft_exit(t_state *maiboyerlpb, t_u8 exit_status);
|
||||
void print_node_data(t_node *t, t_usize depth);
|
||||
t_node parse_str(t_state *state);
|
||||
void parse_str(t_state *state);
|
||||
t_language *tree_sitter_sh(void);
|
||||
|
||||
t_error get_user_input(t_state *state)
|
||||
|
|
@ -60,7 +60,6 @@ void exec_shcat(t_state *state)
|
|||
t_program_result prog_res;
|
||||
|
||||
prog_res = (t_program_result){.exit = 0};
|
||||
free_node(state->current_node);
|
||||
if (state->ast != NULL && run_program(\
|
||||
&state->ast->data.program, state, &prog_res))
|
||||
printf("Error when execting the Command \n");
|
||||
|
|
@ -77,15 +76,15 @@ void ft_take_args(t_state *state)
|
|||
if (state->str_input == NULL)
|
||||
ft_exit(state, 0);
|
||||
line_history_add(state->str_input);
|
||||
state->current_node = parse_str(state);
|
||||
parse_str(state);
|
||||
exec_shcat(state);
|
||||
mem_free(state->str_input);
|
||||
}
|
||||
}
|
||||
|
||||
t_first_parser *create_myparser(void)
|
||||
t_parser *create_myparser(void)
|
||||
{
|
||||
t_first_parser *parser;
|
||||
t_parser *parser;
|
||||
|
||||
parser = ts_parser_new(tree_sitter_sh());
|
||||
return (parser);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/04 14:17:01 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:27:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#include "me/mem/mem.h"
|
||||
#include "parser/api.h"
|
||||
|
||||
void ts_parser_delete(t_first_parser *self);
|
||||
void ts_parser_delete(t_parser *self);
|
||||
|
||||
void ft_free(void *ptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/11 16:41:52 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:28:35 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/colors.h"
|
||||
#include "app/env.h"
|
||||
#include "app/node.h"
|
||||
#include "app/signal_handler.h"
|
||||
#include "app/state.h"
|
||||
#include "ast/ast.h"
|
||||
|
|
@ -28,9 +27,9 @@
|
|||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
t_error ast_from_node(t_parse_node node, t_str input, t_ast_node *out);
|
||||
t_error ast_from_node(t_node node, t_str input, t_ast_node *out);
|
||||
t_error get_user_input(t_state *state);
|
||||
t_first_parser *create_myparser(void);
|
||||
t_parser *create_myparser(void);
|
||||
void ast_print_node(t_ast_node self);
|
||||
void ft_exit(t_state *maiboyerlpb, t_u8 exit_status);
|
||||
void exec_shcat(t_state *state);
|
||||
|
|
@ -83,6 +82,7 @@ t_error populate_env(t_hashmap_env *env, t_str envp[])
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
void print_node_data(t_node *t, t_usize depth)
|
||||
{
|
||||
t_usize idx;
|
||||
|
|
@ -98,12 +98,12 @@ void print_node_data(t_node *t, t_usize depth)
|
|||
while (idx < t->childs_count)
|
||||
print_node_data(&t->childs[idx++], depth + 1);
|
||||
}
|
||||
*/
|
||||
|
||||
t_node parse_str(t_state *state)
|
||||
void parse_str(t_state *state)
|
||||
{
|
||||
t_first_tree *tree;
|
||||
t_parse_node node;
|
||||
t_node ret;
|
||||
t_tree *tree;
|
||||
t_node node;
|
||||
t_ast_node out;
|
||||
|
||||
tree = ts_parser_parse_string(state->parser, state->str_input, str_len(state->str_input));
|
||||
|
|
@ -115,9 +115,7 @@ t_node parse_str(t_state *state)
|
|||
}
|
||||
else
|
||||
state->ast = out;
|
||||
ret = build_node(node, state->str_input);
|
||||
ts_tree_delete(tree);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/28 18:36:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/06 15:35:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/node.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_node build_node(t_parse_node current, t_const_str input);
|
||||
|
||||
t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
|
||||
{
|
||||
t_node *ret;
|
||||
t_usize idx;
|
||||
t_parse_node child;
|
||||
|
||||
ret = mem_alloc_array(sizeof(*ret), count);
|
||||
if (ret == NULL)
|
||||
return (NULL);
|
||||
idx = 0;
|
||||
while (idx < count)
|
||||
{
|
||||
child = ts_node_child(parent, idx);
|
||||
ret[idx] = build_node(child, input);
|
||||
ret[idx].field = ts_node_field_id_for_child(parent, idx);
|
||||
ret[idx].field_str = ts_language_field_name_for_id(\
|
||||
ts_node_language(parent), ret[idx].field);
|
||||
idx++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_node build_node(t_parse_node curr, t_const_str input)
|
||||
{
|
||||
t_node out;
|
||||
|
||||
out.kind = ts_node_symbol(curr);
|
||||
out.kind_str = ts_language_symbol_name(ts_node_language(curr), out.kind);
|
||||
out.start = ts_node_start_byte(curr);
|
||||
out.end = ts_node_end_byte(curr);
|
||||
out.input = input;
|
||||
out.single_str = NULL;
|
||||
out.field_str = NULL;
|
||||
out.field = 0;
|
||||
out.childs_count = ts_node_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 self)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (self.single_str)
|
||||
mem_free(self.single_str);
|
||||
idx = 0;
|
||||
while (idx < self.childs_count)
|
||||
free_node(self.childs[idx++]);
|
||||
if (self.childs_count != 0)
|
||||
mem_free(self.childs);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue