clean instruction (token, parser, error) whatever succes or error, still issue lexing after syntax error

This commit is contained in:
AntoHesse 2017-03-04 02:51:52 +01:00
parent dc423db858
commit 0f684e6189
6 changed files with 32 additions and 12 deletions

View file

@ -228,6 +228,7 @@ main/shell_exit.c\
main/shell_get_avdata.c\
main/shell_get_opts.c\
main/shell_init.c\
main/instruction_free.c\
parser/add_case.c\
parser/add_cmd.c\
parser/add_condition.c\

View file

@ -78,6 +78,9 @@ void shell_exit(void);
int data_init(void);
void data_exit(void);
int instruction_free(t_list **token, t_parser *parser,
t_btree **ast);
char *ft_putast(void *node);
void ft_putast2(void *node);

View file

@ -89,8 +89,8 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state);
int push_stack(t_sym *stack, t_sym new_sym);
int pop_stack(t_sym **stack, t_sym erase_sym);
*/
int error_syntax(t_list **token);
int error_EOF(void);
int error_syntax(t_list **token, t_parser *parser, t_btree **ast);
int error_EOF(t_list **token, t_parser *parser, t_btree **ast);
int ft_read_stack(t_sym *stack);
char *read_state(t_sym current);

View file

@ -0,0 +1,9 @@
#include "parser.h"
int instruction_free(t_list **token, t_parser *parser, t_btree **ast)
{
ft_lstdel(token, &token_free);
ft_lstdel(&parser->stack, NULL);
btree_del(ast, &ast_free);
return (0);
}

View file

@ -33,7 +33,8 @@ int handle_instruction(int fd)
{
if (ret == -1)
return (-1);
return (parser.state == UNDEFINED ? error_EOF() : 1);
return (parser.state == UNDEFINED ? error_EOF(&token,
&parser, &ast) : 1);
}
ft_strappend(&lexer.str, str);
if (get_lexer_stack(lexer) == BACKSLASH)
@ -56,16 +57,15 @@ int handle_instruction(int fd)
if (parser.state == SUCCESS)
break ;
else if (parser.state == ERROR && !SH_IS_INTERACTIVE(data_singleton()->opts))
return (error_syntax(&token));
return (error_syntax(&token, &parser, &ast));
else if (parser.state == ERROR)
error_syntax(&token);
token = NULL;
error_syntax(&token, &parser, &ast);
}
DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast);
if (ft_exec(&ast))
return (1);
btree_del(&ast, &ast_free);
instruction_free(&token, &parser, &ast);
ft_add_str_in_history(lexer.str);
return (0);
}

View file

@ -50,13 +50,16 @@ t_errormatch g_errormatch[] =
{0, NULL},
};
int error_syntax(t_list **lst)
int error_syntax(t_list **lst, t_parser *parser,
t_btree **ast)
{
t_token *token;
int i;
int temp;
token = (*lst)->content;
i = 0;
temp = 0;
while (g_errormatch[i].token)
{
if (g_errormatch[i].token == token->type)
@ -64,16 +67,20 @@ int error_syntax(t_list **lst)
ft_putstr_fd("syntax error near unexpected token `", 2);
ft_putstr_fd(g_errormatch[i].error, 2);
ft_putstr_fd("'\n", 2);
return (1);
temp = 1;
break ;
}
i++;
}
ft_putstr_fd("grammar error, notify ariard", 2);
instruction_free(lst, parser, ast);
if (temp == 0)
ft_putstr_fd("grammar error, notify ariard", 2);
return (1);
}
int error_EOF(void)
int error_EOF(t_list **lst, t_parser *parser, t_btree **ast)
{
ft_putstr_fd("syntax error near unexpected EOF", 2);
instruction_free(lst, parser, ast);
return (1);
}