This commit is contained in:
Loic Deridder
2025-01-24 10:19:33 +01:00
5 changed files with 19 additions and 4 deletions

View File

@@ -129,6 +129,10 @@ void debug_linked_list(t_node *head, char *msg)
pres = ft_strdup("D_RED_R "); pres = ft_strdup("D_RED_R ");
else if (current->pressision == PARAMETER) else if (current->pressision == PARAMETER)
pres = ft_strdup("PARAMETER"); pres = ft_strdup("PARAMETER");
else if (current->pressision == RED_FILE)
pres = ft_strdup("RED_FILE ");
else if (current->pressision == LIM)
pres = ft_strdup("LIM ");
else else
pres = ft_strdup("??? "); pres = ft_strdup("??? ");

View File

@@ -48,10 +48,16 @@ t_token get_token(char *str)
return (token); return (token);
} }
t_pres get_pressision(char *s, t_token token, t_token last_token) t_pres get_pressision(char *s, t_token token,
t_token last_token, t_pres last_pres)
{ {
if (token == OPERATOR) if (token == OPERATOR)
return (get_operator(s)); return (get_operator(s));
else if (last_token == OPERATOR && (last_pres == RED_R
|| last_pres == RED_L || last_pres == D_RED_R))
return (RED_FILE);
else if (last_token == OPERATOR && last_pres == HEREDOC)
return (LIM);
else if (last_token == OPERATOR || last_token == UNSET) else if (last_token == OPERATOR || last_token == UNSET)
return (COMMAND); return (COMMAND);
return (PARAMETER); return (PARAMETER);

View File

@@ -39,14 +39,17 @@ static void set_token(t_node *head)
{ {
t_node *it; t_node *it;
t_token last_token; t_token last_token;
t_pres last_pres;
it = head; it = head;
last_token = UNSET; last_token = UNSET;
last_pres = UNDEFINED;
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, last_token); it->pressision = get_pressision(it->val, it->token, last_token, last_pres);
last_token = it->token; last_token = it->token;
last_pres = it->pressision;
it = it->next; it = it->next;
} }
} }

View File

@@ -35,7 +35,9 @@ typedef enum e_pres
RED_R, RED_R,
HEREDOC, HEREDOC,
D_RED_R, D_RED_R,
PARAMETER PARAMETER,
RED_FILE,
LIM
} t_pres; } t_pres;
typedef struct s_node typedef struct s_node
@@ -52,7 +54,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 *s, t_token token, t_token last_token); t_pres get_pressision(char *s, t_token token, t_token last_token, t_pres last_pres);
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);