update: added folding into cmd and changed fold_word name
This commit is contained in:
parent
7fb16c6a90
commit
5c452993d6
15 changed files with 112 additions and 62 deletions
|
|
@ -1,8 +1,8 @@
|
|||
SRC_FILES = \
|
||||
env \
|
||||
_env_norm_helper \
|
||||
ft_exit \
|
||||
_helper_main \
|
||||
env \
|
||||
ft_exit \
|
||||
main \
|
||||
signal_handler \
|
||||
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/10/06 15:10:43 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/10/07 12:09:42 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ endif
|
|||
# CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument
|
||||
CFLAGS_ADDITIONAL += -gcolumn-info -g3 -fno-builtin
|
||||
# CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)'
|
||||
# CFLAGS_ADDITIONAL += -O2
|
||||
CFLAGS_ADDITIONAL += -O2
|
||||
# CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log
|
||||
# CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O3
|
||||
# CFLAGS_ADDITIONAL += -I$(shell realpath ./includes) -I$(shell realpath ./output/include)
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ me_alloc/merge_blocks \
|
|||
me_alloc/pages \
|
||||
me_alloc/realloc \
|
||||
vg/dummy_block \
|
||||
vg/dummy_mem_status \
|
||||
vg/dummy_mempool \
|
||||
vg/dummy_mempool_bis \
|
||||
vg/dummy_mem_status \
|
||||
vg/valgrind_block \
|
||||
vg/valgrind_mem_status \
|
||||
vg/valgrind_mempool \
|
||||
vg/valgrind_mempool_bis \
|
||||
vg/valgrind_mem_status \
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
SRC_FILES = \
|
||||
_here_doc \
|
||||
_not_done_boucle_print \
|
||||
_not_done_function \
|
||||
_not_done_scripting_print \
|
||||
ast_alloc/ast_alloc \
|
||||
ast_alloc/ast_alloc_scripting \
|
||||
ast_free/ast_free \
|
||||
|
|
@ -19,10 +23,6 @@ from_node/other_node \
|
|||
from_node/redirect_node \
|
||||
from_node/scripting_node \
|
||||
from_node/string_node \
|
||||
_here_doc \
|
||||
_not_done_boucle_print \
|
||||
_not_done_function \
|
||||
_not_done_scripting_print \
|
||||
print_ast/ast_print \
|
||||
print_ast/ast_print_arithmetic \
|
||||
print_ast/ast_print_command \
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
SRC_FILES = \
|
||||
builtins/cd \
|
||||
_read_dir \
|
||||
builtins/_debug \
|
||||
builtins/cd \
|
||||
builtins/echo \
|
||||
builtins/env \
|
||||
builtins/exit \
|
||||
builtins/export \
|
||||
builtins/pwd \
|
||||
builtins/unset \
|
||||
_read_dir \
|
||||
run_arithmetic/arithmetic \
|
||||
run_arithmetic/arithmetic_operation \
|
||||
run_arithmetic/_get_op \
|
||||
run_arithmetic/operator_bis \
|
||||
run_arithmetic/_run_arith \
|
||||
run_arithmetic/_to_ast_node \
|
||||
run_arithmetic/arithmetic \
|
||||
run_arithmetic/arithmetic_operation \
|
||||
run_arithmetic/operator_bis \
|
||||
run_ast/_ast_into_str \
|
||||
run_ast/_ast_into_str2 \
|
||||
run_ast/_ast_into_str3 \
|
||||
|
|
@ -21,21 +21,21 @@ run_ast/_ast_into_str4 \
|
|||
run_ast/_ast_into_str5 \
|
||||
run_ast/_ast_into_str6 \
|
||||
run_ast/_get_pid \
|
||||
run_ast/_run_exit_code \
|
||||
run_ast/_run_exp_operators \
|
||||
run_ast/_spawn_cmd \
|
||||
run_ast/_spawn_cmd_redir_fd \
|
||||
run_ast/_spawn_cmd_redir_heredoc \
|
||||
run_ast/run_builtins \
|
||||
run_ast/run_builtins2 \
|
||||
run_ast/run_cmd_sub \
|
||||
run_ast/run_command \
|
||||
run_ast/_run_exit_code \
|
||||
run_ast/run_expansion \
|
||||
run_ast/run_expansion_builtin \
|
||||
run_ast/_run_exp_operators \
|
||||
run_ast/run_list \
|
||||
run_ast/run_pipeline \
|
||||
run_ast/run_pipeline_helper \
|
||||
run_ast/run_program \
|
||||
run_ast/run_subshell \
|
||||
run_ast/run_words \
|
||||
run_ast/_spawn_cmd \
|
||||
run_ast/_spawn_cmd_redir_fd \
|
||||
run_ast/_spawn_cmd_redir_heredoc \
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ SRC_FILES = \
|
|||
line \
|
||||
line_edit_actions \
|
||||
line_edit_actions2 \
|
||||
line_editing \
|
||||
line_editing2 \
|
||||
line_edit_mode \
|
||||
line_edit_mode_interal \
|
||||
line_edit_mode_specific_key \
|
||||
line_editing \
|
||||
line_editing2 \
|
||||
line_globals \
|
||||
line_history \
|
||||
line_internals \
|
||||
|
|
|
|||
|
|
@ -1,23 +1,24 @@
|
|||
SRC_FILES = \
|
||||
passes \
|
||||
passes/double_quote_parsing \
|
||||
passes/fold_cmd \
|
||||
passes/fold_double_amp \
|
||||
passes/fold_double_carret \
|
||||
passes/fold_double_paren \
|
||||
passes/fold_double_pipe \
|
||||
passes/fold_double_quote \
|
||||
passes/fold_expansion \
|
||||
passes/fold_no_quote \
|
||||
passes/fold_redir \
|
||||
passes/fold_whitespace \
|
||||
passes/fold_word \
|
||||
passes/paren_to_nquote \
|
||||
passes/split_double_paren \
|
||||
passes/template_file \
|
||||
tokenizer \
|
||||
tokenizer_utils \
|
||||
token_lifetime \
|
||||
token_name \
|
||||
token_utils \
|
||||
tokenizer \
|
||||
tokenizer_utils \
|
||||
ts_print \
|
||||
|
||||
GEN_FILES = \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 18:43:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 15:27:24 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/07 16:46:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,13 +42,14 @@ t_error ts_double_pipe(t_vec_token input, t_vec_token *output);
|
|||
t_error ts_double_rcarret(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_double_rparen(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_double_string_pass(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_cmd(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_into_word(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_no_quote(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_whitespace(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_paren_to_noquote(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_split_paren(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_do_fuck_all(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_expension(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_redir(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_split_paren(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_paren_to_noquote(t_vec_token input, t_vec_token *output);
|
||||
t_error ts_fold_into_word(t_vec_token input, t_vec_token *output);
|
||||
|
||||
#endif /* PASSES_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/26 17:59:23 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/05 18:54:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/07 16:45:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ enum e_token
|
|||
TOK_AMP, // ampersand == &
|
||||
TOK_AND, // and == &&
|
||||
TOK_CARRET, // any carret == < > << >>
|
||||
TOK_CMD, // a meta token, which contains subtokens
|
||||
TOK_DLCARRET, // double left carret == <<
|
||||
TOK_DLPAREN, // double left parenthesis '(('
|
||||
TOK_DOLLAR, // dollar == $
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 16:50:33 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/07 16:46:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,15 +26,10 @@
|
|||
/// there is a few stuff we want to do, for example:
|
||||
/// - do somekind of arith expansion that will have any token between
|
||||
/// DOLLAR DLPAREN and the matching DRPAREN in it (yard algo)
|
||||
/// - do somekind of parenthesis token will have any token between
|
||||
/// LPAREN and the matching RPAREN in it
|
||||
///
|
||||
/// - do somekind of CMD token that will store every token that consitute
|
||||
/// command into a single token stopping at the correct ending:
|
||||
/// semicolon, pipe, or, and
|
||||
/// - do a smth that will take any <TOK (OR|AND) TOK> into a single token
|
||||
/// - do a smth that will take any TOK PIPE TOK into a single token and
|
||||
/// merge if any of the TOK is also a pipeline
|
||||
/// (merging may be done during the final ast building)
|
||||
|
||||
// here is the signature easily accessible:
|
||||
//
|
||||
|
|
@ -54,6 +49,7 @@ static const struct s_ts_pass_def g_ts_passes[] = {\
|
|||
{ts_double_lcarret, "double lcarret => dlcarret"}, \
|
||||
{ts_double_rcarret, "double rcarrer => drcarret"}, \
|
||||
{ts_fold_into_word, "fold into words"}, \
|
||||
{ts_fold_cmd, "fold into cmd"}, \
|
||||
// there should be an ts_fold_arith here
|
||||
{ts_split_paren, "split double parenthesis"}, \
|
||||
{ts_fold_redir, "fold redir+argument"}, \
|
||||
|
|
|
|||
61
parser/src/passes/fold_cmd.c
Normal file
61
parser/src/passes/fold_cmd.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fold_cmd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/07 16:45:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/string/string.h"
|
||||
#include "parser/passes.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_token.h"
|
||||
#include "parser/token.h"
|
||||
|
||||
static bool _is_cmd_node(enum e_token ttype)
|
||||
{
|
||||
return (ttype == TOK_WHITESPACE || ttype == TOK_WORD);
|
||||
};
|
||||
|
||||
/// This is a sample pass
|
||||
///
|
||||
/// There is a few rules the rest of the tokenizer machinery assumes
|
||||
/// theses function follows:
|
||||
/// - the input vec WILL be freed when the function return, even in
|
||||
/// case of error
|
||||
/// - the output vector isn't populated if the function returns an error,
|
||||
/// thus it shouldn't be freed in case of error
|
||||
/// - the output tokens may not be direct copy of the input tokens,
|
||||
/// but need to be cloned (different allocations for stuff)
|
||||
|
||||
t_error ts_fold_cmd(t_vec_token input, t_vec_token *output)
|
||||
{
|
||||
t_vec_token out;
|
||||
t_usize i;
|
||||
t_usize j;
|
||||
t_token tmp;
|
||||
|
||||
i = 0;
|
||||
out = vec_token_new(input.len, token_free);
|
||||
while (i < input.len)
|
||||
{
|
||||
if (_is_cmd_node(input.buffer[i].type))
|
||||
{
|
||||
j = 0;
|
||||
tmp = token_new(TOK_CMD);
|
||||
while (i + j < input.len \
|
||||
&& _is_cmd_node(input.buffer[i + j].type))
|
||||
vec_token_push(&tmp.subtokens, token_clone(&input.buffer[i + j++]));
|
||||
vec_token_push(&out, tmp);
|
||||
i += j;
|
||||
}
|
||||
else
|
||||
vec_token_push(&out, token_clone(&input.buffer[i++]));
|
||||
}
|
||||
vec_token_free(input);
|
||||
return (*output = out, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fold_double_quote.c :+: :+: :+: */
|
||||
/* fold_word.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 15:30:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/07 16:48:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,7 +32,8 @@ bool _type_extansion(enum e_token type)
|
|||
{
|
||||
if (type == TOK_DOLLAR)
|
||||
return (true);
|
||||
if (type == TOK_NQUOTE || type == TOK_DQUOTE || type == TOK_SQUOTE)
|
||||
if (type == TOK_NQUOTE || type == TOK_DQUOTE || type == TOK_SQUOTE \
|
||||
|| type == TOK_EXPENSION)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/06 13:32:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 13:32:39 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/07 16:47:20 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -62,5 +62,7 @@ t_str token_name(t_token *token)
|
|||
return ("DLPAREN");
|
||||
if (token->type == TOK_DRPAREN)
|
||||
return ("DRPAREN");
|
||||
if (token->type == TOK_CMD)
|
||||
return ("CMD");
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,32 +6,19 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/02 13:22:14 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 23:44:41 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/07 12:14:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/signal_handler.h"
|
||||
#include "me/types.h"
|
||||
#include "signal.h"
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void sig_print_trace(int _idk)
|
||||
{
|
||||
(void)(_idk);
|
||||
print_trace();
|
||||
}
|
||||
|
||||
t_error install_signal(void)
|
||||
{
|
||||
struct sigaction data;
|
||||
|
||||
data = (struct sigaction){};
|
||||
data.sa_handler = SIG_IGN;
|
||||
if (sigaction(SIGINT, &data, NULL))
|
||||
if (signal(SIGINT, SIG_IGN))
|
||||
return (ERROR);
|
||||
if (sigaction(SIGQUIT, &data, NULL))
|
||||
if (signal(SIGQUIT, SIG_IGN))
|
||||
return (ERROR);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ fs/fs_internal \
|
|||
fs/getters \
|
||||
fs/putfd \
|
||||
gnl/get_next_line \
|
||||
hash/hasher \
|
||||
hash/hash_signed \
|
||||
hash/hash_str \
|
||||
hash/hash_unsigned \
|
||||
hash/hasher \
|
||||
hash/sip/sip13 \
|
||||
hash/sip/sip_utils \
|
||||
hash/sip/sip_utils2 \
|
||||
|
|
@ -86,10 +86,6 @@ printf/printf \
|
|||
printf/printf_fd \
|
||||
printf/printf_str \
|
||||
printf/vprintf \
|
||||
string/mod \
|
||||
string/string_insert \
|
||||
string/string_remove \
|
||||
string/string_reserve \
|
||||
str/str_clone \
|
||||
str/str_compare \
|
||||
str/str_find_chr \
|
||||
|
|
@ -106,6 +102,10 @@ str/str_n_find_str \
|
|||
str/str_split \
|
||||
str/str_substring \
|
||||
str/str_trim \
|
||||
string/mod \
|
||||
string/string_insert \
|
||||
string/string_remove \
|
||||
string/string_reserve \
|
||||
|
||||
GEN_FILES = \
|
||||
convert/i16_to_str \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue