diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-17 11:21:54 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-17 11:21:54 +0200 |
| commit | 82c2d94a6513256f9173ff62439e70d3a0b25582 (patch) | |
| tree | 7ba447e2438777ac00610d04b3cbd0ba3b4e804a /src | |
| parent | 46c7f91cdceef0d5dd801ac569fb5d0c76b711aa (diff) | |
| download | minishell-82c2d94a6513256f9173ff62439e70d3a0b25582.tar.gz minishell-82c2d94a6513256f9173ff62439e70d3a0b25582.tar.bz2 minishell-82c2d94a6513256f9173ff62439e70d3a0b25582.zip | |
Added lexer spliting ';;', separator string lookup table in parser for error message
Diffstat (limited to 'src')
| -rw-r--r-- | src/lexer/lexer.c | 26 | ||||
| -rw-r--r-- | src/parser/parser.c | 19 |
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); |
