lexer NORM, bquote/dquote lexing refactoring

This commit is contained in:
Jack Halford 2017-03-16 23:17:33 +01:00
parent cf141bd2b4
commit 0c848e75d3
20 changed files with 52 additions and 71 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # 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_dquote.c\
lexer/lexer_end.c\ lexer/lexer_end.c\
lexer/lexer_great.c\ lexer/lexer_great.c\
lexer/lexer_greatand.c\
lexer/lexer_heredoc.c\ lexer/lexer_heredoc.c\
lexer/lexer_init.c\ lexer/lexer_init.c\
lexer/lexer_less.c\ lexer/lexer_less.c\
lexer/lexer_lessand.c\
lexer/lexer_lex.c\ lexer/lexer_lex.c\
lexer/lexer_newline.c\ lexer/lexer_newline.c\
lexer/lexer_number.c\ lexer/lexer_number.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ /* 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, QUOTE,
DQUOTE, DQUOTE,
BQUOTE, BQUOTE,
DQUOTE_BQUOTE,
BACKSLASH, BACKSLASH,
CURLY_BRACKETS, CURLY_BRACKETS,
ASSIGNEMENT_WORD, ASSIGNEMENT_WORD,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* 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 "completion.h"
# include "hash.h" # include "hash.h"
#ifndef DEBUG
# define DEBUG_MODE 0
#else
# define DEBUG_MODE 1
#endif
struct s_data struct s_data
{ {
t_flag opts; t_flag opts;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* 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_STATE_MASK;
p->attrs |= PROCESS_COMPLETED; p->attrs |= PROCESS_COMPLETED;
if (WIFSIGNALED(status)) if (WIFSIGNALED(status) && DEBUG_MODE)
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}",
(int)pid, WTERMSIG(status)); (int)pid, WTERMSIG(status));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ /* 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) int lexer_bquote(t_list **alst, t_lexer *lexer)
{ {
t_token *token; t_token *token;
int top_state; int back;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = TK_WORD;
if (lexer->state == DQUOTE_BQUOTE) back = 0;
token_append(token, lexer, 1, 0);
else
token_append(token, lexer, 0, 0);
if (lexer->str[lexer->pos] == '`') if (lexer->str[lexer->pos] == '`')
{ {
lexer->pos++; if (get_lexer_stack(*lexer) != BQUOTE)
if (!(lexer->stack && (*(int*)lexer->stack->content == BQUOTE
|| *(int*)lexer->stack->content == DQUOTE_BQUOTE)))
{
push(&lexer->stack, lexer->state); push(&lexer->stack, lexer->state);
return (lexer_lex(alst, lexer)); else
} lexer->state = pop(&lexer->stack) == DQUOTE ? DQUOTE : DEFAULT;
top_state = pop(&lexer->stack);
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
return (lexer_lex(alst, lexer));
} }
if (lexer->str[lexer->pos] == '\\') else if (lexer->str[lexer->pos] == '\\' && (back = 1))
{ {
lexer->pos++; lexer->pos++;
if (lexer->str[lexer->pos] == 0) if (lexer->str[lexer->pos] == 0)
{ return (push(&lexer->stack, BACKSLASH) ? 0 : 0);
push(&lexer->stack, BACKSLASH);
return (0);
}
else
token_append(token, lexer, 1, 1);
lexer->pos++;
return (lexer_lex(alst,lexer));
} }
token_append(token, lexer, back, back);
lexer->pos++; lexer->pos++;
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ /* 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]; c = lexer->str[lexer->pos];
if ((lexer->state = get_state_global(lexer))) if ((lexer->state = get_state_global(lexer)))
{
DG("got state %i",lexer->state);
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
}
if ((lexer->state = get_state_redir(lexer))) if ((lexer->state = get_state_redir(lexer)))
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
DG("no special state, %c",lexer->str[lexer->pos]);
lexer->state = ft_isdigit(c) ? NUMBER : WORD; lexer->state = ft_isdigit(c) ? NUMBER : WORD;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = TK_WORD;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ /* 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; token->type = TK_WORD;
if (lexer->str[lexer->pos] == '"') if (lexer->str[lexer->pos] == '"')
{ {
lexer->pos++; if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD))
if (!(lexer->stack && *(int*)lexer->stack->content == DQUOTE)) pop(&lexer->stack);
{
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);
else else
token_append(token, lexer, 1, 1); push(&lexer->stack, DQUOTE);
lexer->pos++;
return (lexer_lex(alst,lexer));
} }
else if (lexer->str[lexer->pos] == '`') else if (lexer->str[lexer->pos] == '\\')
{ {
lexer->state = DQUOTE_BQUOTE; if (lexer->str[lexer->pos + 1] == 0)
return (lexer_bquote(alst, lexer)); 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++; lexer->pos++;
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */ /* 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; t_token *token;
if (lexer->str[lexer->pos] == '#') if (lexer->str[lexer->pos] == '#')
while (lexer->str[++lexer->pos]); while (lexer->str[++lexer->pos])
;
if (*alst && (lexer->state == QUOTE if (*alst && (lexer->state == QUOTE
|| lexer->state == DQUOTE || lexer->state == DQUOTE
|| lexer->state == BQUOTE)) || lexer->state == BQUOTE))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ /* 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_quote,
&lexer_dquote, &lexer_dquote,
&lexer_bquote, &lexer_bquote,
&lexer_bquote,
&lexer_backslash, &lexer_backslash,
&lexer_curly_braces, &lexer_curly_braces,
&lexer_assignement_word, &lexer_assignement_word,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */