feat: return error token on onclosed double
This commit is contained in:
parent
55ba622714
commit
914d9cf644
@ -57,10 +57,15 @@ static char *ft_parse_quotes(t_lexer *lexer)
|
|||||||
while (lexer->current_char != '\0' && lexer->current_char != qc)
|
while (lexer->current_char != '\0' && lexer->current_char != qc)
|
||||||
ft_lexer_readchar(lexer);
|
ft_lexer_readchar(lexer);
|
||||||
len = lexer->pos - start;
|
len = lexer->pos - start;
|
||||||
word = malloc(sizeof(char) * len);
|
word = malloc(sizeof(char) * len + 1);
|
||||||
ft_strlcpy(word, lexer->input + start, len + 1);
|
ft_strlcpy(word, lexer->input + start, len + 1);
|
||||||
if (lexer->current_char == qc)
|
if (lexer->current_char == qc)
|
||||||
ft_lexer_readchar(lexer);
|
ft_lexer_readchar(lexer);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(word);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
return (word);
|
return (word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +82,7 @@ char *ft_lexer_readword(t_lexer *lexer)
|
|||||||
}
|
}
|
||||||
while (ft_isprint(lexer->current_char) && lexer->current_char != '<'
|
while (ft_isprint(lexer->current_char) && lexer->current_char != '<'
|
||||||
&& lexer->current_char != '>' && lexer->current_char != '|'
|
&& lexer->current_char != '>' && lexer->current_char != '|'
|
||||||
&& lexer->current_char != '\0')
|
&& lexer->current_char != '\0' && !ft_isspace(lexer->current_char))
|
||||||
{
|
{
|
||||||
ft_lexer_readchar(lexer);
|
ft_lexer_readchar(lexer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ t_list *ft_parse_input(t_lexer *lexer)
|
|||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
token = ft_token_next(lexer);
|
token = ft_token_next(lexer);
|
||||||
if (token->type == T_EOF || token->type == T_ERROR)
|
if (token->type == T_EOF)
|
||||||
break ;
|
break ;
|
||||||
ft_lstadd_back(&list, ft_lstnew(token));
|
ft_lstadd_back(&list, ft_lstnew(token));
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ t_list *ft_parse_input(t_lexer *lexer)
|
|||||||
* 1. Skips any whitespace characters.
|
* 1. Skips any whitespace characters.
|
||||||
* 2. Checks the current character in the lexer:
|
* 2. Checks the current character in the lexer:
|
||||||
* - If it is the end-of-file character ('\0'), creates an EOF token.
|
* - If it is the end-of-file character ('\0'), creates an EOF token.
|
||||||
* - If it is a special character ('<', '>', '|'), parses
|
* - If it is a special character ('<', '>', '|'), parses
|
||||||
* the token accordingly.
|
* the token accordingly.
|
||||||
* - If it is a printable character, reads the word and creates a word token.
|
* - If it is a printable character, reads the word and creates a word token.
|
||||||
* - Otherwise, creates an error token.
|
* - Otherwise, creates an error token.
|
||||||
@ -77,6 +77,8 @@ t_token *ft_token_next(t_lexer *lexer)
|
|||||||
else if (ft_isprint(lexer->current_char))
|
else if (ft_isprint(lexer->current_char))
|
||||||
{
|
{
|
||||||
word = ft_lexer_readword(lexer);
|
word = ft_lexer_readword(lexer);
|
||||||
|
if (!word)
|
||||||
|
return (ft_token_new(T_ERROR, &lexer->current_char, current_pos));
|
||||||
token = ft_token_new(T_WORD, word, current_pos);
|
token = ft_token_new(T_WORD, word, current_pos);
|
||||||
free(word);
|
free(word);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user