- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_python_ast.js
More file actions
Latest commit
26 lines (19 loc) · 719 Bytes
/
Copy pathdebug_python_ast.js
File metadata and controls
26 lines (19 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const{ getParser, initGrammars, loadAllGrammars }=require('./dist/extraction/grammars');
(async()=>{
awaitinitGrammars();
awaitloadAllGrammars();
constparser=getParser('python');
constcode=`class Child(Parent):
pass`;
consttree=parser.parse(code);
functionwalk(node,depth=0){
constindent=' '.repeat(depth);
constpreview=node.text.substring(0,30).replace(/\n/g,'\\n');
console.log(`${indent}${node.type} [${node.startPosition.row}:${node.startPosition.column}] "${preview}"`);
for(leti=0;i<node.namedChildCount;i++){
constchild=node.namedChild(i);
if(child)walk(child,depth+1);
}
}
walk(tree.rootNode);
})();