Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 8c6c675

Browse files
author
Juanjo Alvarez
committed
Fix remaining tokens that were not identifiers but should
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 92a2646 commit 8c6c675

File tree

5 files changed

+160
-48
lines changed

5 files changed

+160
-48
lines changed

driver/normalizer/normalizer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,23 @@ func funcDefMap(typ string, async bool) Mapping {
6060
))
6161
}
6262

63+
func tokenIsIdentifier(typ, tokenKey string, roles... role.Role) Mapping {
64+
return AnnotateType(typ, MapObj(
65+
Fields{
66+
{Name: tokenKey, Op: Var("name")},
67+
},
68+
Fields{
69+
{Name: tokenKey, Op: UASTType(uast.Identifier{}, Obj{
70+
"Name": Var("name"),
71+
})},
72+
}),
73+
roles...)
74+
}
75+
6376
var Normalizers = []Mapping{
77+
78+
tokenIsIdentifier("keyword", "arg", role.Name),
79+
6480
MapSemantic("Str", uast.String{}, MapObj(
6581
Obj{
6682
"s": Var("val"),

fixtures/functioncalls.py.sem.uast

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,12 @@
260260
},
261261
keywords: [
262262
{ '@type': "keyword",
263-
'@token': "b",
264263
'@role': [Argument, Call, Function, Name],
265264
'@pos': { '@type': "uast:Positions",
266265
},
266+
'@token': { '@type': "uast:Identifier",
267+
Name: "b",
268+
},
267269
value: { '@type': "Num",
268270
'@token': 1,
269271
'@role': [Argument, Expression, Literal, Number, Primitive, Value],
@@ -282,10 +284,12 @@
282284
},
283285
},
284286
{ '@type': "keyword",
285-
'@token': "c",
286287
'@role': [Argument, Call, Function, Name],
287288
'@pos': { '@type': "uast:Positions",
288289
},
290+
'@token': { '@type': "uast:Identifier",
291+
Name: "c",
292+
},
289293
value: { '@type': "Num",
290294
'@token': 2,
291295
'@role': [Argument, Expression, Literal, Number, Primitive, Value],
@@ -444,7 +448,9 @@
444448
'@role': [Argument, Call, Function, Name],
445449
'@pos': { '@type': "uast:Positions",
446450
},
447-
'@token': ~,
451+
'@token': { '@type': "uast:Identifier",
452+
Name: ~,
453+
},
448454
value: { '@type': "uast:Identifier",
449455
'@role': [Argument, Value],
450456
'@pos': { '@type': "uast:Positions",

fixtures/issue62_b.py.sem.uast

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,12 @@
14981498
},
14991499
keywords: [
15001500
{ '@type': "keyword",
1501-
'@token': "linguist",
15021501
'@role': [Argument, Call, Function, Name],
15031502
'@pos': { '@type': "uast:Positions",
15041503
},
1504+
'@token': { '@type': "uast:Identifier",
1505+
Name: "linguist",
1506+
},
15051507
value: { '@type': "uast:String",
15061508
'@role': [Argument, Value],
15071509
'@pos': { '@type': "uast:Positions",
@@ -1521,10 +1523,12 @@
15211523
},
15221524
},
15231525
{ '@type': "keyword",
1524-
'@token': "bblfsh_endpoint",
15251526
'@role': [Argument, Call, Function, Name],
15261527
'@pos': { '@type': "uast:Positions",
15271528
},
1529+
'@token': { '@type': "uast:Identifier",
1530+
Name: "bblfsh_endpoint",
1531+
},
15281532
value: { '@type': "uast:String",
15291533
'@role': [Argument, Value],
15301534
'@pos': { '@type': "uast:Positions",

0 commit comments

Comments
 (0)