diff --git a/parser/src/passes.c b/parser/src/passes.c index a9b89b72..c2279cb9 100644 --- a/parser/src/passes.c +++ b/parser/src/passes.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */ -/* Updated: 2024/10/08 13:40:48 by maiboyer ### ########.fr */ +/* Updated: 2024/10/08 14:52:02 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,10 +50,10 @@ 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"}, \ + {ts_fold_cmd, "fold into cmd"}, \ }; t_error ts_apply_passes(t_vec_token ts, t_vec_token *out) @@ -72,7 +72,7 @@ t_error ts_apply_passes(t_vec_token ts, t_vec_token *out) else me_printf("Applied '%s' pass\n", g_ts_passes[i].name); ts = next; - //ts_print(&ts); + ts_print(&ts); i++; } return (*out = ts, NO_ERROR); @@ -104,7 +104,7 @@ t_error ts_dq_apply_passes(t_vec_token ts, t_vec_token *out) else me_printf("Applied '%s' dq_pass\n", g_ts_dq_passes[i].name); ts = next; - //ts_print(&ts); + ts_print(&ts); i++; } return (*out = ts, NO_ERROR); diff --git a/parser/src/passes/fold_cmd.c b/parser/src/passes/fold_cmd.c index 8960f82d..a226e1c3 100644 --- a/parser/src/passes/fold_cmd.c +++ b/parser/src/passes/fold_cmd.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */ -/* Updated: 2024/10/08 13:40:23 by maiboyer ### ########.fr */ +/* Updated: 2024/10/08 14:44:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ static bool _is_cmd_node(enum e_token ttype) { - return (ttype == TOK_WHITESPACE || ttype == TOK_WORD); + return (ttype == TOK_WHITESPACE || ttype == TOK_WORD || ttype == TOK_REDIR); }; /// This is a sample pass @@ -49,12 +49,18 @@ t_error ts_fold_cmd(t_vec_token input, t_vec_token *output) tmp = token_new_meta(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++])); + { + if (input.buffer[i + j].type != TOK_WHITESPACE) + vec_token_push(&tmp.subtokens, token_clone(&input.buffer[i + j])); + 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); diff --git a/parser/src/token_lifetime.c b/parser/src/token_lifetime.c index ee7eaccb..1dc63c13 100644 --- a/parser/src/token_lifetime.c +++ b/parser/src/token_lifetime.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/28 14:37:13 by maiboyer #+# #+# */ -/* Updated: 2024/10/06 13:33:34 by maiboyer ### ########.fr */ +/* Updated: 2024/10/08 14:46:59 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,8 @@ void token_free(t_token tok) { - if (tok.string.buf != NULL) - string_free(tok.string); - if (tok.subtokens.buffer != NULL) - vec_token_free(tok.subtokens); + string_free(tok.string); + vec_token_free(tok.subtokens); } t_token token_new(enum e_token type) diff --git a/parser/src/token_name.c b/parser/src/token_name.c index fc5f4d31..5fc33dcd 100644 --- a/parser/src/token_name.c +++ b/parser/src/token_name.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/06 13:32:28 by maiboyer #+# #+# */ -/* Updated: 2024/10/07 16:47:20 by maiboyer ### ########.fr */ +/* Updated: 2024/10/08 14:28:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,5 +64,7 @@ t_str token_name(t_token *token) return ("DRPAREN"); if (token->type == TOK_CMD) return ("CMD"); + if (token->type == TOK_REDIR) + return ("REDIR"); return (NULL); } diff --git a/parser/src/token_utils.c b/parser/src/token_utils.c index 03551d5c..1f44f4c1 100644 --- a/parser/src/token_utils.c +++ b/parser/src/token_utils.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/06 13:33:12 by maiboyer #+# #+# */ -/* Updated: 2024/10/08 13:40:57 by maiboyer ### ########.fr */ +/* Updated: 2024/10/08 14:51:41 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/parser/src/yarn/yarn.c b/parser/src/yarn/yarn.c index 7965ddbc..e40d0c32 100644 --- a/parser/src/yarn/yarn.c +++ b/parser/src/yarn/yarn.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */ -/* Updated: 2024/10/08 14:20:10 by rparodi ### ########.fr */ +/* Updated: 2024/10/08 14:51:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "me/types.h" #include "me/vec/vec_token.h" #include "parser/token.h" +#include int _get_precedance(t_token *token) { @@ -25,8 +26,9 @@ int _get_precedance(t_token *token) return (1); return (0); } +t_str token_name(t_token *token); -t_error yarn(t_vec_token *list, t_vec_token *output) +t_error yarn(t_vec_token ts, t_vec_token *out) { t_token tmp; t_token tmp2; @@ -35,7 +37,7 @@ t_error yarn(t_vec_token *list, t_vec_token *output) output_queue = vec_token_new(16, token_free);; operator_stack = vec_token_new(16, token_free);; - while (!vec_token_pop_front(list, &tmp)) + while (!vec_token_pop_front(&ts, &tmp)) { if (tmp.type == TOK_CMD) vec_token_push(&output_queue, tmp); @@ -59,14 +61,20 @@ t_error yarn(t_vec_token *list, t_vec_token *output) } if (!(vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type == TOK_LPAREN)) return (ERROR); - vec_token_pop(&operator_stack, NULL); + token_free(tmp); + vec_token_pop(&operator_stack, &tmp); + token_free(tmp); } + else + printf("TOK WTF? %s", token_name(&tmp)); } while (!vec_token_pop(&operator_stack, &tmp)) { if (tmp.type == TOK_LPAREN) - return (ERROR); + return (token_free(tmp), ERROR); vec_token_push(&output_queue, tmp); } - return (*output = output_queue, NO_ERROR); + vec_token_free(ts); + vec_token_free(operator_stack); + return (*out = output_queue, NO_ERROR); } diff --git a/sources/main.c b/sources/main.c index 27997628..5b268589 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/10/08 14:22:42 by rparodi ### ########.fr */ +/* Updated: 2024/10/08 14:41:06 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -101,21 +101,20 @@ void print_node_data(t_node *t, t_usize depth) } */ -t_error yarn(t_vec_token *list, t_vec_token *output); +t_error yarn(t_vec_token ts, t_vec_token *output); void parse_str(t_state *state) { t_vec_token tokens; - t_vec_token tok_yarn; if (tokenize(state->str_input, &tokens)) return ; if (ts_apply_passes(tokens, &tokens)) return ; - if (yarn(&tokens, &tok_yarn)) + if (yarn(tokens, &tokens)) return ; printf("\n\nEND TOKENS\n"); - ts_print(&tok_yarn); + ts_print(&tokens); vec_token_free(tokens); } diff --git a/test_pipeline.sh b/test_pipeline.sh index 77b34bc3..1df49a16 100755 --- a/test_pipeline.sh +++ b/test_pipeline.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -make && valgrind --leak-check=full --show-leak-kinds=none --track-origins=yes --track-fds=yes --trace-children=yes --read-var-info=yes --read-inline-info=yes ./minishell <<<'cat