Skip to content

Commit

Permalink
fix<fix_double_quote>: fix double quote test 10
Browse files Browse the repository at this point in the history
  • Loading branch information
majerugo committed Jan 20, 2024
1 parent 33f2fc6 commit 916e7fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ char *get_word(struct lexer *lexer, bool *is_diactivated)
{
word_index -= 1;
handle_back_slash_in_double_quote(lexer, word, &word_index);
if (lexer->data[lexer->index] == '$')
{
break;
}
}

// Handle the double quote
Expand Down
30 changes: 2 additions & 28 deletions src/lexer/lexer_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool check_variable_name(struct lexer *lexer, char **word, unsigned *word_index,
char *curr_word = *word;
*is_in_braces = false;
// Handle variable in double quote
if (lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE)
if (lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE || lexer->curr_tok.type == TOKEN_VARIABLE_AND_DOUBLE_QUOTE)
{
lexer->curr_tok.type = TOKEN_VARIABLE_AND_DOUBLE_QUOTE;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ bool check_variable_name(struct lexer *lexer, char **word, unsigned *word_index,
// Not a valid variable name
else
{
if (lexer->curr_tok.type != TOKEN_DOUBLE_QUOTE)
if (lexer->curr_tok.type != TOKEN_VARIABLE_AND_DOUBLE_QUOTE)
{
lexer->curr_tok.type = TOKEN_WORD;
}
Expand Down Expand Up @@ -190,32 +190,6 @@ bool check_variable_name(struct lexer *lexer, char **word, unsigned *word_index,
return true;
}

void handle_back_slash_in_double_quote(struct lexer *lexer, char *word,
unsigned *word_index)
{
if (lexer->data[lexer->index] == '\"'
|| lexer->data[lexer->index] == '$'
|| lexer->data[lexer->index] == '\\'
|| lexer->data[lexer->index] == '\n'
|| lexer->data[lexer->index] == '`')
{
if (lexer->data[lexer->index] != '\n')
{
word[*word_index] = lexer->data[lexer->index];
}
else
{
*word_index -= 1;
}
lexer->index += 1;
}
else
{
word[*word_index] = '\\';
}
*word_index += 1;
}

bool handle_dollar(struct lexer *lexer, char **word, unsigned *word_index,
bool *is_in_braces)
{
Expand Down
28 changes: 27 additions & 1 deletion src/lexer/lexer_utils2.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,30 @@ bool check_variable_name_simulated(const char *data, int index)
}

return true;
}
}

void handle_back_slash_in_double_quote(struct lexer *lexer, char *word,
unsigned *word_index)
{
if (lexer->data[lexer->index] == '\"'
|| lexer->data[lexer->index] == '$'
|| lexer->data[lexer->index] == '\\'
|| lexer->data[lexer->index] == '\n'
|| lexer->data[lexer->index] == '`')
{
if (lexer->data[lexer->index] != '\n')
{
word[*word_index] = lexer->data[lexer->index];
}
else
{
*word_index -= 1;
}
lexer->index += 1;
}
else
{
word[*word_index] = '\\';
}
*word_index += 1;
}
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ int main(int argc, char **argv)
{
errx(1, "Error while creating lexer");
}

/*while (lexer_peek(lexer).type != TOKEN_EOF)
/* while (lexer_peek(lexer).type != TOKEN_EOF)
{
struct token token = lexer_pop(lexer);
print_token(token);
print_token(lexer->curr_tok);
printf("value: %s\n", token.data);
}*/

Expand Down

0 comments on commit 916e7fa

Please sign in to comment.