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

Commit 4069510

Browse files
authored
Merge pull request #121 from juanjux/fix/misc_annotations2
Fix unannotated nodes
2 parents fb104a8 + e4fb9eb commit 4069510

File tree

6 files changed

+40
-399
lines changed

6 files changed

+40
-399
lines changed

ANNOTATION.md

Lines changed: 0 additions & 363 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To initialize the build system execute: `bblfsh-sdk prepare-build`, at the root
1515
To execute the tests just execute `make test`, this will execute the test over the native and the go components of the driver. Use `make test-native` to run the test only over the native component or `make test-driver` to run the test just over the go component.
1616

1717
The build is done executing `make build`. To evaluate the result using a docker container, execute:
18-
`docker run -it bblfsh/python-driver:dev-<commit[:7]>`
18+
`docker run -it bblfsh/python-driver:dev-<commit[:7]>-dirty`
1919

2020

2121
License

driver/normalizer/annotation.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ var Transformers = []transformer.Tranformer{
4848
positioner.NewFillOffsetFromLineCol(),
4949
}
5050

51+
// Common for FunctionDef, AsyncFunctionDef and Lambda
52+
var argumentsAnn = On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
53+
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
54+
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
55+
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
56+
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
57+
)
58+
5159
// AnnotationRules describes how a UAST should be annotated with `uast.Role`.
5260
//
5361
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/ann
@@ -113,6 +121,8 @@ var AnnotationRules = On(Any).Self(
113121
On(HasInternalRole("n")).Roles(uast.Literal, uast.Number, uast.Expression),
114122
),
115123
On(pyast.BoolLiteral).Roles(uast.Literal, uast.Boolean, uast.Expression, uast.Primitive),
124+
// another grouping node like "arguments"
125+
On(pyast.BoolOp).Roles(uast.Expression, uast.Boolean, uast.Incomplete),
116126
On(pyast.JoinedStr).Roles(uast.Literal, uast.String, uast.Expression, uast.Primitive).Children(
117127
On(pyast.FormattedValue).Roles(uast.Expression, uast.Incomplete),
118128
),
@@ -127,15 +137,8 @@ var AnnotationRules = On(Any).Self(
127137

128138
// FIXME: the FunctionDeclarationReceiver is not set for methods; it should be taken from the parent
129139
// Type node Token (2 levels up) but the SDK doesn't allow this
130-
On(pyast.FunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier).Children(
131-
On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
132-
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
133-
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
134-
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
135-
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
136-
),
137-
),
138-
On(pyast.AsyncFunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier, uast.Incomplete),
140+
On(pyast.FunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier).Children(argumentsAnn),
141+
On(pyast.AsyncFunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier, uast.Incomplete).Children(argumentsAnn),
139142
On(pyast.FuncDecorators).Roles(uast.Function, uast.Declaration, uast.Call, uast.Incomplete),
140143
On(pyast.FuncDefBody).Roles(uast.Function, uast.Declaration, uast.Body),
141144
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
@@ -150,6 +153,7 @@ var AnnotationRules = On(Any).Self(
150153
// FIXME: change to Function, Declaration, ArgumentS once the PR has been merged
151154
On(pyast.Lambda).Roles(uast.Function, uast.Declaration, uast.Expression, uast.Incomplete).Children(
152155
On(pyast.LambdaBody).Roles(uast.Function, uast.Declaration, uast.Body),
156+
argumentsAnn,
153157
),
154158

155159
On(pyast.Attribute).Roles(uast.Identifier, uast.Expression).Children(

fixtures/functiondef_simple.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,15 @@ Module {
385385
. . . }
386386
. . . Children: {
387387
. . . . 0: arguments {
388-
. . . . . Roles: Unannotated
388+
. . . . . Roles: Function,Declaration,Incomplete,Argument
389389
. . . . . Properties: {
390390
. . . . . . internalRole: args
391391
. . . . . . kwarg: <nil>
392392
. . . . . . vararg: <nil>
393393
. . . . . }
394394
. . . . . Children: {
395395
. . . . . . 0: arg {
396-
. . . . . . . Roles: Unannotated
396+
. . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
397397
. . . . . . . TOKEN "arg1"
398398
. . . . . . . StartPosition: {
399399
. . . . . . . . Offset: 125

fixtures/issue_server101.py.uast

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ pyid to C{bool}."
21802180
. . . . . . . . . . . . . . . . . }
21812181
. . . . . . . . . . . . . . . . }
21822182
. . . . . . . . . . . . . . . . 2: BoolOp {
2183-
. . . . . . . . . . . . . . . . . Roles: If,Condition
2183+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
21842184
. . . . . . . . . . . . . . . . . StartPosition: {
21852185
. . . . . . . . . . . . . . . . . . Offset: 4120
21862186
. . . . . . . . . . . . . . . . . . Line: 107
@@ -2339,7 +2339,7 @@ pyid to C{bool}."
23392339
. . . . . . . . . . . . . }
23402340
. . . . . . . . . . . . }
23412341
. . . . . . . . . . . . 2: BoolOp {
2342-
. . . . . . . . . . . . . Roles: If,Condition
2342+
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
23432343
. . . . . . . . . . . . . StartPosition: {
23442344
. . . . . . . . . . . . . . Offset: 3899
23452345
. . . . . . . . . . . . . . Line: 102
@@ -2566,7 +2566,7 @@ pyid to C{bool}."
25662566
. . . . . . . . . }
25672567
. . . . . . . . }
25682568
. . . . . . . . 2: BoolOp {
2569-
. . . . . . . . . Roles: If,Condition
2569+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
25702570
. . . . . . . . . StartPosition: {
25712571
. . . . . . . . . . Offset: 3779
25722572
. . . . . . . . . . Line: 100
@@ -3150,7 +3150,7 @@ pyid to C{bool}."
31503150
. . . . . . . . . . . . . }
31513151
. . . . . . . . . . . . }
31523152
. . . . . . . . . . . . 1: BoolOp {
3153-
. . . . . . . . . . . . . Roles: If,Condition
3153+
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
31543154
. . . . . . . . . . . . . StartPosition: {
31553155
. . . . . . . . . . . . . . Offset: 4605
31563156
. . . . . . . . . . . . . . Line: 120
@@ -4058,7 +4058,7 @@ pyid to C{bool}."
40584058
. . . . . . . . . }
40594059
. . . . . . . . }
40604060
. . . . . . . . 1: BoolOp {
4061-
. . . . . . . . . Roles: If,Condition
4061+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
40624062
. . . . . . . . . StartPosition: {
40634063
. . . . . . . . . . Offset: 5124
40644064
. . . . . . . . . . Line: 134
@@ -4468,7 +4468,7 @@ pyid to C{bool}."
44684468
. . . . . . . . . }
44694469
. . . . . . . . }
44704470
. . . . . . . . 1: BoolOp {
4471-
. . . . . . . . . Roles: If,Condition
4471+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
44724472
. . . . . . . . . StartPosition: {
44734473
. . . . . . . . . . Offset: 5291
44744474
. . . . . . . . . . Line: 138
@@ -5024,7 +5024,7 @@ pyid to C{bool}."
50245024
. . . . . . . . . }
50255025
. . . . . . . . }
50265026
. . . . . . . . 1: BoolOp {
5027-
. . . . . . . . . Roles: If,Condition
5027+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
50285028
. . . . . . . . . StartPosition: {
50295029
. . . . . . . . . . Offset: 5421
50305030
. . . . . . . . . . Line: 141
@@ -6619,7 +6619,7 @@ pyid to C{bool}."
66196619
. . . . . . . . . . . . . . . . . }
66206620
. . . . . . . . . . . . . . . . }
66216621
. . . . . . . . . . . . . . . . 1: BoolOp {
6622-
. . . . . . . . . . . . . . . . . Roles: If,Condition
6622+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
66236623
. . . . . . . . . . . . . . . . . StartPosition: {
66246624
. . . . . . . . . . . . . . . . . . Offset: 6974
66256625
. . . . . . . . . . . . . . . . . . Line: 175
@@ -13238,7 +13238,7 @@ pyid to C{bool}."
1323813238
. . . . . . . . . . . . . . . . . }
1323913239
. . . . . . . . . . . . . . . . }
1324013240
. . . . . . . . . . . . . . . . 2: BoolOp {
13241-
. . . . . . . . . . . . . . . . . Roles: If,Condition
13241+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
1324213242
. . . . . . . . . . . . . . . . . StartPosition: {
1324313243
. . . . . . . . . . . . . . . . . . Offset: 11161
1324413244
. . . . . . . . . . . . . . . . . . Line: 282
@@ -13417,7 +13417,7 @@ pyid to C{bool}."
1341713417
. . . . . . . . . . . . . }
1341813418
. . . . . . . . . . . . }
1341913419
. . . . . . . . . . . . 2: BoolOp {
13420-
. . . . . . . . . . . . . Roles: If,Condition
13420+
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
1342113421
. . . . . . . . . . . . . StartPosition: {
1342213422
. . . . . . . . . . . . . . Offset: 10503
1342313423
. . . . . . . . . . . . . . Line: 270
@@ -13428,7 +13428,7 @@ pyid to C{bool}."
1342813428
. . . . . . . . . . . . . }
1342913429
. . . . . . . . . . . . . Children: {
1343013430
. . . . . . . . . . . . . . 0: BoolOp {
13431-
. . . . . . . . . . . . . . . Roles: Unannotated
13431+
. . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete
1343213432
. . . . . . . . . . . . . . . StartPosition: {
1343313433
. . . . . . . . . . . . . . . . Offset: 10504
1343413434
. . . . . . . . . . . . . . . . Line: 270
@@ -13583,7 +13583,7 @@ pyid to C{bool}."
1358313583
. . . . . . . . . . . . . . . }
1358413584
. . . . . . . . . . . . . . }
1358513585
. . . . . . . . . . . . . . 1: BoolOp {
13586-
. . . . . . . . . . . . . . . Roles: Unannotated
13586+
. . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete
1358713587
. . . . . . . . . . . . . . . StartPosition: {
1358813588
. . . . . . . . . . . . . . . . Offset: 10593
1358913589
. . . . . . . . . . . . . . . . Line: 272
@@ -17516,7 +17516,7 @@ pyid to C{bool}."
1751617516
. . . . . . . . . }
1751717517
. . . . . . . . }
1751817518
. . . . . . . . 1: BoolOp {
17519-
. . . . . . . . . Roles: If,Condition
17519+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
1752017520
. . . . . . . . . StartPosition: {
1752117521
. . . . . . . . . . Offset: 15326
1752217522
. . . . . . . . . . Line: 384
@@ -18115,7 +18115,7 @@ pyid to C{bool}."
1811518115
. . . . . . . . . . . . . . . . . }
1811618116
. . . . . . . . . . . . . . . . }
1811718117
. . . . . . . . . . . . . . . . 1: BoolOp {
18118-
. . . . . . . . . . . . . . . . . Roles: If,Condition
18118+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
1811918119
. . . . . . . . . . . . . . . . . StartPosition: {
1812018120
. . . . . . . . . . . . . . . . . . Offset: 15717
1812118121
. . . . . . . . . . . . . . . . . . Line: 392
@@ -22242,7 +22242,7 @@ pyid to C{bool}."
2224222242
. . . . . . . . . . . . . }
2224322243
. . . . . . . . . . . . }
2224422244
. . . . . . . . . . . . 1: BoolOp {
22245-
. . . . . . . . . . . . . Roles: If,Condition
22245+
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
2224622246
. . . . . . . . . . . . . StartPosition: {
2224722247
. . . . . . . . . . . . . . Offset: 18014
2224822248
. . . . . . . . . . . . . . Line: 450
@@ -32161,7 +32161,7 @@ pyid to C{bool}."
3216132161
. . . . . . . . . . . . . . . . . . . . . . . . . }
3216232162
. . . . . . . . . . . . . . . . . . . . . . . . }
3216332163
. . . . . . . . . . . . . . . . . . . . . . . . 2: BoolOp {
32164-
. . . . . . . . . . . . . . . . . . . . . . . . . Roles: If,Condition
32164+
. . . . . . . . . . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3216532165
. . . . . . . . . . . . . . . . . . . . . . . . . StartPosition: {
3216632166
. . . . . . . . . . . . . . . . . . . . . . . . . . Offset: 25811
3216732167
. . . . . . . . . . . . . . . . . . . . . . . . . . Line: 644
@@ -32363,7 +32363,7 @@ pyid to C{bool}."
3236332363
. . . . . . . . . . . . . . . . . . . . . }
3236432364
. . . . . . . . . . . . . . . . . . . . }
3236532365
. . . . . . . . . . . . . . . . . . . . 2: BoolOp {
32366-
. . . . . . . . . . . . . . . . . . . . . Roles: If,Condition
32366+
. . . . . . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3236732367
. . . . . . . . . . . . . . . . . . . . . StartPosition: {
3236832368
. . . . . . . . . . . . . . . . . . . . . . Offset: 25545
3236932369
. . . . . . . . . . . . . . . . . . . . . . Line: 639
@@ -32567,7 +32567,7 @@ pyid to C{bool}."
3256732567
. . . . . . . . . . . . . . . . . }
3256832568
. . . . . . . . . . . . . . . . }
3256932569
. . . . . . . . . . . . . . . . 2: BoolOp {
32570-
. . . . . . . . . . . . . . . . . Roles: If,Condition
32570+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3257132571
. . . . . . . . . . . . . . . . . StartPosition: {
3257232572
. . . . . . . . . . . . . . . . . . Offset: 25192
3257332573
. . . . . . . . . . . . . . . . . . Line: 633
@@ -33640,7 +33640,7 @@ pyid to C{bool}."
3364033640
. . . . . . . . . }
3364133641
. . . . . . . . }
3364233642
. . . . . . . . 1: BoolOp {
33643-
. . . . . . . . . Roles: If,Condition
33643+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3364433644
. . . . . . . . . StartPosition: {
3364533645
. . . . . . . . . . Offset: 26372
3364633646
. . . . . . . . . . Line: 660
@@ -36128,7 +36128,7 @@ pyid to C{bool}."
3612836128
. . . . . . . . . . . . . . . . . }
3612936129
. . . . . . . . . . . . . . . . }
3613036130
. . . . . . . . . . . . . . . . 2: BoolOp {
36131-
. . . . . . . . . . . . . . . . . Roles: If,Condition
36131+
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3613236132
. . . . . . . . . . . . . . . . . StartPosition: {
3613336133
. . . . . . . . . . . . . . . . . . Offset: 27328
3613436134
. . . . . . . . . . . . . . . . . . Line: 692
@@ -37202,7 +37202,7 @@ pyid to C{bool}."
3720237202
. . . . . . . . . . . . . }
3720337203
. . . . . . . . . . . . }
3720437204
. . . . . . . . . . . . 1: BoolOp {
37205-
. . . . . . . . . . . . . Roles: If,Condition
37205+
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
3720637206
. . . . . . . . . . . . . StartPosition: {
3720737207
. . . . . . . . . . . . . . Offset: 28512
3720837208
. . . . . . . . . . . . . . Line: 724
@@ -51241,7 +51241,7 @@ pyid to C{bool}."
5124151241
. . . . . . . . . }
5124251242
. . . . . . . . }
5124351243
. . . . . . . . 1: BoolOp {
51244-
. . . . . . . . . Roles: If,Condition
51244+
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
5124551245
. . . . . . . . . StartPosition: {
5124651246
. . . . . . . . . . Offset: 37438
5124751247
. . . . . . . . . . Line: 953

fixtures/lambda.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ Module {
3232
. . . . . }
3333
. . . . . Children: {
3434
. . . . . . 0: arguments {
35-
. . . . . . . Roles: Unannotated
35+
. . . . . . . Roles: Function,Declaration,Incomplete,Argument
3636
. . . . . . . Properties: {
3737
. . . . . . . . internalRole: args
3838
. . . . . . . . kwarg: <nil>
3939
. . . . . . . . vararg: <nil>
4040
. . . . . . . }
4141
. . . . . . . Children: {
4242
. . . . . . . . 0: arg {
43-
. . . . . . . . . Roles: Unannotated
43+
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
4444
. . . . . . . . . TOKEN "x"
4545
. . . . . . . . . StartPosition: {
4646
. . . . . . . . . . Offset: 7

0 commit comments

Comments
 (0)