aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lexer/lexer.c26
-rw-r--r--src/parser/parser.c19
2 files changed, 29 insertions, 16 deletions
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 7a39373..4d5e3b1 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/09/16 20:17:10 by charles ### ########.fr */
+/* Updated: 2020/09/17 10:59:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -55,7 +55,7 @@ int tok_len(char *input)
return (i + 1);
if (lexer_sep(input[i]))
{
- if (input[i] == input[i + 1])
+ if (input[i] != ';' && input[i] == input[i + 1])
i++;
return (i + 1 + lexer_space(&input[i + 1]));
}
@@ -105,22 +105,22 @@ t_tok_lst *create_token_list(char *input, t_tok_lst **lst)
int lexer(char *input, t_tok_lst **out)
{
int status;
- t_tok_lst *curr;
+ /* t_tok_lst *curr; */
if (!input)
return (2);
*out = NULL;
*out = create_token_list(input, out);
status = lexer_trim(*out);
- curr = *out;
- while (curr != NULL)
- {
- if (!(curr->tag & TAG_IS_STR))
- {
- free(curr->content);
- curr->content = NULL;
- }
- curr = curr->next;
- }
+ /* curr = *out; */
+ /* while (curr != NULL) */
+ /* { */
+ /* if (!(curr->tag & TAG_IS_STR)) */
+ /* { */
+ /* free(curr->content); */
+ /* curr->content = NULL; */
+ /* } */
+ /* curr = curr->next; */
+ /* } */
return (status);
}
diff --git a/src/parser/parser.c b/src/parser/parser.c
index ddbbc0b..3a61a2c 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
-/* Updated: 2020/09/16 20:19:05 by charles ### ########.fr */
+/* Updated: 2020/09/17 11:20:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,18 @@
#include "parser.h"
+static char *g_sep_str_lookup[] = {
+ [TAG_END] = ";",
+ [TAG_AND] = "&&",
+ [TAG_OR] = "||",
+ [TAG_PIPE] = "|",
+ [TAG_REDIR_IN] = "<",
+ [TAG_REDIR_OUT] = ">",
+ [TAG_REDIR_APPEND] = ">>",
+ [TAG_PARENT_OPEN] = "(",
+ [TAG_PARENT_CLOSE] = ")",
+};
+
/*
** push redirection token
** push while token is str and stick
@@ -28,7 +40,8 @@ t_parsed *parse_redir(t_tok_lst *input, t_tok_lst **redirs)
tok_lst_push_back(redirs, tok_lst_uncons(&input));
if (input == NULL)
return (parsed_error("syntax error near unexpected token `newline'\n"));
- // FIXME big condition could be avoided with lexer not putting STICK if the next tokens isn't a string
+ // FIXME big condition could be avoided with lexer not putting STICK
+ // if the next tokens isn't a string
while (input != NULL
&& input->tag & TAG_IS_STR && input->tag & TAG_STICK
&& input->next != NULL && input->next->tag & TAG_IS_STR)
@@ -86,7 +99,7 @@ t_parsed *parse_op(t_tok_lst *input)
return (left);
sep_tag = input->tag;
if (!(sep_tag & TAG_IS_SEP))
- return (parsed_error("syntax error near unexpected token `%s'\n", input->content));
+ return (parsed_error("syntax error near unexpected token `%s'\n", g_sep_str_lookup[sep_tag]));
ft_lstpop_front((t_ftlst**)&input, free);
if (input == NULL && sep_tag == TAG_END)
return (left);