From 454bd76abc82cc9a6ab974b59e88aeb03bd70184 Mon Sep 17 00:00:00 2001 From: Matteo Flebus Date: Mon, 19 Jan 2026 18:19:35 +0100 Subject: [PATCH] fix(lexer): now really handling quotes --- src/lexer/lexer.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index fd54c98..c135497 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -236,11 +236,6 @@ static bool update_lexing_mode(char *stream, ssize_t i, enum lexing_mode *lexing_mode) { enum lexing_mode mode_before_update = *lexing_mode; - // SECOND quote - if (*lexing_mode == LEXER_QUOTE && stream[i] == '\'') - *lexing_mode = LEXER_NORMAL; - if (*lexing_mode == LEXER_DOUBLE_QUOTE && stream[i] == '"') - *lexing_mode = LEXER_NORMAL; // FIRST quote if (*lexing_mode == LEXER_NORMAL) @@ -251,6 +246,16 @@ static bool update_lexing_mode(char *stream, ssize_t i, if (stream[i] == '\'') *lexing_mode = LEXER_QUOTE; } + + // SECOND quote + else + { + if (*lexing_mode == LEXER_QUOTE && stream[i] == '\'') + *lexing_mode = LEXER_NORMAL; + if (*lexing_mode == LEXER_DOUBLE_QUOTE && stream[i] == '"') + *lexing_mode = LEXER_NORMAL; + } + return *lexing_mode != mode_before_update; } @@ -270,8 +275,10 @@ struct token *peek_token(void) while (i < remaining_chars) { - // true if we didn't encounter a quotes of any type at stream[i] - if (!update_lexing_mode(stream, i, &lexing_mode)) + // true if we didn't encounter a quote of any type at stream[i] + // AND we are not inside quotes + if (!update_lexing_mode(stream, i, &lexing_mode) + && lexing_mode == LEXER_NORMAL) { if (is_special_char(stream[i])) { @@ -309,8 +316,10 @@ struct token *pop_token(void) while (i < remaining_chars) { - // true if we didn't encounter a quotes of any type at stream[i] - if (!update_lexing_mode(stream, i, &lexing_mode)) + // true if we didn't encounter a quote of any type at stream[i] + // AND we are not inside quotes + if (!update_lexing_mode(stream, i, &lexing_mode) + && lexing_mode == LEXER_NORMAL) { if (is_special_char(stream[i])) {