DTStack / DTStack/dt-python-parser

Problem when using listener mode

Đang mở
#26 0 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ả

When using listener mode the parser is always expecting a line break after each line of python code.
For instance,
```
const parser = new Python3Parser();
const python ='import sys\nfor i in sys.argv:\n print(i)';
// parseTree
const tree = parser.parse(python);
class MyListener extends Python3Listener {
enterImport_name(ctx): void {
let importName = ctx
.getText()
.toLowerCase()
.match(/(?<=import).+/)?.[0];
console.log('ImportName', importName);
}
}
const listenTableName = new MyListener();
parser.listen(listenTableName, tree);
```
The above code will work but when I remove '\n' from the python code it won't (Given below).

```
const parser = new Python3Parser();
const python ='import sys';
// parseTree
const tree = parser.parse(python);
class MyListener extends Python3Listener {
enterImport_name(ctx): void {
let importName = ctx
.getText()
.toLowerCase()
.match(/(?<=import).+/)?.[0];
console.log('ImportName', importName);
}
}
const listenTableName = new MyListener();
parser.listen(listenTableName, tree);
```
Is there a work around for this? I want to dynamically pass the python code to the parser so it might not always have a line break.

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.