From 0441253ef1a62b6915e87b17113bb3c8f4a71097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Wed, 25 Sep 2024 16:54:42 +0200 Subject: [PATCH] feat: starting the parser (header and main function) --- includes/parser | 2 +- parser/Filelist.parser.mk | 6 ++++++ parser/includes/token/token.h | 39 +++++++++++++++++++++++++++++++++++ parser/token/token.c | 29 ++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 parser/Filelist.parser.mk create mode 100644 parser/includes/token/token.h create mode 100644 parser/token/token.c diff --git a/includes/parser b/includes/parser index 6891663a..c87daae3 120000 --- a/includes/parser +++ b/includes/parser @@ -1 +1 @@ -../parser/include/parser \ No newline at end of file +../parser/includes \ No newline at end of file diff --git a/parser/Filelist.parser.mk b/parser/Filelist.parser.mk new file mode 100644 index 00000000..f4ac3c2a --- /dev/null +++ b/parser/Filelist.parser.mk @@ -0,0 +1,6 @@ +SRC_FILES = \ + \ + +GEN_FILES = \ + \ + diff --git a/parser/includes/token/token.h b/parser/includes/token/token.h new file mode 100644 index 00000000..d0b24750 --- /dev/null +++ b/parser/includes/token/token.h @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/25 11:38:28 by rparodi #+# #+# */ +/* Updated: 2024/09/25 16:32:40 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TOKEN_H +# define TOKEN_H + +#include "me/string/string.h" + +enum e_token +{ + AMP, + DOLLAR, + DQUOTE, + LPAREN, + NQUOTE, + PIPE, + CARRET, + RPAREN, + SEMICOLON, + SQUOTE, + WHITESPACE +}; + +typedef struct s_token +{ + t_string raw; + enum e_token TokenType; +} t_token; + +#endif diff --git a/parser/token/token.c b/parser/token/token.c new file mode 100644 index 00000000..aef2e76f --- /dev/null +++ b/parser/token/token.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/25 16:27:03 by rparodi #+# #+# */ +/* Updated: 2024/09/25 16:54:08 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser/token/token.h" +#include "me/string/string.h" +#include "me/types.h" + +t_error handle_quote(t_string raw, enum e_token actual, int *output); +t_error handle_arithmetic(t_string raw, enum e_token actual, int *output); + +t_error tokeniser(t_string raw, enum e_token actual, int *output) +{ + if (!raw.buf || raw.len == 0 || raw.capacity == 0) + return (ERROR); + if (handle_quote(raw, actual, output)) + return (ERROR); + else if (handle_arithmetic(raw, actual, output)) + return (ERROR); + return (NO_ERROR); +}