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

@ -2,6 +2,7 @@ SRC_FILES = \
passes \ passes \
passes/double_quote_parsing \ passes/double_quote_parsing \
passes/fold_expansion \ passes/fold_expansion \
passes/fold_whitespace \
passes/template_file \ passes/template_file \
token_lifetime \ token_lifetime \
tokenizer \ tokenizer \

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/02 18:43:41 by maiboyer #+# #+# */ /* Created: 2024/10/02 18:43:41 by maiboyer #+# #+# */
/* Updated: 2024/10/03 22:31:21 by maiboyer ### ########.fr */ /* Updated: 2024/10/04 18:30:05 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,5 +38,6 @@ t_error ts_dq_apply_passes(t_vec_token ts, t_vec_token *out);
t_error ts_do_fuck_all(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_expension(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_double_string_pass(t_vec_token input, t_vec_token *output);
t_error ts_fold_whitespace(t_vec_token input, t_vec_token *output);
#endif /* PASSES_H */ #endif /* PASSES_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */ /* 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 /// or t_ts_pass
/// ///
/// there is a few stuff we want to do, for example: /// 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 /// - combine any *QUOTE token that are next to eachothers
/// into a single metatoken WORD /// into a single metatoken WORD
/// - combine multiple tokens into a single if they can /// - combine multiple tokens into a single if they can
@ -41,6 +39,7 @@
static const struct s_ts_pass_def g_ts_passes[] = {\ static const struct s_ts_pass_def g_ts_passes[] = {\
{ts_double_string_pass, "double string parser"}, \ {ts_double_string_pass, "double string parser"}, \
{ts_fold_expension, "fold expansion"}, {ts_fold_expension, "fold expansion"},
{ts_fold_whitespace, "fold whitespace"},
}; };
t_error ts_apply_passes(t_vec_token ts, t_vec_token *out) 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> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */ /* 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; i = 0;
out = vec_token_new(input.len, token_free); 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) while (i < input.len)
{ {
if (input.len >= i + 1) if (i + 1 >= input.len)
{ vec_token_push(&out, token_clone(&input.buffer[i]));
if (input.buffer[i].type == TOK_WHITESPACE) else if (input.buffer[i].type == TOK_WHITESPACE
i++; && input.buffer[i + 1].type == TOK_WHITESPACE)
} ;
else
vec_token_push(&out, token_clone(&input.buffer[i]));
i++; i++;
} }
vec_token_free(input); vec_token_free(input);
return (*output = out, NO_ERROR); 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"},
};