update: fixed fold whitespace

This commit is contained in:
maix0 2024-10-04 18:32:30 +02:00
parent 3b869b9412
commit f5c9ee02c5
4 changed files with 13 additions and 17 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
/* Updated: 2024/10/04 17:27:36 by rparodi ### ########.fr */
/* Updated: 2024/10/04 18:32:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,8 +24,6 @@
/// or t_ts_pass
///
/// there is a few stuff we want to do, for example:
/// - combine any whitespace token that are following eachother into a
/// single one, basically discarding duplicates
/// - combine any *QUOTE token that are next to eachothers
/// into a single metatoken WORD
/// - combine multiple tokens into a single if they can
@ -41,6 +39,7 @@
static const struct s_ts_pass_def g_ts_passes[] = {\
{ts_double_string_pass, "double string parser"}, \
{ts_fold_expension, "fold expansion"},
{ts_fold_whitespace, "fold whitespace"},
};
t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
/* Updated: 2024/10/04 17:47:32 by rparodi ### ########.fr */
/* Updated: 2024/10/04 18:32:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,22 +33,17 @@ t_error ts_fold_whitespace(t_vec_token input, t_vec_token *output)
i = 0;
out = vec_token_new(input.len, token_free);
if (input.buffer[i].type == TOK_WHITESPACE)
vec_token_push(&out, token_clone(&input.buffer[i]));
while (i < input.len)
{
if (input.len >= i + 1)
{
if (input.buffer[i].type == TOK_WHITESPACE)
i++;
}
if (i + 1 >= input.len)
vec_token_push(&out, token_clone(&input.buffer[i]));
else if (input.buffer[i].type == TOK_WHITESPACE
&& input.buffer[i + 1].type == TOK_WHITESPACE)
;
else
vec_token_push(&out, token_clone(&input.buffer[i]));
i++;
}
vec_token_free(input);
return (*output = out, NO_ERROR);
}
static const struct s_ts_pass_def g_ts_dq_passes[] = {\
{ts_do_fuck_all, "does nothing lol"}, \
{ts_fold_whitespace, "fold whitespace"},
};