File tree Expand file tree Collapse file tree 4 files changed +222
-106
lines changed Expand file tree Collapse file tree 4 files changed +222
-106
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import ast
3
+ import sys
4
+
5
+ filename = sys .argv [1 ]
6
+ print ('Crawling file:' , filename )
7
+
8
+
9
+ with open (filename , 'r' ) as f :
10
+ source = f .read ()
11
+
12
+ t = ast .parse (source )
13
+ print (t )
14
+
15
+ shift = 3
16
+ def print_node (node , indent = 0 ):
17
+ if isinstance (node , ast .AST ):
18
+ print (' ' * indent , "NODE" , node .__class__ .__name__ )
19
+ for field in node ._fields :
20
+ print (' ' * indent ,'-' , field )
21
+ f = getattr (node , field )
22
+ if isinstance (f , list ):
23
+ for f2 in f :
24
+ print_node (f2 , indent = indent + shift )
25
+ else :
26
+ print_node (f , indent = indent + shift )
27
+ else :
28
+ print (' ' * indent , 'OBJ' , node )
29
+
30
+ print_node (t )
31
+
32
+ # print(ast.dump(t))
33
+
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ pub enum Statement {
55
55
Break ,
56
56
Continue ,
57
57
Return {
58
- value : Option < Box < Expression > > ,
58
+ value : Option < Expression > ,
59
59
} ,
60
60
Import {
61
61
import_parts : Vec < SingleImport > ,
Original file line number Diff line number Diff line change @@ -168,10 +168,10 @@ FlowStatement: ast::LocatedStatement = {
168
168
node: ast::Statement::Continue,
169
169
}
170
170
},
171
- <loc:@L> "return" <t :TestList?> => {
171
+ <loc:@L> "return" <value :TestList?> => {
172
172
ast::LocatedStatement {
173
173
location: loc,
174
- node: ast::Statement::Return { value: t.map(Box::new) },
174
+ node: ast::Statement::Return { value },
175
175
}
176
176
},
177
177
<loc:@L> <y:YieldExpr> => {
You can’t perform that action at this time.
0 commit comments