lexer_bang and lexer_dquote
This commit is contained in:
parent
b013ffedbf
commit
41b42d8803
8 changed files with 45 additions and 9 deletions
|
|
@ -226,6 +226,7 @@ lexer/insert_newline.c\
|
|||
lexer/isrw_delim.c\
|
||||
lexer/keep_last_type.c\
|
||||
lexer/lexer_backslash.c\
|
||||
lexer/lexer_bang.c\
|
||||
lexer/lexer_bquote.c\
|
||||
lexer/lexer_curly_braces.c\
|
||||
lexer/lexer_default.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/23 15:18:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:17:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,6 +24,7 @@ enum e_lexstate
|
|||
HEREDOC,
|
||||
NEWLINE,
|
||||
DELIM,
|
||||
BANG,
|
||||
SEP,
|
||||
WORD,
|
||||
NUMBER,
|
||||
|
|
@ -99,6 +100,7 @@ int lexer_default(t_list **alst, t_lexer *lexer);
|
|||
int lexer_newline(t_list **alst, t_lexer *lexer);
|
||||
int lexer_heredoc(t_list **alst, t_lexer *lexer);
|
||||
int lexer_delim(t_list **alst, t_lexer *lexer);
|
||||
int lexer_bang(t_list **alst, t_lexer *lexer);
|
||||
int lexer_sep(t_list **alst, t_lexer *lexer);
|
||||
int lexer_word(t_list **alst, t_lexer *lexer);
|
||||
int lexer_number(t_list **alst, t_lexer *lexer);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
||||
/* Updated: 2017/03/27 17:48:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:10:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ static int c_is_delim(char c)
|
|||
return (0);
|
||||
}
|
||||
|
||||
char *c_strdupi(char *s, int (*f)(char))
|
||||
char *c_strdupi(char *s, int (*f)(char))
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:13:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,7 +24,8 @@ t_lexstate get_state_global(t_lexer *lexer)
|
|||
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
|
||||
ret = 0;
|
||||
if ((ft_is_delim(c) && (ret = DELIM))
|
||||
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))
|
||||
|| ((c == '&' || c == ';' || c == '|') && (ret = SEP))
|
||||
|| ((c == '!') && (ret = BANG))
|
||||
|| ((c == '\\') && (ret = BACKSLASH))
|
||||
|| ((c == '\n') && (ret = NEWLINE))
|
||||
|| ((c == '\'') && (ret = QUOTE))
|
||||
|
|
|
|||
31
42sh/src/lexer/lexer_bang.c
Normal file
31
42sh/src/lexer/lexer_bang.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lexer_bang.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/27 18:12:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/27 18:18:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int lexer_bang(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
if (token->type)
|
||||
{
|
||||
token->type = TK_BANG;
|
||||
lexer->state = DEFAULT;
|
||||
lexer->pos++;
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
}
|
||||
token->type = TK_WORD;
|
||||
lexer->state = WORD;
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 16:08:35 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:19:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
|
|||
else
|
||||
push(&lexer->stack, DQUOTE);
|
||||
}
|
||||
else if (lexer->str[lexer->pos] == '\\')
|
||||
else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0)
|
||||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/22 18:13:29 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:13:01 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
|||
&lexer_heredoc,
|
||||
&lexer_newline,
|
||||
&lexer_delim,
|
||||
&lexer_bang,
|
||||
&lexer_sep,
|
||||
&lexer_word,
|
||||
&lexer_number,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 15:23:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/27 18:11:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue