Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexer freezes on this Python code #24

Open
joshi1983 opened this issue Jun 22, 2023 · 1 comment
Open

lexer freezes on this Python code #24

joshi1983 opened this issue Jun 22, 2023 · 1 comment

Comments

@joshi1983
Copy link
Contributor

joshi1983 commented Jun 22, 2023

Steps to reproduce:

  1. Try to run lexer("print('\'m')")
  2. Notice that it freezes.

I traced the freeze to an infinite do-while loop in the lexer.
In the following code, input is set to the code "print('\'m')" but current variable reaches into the billions,
currentChar === undefined, and
validator.test(currentChar) is returning false when currentChar is undefined.

  /**
     * 过滤(提取) 引号中的内容
     */
    // eslint-disable-next-line
    const matchQuotation = (currentChar, validator, TokenType) => {
        do {
            if (currentChar === '\n') {
                line++;
            }
            currentChar = input[++current];
        } while (!validator.test(currentChar));
        ++current;
    };

I wonder if this has anything to do with the backslashed quotation mark. Maybe the grammar doesn't define STRING properly for escaped quotes.

I edited this issue because I first thought the bug was reproducible by parsing but it actually requires running the lexer function on the code.

@joshi1983 joshi1983 changed the title Parse freezes on this Python code lexer freezes on this Python code Jun 22, 2023
@joshi1983
Copy link
Contributor Author

HaydenOrz do you want to try this? I ask because you did a great job with another lexer bug a couple weeks ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant