Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9041c2ce6a
5 changed files with 40 additions and 46 deletions
4
Makefile
4
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
# Updated: 2024/08/12 17:53:35 by rparodi ### ########.fr #
|
# Updated: 2024/08/14 17:36:13 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# TODO: ADD THIS WHEN FINISHING THIS:
|
# TODO: ADD THIS WHEN FINISHING THIS:
|
||||||
CFLAGS_ADDITIONAL += -DNVALGRIND
|
# CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||||
CFLAGS_ADDITIONAL += -O0 -Wno-cpp
|
CFLAGS_ADDITIONAL += -O0 -Wno-cpp
|
||||||
|
|
||||||
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,13 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/09 15:07:10 by rparodi #+# #+# */
|
/* Created: 2024/08/09 15:07:10 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/08/09 15:16:00 by rparodi ### ########.fr */
|
/* Updated: 2024/08/14 17:28:46 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ast/_from_node.h"
|
#include "ast/_from_node.h"
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
#include "gmr/field_identifiers.h"
|
#include "gmr/field_identifiers.h"
|
||||||
#include "gmr/field_identifiers.h"
|
|
||||||
#include "gmr/symbols.h"
|
|
||||||
#include "gmr/symbols.h"
|
#include "gmr/symbols.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
@ -22,10 +20,9 @@
|
||||||
#include "parser/api.h"
|
#include "parser/api.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
t_error build_sym_negated_command(\
|
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
|
||||||
{
|
{
|
||||||
t_ast_node ret;
|
t_ast_node ret;
|
||||||
|
|
||||||
(void)(out);
|
(void)(out);
|
||||||
(void)(input);
|
(void)(input);
|
||||||
|
|
@ -42,12 +39,12 @@ t_error build_sym_negated_command(\
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error build_sym_pipeline(\
|
t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
|
||||||
{
|
{
|
||||||
t_ast_node ret;
|
t_ast_node ret;
|
||||||
t_ast_node tmp;
|
t_ast_node tmp;
|
||||||
t_usize i;
|
t_ast_node tmp2;
|
||||||
|
t_usize i;
|
||||||
|
|
||||||
(void)(out);
|
(void)(out);
|
||||||
(void)(input);
|
(void)(input);
|
||||||
|
|
@ -61,16 +58,23 @@ t_error build_sym_pipeline(\
|
||||||
while (i < ts_node_child_count(self))
|
while (i < ts_node_child_count(self))
|
||||||
{
|
{
|
||||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||||
continue ;
|
continue;
|
||||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||||
return (ast_free(ret), ERROR);
|
return (ast_free(ret), ERROR);
|
||||||
vec_ast_push(&ret->data.pipeline.statements, tmp);
|
if (tmp->kind == AST_PIPELINE)
|
||||||
|
{
|
||||||
|
while (!vec_ast_pop_front(&tmp->data.pipeline.statements, &tmp2))
|
||||||
|
vec_ast_push(&ret->data.pipeline.statements, tmp2);
|
||||||
|
ast_free(tmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
vec_ast_push(&ret->data.pipeline.statements, tmp);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
(void)(out);
|
(void)(out);
|
||||||
(void)(input);
|
(void)(input);
|
||||||
|
|
@ -83,11 +87,10 @@ t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error build_sym_variable_assignment(\
|
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
|
||||||
{
|
{
|
||||||
t_ast_node ret;
|
t_ast_node ret;
|
||||||
t_parse_node temp_ast;
|
t_parse_node temp_ast;
|
||||||
|
|
||||||
(void)(self);
|
(void)(self);
|
||||||
(void)(input);
|
(void)(input);
|
||||||
|
|
@ -106,8 +109,7 @@ t_error build_sym_variable_assignment(\
|
||||||
}
|
}
|
||||||
if (ts_node_child_count(self) > 2)
|
if (ts_node_child_count(self) > 2)
|
||||||
{
|
{
|
||||||
if (ast_from_node(ts_node_child(self, 2), \
|
if (ast_from_node(ts_node_child(self, 2), input, &ret->data.variable_assignment.value))
|
||||||
input, &ret->data.variable_assignment.value))
|
|
||||||
return (ast_free(ret), ERROR);
|
return (ast_free(ret), ERROR);
|
||||||
}
|
}
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/08/12 16:35:07 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/14 17:37:41 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -469,7 +469,7 @@ t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
}
|
}
|
||||||
else if (ts_node_field_id_for_child(self, i) == field_op)
|
else if (ts_node_field_id_for_child(self, i) == field_op)
|
||||||
{
|
{
|
||||||
temp = ts_node_symbol(ts_node_child(self, i));
|
temp = ts_node_grammar_symbol(ts_node_child(self, i));
|
||||||
if (temp == anon_sym_PIPE_PIPE)
|
if (temp == anon_sym_PIPE_PIPE)
|
||||||
ret->data.list.op = AST_LIST_OR;
|
ret->data.list.op = AST_LIST_OR;
|
||||||
if (temp == anon_sym_AMP_AMP)
|
if (temp == anon_sym_AMP_AMP)
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,13 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/06 18:27:48 by rparodi #+# #+# */
|
/* Created: 2024/08/06 18:27:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/08/06 18:30:53 by rparodi ### ########.fr */
|
/* Updated: 2024/08/14 17:31:57 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ast/_from_node.h"
|
#include "ast/_from_node.h"
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
#include "gmr/field_identifiers.h"
|
#include "gmr/field_identifiers.h"
|
||||||
#include "gmr/field_identifiers.h"
|
|
||||||
#include "gmr/symbols.h"
|
|
||||||
#include "gmr/symbols.h"
|
#include "gmr/symbols.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
@ -22,13 +20,13 @@
|
||||||
#include "parser/api.h"
|
#include "parser/api.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||||
{
|
{
|
||||||
t_vec_ast *vec;
|
t_vec_ast *vec;
|
||||||
|
|
||||||
vec = NULL;
|
vec = NULL;
|
||||||
if (!(redirection->kind == AST_FILE_REDIRECTION || \
|
|
||||||
redirection->kind == AST_HEREDOC_REDIRECTION))
|
if (node == NULL || redirection == NULL || !(redirection->kind == AST_FILE_REDIRECTION || redirection->kind == AST_HEREDOC_REDIRECTION))
|
||||||
return (ast_free(redirection));
|
return (ast_free(redirection));
|
||||||
if (node->kind == AST_CASE)
|
if (node->kind == AST_CASE)
|
||||||
vec = &node->data.case_.suffixes_redirections;
|
vec = &node->data.case_.suffixes_redirections;
|
||||||
|
|
@ -37,9 +35,9 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||||
else if (node->kind == AST_COMPOUND_STATEMENT)
|
else if (node->kind == AST_COMPOUND_STATEMENT)
|
||||||
vec = &node->data.compound_statement.suffixes_redirections;
|
vec = &node->data.compound_statement.suffixes_redirections;
|
||||||
else if (node->kind == AST_LIST)
|
else if (node->kind == AST_LIST)
|
||||||
vec = &node->data.list.suffixes_redirections;
|
return (_append_redirection(node->data.list.right, redirection));
|
||||||
else if (node->kind == AST_PIPELINE)
|
else if (node->kind == AST_PIPELINE && node->data.pipeline.statements.len != 0)
|
||||||
vec = &node->data.pipeline.suffixes_redirections;
|
return (_append_redirection(node->data.pipeline.statements.buffer[node->data.pipeline.statements.len - 1], redirection));
|
||||||
else if (node->kind == AST_SUBSHELL)
|
else if (node->kind == AST_SUBSHELL)
|
||||||
vec = &node->data.subshell.suffixes_redirections;
|
vec = &node->data.subshell.suffixes_redirections;
|
||||||
else
|
else
|
||||||
|
|
@ -50,9 +48,9 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||||
(ast_free(redirection));
|
(ast_free(redirection));
|
||||||
}
|
}
|
||||||
|
|
||||||
t_ast_terminator_kind _select_term(t_parse_node node)
|
t_ast_terminator_kind _select_term(t_parse_node node)
|
||||||
{
|
{
|
||||||
t_symbol symbol;
|
t_symbol symbol;
|
||||||
|
|
||||||
symbol = ts_node_grammar_symbol(ts_node_child(node, 0));
|
symbol = ts_node_grammar_symbol(ts_node_child(node, 0));
|
||||||
if (symbol == anon_sym_SEMI)
|
if (symbol == anon_sym_SEMI)
|
||||||
|
|
@ -63,10 +61,10 @@ t_ast_terminator_kind _select_term(t_parse_node node)
|
||||||
return (AST_TERM_NONE);
|
return (AST_TERM_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_str _extract_str(t_parse_node self, t_const_str input)
|
t_str _extract_str(t_parse_node self, t_const_str input)
|
||||||
{
|
{
|
||||||
t_usize start;
|
t_usize start;
|
||||||
t_usize end;
|
t_usize end;
|
||||||
t_str result;
|
t_str result;
|
||||||
|
|
||||||
start = ts_node_start_byte(self);
|
start = ts_node_start_byte(self);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/08/13 17:08:05 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/14 17:39:16 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -577,7 +577,6 @@ t_error run_list(t_ast_list *list, t_state *state, t_list_result *out)
|
||||||
if (list == NULL || state == NULL || out == NULL)
|
if (list == NULL || state == NULL || out == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
append = NULL;
|
append = NULL;
|
||||||
printf("LIST\n");
|
|
||||||
if (list->right->kind == AST_COMMAND)
|
if (list->right->kind == AST_COMMAND)
|
||||||
append = &list->right->data.command.suffixes_redirections;
|
append = &list->right->data.command.suffixes_redirections;
|
||||||
if (list->right->kind == AST_PIPELINE)
|
if (list->right->kind == AST_PIPELINE)
|
||||||
|
|
@ -595,9 +594,6 @@ t_error run_list(t_ast_list *list, t_state *state, t_list_result *out)
|
||||||
right = -1;
|
right = -1;
|
||||||
if (_run_get_exit_code(list->left, state, &left))
|
if (_run_get_exit_code(list->left, state, &left))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
printf("left == %i\n", left);
|
|
||||||
printf("(list->op == AST_LIST_AND && left == 0) == %s\n", (list->op == AST_LIST_AND && left == 0) ? "true" : "false");
|
|
||||||
printf("(list->op == AST_LIST_OR && left != 0) == %s\n", (list->op == AST_LIST_OR && left != 0) ? "true" : "false");
|
|
||||||
if ((list->op == AST_LIST_OR && left != 0) || (list->op == AST_LIST_AND && left == 0))
|
if ((list->op == AST_LIST_OR && left != 0) || (list->op == AST_LIST_AND && left == 0))
|
||||||
{
|
{
|
||||||
if (_run_get_exit_code(list->right, state, &right))
|
if (_run_get_exit_code(list->right, state, &right))
|
||||||
|
|
@ -852,8 +848,6 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_vec_ast redirection, t_state *state
|
||||||
info = (t_spawn_info){};
|
info = (t_spawn_info){};
|
||||||
if (cmd_pipe.input != NULL)
|
if (cmd_pipe.input != NULL)
|
||||||
info.stdin = fd(cmd_pipe.input);
|
info.stdin = fd(cmd_pipe.input);
|
||||||
if (cmd_pipe.input != NULL && !(cmd_pipe.input->perms & FD_READ))
|
|
||||||
printf("PERMISSION ERROR for %s !\n", cmd_pipe.input->name);
|
|
||||||
if (cmd_pipe.create_output)
|
if (cmd_pipe.create_output)
|
||||||
info.stdout = piped();
|
info.stdout = piped();
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue