update: fixed leak and stuff
This commit is contained in:
parent
75581c7ee0
commit
8d796c4094
8 changed files with 39 additions and 26 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue