aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-08-27 10:30:15 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-08-27 10:30:15 +0200
commitc92f5a129f5f84ce63b0564794df4260f4d4bd00 (patch)
treee35076af62e5b1fc61fa6a2e17989b2d20ea61f6
parent454d439575489934791c04329df6e82e56dabf54 (diff)
downloadminishell-c92f5a129f5f84ce63b0564794df4260f4d4bd00.tar.gz
minishell-c92f5a129f5f84ce63b0564794df4260f4d4bd00.tar.bz2
minishell-c92f5a129f5f84ce63b0564794df4260f4d4bd00.zip
Renaming lexer function to french
-rw-r--r--include/lexer.h21
-rw-r--r--src/lexer/lexer.c30
-rw-r--r--src/lexer/lexer_utils.c13
-rw-r--r--src/lexer/tok_lst.c35
-rw-r--r--src/lexer/trim.c4
5 files changed, 71 insertions, 32 deletions
diff --git a/include/lexer.h b/include/lexer.h
index 89917d3..23646c2 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */
-/* Updated: 2020/08/27 09:26:33 by charles ### ########.fr */
+/* Updated: 2020/08/27 09:57:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -50,13 +50,13 @@ enum e_tok ret_token(char *input, int i);
enum e_tok ret_token_sep_redir_append(char *input, int i);
int lexer_sep(char input);
-int lexer_verif_entre_cote(char *input, int i);
-int lexe_space(char *input);
+int lexer_check_between_quote(char *input, int i);
+int lexer_space(char *input);
t_token *push_token_enum(t_token *lst_token);
-t_ftlst *lexe_trim_out(t_ftlst *lst);
+t_ftlst *lexer_trim_out(t_ftlst *lst);
/*
** token.c
@@ -77,11 +77,14 @@ void token_set_contentf(t_ftlst *token_lst, char *content);
** \warning DO NOT change the order of the fields
*/
-typedef struct s_tlst
+typedef struct s_tok_lst
{
- char *content;
- struct s_tlst *next;
- enum e_tok tag;
-} t_tlst;
+ char *content;
+ struct s_tok_lst *next;
+ enum e_tok tag;
+} t_tok_lst;
+
+t_tok_lst *tok_lst_new(enum e_tok tag, char *content);
+t_tok_lst *tok_lst_new_until(enum e_tok tag, char *content, size_t n);
#endif
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 6a8a0ca..f820ebb 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -6,13 +6,13 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:25 by nahaddac #+# #+# */
-/* Updated: 2020/07/19 16:08:40 by charles ### ########.fr */
+/* Updated: 2020/08/27 09:56:46 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
-int len_is_not_sep(char *input)
+int len_until_sep(char *input)
{
int i;
@@ -23,7 +23,7 @@ int len_is_not_sep(char *input)
{
i +=2;
if (input[i] == '\\')
- i += len_is_not_sep(&input[i]);
+ i += len_until_sep(&input[i]);
}
if (lexer_sep(input[i]))
return(i);
@@ -59,24 +59,24 @@ int check_input(char *input)
if (lexer_sep(input[i]))
{
if (input[i] == ';')
- return (i += lexe_space(&input[i + 1]) + 1);
+ return (i += lexer_space(&input[i + 1]) + 1);
while(input[i] == input[i + 1] && op < 2)
{
i++;
op++;
}
- i += lexe_space(&input[i + 1]);
+ i += lexer_space(&input[i + 1]);
return (i + 1);
}
if (input[i] == 39 || input[i] == '"')
- return(lexer_verif_entre_cote(input, i));
+ return(lexer_check_between_quote(input, i));
if (input[i] == ' ')
{
while(input[++i] == ' ')
;
return (i);
}
- return(len_is_not_sep(&input[i]));
+ return(len_until_sep(&input[i]));
}
@@ -89,7 +89,7 @@ int check_input_out(char *input)
while(input[i] != '\0')
{
j = 0;
- j += len_is_not_sep(&input[i]);
+ j += len_until_sep(&input[i]);
if (j != 0)
return(j);
i += j;
@@ -99,7 +99,7 @@ int check_input_out(char *input)
return(0);
}
-enum e_tok token_verif_stick(t_token *lst_token)
+enum e_tok token_check_stick(t_token *lst_token)
{
int i;
@@ -110,7 +110,7 @@ enum e_tok token_verif_stick(t_token *lst_token)
return(lst_token->tag | TAG_STICK);
}
-enum e_tok token_str_or_cote(t_token *lst_token)
+enum e_tok token_str_or_quote(t_token *lst_token)
{
int i;
@@ -120,17 +120,17 @@ enum e_tok token_str_or_cote(t_token *lst_token)
if(lst_token->content[i] == '\'')
{
lst_token->tag = TAG_STR_SINGLE;
- return(token_verif_stick(lst_token));
+ return(token_check_stick(lst_token));
}
if(lst_token->content[i] == '"')
{
lst_token->tag = TAG_STR_DOUBLE;
- return(token_verif_stick(lst_token));
+ return(token_check_stick(lst_token));
}
else
{
lst_token->tag = TAG_STR;
- return(token_verif_stick(lst_token));
+ return(token_check_stick(lst_token));
}
i++;
}
@@ -143,7 +143,7 @@ t_token *push_token_enum(t_token *lst_token)
tk = ret_token(lst_token->content, 0);
if (tk == 0)
- lst_token->tag = token_str_or_cote(lst_token);
+ lst_token->tag = token_str_or_quote(lst_token);
else
lst_token->tag = tk;
return (lst_token);
@@ -181,6 +181,6 @@ t_ftlst *lexer(char *input)
return (NULL);
lst = NULL;
lst = create_token_list(input, &lst);
- lst = lexe_trim_out(lst);
+ lst = lexer_trim_out(lst);
return (lst);
}
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c
index 74b1fa4..60363a5 100644
--- a/src/lexer/lexer_utils.c
+++ b/src/lexer/lexer_utils.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:15 by nahaddac #+# #+# */
-/* Updated: 2020/07/16 08:18:17 by nahaddac ### ########.fr */
+/* Updated: 2020/08/27 09:55:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -45,7 +45,7 @@ enum e_tok ret_token(char *input, int i)
}
// check is char is separator
-// ft_strchr(";&|><()", input)
+// /!\ can be replaced by ft_strchr(";&|><()", input) == NULL
int lexer_sep(char input)
{
char *sep;
@@ -63,7 +63,8 @@ int lexer_sep(char input)
}
// skip spaces
-int lexe_space(char *input)
+// /!\ can be replaced by strspn
+int lexer_space(char *input)
{
int i;
@@ -73,7 +74,7 @@ int lexe_space(char *input)
return(i);
}
-static int lex_verif_simple_cote(char *input, int i)
+static int lex_check_single_quote(char *input, int i)
{
i++;
while(input[i] != '\0')
@@ -90,10 +91,10 @@ static int lex_verif_simple_cote(char *input, int i)
return(i + 1);
}
-int lexer_verif_entre_cote(char *input, int i)
+int lexer_check_between_quote(char *input, int i)
{
if(input[i] == '\'')
- return(lex_verif_simple_cote(input, i));
+ return(lex_check_single_quote(input, i));
i++;
while(input[i] != '"' && (input[i] != '\0'))
{
diff --git a/src/lexer/tok_lst.c b/src/lexer/tok_lst.c
new file mode 100644
index 0000000..125e19c
--- /dev/null
+++ b/src/lexer/tok_lst.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* tok_lst.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/08/27 09:32:58 by charles #+# #+# */
+/* Updated: 2020/08/27 09:37:57 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "lexer.h"
+
+t_tok_lst *tok_lst_new(enum e_tok tag, char *content)
+{
+ return (tok_lst_new_until(tag, content, content == NULL ? 0 : ft_strlen(content)));
+}
+
+t_tok_lst *tok_lst_new_until(enum e_tok tag, char *content, size_t n)
+{
+ t_tok_lst *ret;
+
+ if ((ret = malloc(sizeof(t_tok_lst))) == NULL)
+ return (NULL);
+ if (content == NULL)
+ ret->content = NULL;
+ else if ((ret->content = ft_strndup(content, n)) == NULL)
+ {
+ free(ret);
+ return (NULL);
+ }
+ ret->tag = tag;
+ return (ret);
+}
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index 8160ca6..80c44bf 100644
--- a/src/lexer/trim.c
+++ b/src/lexer/trim.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:36 by nahaddac #+# #+# */
-/* Updated: 2020/07/17 10:18:51 by nahaddac ### ########.fr */
+/* Updated: 2020/08/27 10:00:09 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -51,7 +51,7 @@ char *del_quote(char *str)
return (s);
}
-t_ftlst *lexe_trim_out(t_ftlst *lst)
+t_ftlst *lexer_trim_out(t_ftlst *lst)
{
t_ftlst *first;
t_token *tk;