/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* tokens.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/04 18:02:56 by qmennen #+# #+# */ /* Updated: 2025/02/04 20:53:10 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" t_token *ft_parse_token(t_lexer *lexer) { t_token *token; token = NULL; if (lexer->current_char == '|') { token = ft_token_new(T_PIPE, "|", lexer->pos); } else if (lexer->current_char == '<') { token = ft_token_new(T_REDIRECT_IN, "<", lexer->pos); } else if (lexer->current_char == '>' && lexer->input[lexer->pos + 1] == '>') { token = ft_token_new(T_APPEND_OUT, ">>", lexer->pos); ft_lexer_readchar(lexer); } else if (lexer->current_char == '>') { token = ft_token_new(T_REDIRECT_OUT, ">", lexer->pos); } ft_lexer_readchar(lexer); return (token); } t_token *ft_token_new(t_token_type type, char *c, int pos) { t_token *token; token = malloc(sizeof(t_token)); if (!token) { perror("failed assigning token memory"); exit(EXIT_FAILURE); } token->type = type; token->position = pos; if (c) token->value = ft_strdup(c); else token->value = NULL; return (token); }