From 95da4a56fa3fda80761c7453ce1dd2277c252103 Mon Sep 17 00:00:00 2001 From: Matteo Flebus Date: Mon, 19 Jan 2026 17:56:08 +0100 Subject: [PATCH 1/2] Revert "fix(lexer): lexing_mode depending on quote" This reverts commit ed4c3d475c35f875c60b066e22ebf113789efe43. --- src/lexer/lexer.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 2505649..fd54c98 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -270,13 +270,8 @@ struct token *peek_token(void) while (i < remaining_chars) { - // true if encountered a quotes of any type at stream[i] - if (update_lexing_mode(stream, i, &lexing_mode)) - { - i++; - continue; - } - else + // true if we didn't encounter a quotes of any type at stream[i] + if (!update_lexing_mode(stream, i, &lexing_mode)) { if (is_special_char(stream[i])) { @@ -314,13 +309,8 @@ struct token *pop_token(void) while (i < remaining_chars) { - // true if encountered a quotes of any type at stream[i] - if (update_lexing_mode(stream, i, &lexing_mode)) - { - i++; - continue; - } - else + // true if we didn't encounter a quotes of any type at stream[i] + if (!update_lexing_mode(stream, i, &lexing_mode)) { if (is_special_char(stream[i])) { From 454bd76abc82cc9a6ab974b59e88aeb03bd70184 Mon Sep 17 00:00:00 2001 From: Matteo Flebus Date: Mon, 19 Jan 2026 18:19:35 +0100 Subject: [PATCH 2/2] 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])) {