update: changed the way heredocs are parsed
This commit is contained in:
parent
8272d72997
commit
43b969183d
365 changed files with 20907 additions and 51362 deletions
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _here_doc_not_done.c :+: :+: :+: */
|
||||
/* _here_doc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 16:37:28 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/06 10:53:13 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:14:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,12 +36,9 @@ t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, \
|
|||
if (ts_node_field_id_for_child(self, i) == field_op)
|
||||
ret->data.heredoc_redirection.op = \
|
||||
_get_redirection_op(ts_node_child(self, i));
|
||||
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_start)
|
||||
else if (ts_node_field_id_for_child(self, i) == field_del)
|
||||
ret->data.heredoc_redirection.delimiter = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_body)
|
||||
ret->data.heredoc_redirection.content = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 17:26:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/01 09:35:16 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:15:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -79,7 +79,6 @@ void ast_alloc_redirection(t_ast_node_kind kind, t_ast_node ret)
|
|||
if (kind == AST_HEREDOC_REDIRECTION)
|
||||
{
|
||||
ret->data.heredoc_redirection.delimiter = NULL;
|
||||
ret->data.heredoc_redirection.content = NULL;
|
||||
}
|
||||
if (kind == AST_LIST)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/01 09:35:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:14:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -89,7 +89,6 @@ void ast_free_redirection(t_ast_node elem)
|
|||
if (elem->kind == AST_HEREDOC_REDIRECTION)
|
||||
{
|
||||
mem_free(elem->data.heredoc_redirection.delimiter);
|
||||
mem_free(elem->data.heredoc_redirection.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:43:35 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 14:38:32 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:11:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
t_vec_ast *_append_scripting(\
|
||||
t_ast_node node)
|
||||
{
|
||||
|
|
@ -51,6 +52,8 @@ t_error build_sym_for_statement(\
|
|||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
ret = ast_alloc(AST_FOR);
|
||||
i = 0;
|
||||
|
|
@ -78,6 +81,7 @@ t_error build_sym_for_statement(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
t_error build_sym_while_statement(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
|
|
@ -98,6 +102,8 @@ t_error build_sym_while_statement(\
|
|||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
i = 0;
|
||||
if (ts_node_symbol(ts_node_child(self, 0)) == anon_sym_until)
|
||||
|
|
@ -131,6 +137,7 @@ t_error build_sym_while_statement(\
|
|||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
t_error build_sym_do_group(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
|
|
@ -149,6 +156,7 @@ t_error build_sym_do_group(\
|
|||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
ret = ast_alloc(AST_COMPOUND_STATEMENT);
|
||||
i = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 15:29:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:16:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
||||
|
||||
// if (ts_node_symbol(node) == sym_while_statement)
|
||||
// return (build_sym_while_statement(node, input, out));
|
||||
t_error _from_node_inner3(\
|
||||
t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
|
|
@ -45,13 +47,17 @@ t_error _from_node_inner3(\
|
|||
return (build_sym_subshell(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_variable_assignment)
|
||||
return (build_sym_variable_assignment(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_while_statement)
|
||||
return (build_sym_while_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_word)
|
||||
return (build_sym_word(node, input, out));
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
// if (ts_node_symbol(node) == sym_for_statement)
|
||||
// return (build_sym_for_statement(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_function_definition)
|
||||
// return (build_sym_function_definition(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_if_statement)
|
||||
// return (build_sym_if_statement(node, input, out));
|
||||
t_error _from_node_inner2(\
|
||||
t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
|
|
@ -61,14 +67,8 @@ t_error _from_node_inner2(\
|
|||
return (build_sym_file_descriptor(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_file_redirect)
|
||||
return (build_sym_file_redirect(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_for_statement)
|
||||
return (build_sym_for_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_function_definition)
|
||||
return (build_sym_function_definition(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_heredoc_redirect)
|
||||
return (build_sym_heredoc_redirect(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_if_statement)
|
||||
return (build_sym_if_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_list)
|
||||
return (build_sym_list(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_negated_command)
|
||||
|
|
@ -78,6 +78,12 @@ t_error _from_node_inner2(\
|
|||
return (_from_node_inner3(node, input, out));
|
||||
}
|
||||
|
||||
// if (ts_node_symbol(node) == sym_do_group)
|
||||
// return (build_sym_do_group(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_elif_clause)
|
||||
// return (build_sym_elif_clause(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_else_clause)
|
||||
// return (build_sym_else_clause(node, input, out));
|
||||
t_error _from_node_inner(\
|
||||
t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
|
|
@ -93,17 +99,16 @@ t_error _from_node_inner(\
|
|||
return (build_sym_compound_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_concatenation)
|
||||
return (build_sym_concatenation(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_do_group)
|
||||
return (build_sym_do_group(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_elif_clause)
|
||||
return (build_sym_elif_clause(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_else_clause)
|
||||
return (build_sym_else_clause(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_expansion)
|
||||
return (build_sym_expansion(node, input, out));
|
||||
return (_from_node_inner2(node, input, out));
|
||||
}
|
||||
|
||||
|
||||
// else if (ts_node_symbol(node) == sym_case_item)
|
||||
// return (build_sym_case_item(node, input, out));
|
||||
// else if (ts_node_symbol(node) == sym_case_statement)
|
||||
// return (build_sym_case_statement(node, input, out));
|
||||
t_error ast_from_node(\
|
||||
t_parse_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
|
|
@ -124,9 +129,5 @@ t_error ast_from_node(\
|
|||
return (build_sym_arithmetic_ternary_expression(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_unary_expression)
|
||||
return (build_sym_arithmetic_unary_expression(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_case_item)
|
||||
return (build_sym_case_item(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_case_statement)
|
||||
return (build_sym_case_statement(node, input, out));
|
||||
return (_from_node_inner(node, input, out));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:27:48 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 14:42:25 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/15 20:21:18 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,8 @@
|
|||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// else
|
||||
// *vec = _append_scripting(node);
|
||||
void _append_redirection_single(t_ast_node node, t_vec_ast **vec)
|
||||
{
|
||||
if (node->kind == AST_CASE)
|
||||
|
|
@ -30,8 +32,6 @@ void _append_redirection_single(t_ast_node node, t_vec_ast **vec)
|
|||
*vec = &node->data.compound_statement.suffixes_redirections;
|
||||
else if (node->kind == AST_SUBSHELL)
|
||||
*vec = &node->data.subshell.suffixes_redirections;
|
||||
else
|
||||
*vec = _append_scripting(node);
|
||||
}
|
||||
|
||||
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue