tokenizer update

This commit is contained in:
gazhonsepaskwa
2025-01-22 16:05:02 +01:00
parent 6539c3b9cb
commit 8dabbc426f
7 changed files with 44 additions and 20 deletions

View File

@@ -16,13 +16,19 @@
void truncate_comment(char *str) void truncate_comment(char *str)
{ {
int i; int i;
char inquote;
if (!str) if (!str)
return ; return ;
i = 0; i = 0;
inquote = 0;
while (str[i]) while (str[i])
{ {
if (str[i] == '#') if (!inquote && (str[i] == 39 || str[i] == '"'))
inquote = str[i];
else if (inquote && (str[i] == inquote))
inquote = 0;
if (str[i] == '#' && !inquote && str[i - 1] && str[i - 1] != '\\')
{ {
str[i] = 0; str[i] = 0;
return ; return ;

View File

@@ -127,6 +127,8 @@ void debug_linked_list(t_node *head, char *msg)
pres = ft_strdup("HEREDOC "); pres = ft_strdup("HEREDOC ");
else if (current->pressision == D_RED_R) else if (current->pressision == D_RED_R)
pres = ft_strdup("D_RED_R "); pres = ft_strdup("D_RED_R ");
else if (current->pressision == PARAMETER)
pres = ft_strdup("PARAMETER");
else else
pres = ft_strdup("??? "); pres = ft_strdup("??? ");

View File

@@ -48,9 +48,11 @@ t_token get_token(char *str)
return (token); return (token);
} }
t_pres get_pressision(char *s, t_token token) t_pres get_pressision(char *s, t_token token, t_token last_token)
{ {
if (token == OPERATOR) if (token == OPERATOR)
return (get_operator(s)); return (get_operator(s));
else if (last_token == OPERATOR || last_token == UNSET)
return (COMMAND); return (COMMAND);
return (PARAMETER);
} }

View File

@@ -38,12 +38,15 @@ static t_node *tokenize_base(char *str)
static void set_token(t_node *head) static void set_token(t_node *head)
{ {
t_node *it; t_node *it;
t_token last_token;
it = head; it = head;
last_token = UNSET;
while (it != NULL) while (it != NULL)
{ {
it->token = get_token(it->val); it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token); it->pressision = get_pressision(it->val, it->token, last_token);
last_token = it->token;
it = it->next; it = it->next;
} }
} }

View File

@@ -34,7 +34,8 @@ typedef enum e_pres
RED_L, RED_L,
RED_R, RED_R,
HEREDOC, HEREDOC,
D_RED_R D_RED_R,
PARAMETER
} t_pres; } t_pres;
typedef struct s_node typedef struct s_node
@@ -51,7 +52,7 @@ int add_node_back(t_node *head, char *val, t_token token);
int merge_with_next_node(t_node *node); int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack); void free_linked_list(t_node *stack);
t_token get_token(char *str); t_token get_token(char *str);
t_pres get_pressision(char *str, t_token token); t_pres get_pressision(char *s, t_token token, t_token last_token);
int create_node_after(t_node *elem, char *val); int create_node_after(t_node *elem, char *val);
char *copy_meta_xor(char *val, int *copied, int rev); char *copy_meta_xor(char *val, int *copied, int rev);
int is_meta(char c); int is_meta(char c);

View File

@@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */
/* Updated: 2025/01/22 14:24:05 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "tokenizer.h" #include "tokenizer.h"
int is_meta(char c) int is_meta(char c)
@@ -43,7 +55,6 @@ int ft_str_count(char *s, char c)
return (count); return (count);
} }
int trim_nodes(t_node *head) int trim_nodes(t_node *head)
{ {
t_node *it; t_node *it;
@@ -88,4 +99,3 @@ int find_quote_node(t_node *head, char q)
} }
return (0); return (0);
} }

View File