@@ -28,21 +28,43 @@ var Normalize = Transformers([][]Transformer{
28
28
29
29
func funcDefMap (typ string , async bool ) Mapping {
30
30
return MapSemantic (typ , uast.FunctionGroup {}, MapObj (
31
- Obj {
32
- "body" : Var ("body" ),
33
- "name" : Var ("name" ),
31
+ Fields {
32
+ { Name : "body" , Op : Var ("body" )} ,
33
+ { Name : "name" , Op : Var ("name" )} ,
34
34
// Arguments should be converted by the uast.Arguments normalization
35
- "args" : Obj {
35
+ { Name : "args" , Op : Obj {
36
36
"args" : Var ("arguments" ),
37
37
uast .KeyPos : Var ("_pos" ),
38
38
uast .KeyType : Var ("_type" ),
39
+ }},
40
+ // Will be filled only if there is a Python3 type annotation. If the field is
41
+ // missing or the value is nil it DOESNT mean that the function returns None,
42
+ // just that there is no annotation (but the function could still return some
43
+ // other type!).
44
+ {Name : "returns" , Optional : "ret_opt" , Op : Cases ("ret_case" ,
45
+ Is (nil ),
46
+ Obj {
47
+ uast .KeyType : String ("BoxedName" ),
48
+ "boxed_value" : Var ("ret_type" ),
49
+ // No problem dropping this one, it's used by an internal interpreter optimization/cache
50
+ // without semantic meaning
51
+ "ctx" : Any (),
52
+ }),
39
53
},
54
+ {Name : "decorator_list" , Op : Var ("func_decorators" )},
55
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
56
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
40
57
},
41
58
Obj {
42
59
"Nodes" : Arr (
43
- Obj {
60
+ Fields {
44
61
// FIXME: generator=true if it uses yield anywhere in the body
45
- "async" : Bool (async ),
62
+ {Name : "async" , Op : Bool (async )},
63
+ {Name : "decorators" , Op : Var ("func_decorators" )},
64
+ {Name : "comments" , Op : Fields {
65
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
66
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
67
+ }},
46
68
},
47
69
UASTType (uast.Alias {}, Obj {
48
70
// FIXME: can't call identifierWithPos because it would take the position of the
@@ -51,8 +73,17 @@ func funcDefMap(typ string, async bool) Mapping {
51
73
"Name" : Var ("name" ),
52
74
}),
53
75
"Node" : UASTType (uast.Function {}, Obj {
54
- "Type" : UASTType (uast.FunctionType {}, Obj {
55
- "Arguments" : Var ("arguments" ),
76
+ "Type" : UASTType (uast.FunctionType {}, Fields {
77
+ {Name : "Arguments" , Op : Var ("arguments" )},
78
+ {Name : "Returns" , Optional : "ret_opt" , Op : Cases ("ret_case" ,
79
+ // Dont add None here as default, read the comment on the upper
80
+ // side of the annotation
81
+ Is (nil ),
82
+ Arr (UASTType (uast.Argument {},
83
+ Obj {
84
+ "Type" : Var ("ret_type" ),
85
+ },
86
+ )))},
56
87
}),
57
88
"Body" : UASTType (uast.Block {}, Obj {
58
89
"Statements" : Var ("body" ),
@@ -89,7 +120,6 @@ func mapStr(nativeType string) Mapping {
89
120
{Name : "boxed_value" , Op : UASTType (uast.String {}, Obj {
90
121
uast .KeyPos : Var ("pos_" ),
91
122
"Value" : Var ("s" ),
92
- //"Format": String(""),
93
123
})},
94
124
{Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
95
125
{Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
@@ -99,9 +129,11 @@ func mapStr(nativeType string) Mapping {
99
129
100
130
var Normalizers = []Mapping {
101
131
102
- // Box Names, Strings, and Bools into a "BoxedFoo" moving the real node to the
132
+ // Box Names, Strings, Attributes, and Bools into a "BoxedFoo" moving the real node to the
103
133
// "value" property and keeping the comments in the parent (if not, comments would be lost
104
- // when promoting the objects)
134
+ // when promoting the objects).
135
+ // For other objects, the comments are dropped.
136
+ // See: https://github.com/bblfsh/sdk/issues/361
105
137
Map (
106
138
Part ("_" , Fields {
107
139
{Name : uast .KeyType , Op : String ("Name" )},
@@ -121,13 +153,10 @@ var Normalizers = []Mapping{
121
153
}),
122
154
),
123
155
124
- // TODO: uncomment after SDK 2.13.x update
125
- // (upgrade currently blocked by: https://github.com/bblfsh/sdk/issues/353)
126
156
Map (
127
157
Part ("_" , Fields {
128
158
{Name : uast .KeyType , Op : String ("BoolLiteral" )},
129
159
{Name : uast .KeyPos , Op : Var ("pos_" )},
130
- //{Name: "LiteralValue", Op: Var("lv")},
131
160
{Name : "value" , Op : Var ("lv" )},
132
161
{Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
133
162
{Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
@@ -143,6 +172,29 @@ var Normalizers = []Mapping{
143
172
}),
144
173
),
145
174
175
+ Map (
176
+ Part ("_" , Fields {
177
+ {Name : uast .KeyType , Op : String ("Attribute" )},
178
+ {Name : uast .KeyPos , Op : Var ("pos_" )},
179
+ {Name : "attr" , Op : Var ("aname" )},
180
+ // No problem dropping this one, it's used by an internal interpreter optimization
181
+ // cache without semantic meaning
182
+ // without semantic meaning
183
+ {Name : "ctx" , Op : Any ()},
184
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
185
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
186
+ }),
187
+ Part ("_" , Fields {
188
+ {Name : uast .KeyType , Op : String ("BoxedAttribute" )},
189
+ {Name : "boxed_value" , Op : UASTType (uast.Identifier {}, Obj {
190
+ uast .KeyPos : Var ("pos_" ),
191
+ "Name" : Var ("aname" ),
192
+ })},
193
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Var ("noops_previous" )},
194
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Var ("noops_sameline" )},
195
+ }),
196
+ ),
197
+
146
198
mapStr ("Bytes" ),
147
199
mapStr ("Str" ),
148
200
mapStr ("StringLiteral" ),
@@ -165,6 +217,11 @@ var Normalizers = []Mapping{
165
217
AnnotateType ("keyword" , MapObj (
166
218
Fields {
167
219
{Name : "arg" , Op : Var ("name" )},
220
+ // FIXME: change this once we've a way to store other nodes on semantic objects
221
+ // See: https://github.com/bblfsh/sdk/issues/361
222
+ // See: https://github.com/bblfsh/python-driver/issues/178
223
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
224
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
168
225
},
169
226
Fields {
170
227
{Name : "arg" ,
@@ -174,35 +231,40 @@ var Normalizers = []Mapping{
174
231
}),
175
232
role .Name ),
176
233
177
- MapSemantic ("Attribute" , uast.Identifier {}, MapObj (
178
- Obj {"attr" : Var ("name" )},
179
- Obj {"Name" : Var ("name" )},
180
- )),
181
-
182
- MapSemantic ("arg" , uast.Argument {}, MapObj (
183
- Obj {
184
- uast .KeyToken : Var ("name" ),
185
- "default" : Var ("init" ),
186
- },
187
- Obj {
188
- "Name" : identifierWithPos ("name" ),
189
- "Init" : Var ("init" ),
190
- },
191
- )),
192
-
193
234
MapSemantic ("arg" , uast.Argument {}, MapObj (
194
- Obj {
195
- uast .KeyToken : Var ("name" ),
235
+ Fields {
236
+ {Name : uast .KeyToken , Op : Var ("name" )},
237
+ {Name : "default" , Optional : "opt_def" , Op : Var ("init" )},
238
+ // No problem dropping this one, it's used by an internal interpreter optimization/cache
239
+ // without semantic meaning
240
+ {Name : "ctx" , Optional : "opt_ctx" , Op : Any ()},
241
+ // FIXME: change this once we've a way to store other nodes on semantic objects
242
+ // See: https://github.com/bblfsh/sdk/issues/361
243
+ // See: https://github.com/bblfsh/python-driver/issues/178
244
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
245
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
246
+ // This one is pesky - they're ignored by the runtime, could have typing from
247
+ // mypy, or could have anything else, so we can assign to the semantic type
248
+ {Name : "annotation" , Optional : "ann_opt" , Op : Any ()},
196
249
},
197
- Obj {
198
- "Name" : identifierWithPos ("name" ),
250
+ Fields {
251
+ {Name : "Name" , Op : identifierWithPos ("name" )},
252
+ {Name : "Init" , Optional : "opt_def" , Op : Var ("init" )},
199
253
},
200
254
)),
201
255
202
256
MapSemantic ("kwonly_arg" , uast.Argument {}, MapObj (
203
- Obj {
204
- uast .KeyToken : Var ("name" ),
205
- "default" : Var ("init" ),
257
+ Fields {
258
+ {Name : uast .KeyToken , Op : Var ("name" )},
259
+ {Name : "default" , Op : Var ("init" )},
260
+ // FIXME: change this once we've a way to store other nodes on semantic objects
261
+ // See: https://github.com/bblfsh/sdk/issues/361
262
+ // See: https://github.com/bblfsh/python-driver/issues/178
263
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
264
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
265
+ // This one is pesky - they're ignored by the runtime, could have typing from
266
+ // mypy, or could have anything else, so we can assign to the semantic type
267
+ {Name : "annotation" , Op : Any ()},
206
268
},
207
269
Obj {
208
270
"Init" : Var ("init" ),
@@ -211,8 +273,16 @@ var Normalizers = []Mapping{
211
273
)),
212
274
213
275
MapSemantic ("vararg" , uast.Argument {}, MapObj (
214
- Obj {
215
- uast .KeyToken : Var ("name" ),
276
+ Fields {
277
+ {Name : uast .KeyToken , Op : Var ("name" )},
278
+ // FIXME: change this once we've a way to store other nodes on semantic objects
279
+ // See: https://github.com/bblfsh/sdk/issues/361
280
+ // See: https://github.com/bblfsh/python-driver/issues/178
281
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
282
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
283
+ // This one is pesky - they're ignored by the runtime, could have typing from
284
+ // mypy, or could have anything else, so we can assign to the semantic type
285
+ {Name : "annotation" , Op : Any ()},
216
286
},
217
287
Obj {
218
288
"Name" : identifierWithPos ("name" ),
@@ -221,12 +291,20 @@ var Normalizers = []Mapping{
221
291
)),
222
292
223
293
MapSemantic ("kwarg" , uast.Argument {}, MapObj (
224
- Obj {
225
- uast .KeyToken : Var ("name" ),
294
+ Fields {
295
+ {Name : uast .KeyToken , Op : Var ("name" )},
296
+ // FIXME: change this once we've a way to store other nodes on semantic objects
297
+ // See: https://github.com/bblfsh/sdk/issues/361
298
+ // See: https://github.com/bblfsh/python-driver/issues/178
299
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
300
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
301
+ // This one is pesky - they're ignored by the runtime, could have typing from
302
+ // mypy, or could have anything else, so we can assign to the semantic type
303
+ {Name : "annotation" , Op : Any ()},
226
304
},
227
305
Obj {
228
- "Name" : identifierWithPos ("name" ),
229
- "MapVariadic" : Bool (true ),
306
+ "Name" : identifierWithPos ("name" ),
307
+ "MapVariadic" : Bool (true ),
230
308
},
231
309
)),
232
310
@@ -264,14 +342,17 @@ var Normalizers = []Mapping{
264
342
Objs {
265
343
{"Node" : Obj {}},
266
344
{
267
- "Node" : UASTType (uast.Identifier {}, Obj {"Name" : Var ("alias" )}),
345
+ "Node" : UASTType (uast.Identifier {},
346
+ Obj {
347
+ "Name" : Var ("alias" ),
348
+ }),
268
349
}},
269
350
))),
270
351
271
352
// Star imports
272
353
MapSemantic ("ImportFrom" , uast.RuntimeImport {}, MapObj (
273
- Obj {
274
- "names" : Arr (
354
+ Fields {
355
+ { Name : "names" , Op : Arr (
275
356
Obj {
276
357
uast .KeyType : String ("uast:Alias" ),
277
358
uast .KeyPos : Var ("pos" ),
@@ -281,9 +362,14 @@ var Normalizers = []Mapping{
281
362
},
282
363
"Node" : Obj {},
283
364
},
284
- ),
285
- "level" : Var ("level" ),
286
- "module" : Var ("module" ),
365
+ )},
366
+ {Name : "level" , Op : Var ("level" )},
367
+ {Name : "module" , Op : Var ("module" )},
368
+ // FIXME: change this once we've a way to store other nodes on semantic objects
369
+ // See: https://github.com/bblfsh/sdk/issues/361
370
+ // See: https://github.com/bblfsh/python-driver/issues/178
371
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
372
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
287
373
},
288
374
Obj {
289
375
"All" : Bool (true ),
@@ -300,10 +386,15 @@ var Normalizers = []Mapping{
300
386
)),
301
387
302
388
MapSemantic ("ImportFrom" , uast.RuntimeImport {}, MapObj (
303
- Obj {
304
- "names" : Var ("names" ),
305
- "module" : Var ("module" ),
306
- "level" : Var ("level" ),
389
+ Fields {
390
+ {Name : "names" , Op : Var ("names" )},
391
+ {Name : "module" , Op : Var ("module" )},
392
+ {Name : "level" , Op : Var ("level" )},
393
+ // FIXME: change this once we've a way to store other nodes on semantic objects
394
+ // See: https://github.com/bblfsh/sdk/issues/361
395
+ // See: https://github.com/bblfsh/python-driver/issues/178
396
+ {Name : "noops_previous" , Optional : "np_opt" , Op : Any ()},
397
+ {Name : "noops_sameline" , Optional : "ns_opt" , Op : Any ()},
307
398
},
308
399
Obj {
309
400
"Names" : Var ("names" ),
0 commit comments