parenthesis + syntax fixes
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Hello World tmp.txt
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@ ast.xml
|
|||||||
.TEST_objs
|
.TEST_objs
|
||||||
.mmoat_history
|
.mmoat_history
|
||||||
.heredoc
|
.heredoc
|
||||||
|
run_vg.sh
|
||||||
|
|
||||||
file
|
file
|
||||||
file2
|
file2
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
# include "exec/exec.h"
|
# include "exec/exec.h"
|
||||||
# include "exec/expander.h"
|
# include "exec/expander.h"
|
||||||
|
|
||||||
# define DEBUG 0
|
# define DEBUG 1
|
||||||
|
|
||||||
# ifndef DIO_PATH
|
# ifndef DIO_PATH
|
||||||
# define DIO_PATH "ast.xml"
|
# define DIO_PATH "ast.xml"
|
||||||
|
|||||||
@@ -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)
|
t_node *get_top_token(t_node *lst, t_state *state)
|
||||||
{
|
{
|
||||||
*state = _SUBSH;
|
*state = _SUBSH;
|
||||||
if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst))
|
|
||||||
return (lst);
|
|
||||||
if (find_token("&&", lst))
|
if (find_token("&&", lst))
|
||||||
{
|
{
|
||||||
*state = _AND;
|
*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))
|
else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst))
|
||||||
return (lst);
|
return (lst);
|
||||||
|
else if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst))
|
||||||
|
return (lst);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*state = UNDEF;
|
*state = UNDEF;
|
||||||
|
|||||||
@@ -61,10 +61,8 @@ t_ast_n *parser(char *input, t_msh *msh)
|
|||||||
}
|
}
|
||||||
create_heredoc(lst, msh);
|
create_heredoc(lst, msh);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
|
||||||
dio = drawio_init(DIO_PATH);
|
dio = drawio_init(DIO_PATH);
|
||||||
gen_dio_linked_list(lst, dio);
|
// gen_dio_linked_list(lst, dio);
|
||||||
}
|
|
||||||
ast = get_ast(msh, lst);
|
ast = get_ast(msh, lst);
|
||||||
debug_dio_ast(ast, dio);
|
debug_dio_ast(ast, dio);
|
||||||
if (!ast)
|
if (!ast)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ static int parenthesis_error(t_node *cpy)
|
|||||||
&& !ft_strncmp(cpy->next->val, ")", 1))
|
&& !ft_strncmp(cpy->next->val, ")", 1))
|
||||||
return (syntax_err_mess(cpy->next->val, 0));
|
return (syntax_err_mess(cpy->next->val, 0));
|
||||||
if (cpy->next && !ft_strncmp(cpy->next->val, "(", 1)
|
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 (syntax_err_mess(cpy->next->val, 0));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -71,11 +71,15 @@ int syntax_error(t_node *head)
|
|||||||
t_node *cpy;
|
t_node *cpy;
|
||||||
|
|
||||||
cpy = head;
|
cpy = head;
|
||||||
if (is_aop_operator(cpy) && cpy->next == NULL)
|
if (is_aop_operator(cpy))
|
||||||
return (syntax_err_mess(cpy->val, 0));
|
return (syntax_err_mess(cpy->val, 0));
|
||||||
while (cpy)
|
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);
|
return (1);
|
||||||
if (unexpected_token(cpy))
|
if (unexpected_token(cpy))
|
||||||
return (syntax_err_mess(cpy->val, 0));
|
return (syntax_err_mess(cpy->val, 0));
|
||||||
|
|||||||
@@ -116,19 +116,31 @@ t_node *tokenize(char *str)
|
|||||||
head = tokenize_base(str);
|
head = tokenize_base(str);
|
||||||
if (!head)
|
if (!head)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_token_list(head, "tokenizer");
|
// debug_token_list(head, "tokenizer base");
|
||||||
|
|
||||||
if (!trim_nodes(head))
|
if (!trim_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_token_list(head, "tokenizer");
|
// debug_token_list(head, "trim");
|
||||||
|
|
||||||
if (!unstick_nodes(head))
|
if (!unstick_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_token_list(head, "tokenizer");
|
// debug_token_list(head, "unstick");
|
||||||
|
|
||||||
stick_quote_node(head, 39);
|
stick_quote_node(head, 39);
|
||||||
stick_quote_node(head, '"');
|
stick_quote_node(head, '"');
|
||||||
debug_token_list(head, "tokenizer");
|
// debug_token_list(head, "stick_quote_node");
|
||||||
|
|
||||||
set_token(head);
|
set_token(head);
|
||||||
|
// debug_token_list(head, "set token");
|
||||||
|
|
||||||
|
if (!trim_nodes(head))
|
||||||
|
return (NULL);
|
||||||
|
// debug_token_list(head, "trim2");
|
||||||
|
|
||||||
del_void_nodes(&head);
|
del_void_nodes(&head);
|
||||||
|
// debug_token_list(head, "del_void_nodes");
|
||||||
debug_token_list(head, "tokenizer");
|
debug_token_list(head, "tokenizer");
|
||||||
|
|
||||||
if (syntax_error(head))
|
if (syntax_error(head))
|
||||||
return (free_linked_list(head), NULL);
|
return (free_linked_list(head), NULL);
|
||||||
return (head);
|
return (head);
|
||||||
|
|||||||
Reference in New Issue
Block a user