diff --git a/flake.lock b/flake.lock index c969b891..429ec184 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -141,11 +141,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1723047874, - "narHash": "sha256-i6shgus4+OUD8vg0TZ1qhDvKBfvaWi+SK1xbBSY0z+c=", + "lastModified": 1727525597, + "narHash": "sha256-7cdO6lWNE54nxGk4l9BrVjPAAuKaRFQw9H03nkxWKk8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "472701edc3fc64e8c5a36a98e6f61146eea37c69", + "rev": "ae432fd808730915310847bfc8bcb279e27c5330", "type": "github" }, "original": { diff --git a/parser/Filelist.parser.mk b/parser/Filelist.parser.mk index 09fc7c68..32e1df85 100644 --- a/parser/Filelist.parser.mk +++ b/parser/Filelist.parser.mk @@ -1,5 +1,8 @@ SRC_FILES = \ +dollar \ +quotes \ token \ +token_lifetime \ GEN_FILES = \ \ diff --git a/parser/include/parser/token.h b/parser/include/parser/token.h index 8185ac5b..634bc047 100644 --- a/parser/include/parser/token.h +++ b/parser/include/parser/token.h @@ -6,29 +6,37 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/26 17:59:23 by maiboyer #+# #+# */ -/* Updated: 2024/09/28 11:45:54 by rparodi ### ########.fr */ +/* Updated: 2024/09/28 14:52:09 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef TOKEN_H -#define TOKEN_H +# define TOKEN_H -#include "me/string/string.h" -#include "me/vec/vec_token.h" +# include "me/string/string.h" +# include "me/vec/vec_token.h" enum e_token { - AMP, - CARRET, - DOLLAR, - DQUOTE, - LPAREN, - NQUOTE, - PIPE, - RPAREN, - SEMICOLON, - SQUOTE, - WHITESPACE + AMP, // ampersand == & + AND, // and == && + CARRET, // any carret == < > << >> + DLCARRET, // double left carret == << + DOLLAR, // dollar == $ + DQUOTE, // double quote string + DRCARRET, // double right carret == >> + EXPENSION, // an expension == $ + LCARRET, // left carret == < + LPAREN, // left parenthesis == ( + NQUOTE, // no quote string + OR, // or == || + PIPE, // pipe == | + RCARRET, // right carret == > + RPAREN, // right parenthesis == ) + SEMICOLON, // semicolor == ; + SQUOTE, // single quote string + WHITESPACE, // whitespace outside of quoted strings + WORD, // a meta token, which contains subtokens }; typedef struct s_token @@ -38,6 +46,15 @@ typedef struct s_token enum e_token type; } t_token; +/* LIFETIME */ +// This create a "meta" token consisting of multiple tokens +t_token token_new_meta(enum e_token type); +// This create a "simple" token consisting of a string +t_token token_new(enum e_token type); +void token_free(t_token tok); +bool token_is_meta(t_token tok); + +/* PARSING */ bool is_dollar(char c); bool is_quote(char c); bool is_space(char c); diff --git a/parser/src/dollar.c b/parser/src/dollar.c index 0c3ee5a6..2cc2d3b4 100644 --- a/parser/src/dollar.c +++ b/parser/src/dollar.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/27 22:18:46 by rparodi #+# #+# */ -/* Updated: 2024/09/28 11:47:09 by rparodi ### ########.fr */ +/* Updated: 2024/09/28 14:50:56 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,12 @@ #include "me/types.h" #include +// MAIX: C'est necessaire de split ca dans une fonction a par vu que ca retourne +// la valeur de la comparaion ? +// Ca serai pas mieux de faire une fonction du genre +// "bool create_single_char_token(char c, t_token *tok)" qui cree un token +// dans `tok` et retourne true si il a match un char qui correspond +// a un token specific (genre $ ou parentheses par example) /** * @brief boolean function that's say if it's a dollar or not * diff --git a/parser/src/token.c b/parser/src/token.c index 8433b3b8..e71266d6 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/28 12:16:45 by rparodi ### ########.fr */ +/* Updated: 2024/09/28 14:48:31 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,9 @@ #include #include "me/mem/mem.h" + +// MAIX: attention les whitespace peuvent aussi etre des tab. de memoire il y a +// une fonction "me_isspace" qui check ce qu'on veut dans "me/char/char.h" /** * @brief boolean function that's say if it's a space or not * @@ -31,22 +34,27 @@ bool is_space(char c) return (false); } +// MAIX: tu peux faire un token par character "whitespace", vu qu'on va +// manipuler la list de token apres pour faire des truc plus simple a process +// on se debrouillera pour plus avoir plein de token whitespace :) t_error start_analyse(t_const_str raw, enum e_token list, t_vec_token *output) { t_usize i; t_token token; i = 0; - mem_alloc(sizeof(t_token)); while (raw[i] != '\0') { if (is_space(raw[i])) - token = + token = token_new(WHITESPACE); i++; } return (NO_ERROR); } +// MAIX: attention tu ne fais rien avec le vec_token ici :D +// aussi l'argument list est censer faire quoi ? +// c'est un reste d'une version ancienne ? t_error tokeniser(t_const_str raw, enum e_token list) { t_vec_token output; diff --git a/parser/src/token_lifetime.c b/parser/src/token_lifetime.c new file mode 100644 index 00000000..c43ccd75 --- /dev/null +++ b/parser/src/token_lifetime.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token_lifetime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/28 14:37:13 by maiboyer #+# #+# */ +/* Updated: 2024/09/28 14:57:17 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "me/vec/vec_token.h" +#include "parser/token.h" + +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); +} + +t_token token_new(enum e_token type) +{ + return ((t_token){.type = type, .string = string_new(16), \ + .subtokens = {NULL, 0, 0, NULL}}); +} + +t_token token_new_meta(enum e_token type) +{ + return ((t_token){.type = type, .string = {NULL, 0, 0}, \ + .subtokens = vec_token_new(16, token_free)}); +} + +bool token_is_meta(t_token tok) +{ + if (tok.type == WORD) + return (true); + return (false); +}