aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-07-17 10:36:50 +0200
committerCharles <sircharlesaze@gmail.com>2020-07-18 08:57:13 +0200
commit134e5ca4fe0a1051fb7946874953608894959a13 (patch)
treed0d191f5590bbd5928c1763d5f8f1bce5dcf7d8e /src
parenta4e95774030937568dfed6a9445b61e41d1c8478 (diff)
downloadminishell-134e5ca4fe0a1051fb7946874953608894959a13.tar.gz
minishell-134e5ca4fe0a1051fb7946874953608894959a13.tar.bz2
minishell-134e5ca4fe0a1051fb7946874953608894959a13.zip
lexer OK, Added escape handling
Diffstat (limited to 'src')
-rw-r--r--src/lexer/lexer.c7
-rw-r--r--src/lexer/trim.c13
-rw-r--r--src/parse/parse.c2
-rw-r--r--src/parse/parse_error.c132
4 files changed, 75 insertions, 79 deletions
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 7bacb9f..32b9eeb 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:25 by nahaddac #+# #+# */
-/* Updated: 2020/07/16 11:39:11 by nahaddac ### ########.fr */
+/* Updated: 2020/07/17 13:06:17 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,6 +24,7 @@ int len_is_not_sep(char *input)
i +=2;
if (input[i] == '\\')
i += len_is_not_sep(&input[i]);
+
}
if (lexer_sep(input[i]))
return(i);
@@ -47,9 +48,7 @@ int check_input(char *input)
i = 0;
op = 1;
if (input[i] == '\\' && lexer_sep(input[i + 1]))
- {
i += 2;
- }
if (input[i] == '(' || input[i] == ')')
return (i + 1);
if (lexer_sep(input[i]))
@@ -173,6 +172,6 @@ t_ftlst *lexer(char *input)
return (NULL);
lst = NULL;
lst = create_token_list(input, &lst);
- //lst = lexe_trim_out(lst);
+ lst = lexe_trim_out(lst);
return (lst);
}
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index 710dc14..8160ca6 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/16 10:28:57 by nahaddac ### ########.fr */
+/* Updated: 2020/07/17 10:18:51 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,16 +19,13 @@ char *del_space(t_token *tk)
char *s;
i = 0;
- while(tk->content[++i] != '\0')
+ while(tk->content[i] != '\0')
{
- if(tk->content[i] == '\\' && tk->content[i + 1] == ' ')
- {
- i += 2;
- if (tk->content[i] == '\0')
- tk->tag = tk->tag | TAG_STICK;
- }
+ if(tk->content[i] == '\\')
+ return tk->content;
if(tk->content[i] == ' ')
break;
+ i++;
}
s = ft_strsubf(tk->content, 0, i);
return(s);
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 5633a23..69cba8d 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
-/* Updated: 2020/07/14 11:48:42 by nahaddac ### ########.fr */
+/* Updated: 2020/07/17 10:36:39 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c
index 6df86e2..42d46ea 100644
--- a/src/parse/parse_error.c
+++ b/src/parse/parse_error.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */
-/* Updated: 2020/07/15 18:31:51 by charles ### ########.fr */
+/* Updated: 2020/07/17 11:24:23 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,68 +28,68 @@
// return first;
// }
-int out_error_first(t_token *tk)
-{
- int i;
-
- i = 0;
- if(tk->tag & TAG_IS_SEP)
- return(1);
- if (tk->tag & TAG_IS_REDIR)
- {
- while(tk->content[i])
- i++;
- if (tk->tag & TAG_REDIR_APPEND && i <= 2)
- return (0);
- else
- return(1);
- }
- return(0);
-}
-
-t_token *error_syntax_simple(t_ftlst *in)
-{
- t_token *tk;
- size_t i;
- /* t_ftlst *first; */
-
- tk = in->data;
- /* first = in; */
- if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
- {
- if (out_error_first(tk))
- {
- i = ft_strlen(tk->content);
- if (i >= 2)
- tk->content[2] = '\0';
- tk->content =
- ft_strjoin3("minishell: syntax error near unexpected token `",
- tk->content, "'");
- return(tk);
- }
- }
- while(in != NULL)
- {
- i = 0;
- tk = in->data;
- if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
- {
- if (((t_token *)in->next->data)->tag &
- ((t_token*)in->next->data)->tag & TAG_IS_SEP ||
- (((t_token*)in->next->data)->tag & TAG_IS_REDIR))
- {
- tk = in->next->data;
- i = ft_strlen(tk->content);
- if (i >= 3)
- tk->content[2] = '\0';
- tk->content =
- ft_strjoin3("minishell: syntax error near unexpected token `",
- tk->content, "'");
- printf("%s\n",tk->content );
- return(tk);
- }
- }
- in = in->next;
- }
- return 0;
-}
+// int out_error_first(t_token *tk)
+// {
+// int i;
+//
+// i = 0;
+// if(tk->tag & TAG_IS_SEP)
+// return(1);
+// if (tk->tag & TAG_IS_REDIR)
+// {
+// while(tk->content[i])
+// i++;
+// if (tk->tag & TAG_REDIR_APPEND && i <= 2)
+// return (0);
+// else
+// return(1);
+// }
+// return(0);
+// }
+//
+// t_token *error_syntax_simple(t_ftlst *in)
+// {
+// t_token *tk;
+// size_t i;
+// /* t_ftlst *first; */
+//
+// tk = in->data;
+// /* first = in; */
+// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
+// {
+// if (out_error_first(tk))
+// {
+// i = ft_strlen(tk->content);
+// if (i >= 2)
+// tk->content[2] = '\0';
+// tk->content =
+// ft_strjoin3("minishell: syntax error near unexpected token `",
+// tk->content, "'");
+// return(tk);
+// }
+// }
+// while(in != NULL)
+// {
+// i = 0;
+// tk = in->data;
+// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
+// {
+// if (((t_token *)in->next->data)->tag &
+// ((t_token*)in->next->data)->tag & TAG_IS_SEP ||
+// (((t_token*)in->next->data)->tag & TAG_IS_REDIR))
+// {
+// tk = in->next->data;
+// i = ft_strlen(tk->content);
+// if (i >= 3)
+// tk->content[2] = '\0';
+// tk->content =
+// ft_strjoin3("minishell: syntax error near unexpected token `",
+// tk->content, "'");
+// printf("%s\n",tk->content );
+// return(tk);
+// }
+// }
+// in = in->next;
+// }
+// return 0;
+// }