11package normalizer
22
33import (
4- "gopkg.in/bblfsh/sdk.v1 /uast"
5- "gopkg.in/bblfsh/sdk.v1 /uast/role"
6- . "gopkg.in/bblfsh/sdk.v1 /uast/transformer"
7- "gopkg.in/bblfsh/sdk.v1 /uast/transformer/positioner"
4+ "gopkg.in/bblfsh/sdk.v2 /uast"
5+ "gopkg.in/bblfsh/sdk.v2 /uast/role"
6+ . "gopkg.in/bblfsh/sdk.v2 /uast/transformer"
7+ "gopkg.in/bblfsh/sdk.v2 /uast/transformer/positioner"
88)
99
1010var Native = Transformers ([][]Transformer {
@@ -22,7 +22,7 @@ var Code = []CodeTransformer{
2222}
2323
2424func annotateTypeToken (typ , token string , roles ... role.Role ) Mapping {
25- return AnnotateTypeFields (typ ,
25+ return AnnotateType (typ ,
2626 FieldRoles {
2727 uast .KeyToken : {Add : true , Op : String (token )},
2828 }, roles ... )
@@ -185,9 +185,9 @@ var Annotations = []Mapping{
185185 annotateTypeToken ("Pass" , "pass" , role .Noop , role .Statement ),
186186 annotateTypeToken ("Assert" , "assert" , role .Assert , role .Statement ),
187187
188- AnnotateTypeFields ("Name" , FieldRoles {"id" : {Rename : uast .KeyToken }},
188+ AnnotateType ("Name" , FieldRoles {"id" : {Rename : uast .KeyToken }},
189189 role .Identifier , role .Expression ),
190- AnnotateTypeFields ("Attribute" , FieldRoles {"attr" : {Rename : uast .KeyToken }},
190+ AnnotateType ("Attribute" , FieldRoles {"attr" : {Rename : uast .KeyToken }},
191191 role .Identifier , role .Expression ),
192192
193193 // Binary Expressions
@@ -198,20 +198,20 @@ var Annotations = []Mapping{
198198 }, role .Expression , role .Binary ),
199199
200200 // Primitive Literals
201- AnnotateTypeFields ("Str" , FieldRoles {"s" : {Rename : uast .KeyToken }},
201+ AnnotateType ("Str" , FieldRoles {"s" : {Rename : uast .KeyToken }},
202202 role .Literal , role .String , role .Expression , role .Primitive ),
203- AnnotateTypeFields ("Bytes" , FieldRoles {"s" : {Rename : uast .KeyToken }},
203+ AnnotateType ("Bytes" , FieldRoles {"s" : {Rename : uast .KeyToken }},
204204 role .Literal , role .ByteString , role .Expression , role .Primitive ),
205- AnnotateTypeFields ("StringLiteral" , FieldRoles {"s" : {Rename : uast .KeyToken }},
205+ AnnotateType ("StringLiteral" , FieldRoles {"s" : {Rename : uast .KeyToken }},
206206 role .Literal , role .String , role .Expression , role .Primitive ),
207- AnnotateTypeFields ("BoolLiteral" , FieldRoles {"LiteralValue" : {Rename : uast .KeyToken }},
207+ AnnotateType ("BoolLiteral" , FieldRoles {"LiteralValue" : {Rename : uast .KeyToken }},
208208 role .Literal , role .Boolean , role .Expression , role .Primitive ),
209209 annotateTypeToken ("NoneLiteral" , "None" , role .Literal , role .Null , role .Expression , role .Primitive ),
210- AnnotateTypeFields ("Num" , FieldRoles {"n" : {Rename : uast .KeyToken }},
210+ AnnotateType ("Num" , FieldRoles {"n" : {Rename : uast .KeyToken }},
211211 role .Expression , role .Literal , role .Number , role .Primitive ),
212- AnnotateTypeFields ("BoolLiteral" , FieldRoles {"LiteralValue" : {Rename : uast .KeyToken }},
212+ AnnotateType ("BoolLiteral" , FieldRoles {"LiteralValue" : {Rename : uast .KeyToken }},
213213 role .Expression , role .Literal , role .Boolean , role .Primitive ),
214- AnnotateTypeFields ("Dict" , FieldRoles {
214+ AnnotateType ("Dict" , FieldRoles {
215215 "keys" : {Arr : true , Roles : role.Roles {role .Map , role .Key }},
216216 "values" : {Arr : true , Roles : role.Roles {role .Map , role .Value }},
217217 }, role .Expression , role .Literal , role .Primitive , role .Map ),
@@ -225,7 +225,7 @@ var Annotations = []Mapping{
225225 // targets[] => Left
226226 // value => Right
227227 //
228- AnnotateTypeFields ("Assign" , FieldRoles {
228+ AnnotateType ("Assign" , FieldRoles {
229229 "targets" : {Arr : true , Roles : role.Roles {role .Left }},
230230 "value" : {Roles : role.Roles {role .Right }},
231231 }, role .Binary , role .Expression , role .Assignment ),
@@ -271,12 +271,12 @@ var Annotations = []Mapping{
271271
272272 // python 2 exception handling
273273 AnnotateType ("TryExcept" , nil , role .Try , role .Catch , role .Statement ),
274- AnnotateTypeFields ("ExceptHandler" , FieldRoles {"name" : {Rename : uast .KeyToken }},
274+ AnnotateType ("ExceptHandler" , FieldRoles {"name" : {Rename : uast .KeyToken }},
275275 role .Try , role .Catch , role .Identifier ),
276276 AnnotateType ("TryFinally" , nil , role .Try , role .Finally , role .Statement ),
277277 AnnotateType ("Raise" , nil , role .Throw ),
278278
279- AnnotateTypeFields ("Raise" ,
279+ AnnotateType ("Raise" ,
280280 FieldRoles {
281281 "exc" : {Opt : true , Roles : role.Roles {role .Call }},
282282 uast .KeyToken : {Add : true , Op : String ("raise" )},
@@ -296,7 +296,7 @@ var Annotations = []Mapping{
296296 AnnotateType ("SetComp" , nil , role .Set , role .For , role .Expression ),
297297
298298 // FIXME: once we have an async Role we should interpret the is_async property
299- AnnotateTypeFields ("comprehension" , FieldRoles {
299+ AnnotateType ("comprehension" , FieldRoles {
300300 "ifs" : {Arr : true , Roles : role.Roles {role .If , role .Condition }},
301301 "iter" : {Roles : role.Roles {role .For , role .Update , role .Statement }},
302302 "target" : {Roles : role.Roles {role .For , role .Expression }},
@@ -327,7 +327,7 @@ var Annotations = []Mapping{
327327
328328 // Formal Arguments
329329 // FIXME: opt: true + arr: true seems to cause a crash in the SDK
330- AnnotateTypeFields ("arguments" , FieldRoles {
330+ AnnotateType ("arguments" , FieldRoles {
331331 "args" : {Arr : true , Roles : role.Roles {role .Function , role .Declaration , role .Argument , role .Name , role .Identifier }},
332332 "defaults" : {Arr : true , Roles : role.Roles {role .Function , role .Declaration , role .ArgsList , role .Value , role .Default }},
333333 // Default arguments: Python's AST puts default arguments on a sibling list to the one of
@@ -341,48 +341,48 @@ var Annotations = []Mapping{
341341 "vararg" : {Opt : true , Roles : role.Roles {role .Function , role .Declaration , role .ArgsList , role .Name , role .Identifier }},
342342 }, role .Function , role .Declaration , role .Argument , role .Incomplete ),
343343
344- AnnotateTypeFields ("arguments" , FieldRoles {
344+ AnnotateType ("arguments" , FieldRoles {
345345 "args" : {Arr : true , Roles : role.Roles {role .Function , role .Declaration , role .Argument , role .Name , role .Identifier }},
346346 "defaults" : {Arr : true , Roles : role.Roles {role .Function , role .Declaration , role .ArgsList , role .Value , role .Default }},
347347 "kwarg" : {Opt : true , Roles : role.Roles {role .Function , role .Declaration , role .ArgsList , role .Map , role .Name , role .Identifier }},
348348 "vararg" : {Opt : true , Roles : role.Roles {role .Function , role .Declaration , role .ArgsList , role .Name , role .Identifier }},
349349 }, role .Function , role .Declaration , role .Argument , role .Incomplete ),
350350
351351 // Function Calls
352- AnnotateTypeFields ("Call" , FieldRoles {
352+ AnnotateType ("Call" , FieldRoles {
353353 "args" : {Arr : true , Roles : role.Roles {role .Function , role .Call , role .Positional , role .Argument , role .Name }},
354354 "func" : {Roles : role.Roles {role .Call , role .Callee }},
355355 "keywords" : {Arr : true , Roles : role.Roles {role .Function , role .Call , role .Argument }},
356356 }, role .Function , role .Call , role .Expression ),
357357
358358 // Keywords are additionally annotated in FunctionDef and ClassDef
359- AnnotateTypeFields ("keyword" , FieldRoles {
359+ AnnotateType ("keyword" , FieldRoles {
360360 "value" : {Roles : role.Roles {role .Argument , role .Value }},
361361 "arg" : {Rename : uast .KeyToken },
362362 }, role .Name ),
363363
364364 // Comments and non significative whitespace
365365 AnnotateType ("SameLineNoops" , nil , role .Comment ),
366366
367- AnnotateTypeFields ("PreviousNoops" , FieldRoles {
367+ AnnotateType ("PreviousNoops" , FieldRoles {
368368 "lines" : {Arr : true , Roles : role.Roles {role .Noop }},
369369 }, role .Noop ),
370370
371- AnnotateTypeFields ("RemainderNoops" , FieldRoles {
371+ AnnotateType ("RemainderNoops" , FieldRoles {
372372 "lines" : {Arr : true , Roles : role.Roles {role .Noop }},
373373 }, role .Noop ),
374374
375- AnnotateTypeFields ("NoopLine" , FieldRoles {
375+ AnnotateType ("NoopLine" , FieldRoles {
376376 "noop_line" : {Rename : uast .KeyToken },
377377 }, role .Noop , role .Comment ),
378378
379- AnnotateTypeFields ("NoopSameLine" , FieldRoles {
379+ AnnotateType ("NoopSameLine" , FieldRoles {
380380 "s" : {Rename : uast .KeyToken },
381381 }, role .Noop , role .Comment ),
382382
383383 // Qualified Identifiers
384384 // a.b.c ("a" and "b" will be Qualified+Identifier, "c" will be just Identifier)
385- AnnotateTypeFields ("Attribute" , FieldRoles {
385+ AnnotateType ("Attribute" , FieldRoles {
386386 "value" : {Arr : true , Roles : role.Roles {role .Qualified }},
387387 }),
388388
@@ -458,20 +458,20 @@ var Annotations = []Mapping{
458458 },
459459 }, role .Type , role .Declaration , role .Identifier , role .Statement ),
460460
461- AnnotateTypeFields ("ClassDef" , FieldRoles {
461+ AnnotateType ("ClassDef" , FieldRoles {
462462 "keywords" : {Arr : true , Roles : role.Roles {role .Incomplete }},
463463 }),
464464
465465 // These two (exec & print) are AST nodes in Python2 but we convert them to functions
466466 // in the UAST like they are in Python3
467- AnnotateTypeFields ("Exec" , FieldRoles {
467+ AnnotateType ("Exec" , FieldRoles {
468468 "body" : {Roles : role.Roles {role .Call , role .Argument , role .Positional }},
469469 "globals" : {Roles : role.Roles {role .Call , role .Argument , role .Positional }},
470470 "locals" : {Roles : role.Roles {role .Call , role .Argument , role .Positional }},
471471 uast .KeyToken : {Add : true , Op : String ("exec" )},
472472 }, role .Function , role .Call , role .Expression ),
473473
474- AnnotateTypeFields ("Print" , FieldRoles {
474+ AnnotateType ("Print" , FieldRoles {
475475 "values" : {Arr : true , Roles : role.Roles {role .Call , role .Argument , role .Positional }},
476476 uast .KeyToken : {Add : true , Op : String ("print" )},
477477 }, role .Function , role .Call , role .Callee , role .Identifier , role .Expression ),
0 commit comments