DTStack / DTStack/dt-python-parser

lexer freezes on this Python code

Đang mở
#24 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
25
Fork
7
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.