tokenizer update
This commit is contained in:
@@ -15,14 +15,20 @@
|
||||
|
||||
void truncate_comment(char *str)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
char inquote;
|
||||
|
||||
if (!str)
|
||||
return ;
|
||||
i = 0;
|
||||
inquote = 0;
|
||||
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;
|
||||
return ;
|
||||
|
||||
@@ -106,27 +106,29 @@ void debug_linked_list(t_node *head, char *msg)
|
||||
|
||||
// set vals for pressision token
|
||||
if (current->pressision == COMMAND)
|
||||
pres = ft_strdup("COMMAND");
|
||||
pres = ft_strdup("COMMAND ");
|
||||
else if (current->pressision == UNDEFINED)
|
||||
pres = ft_strdup("UNDEF ");
|
||||
pres = ft_strdup("UNDEF ");
|
||||
else if (current->pressision == AND)
|
||||
pres = ft_strdup("AND ");
|
||||
pres = ft_strdup("AND ");
|
||||
else if (current->pressision == OR)
|
||||
pres = ft_strdup("OR ");
|
||||
pres = ft_strdup("OR ");
|
||||
else if (current->pressision == PIPE)
|
||||
pres = ft_strdup("PIPE ");
|
||||
pres = ft_strdup("PIPE ");
|
||||
else if (current->pressision == SUBSH_S)
|
||||
pres = ft_strdup("SUBSH_S");
|
||||
pres = ft_strdup("SUBSH_S ");
|
||||
else if (current->pressision == SUBSH_E)
|
||||
pres = ft_strdup("SUBSH_E");
|
||||
pres = ft_strdup("SUBSH_E ");
|
||||
else if (current->pressision == RED_L)
|
||||
pres = ft_strdup("RED_L ");
|
||||
pres = ft_strdup("RED_L ");
|
||||
else if (current->pressision == RED_R)
|
||||
pres = ft_strdup("RED_R ");
|
||||
pres = ft_strdup("RED_R ");
|
||||
else if (current->pressision == HEREDOC)
|
||||
pres = ft_strdup("HEREDOC");
|
||||
pres = ft_strdup("HEREDOC ");
|
||||
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
|
||||
pres = ft_strdup("??? ");
|
||||
|
||||
|
||||
@@ -48,9 +48,11 @@ t_token get_token(char *str)
|
||||
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)
|
||||
return (get_operator(s));
|
||||
return (COMMAND);
|
||||
else if (last_token == OPERATOR || last_token == UNSET)
|
||||
return (COMMAND);
|
||||
return (PARAMETER);
|
||||
}
|
||||
|
||||
@@ -38,12 +38,15 @@ static t_node *tokenize_base(char *str)
|
||||
static void set_token(t_node *head)
|
||||
{
|
||||
t_node *it;
|
||||
t_token last_token;
|
||||
|
||||
it = head;
|
||||
last_token = UNSET;
|
||||
while (it != NULL)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ typedef enum e_pres
|
||||
RED_L,
|
||||
RED_R,
|
||||
HEREDOC,
|
||||
D_RED_R
|
||||
D_RED_R,
|
||||
PARAMETER
|
||||
} t_pres;
|
||||
|
||||
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);
|
||||
void free_linked_list(t_node *stack);
|
||||
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);
|
||||
char *copy_meta_xor(char *val, int *copied, int rev);
|
||||
int is_meta(char c);
|
||||
|
||||
@@ -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"
|
||||
|
||||
int is_meta(char c)
|
||||
@@ -43,7 +55,6 @@ int ft_str_count(char *s, char c)
|
||||
return (count);
|
||||
}
|
||||
|
||||
|
||||
int trim_nodes(t_node *head)
|
||||
{
|
||||
t_node *it;
|
||||
@@ -88,4 +99,3 @@ int find_quote_node(t_node *head, char q)
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
0
tests/tokenizer/tokenizer_utils2.c
Normal file
0
tests/tokenizer/tokenizer_utils2.c
Normal file
Reference in New Issue
Block a user