cleaner main, added ft_lexer to encapsulate all phases of tokenization
This commit is contained in:
parent
b08b727779
commit
7265a6c340
9 changed files with 43 additions and 21 deletions
|
|
@ -116,6 +116,7 @@ job-control/sigtstp_handler.c\
|
|||
job-control/sigttin_handler.c\
|
||||
job-control/sigttou_handler.c\
|
||||
lexer/command_getoutput.c\
|
||||
lexer/ft_lexer.c\
|
||||
lexer/ft_post_tokenize.c\
|
||||
lexer/ft_tokenize.c\
|
||||
lexer/get_lexer_state.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:14:58 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:36:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -73,9 +73,11 @@ typedef enum e_lexstate t_lexstate;
|
|||
|
||||
extern int (*g_lexer[])(t_list **alst, char *str);
|
||||
|
||||
t_token *token_init();
|
||||
int ft_lexer(t_list **alst, char **str);
|
||||
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
||||
int ft_post_tokenize(t_list **alst, char **str);
|
||||
|
||||
t_token *token_init();
|
||||
int token_append(t_token *token, char c, short int esc);
|
||||
void token_free(void *data, size_t size);
|
||||
int token_cmp_type(t_token *token, t_type *ref);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 14:49:22 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:45:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 14:34:40 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:45:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,12 +17,8 @@ void process_free(void *content, size_t content_size)
|
|||
t_process *p;
|
||||
|
||||
(void)content_size;
|
||||
DG("check 0");
|
||||
p = content;
|
||||
DG("check 1");
|
||||
ft_strdel(&p->path);
|
||||
DG("check 2");
|
||||
ft_sstrfree(p->av);
|
||||
DG("check 3");
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
28
42sh/src/lexer/ft_lexer.c
Normal file
28
42sh/src/lexer/ft_lexer.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lexer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:42:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int ft_lexer(t_list **alst, char **command)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if (!*command)
|
||||
ret = 1;
|
||||
else if (ft_tokenize(alst, *command, DEFAULT))
|
||||
ret = 1;
|
||||
else if (ft_post_tokenize(alst, command))
|
||||
ret = 1;
|
||||
ft_strdel(command);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:22:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:29:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 14:55:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:34:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:22:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:45:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,23 +19,18 @@ int shell_single_command(char *command)
|
|||
|
||||
token = NULL;
|
||||
ast = NULL;
|
||||
if (!command)
|
||||
return (0);
|
||||
|
||||
DG("{inv}{mag}got command '%s'", command);
|
||||
if (ft_tokenize(&token, command, DEFAULT))
|
||||
if (ft_lexer(&token, &command) || !token)
|
||||
return (1);
|
||||
if (ft_post_tokenize(&token, &command))
|
||||
return (1);
|
||||
if (!token)
|
||||
return (0);
|
||||
ft_strdel(&command);
|
||||
|
||||
token_print(token);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
if (ft_exec(&ast))
|
||||
return (1);
|
||||
DG("after exec!");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 16:10:41 by wescande ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:45:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue