fix(lexer): now really handling quotes
This commit is contained in:
parent
95da4a56fa
commit
454bd76abc
1 changed files with 18 additions and 9 deletions
|
|
@ -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]))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue