DTStack / DTStack/dt-python-parser

Problem when using listener mode

未關閉
#26 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
25
分支
7
PR 合併指標
30 天內沒有已合併 PR

描述

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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。