diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-13 17:49:48 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-13 17:49:48 +0200 |
| commit | 10ec6292d997ac18803df92469d2ab4ee03166e7 (patch) | |
| tree | ffeb2baf5a63f63b1bcaa24f1b91d1f81c54b982 /src/lexer/lexer_utils.c | |
| parent | 9ef012a8016b81fc6063c4fc9e861a22b5bd5dac (diff) | |
| download | minishell-10ec6292d997ac18803df92469d2ab4ee03166e7.tar.gz minishell-10ec6292d997ac18803df92469d2ab4ee03166e7.tar.bz2 minishell-10ec6292d997ac18803df92469d2ab4ee03166e7.zip | |
Refactoring lexer to understand it
Diffstat (limited to 'src/lexer/lexer_utils.c')
| -rw-r--r-- | src/lexer/lexer_utils.c | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c deleted file mode 100644 index d848f95..0000000 --- a/src/lexer/lexer_utils.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* lexer_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/07/16 08:18:15 by nahaddac #+# #+# */ -/* Updated: 2020/09/13 11:00:45 by nahaddac ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "lexer.h" - -// check for append tag -enum e_tok ret_token_sep_redir_append(char *input, int i) -{ - if (input[i + 1] == '>') - return(TAG_REDIR_APPEND); - return (TAG_REDIR_OUT); - -} - -// return token tag corresponding to string id -enum e_tok ret_token(char *input, int i) -{ - if (input[i] == ';') - return(TAG_END); - if (input[i] == '&' && input[i + 1] == '&') - return(TAG_AND); - if (input[i] == '|' && input[i + 1] == '|') - return(TAG_OR); - if(input[i] == '|') - return(TAG_PIPE); - if (input[i] == '>') - return(ret_token_sep_redir_append(input,i)); - if (input[i] == '<') - return(TAG_REDIR_IN); - if (input[i] == '(') - return(TAG_PARENT_OPEN); - if (input[i] == ')') - return(TAG_PARENT_CLOSE); - return(0); - -} - -// check is char is separator -// /!\ can be replaced by ft_strchr(";&|><()", input) == NULL -int lexer_sep(char input) -{ - char *sep; - int i; - - i = 0; - sep = ";&|><()"; - while(sep[i] != '\0') - { - if(sep[i] == input) - return(1); - i++; - } - return (0); -} - -// skip spaces -// /!\ can be replaced by strspn -int lexer_space(char *input) -{ - int i; - - i=0; - while(ft_isblank(input[i])) - i++; - return(i); -} - -static int lex_check_single_quote(char *input, int i) -{ - i++; - while(input[i] != '\0') - { - if(input[i] == '\\') - i+=1; - if(input[i] == '\'') - break; - ++i; - } - if (ft_isblank(input[i + 1])) - while(ft_isblank(input[i + 1])) - i++; - return(i + 1); -} - -int lexer_check_between_quote(char *input, int i) -{ - if(input[i] == '\'') - return(lex_check_single_quote(input, i)); - i++; - while(input[i] != '"' && (input[i] != '\0')) - { - if (input[i] == '\\') - i += 1; - ++i; - } - if (ft_isblank(input[i + 1])) - while(ft_isblank(input[i + 1])) - i++; - return(i + 1); -} |
