Update
This commit is contained in:
parent
3b197d82c2
commit
ff6bba98de
3 changed files with 104 additions and 59 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/06/20 23:15:26 by maiboyer ### ########.fr */
|
/* Updated: 2024/06/22 02:19:41 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -383,6 +383,17 @@ void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
|
||||||
|
|
||||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
||||||
|
|
||||||
|
/* FUNCTION THAT ARE DONE */
|
||||||
|
|
||||||
|
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
|
||||||
|
/* FUNCTION THAT ARE NOT DONE */
|
||||||
|
|
||||||
t_error build_sym_arithmetic_binary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_arithmetic_binary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_arithmetic_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_arithmetic_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_arithmetic_literal(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_arithmetic_literal(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
|
@ -392,12 +403,9 @@ t_error build_sym_arithmetic_ternary_expression(t_parse_node self, t_const_str i
|
||||||
t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
|
|
@ -415,27 +423,52 @@ t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, t_ast_node *
|
||||||
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_variable_assignments(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_variable_assignments(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_variable_name(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_variable_name(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||||
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out);
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
|
{
|
||||||
|
(void)(self);
|
||||||
|
(void)(input);
|
||||||
|
(void)(out);
|
||||||
|
if (out == NULL)
|
||||||
|
return (ERROR);
|
||||||
|
if (ts_node_grammar_symbol(self) != sym_concatenation)
|
||||||
|
return (ERROR);
|
||||||
|
return (ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
|
{
|
||||||
|
t_ast_node ret;
|
||||||
|
t_str temp_str;
|
||||||
|
|
||||||
|
if (out == NULL)
|
||||||
|
return (ERROR);
|
||||||
|
if (ts_node_grammar_symbol(self) != sym_string_content)
|
||||||
|
return (ERROR);
|
||||||
|
ret = ast_alloc(AST_RAW_STRING);
|
||||||
|
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
|
||||||
|
ret->data.raw_string.str = temp_str;
|
||||||
|
ret->data.raw_string.len = str_len(temp_str);
|
||||||
|
printf("temp_str = '%s'\n", temp_str);
|
||||||
|
return (*out = ret, NO_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
{
|
{
|
||||||
t_ast_node ret;
|
t_ast_node ret;
|
||||||
|
|
@ -490,10 +523,33 @@ static inline t_vec_ast *_vec_command(t_ast_command *val, t_usize i)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void _append_redirection(t_ast_command *val, t_ast_node redirection)
|
static inline void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||||
{
|
{
|
||||||
(void)(val);
|
t_vec_ast *vec;
|
||||||
(void)(redirection);
|
|
||||||
|
vec = NULL;
|
||||||
|
if (node->kind == AST_CASE)
|
||||||
|
vec = &node->data.case_.suffixes_redirections;
|
||||||
|
if (node->kind == AST_COMMAND)
|
||||||
|
vec = &node->data.command.suffixes_redirections;
|
||||||
|
if (node->kind == AST_COMPOUND_STATEMENT)
|
||||||
|
vec = &node->data.compound_statement.suffixes_redirections;
|
||||||
|
if (node->kind == AST_FOR)
|
||||||
|
vec = &node->data.for_.suffixes_redirections;
|
||||||
|
if (node->kind == AST_IF)
|
||||||
|
vec = &node->data.if_.suffixes_redirections;
|
||||||
|
if (node->kind == AST_LIST)
|
||||||
|
vec = &node->data.list.suffixes_redirections;
|
||||||
|
if (node->kind == AST_PIPELINE)
|
||||||
|
vec = &node->data.pipeline.suffixes_redirections;
|
||||||
|
if (node->kind == AST_SUBSHELL)
|
||||||
|
vec = &node->data.subshell.suffixes_redirections;
|
||||||
|
if (node->kind == AST_UNTIL)
|
||||||
|
vec = &node->data.until.suffixes_redirections;
|
||||||
|
if (node->kind == AST_WHILE)
|
||||||
|
vec = &node->data.while_.suffixes_redirections;
|
||||||
|
if (vec)
|
||||||
|
vec_ast_push(vec, redirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
|
|
@ -512,6 +568,7 @@ t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
|
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
|
||||||
temp->data.raw_string.str = temp_str;
|
temp->data.raw_string.str = temp_str;
|
||||||
temp->data.raw_string.len = str_len(temp_str);
|
temp->data.raw_string.len = str_len(temp_str);
|
||||||
|
printf("temp_str = '%s'\n", temp_str);
|
||||||
vec_ast_push(&ret->data.word.inner, temp);
|
vec_ast_push(&ret->data.word.inner, temp);
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
@ -543,6 +600,40 @@ t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
|
{
|
||||||
|
t_ast_node ret;
|
||||||
|
t_ast_node *output;
|
||||||
|
t_usize i;
|
||||||
|
t_symbol temp;
|
||||||
|
|
||||||
|
if (out == NULL)
|
||||||
|
return (ERROR);
|
||||||
|
|
||||||
|
ret = ast_alloc(AST_LIST);
|
||||||
|
i = 0;
|
||||||
|
output = &ret->data.list.left;
|
||||||
|
while (i < ts_node_named_child_count(self))
|
||||||
|
{
|
||||||
|
if (ts_node_field_id_for_child(self, i) == field_cmd)
|
||||||
|
{
|
||||||
|
if (ast_from_node(ts_node_named_child(self, i), input, output))
|
||||||
|
return (ast_free(ret), ERROR);
|
||||||
|
}
|
||||||
|
else if (ts_node_field_id_for_child(self, i) == field_op)
|
||||||
|
{
|
||||||
|
temp = ts_node_grammar_symbol(ts_node_named_child(self, i));
|
||||||
|
if (temp == anon_sym_PIPE_PIPE)
|
||||||
|
ret->data.list.op = AST_LIST_OR;
|
||||||
|
if (temp == anon_sym_AMP_AMP)
|
||||||
|
ret->data.list.op = AST_LIST_AND;
|
||||||
|
output = &ret->data.list.right;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (*out = ret, NO_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
||||||
{
|
{
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
|
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/05/23 15:27:13 by maiboyer ### ########.fr */
|
/* Updated: 2024/06/21 13:55:02 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,7 +36,6 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
||||||
{
|
{
|
||||||
t_usize i;
|
t_usize i;
|
||||||
t_spawn_info spawn_info;
|
t_spawn_info spawn_info;
|
||||||
t_str tmp;
|
|
||||||
|
|
||||||
spawn_info.arguments =
|
spawn_info.arguments =
|
||||||
vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
|
vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
|
||||||
|
|
@ -58,10 +57,6 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
||||||
printf("PAS ENCORE HANDLE FDP asignement!\n");
|
printf("PAS ENCORE HANDLE FDP asignement!\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (handle_node_getstr(&self->childs[i], shcat, &tmp))
|
|
||||||
return (vec_str_free(spawn_info.arguments), ERROR);
|
|
||||||
if (vec_str_push(&spawn_info.arguments, str_clone(tmp)))
|
|
||||||
return (ERROR);
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,13 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/06/20 23:04:03 by maiboyer ### ########.fr */
|
/* Updated: 2024/06/21 13:53:27 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "app/env.h"
|
#include "app/env.h"
|
||||||
#include "app/node.h"
|
#include "app/node.h"
|
||||||
#include "app/node/handle_concat.h"
|
|
||||||
#include "app/node/handle_program.h"
|
|
||||||
#include "app/signal_handler.h"
|
#include "app/signal_handler.h"
|
||||||
#include "gmr/symbols.h"
|
|
||||||
#include "me/hashmap/hashmap_env.h"
|
#include "me/hashmap/hashmap_env.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
@ -76,20 +73,6 @@ t_error populate_env(t_hashmap_env *env, t_str envp[])
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error handle_node_getstr(t_node *self, t_utils *shcat, t_str *out)
|
|
||||||
{
|
|
||||||
*out = NULL;
|
|
||||||
if (self->kind == sym_word)
|
|
||||||
{
|
|
||||||
*out = node_getstr(self);
|
|
||||||
return (NO_ERROR);
|
|
||||||
}
|
|
||||||
if (self->kind == sym_concatenation)
|
|
||||||
return (handle_concat(self, shcat, out));
|
|
||||||
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_node_data(t_node *t, t_usize depth)
|
void print_node_data(t_node *t, t_usize depth)
|
||||||
{
|
{
|
||||||
t_usize idx;
|
t_usize idx;
|
||||||
|
|
@ -131,34 +114,10 @@ t_node parse_str(t_parser *parser, t_const_str input)
|
||||||
return (parse_to_nodes(parser->parser, input));
|
return (parse_to_nodes(parser->parser, input));
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret);
|
|
||||||
|
|
||||||
void print_node_concat(t_node *self)
|
|
||||||
{
|
|
||||||
if (self->kind != sym_concatenation)
|
|
||||||
{
|
|
||||||
t_usize i = 0;
|
|
||||||
while (i < self->childs_count)
|
|
||||||
print_node_concat(&self->childs[i++]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
t_str ret;
|
|
||||||
if (handle_concat(self, NULL, &ret))
|
|
||||||
return ((void)printf("ERROR\n"));
|
|
||||||
printf("concat value = '%s'\n", ret);
|
|
||||||
free(ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec_shcat(t_utils *shcat)
|
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);
|
free_node(shcat->current_node);
|
||||||
(void)ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_take_args(t_utils *shcat)
|
void ft_take_args(t_utils *shcat)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue