parenthesis + syntax fixes
This commit is contained in:
@@ -72,8 +72,6 @@ static t_node *find_token(char *tok, t_node *lst)
|
||||
t_node *get_top_token(t_node *lst, t_state *state)
|
||||
{
|
||||
*state = _SUBSH;
|
||||
if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst))
|
||||
return (lst);
|
||||
if (find_token("&&", lst))
|
||||
{
|
||||
*state = _AND;
|
||||
@@ -91,6 +89,8 @@ t_node *get_top_token(t_node *lst, t_state *state)
|
||||
}
|
||||
else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst))
|
||||
return (lst);
|
||||
else if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst))
|
||||
return (lst);
|
||||
else
|
||||
{
|
||||
*state = UNDEF;
|
||||
|
||||
@@ -61,10 +61,8 @@ t_ast_n *parser(char *input, t_msh *msh)
|
||||
}
|
||||
create_heredoc(lst, msh);
|
||||
if (DEBUG)
|
||||
{
|
||||
dio = drawio_init(DIO_PATH);
|
||||
gen_dio_linked_list(lst, dio);
|
||||
}
|
||||
// gen_dio_linked_list(lst, dio);
|
||||
ast = get_ast(msh, lst);
|
||||
debug_dio_ast(ast, dio);
|
||||
if (!ast)
|
||||
|
||||
@@ -25,7 +25,7 @@ static int parenthesis_error(t_node *cpy)
|
||||
&& !ft_strncmp(cpy->next->val, ")", 1))
|
||||
return (syntax_err_mess(cpy->next->val, 0));
|
||||
if (cpy->next && !ft_strncmp(cpy->next->val, "(", 1)
|
||||
&& !is_aop_operator(cpy))
|
||||
&& !is_aop_operator(cpy) && ft_strncmp(cpy->next->val, "(", 1))
|
||||
return (syntax_err_mess(cpy->next->val, 0));
|
||||
return (0);
|
||||
}
|
||||
@@ -71,11 +71,15 @@ int syntax_error(t_node *head)
|
||||
t_node *cpy;
|
||||
|
||||
cpy = head;
|
||||
if (is_aop_operator(cpy) && cpy->next == NULL)
|
||||
if (is_aop_operator(cpy))
|
||||
return (syntax_err_mess(cpy->val, 0));
|
||||
while (cpy)
|
||||
{
|
||||
if (redir_error(cpy) || parenthesis_error(cpy) || aop_error(cpy))
|
||||
if (redir_error(cpy))
|
||||
return (1);
|
||||
if (parenthesis_error(cpy))
|
||||
return (1);
|
||||
if (aop_error(cpy))
|
||||
return (1);
|
||||
if (unexpected_token(cpy))
|
||||
return (syntax_err_mess(cpy->val, 0));
|
||||
|
||||
@@ -116,19 +116,31 @@ t_node *tokenize(char *str)
|
||||
head = tokenize_base(str);
|
||||
if (!head)
|
||||
return (NULL);
|
||||
debug_token_list(head, "tokenizer");
|
||||
// debug_token_list(head, "tokenizer base");
|
||||
|
||||
if (!trim_nodes(head))
|
||||
return (NULL);
|
||||
debug_token_list(head, "tokenizer");
|
||||
// debug_token_list(head, "trim");
|
||||
|
||||
if (!unstick_nodes(head))
|
||||
return (NULL);
|
||||
debug_token_list(head, "tokenizer");
|
||||
// debug_token_list(head, "unstick");
|
||||
|
||||
stick_quote_node(head, 39);
|
||||
stick_quote_node(head, '"');
|
||||
debug_token_list(head, "tokenizer");
|
||||
// debug_token_list(head, "stick_quote_node");
|
||||
|
||||
set_token(head);
|
||||
// debug_token_list(head, "set token");
|
||||
|
||||
if (!trim_nodes(head))
|
||||
return (NULL);
|
||||
// debug_token_list(head, "trim2");
|
||||
|
||||
del_void_nodes(&head);
|
||||
// debug_token_list(head, "del_void_nodes");
|
||||
debug_token_list(head, "tokenizer");
|
||||
|
||||
if (syntax_error(head))
|
||||
return (free_linked_list(head), NULL);
|
||||
return (head);
|
||||
|
||||
Reference in New Issue
Block a user