lexer NORM, bquote/dquote lexing refactoring
This commit is contained in:
parent
cf141bd2b4
commit
0c848e75d3
20 changed files with 52 additions and 71 deletions
|
|
@ -6,7 +6,7 @@
|
|||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||
# Updated: 2017/03/15 18:11:31 by jhalford ### ########.fr #
|
||||
# Updated: 2017/03/16 23:02:12 by jhalford ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -223,11 +223,9 @@ lexer/lexer_delim.c\
|
|||
lexer/lexer_dquote.c\
|
||||
lexer/lexer_end.c\
|
||||
lexer/lexer_great.c\
|
||||
lexer/lexer_greatand.c\
|
||||
lexer/lexer_heredoc.c\
|
||||
lexer/lexer_init.c\
|
||||
lexer/lexer_less.c\
|
||||
lexer/lexer_lessand.c\
|
||||
lexer/lexer_lex.c\
|
||||
lexer/lexer_newline.c\
|
||||
lexer/lexer_number.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/15 21:54:52 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 20:24:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 19:07:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:29:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,7 +34,6 @@ enum e_lexstate
|
|||
QUOTE,
|
||||
DQUOTE,
|
||||
BQUOTE,
|
||||
DQUOTE_BQUOTE,
|
||||
BACKSLASH,
|
||||
CURLY_BRACKETS,
|
||||
ASSIGNEMENT_WORD,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/15 16:35:42 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/16 23:01:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,6 +32,12 @@
|
|||
# include "completion.h"
|
||||
# include "hash.h"
|
||||
|
||||
#ifndef DEBUG
|
||||
# define DEBUG_MODE 0
|
||||
#else
|
||||
# define DEBUG_MODE 1
|
||||
#endif
|
||||
|
||||
struct s_data
|
||||
{
|
||||
t_flag opts;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/14 22:53:17 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/16 20:13:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/16 18:40:47 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:45:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 16:50:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 23:00:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ int mark_process_status(pid_t pid, int status)
|
|||
{
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
p->attrs |= PROCESS_COMPLETED;
|
||||
if (WIFSIGNALED(status))
|
||||
if (WIFSIGNALED(status) && DEBUG_MODE)
|
||||
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}",
|
||||
(int)pid, WTERMSIG(status));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 18:42:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:42:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 18:51:31 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 20:08:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 18:40:59 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:42:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 18:24:01 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 22:23:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 19:33:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/16 22:50:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 19:03:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:41:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 22:04:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 22:36:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 23:32:14 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/16 22:30:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,40 +15,25 @@
|
|||
int lexer_bquote(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_token *token;
|
||||
int top_state;
|
||||
int back;
|
||||
|
||||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
if (lexer->state == DQUOTE_BQUOTE)
|
||||
token_append(token, lexer, 1, 0);
|
||||
else
|
||||
token_append(token, lexer, 0, 0);
|
||||
back = 0;
|
||||
if (lexer->str[lexer->pos] == '`')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (!(lexer->stack && (*(int*)lexer->stack->content == BQUOTE
|
||||
|| *(int*)lexer->stack->content == DQUOTE_BQUOTE)))
|
||||
{
|
||||
if (get_lexer_stack(*lexer) != BQUOTE)
|
||||
push(&lexer->stack, lexer->state);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
top_state = pop(&lexer->stack);
|
||||
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
|
||||
return (lexer_lex(alst, lexer));
|
||||
else
|
||||
lexer->state = pop(&lexer->stack) == DQUOTE ? DQUOTE : DEFAULT;
|
||||
}
|
||||
if (lexer->str[lexer->pos] == '\\')
|
||||
else if (lexer->str[lexer->pos] == '\\' && (back = 1))
|
||||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
{
|
||||
push(&lexer->stack, BACKSLASH);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst,lexer));
|
||||
return (push(&lexer->stack, BACKSLASH) ? 0 : 0);
|
||||
}
|
||||
token_append(token, lexer, back, back);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 16:20:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:42:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,9 +19,13 @@ int lexer_default(t_list **alst, t_lexer *lexer)
|
|||
|
||||
c = lexer->str[lexer->pos];
|
||||
if ((lexer->state = get_state_global(lexer)))
|
||||
{
|
||||
DG("got state %i",lexer->state);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
if ((lexer->state = get_state_redir(lexer)))
|
||||
return (lexer_lex(alst, lexer));
|
||||
DG("no special state, %c",lexer->str[lexer->pos]);
|
||||
lexer->state = ft_isdigit(c) ? NUMBER : WORD;
|
||||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:09:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 22:59:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,32 +20,21 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
|
|||
token->type = TK_WORD;
|
||||
if (lexer->str[lexer->pos] == '"')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (!(lexer->stack && *(int*)lexer->stack->content == DQUOTE))
|
||||
{
|
||||
push(&lexer->stack, DQUOTE);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
lexer->state = WORD;
|
||||
pop(&lexer->stack);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
if (lexer->str[lexer->pos] == '\\')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
return (0);
|
||||
if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD))
|
||||
pop(&lexer->stack);
|
||||
else
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst,lexer));
|
||||
push(&lexer->stack, DQUOTE);
|
||||
}
|
||||
else if (lexer->str[lexer->pos] == '`')
|
||||
else if (lexer->str[lexer->pos] == '\\')
|
||||
{
|
||||
lexer->state = DQUOTE_BQUOTE;
|
||||
return (lexer_bquote(alst, lexer));
|
||||
if (lexer->str[lexer->pos + 1] == 0)
|
||||
return(lexer_backslash(alst, lexer));
|
||||
token_append(token, lexer, 1, 1);
|
||||
}
|
||||
token_append(token, lexer, 1, 0);
|
||||
else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE))
|
||||
return (lexer_lex(alst, lexer));
|
||||
else
|
||||
token_append(token, lexer, 1, 0);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/09 14:53:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 23:17:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,8 @@ int lexer_end(t_list **alst, t_lexer *lexer)
|
|||
t_token *token;
|
||||
|
||||
if (lexer->str[lexer->pos] == '#')
|
||||
while (lexer->str[++lexer->pos]);
|
||||
while (lexer->str[++lexer->pos])
|
||||
;
|
||||
if (*alst && (lexer->state == QUOTE
|
||||
|| lexer->state == DQUOTE
|
||||
|| lexer->state == BQUOTE))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 19:07:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 21:42:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,7 +27,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
|||
&lexer_quote,
|
||||
&lexer_dquote,
|
||||
&lexer_bquote,
|
||||
&lexer_bquote,
|
||||
&lexer_backslash,
|
||||
&lexer_curly_braces,
|
||||
&lexer_assignement_word,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 18:01:32 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 23:02:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue