From 58abb9b168d1208b93ad9c7e523761d563913e3a Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 27 Sep 2024 22:37:41 +0200 Subject: [PATCH] style : norming all the header (sorted the enum) --- parser/include/parser/token.h | 4 +-- parser/src/{what_is_it.c => dollar.c} | 10 +++--- parser/src/quotes.c | 45 +++++++++++++++++++++++++++ parser/src/token.c | 17 +++++++++- 4 files changed, 68 insertions(+), 8 deletions(-) rename parser/src/{what_is_it.c => dollar.c} (78%) create mode 100644 parser/src/quotes.c diff --git a/parser/include/parser/token.h b/parser/include/parser/token.h index ef0809c9..edc47346 100644 --- a/parser/include/parser/token.h +++ b/parser/include/parser/token.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/26 17:59:23 by maiboyer #+# #+# */ -/* Updated: 2024/09/27 11:38:18 by rparodi ### ########.fr */ +/* Updated: 2024/09/27 22:37:22 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,12 +21,12 @@ enum e_token { AMP, + CARRET, DOLLAR, DQUOTE, LPAREN, NQUOTE, PIPE, - CARRET, RPAREN, SEMICOLON, SQUOTE, diff --git a/parser/src/what_is_it.c b/parser/src/dollar.c similarity index 78% rename from parser/src/what_is_it.c rename to parser/src/dollar.c index 270458cd..7eff09b6 100644 --- a/parser/src/what_is_it.c +++ b/parser/src/dollar.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* what_is_it.c :+: :+: :+: */ +/* dollar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/09/27 11:46:45 by rparodi #+# #+# */ -/* Updated: 2024/09/27 12:48:18 by rparodi ### ########.fr */ +/* Created: 2024/09/27 22:18:46 by rparodi #+# #+# */ +/* Updated: 2024/09/27 22:20:40 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,9 @@ #include "me/types.h" #include -bool is_quote(char c) +bool is_dollar(char c) { - if (c == '"' || c == '\'') + if (c == '$') return (true); return (false); } diff --git a/parser/src/quotes.c b/parser/src/quotes.c new file mode 100644 index 00000000..18952550 --- /dev/null +++ b/parser/src/quotes.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* quotes.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/27 11:46:45 by rparodi #+# #+# */ +/* Updated: 2024/09/27 22:35:20 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "me/vec/vec_token.h" +#include "parser/token.h" +#include "me/string/string.h" +#include "me/types.h" +#include + +bool is_quote(char c) +{ + if (c == '"' || c == '\'') + return (true); + return (false); +} + +t_error find_end_string(t_str raw, t_usize *start, t_token *output) +{ + if (!raw || !output) + return (ERROR); + if (is_quote(raw[(*start)])) + { + string_push_char(output->string, raw[(*start)]); + (*start)++; + if (raw[(*start)] == '\0') + return (ERROR); + while (raw[(*start)] != '\0') + { + string_push_char(output->string.buf, raw[(*start)]); + if (is_quote(raw[(*start)])) + return (NO_ERROR); + (*start)++; + } + } + return (ERROR); +} diff --git a/parser/src/token.c b/parser/src/token.c index 514b143a..83feaf38 100644 --- a/parser/src/token.c +++ b/parser/src/token.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/25 16:27:03 by rparodi #+# #+# */ -/* Updated: 2024/09/27 13:14:23 by rparodi ### ########.fr */ +/* Updated: 2024/09/27 22:29:04 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,25 @@ #include "me/types.h" #include "me/vec/vec_token.h" #include +#include + +bool is_space(char c) +{ + if (c == ' ') + return (true); + return (false); +} t_error start_analyse(t_const_str raw, enum e_token list, t_vec_token *output) { + t_usize i; + i = 0; + while (raw[i] != '\0') + { + if (is_space(raw[i])) + i++; + } } t_error tokeniser(t_const_str raw, enum e_token list)