Merge branch 'lexer' into dev

This commit is contained in:
Matteo Flebus 2026-01-19 18:20:08 +01:00
commit e3a038677f

View file

@ -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,13 +275,10 @@ 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 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]))
{
@ -314,13 +316,10 @@ 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 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]))
{