diff --git a/parser/Filelist.parser.mk b/parser/Filelist.parser.mk index 70ac6062..c472c5d5 100644 --- a/parser/Filelist.parser.mk +++ b/parser/Filelist.parser.mk @@ -2,6 +2,7 @@ SRC_FILES = \ passes \ passes/double_quote_parsing \ passes/fold_expansion \ +passes/fold_whitespace \ passes/template_file \ token_lifetime \ tokenizer \ diff --git a/parser/include/parser/passes.h b/parser/include/parser/passes.h index 05eacc9f..1094721f 100644 --- a/parser/include/parser/passes.h +++ b/parser/include/parser/passes.h @@ -6,7 +6,7 @@ /* 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_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_fold_whitespace(t_vec_token input, t_vec_token *output); #endif /* PASSES_H */ diff --git a/parser/src/passes.c b/parser/src/passes.c index c1cd408d..d769d80b 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/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) diff --git a/parser/src/passes/fold_whitespace.c b/parser/src/passes/fold_whitespace.c index a78c7970..c7c74ec4 100644 --- a/parser/src/passes/fold_whitespace.c +++ b/parser/src/passes/fold_whitespace.c @@ -6,7 +6,7 @@ /* 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; 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"}, -};