From df6b7a41ae40d88baa5ce98b5cfedc1b94704818 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Tue, 11 Feb 2025 17:39:05 +0100 Subject: [PATCH] feat: add heredoc token --- inc/typedef.h | 1 + src/main.c | 12 +++++++++++- src/token/token_parse.c | 9 +++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/inc/typedef.h b/inc/typedef.h index 8c19d5a..6b6a6f2 100644 --- a/inc/typedef.h +++ b/inc/typedef.h @@ -20,6 +20,7 @@ typedef enum e_token_type T_REDIRECT_IN, T_REDIRECT_OUT, T_APPEND_OUT, + T_HEREDOC, T_EOF, T_ERROR } t_token_type; diff --git a/src/main.c b/src/main.c index 2d28e6a..5944a3f 100644 --- a/src/main.c +++ b/src/main.c @@ -10,9 +10,18 @@ /* */ /* ************************************************************************** */ +#include "libft.h" #include "minishell.h" #include "utils.h" +static void token_print(void *param) +{ + t_token *token; + + token = (t_token *)param; + printf("token type %i, value %s\n", token->type, token->value); +} + int main(int argc, char **argv, char **envp) { t_minishell *minishell; @@ -28,7 +37,8 @@ int main(int argc, char **argv, char **envp) minishell->line = ft_prompt(minishell); minishell->lexer = ft_lexer_new(minishell->line); minishell->tokens = ft_parse_input(minishell->lexer); - minishell->commands = parser_get_commands(minishell->tokens); + ft_lstiter(minishell->tokens, token_print); + // minishell->commands = parser_get_commands(minishell->tokens); simple_builtins(minishell); free_minishell_line(minishell); ft_lstclear(&minishell->commands, free_command_list); diff --git a/src/token/token_parse.c b/src/token/token_parse.c index 312ff9b..5ce93aa 100644 --- a/src/token/token_parse.c +++ b/src/token/token_parse.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* parse_token.c :+: :+: :+: */ +/* token_parse.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/05 19:10:17 by qmennen #+# #+# */ -/* Updated: 2025/02/05 19:11:21 by qmennen ### ########.fr */ +/* Updated: 2025/02/11 17:38:51 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,11 @@ t_token *ft_parse_token(t_lexer *lexer) { token = ft_token_new(T_PIPE, "|", lexer->pos); } + else if (lexer->current_char == '<' && lexer->input[lexer->pos + 1] == '<') + { + token = ft_token_new(T_HEREDOC, "<<", lexer->pos); + ft_lexer_readchar(lexer); + } else if (lexer->current_char == '<') { token = ft_token_new(T_REDIRECT_IN, "<", lexer->pos);