redirected statement now doesn't break pipeline
This commit is contained in:
parent
4e56302770
commit
f4f749830f
2 changed files with 35 additions and 35 deletions
|
|
@ -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,8 +20,7 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
|
@ -42,11 +39,11 @@ 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_ast_node tmp2;
|
||||||
t_usize i;
|
t_usize i;
|
||||||
|
|
||||||
(void)(out);
|
(void)(out);
|
||||||
|
|
@ -64,6 +61,13 @@ t_error build_sym_pipeline(\
|
||||||
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);
|
||||||
|
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);
|
vec_ast_push(&ret->data.pipeline.statements, tmp);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -83,8 +87,7 @@ 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;
|
||||||
|
|
@ -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,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"
|
||||||
|
|
@ -27,8 +25,8 @@ 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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue