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

Commit 5dee52a

Browse files
author
Juanjo Alvarez
committed
Misc annotation fixes
- Remove Function and Declaration from arguments (they were wrong when in a call and superfluous when under a real declaration node). - Remove Call from arguments (the parent already have it). - Add the Module role to the root node. - Remove duplicated roles for comparisons inside comprehensions.
1 parent 308049c commit 5dee52a

22 files changed

+784
-279
lines changed

ANNOTATION.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@
292292
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Break'\] | Break, Statement |
293293
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Continue'\] | Continue, Statement |
294294
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\] | Expression, Binary |
295-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\]/\*\[@InternalType='Compare\.ops'\] | Expression, Binary, Operator |
296-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\]/\*\[@internalRole\]\[@internalRole='left'\] | Expression, Binary, Left |
297-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare\.comparators'\] | Expression, Binary, Right |
295+
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\]/\*\[@InternalType='Compare\.ops'\] | Expression |
296+
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\]/\*\[@internalRole\]\[@internalRole='left'\] | Expression, Left |
297+
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Compare'\]/\*\[@InternalType='Compare\.comparators'\] | Expression, Right |
298298
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='If'\] | If, Statement |
299299
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='If'\]/\*\[@InternalType='If\.body'\] | If, Body, Then |
300300
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='If'\]/\*\[@internalRole\]\[@internalRole='test'\] | If, Condition |
@@ -349,9 +349,7 @@
349349
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\] | For, Iterator, Expression, Incomplete |
350350
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@internalRole\]\[@internalRole='iter'\] | For, Update, Statement |
351351
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@internalRole\]\[@internalRole='target'\] | For, Expression |
352-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@InternalType='Compare'\] | If, Condition, Expression, Binary |
353-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@InternalType='Compare'\]/\*\[@InternalType='Compare\.ops'\] | Expression, Binary, Operator |
354-
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@InternalType='Compare'\]/\*\[@internalRole\]\[@internalRole='left'\] | Expression, Binary, Left |
352+
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='comprehension'\]/\*\[@InternalType='Compare'\] | If, Condition |
355353
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Delete'\] | Statement, Incomplete |
356354
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Await'\] | Statement, Incomplete |
357355
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Global'\] | Statement, Visibility, World, Incomplete |

driver/normalizer/annotation.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ var AnnotationRules = On(Any).Self(
224224
// Parent of all comparisons
225225
On(pyast.Compare).Roles(uast.Expression, uast.Binary).Children(
226226
// Operators
227-
On(pyast.CompareOps).Roles(uast.Expression, uast.Operator, uast.Incomplete),
227+
On(pyast.CompareOps).Roles(uast.Expression),
228228
// Leftmost element (the others are the comparators below)
229229
On(HasInternalRole("left")).Roles(uast.Expression, uast.Left),
230230
// These hold the members of the comparison (not the operators)
@@ -318,10 +318,7 @@ var AnnotationRules = On(Any).Self(
318318
On(HasInternalRole("iter")).Roles(uast.For, uast.Update, uast.Statement),
319319
On(HasInternalRole("target")).Roles(uast.For, uast.Expression),
320320
// FIXME: see the comment on uast.If, uast.Condition above
321-
On(pyast.Compare).Roles(uast.If, uast.Condition, uast.Expression, uast.Binary).Children(
322-
On(pyast.CompareOps).Roles(uast.Expression, uast.Binary, uast.Operator),
323-
On(HasInternalRole("left")).Roles(uast.Expression, uast.Binary, uast.Left),
324-
),
321+
On(pyast.Compare).Roles(uast.If, uast.Condition),
325322
),
326323

327324
On(pyast.Delete).Roles(uast.Statement, uast.Incomplete),

fixtures/comparisonop.py.uast

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Module {
2727
. . . . . }
2828
. . . . . Children: {
2929
. . . . . . 0: Compare.comparators {
30-
. . . . . . . Roles: Expression,Binary,Right
30+
. . . . . . . Roles: Expression,Right
3131
. . . . . . . Properties: {
3232
. . . . . . . . promotedPropertyList: true
3333
. . . . . . . }
@@ -49,7 +49,13 @@ Module {
4949
. . . . . . . }
5050
. . . . . . }
5151
. . . . . . 1: Num {
52+
<<<<<<< HEAD
5253
. . . . . . . Roles: Literal,Number,Expression,Primitive,Expression,Binary,Left
54+
||||||| merged common ancestors
55+
. . . . . . . Roles: Literal,Number,Expression,Expression,Binary,Left
56+
=======
57+
. . . . . . . Roles: Literal,Number,Expression,Expression,Left
58+
>>>>>>> Misc annotation fixes
5359
. . . . . . . TOKEN "1"
5460
. . . . . . . StartPosition: {
5561
. . . . . . . . Offset: 0
@@ -66,7 +72,7 @@ Module {
6672
. . . . . . . }
6773
. . . . . . }
6874
. . . . . . 2: Compare.ops {
69-
. . . . . . . Roles: Expression,Binary,Operator
75+
. . . . . . . Roles: Expression
7076
. . . . . . . Properties: {
7177
. . . . . . . . promotedPropertyList: true
7278
. . . . . . . }
@@ -104,7 +110,7 @@ Module {
104110
. . . . . }
105111
. . . . . Children: {
106112
. . . . . . 0: Compare.comparators {
107-
. . . . . . . Roles: Expression,Binary,Right
113+
. . . . . . . Roles: Expression,Right
108114
. . . . . . . Properties: {
109115
. . . . . . . . promotedPropertyList: true
110116
. . . . . . . }
@@ -126,7 +132,13 @@ Module {
126132
. . . . . . . }
127133
. . . . . . }
128134
. . . . . . 1: Num {
135+
<<<<<<< HEAD
129136
. . . . . . . Roles: Literal,Number,Expression,Primitive,Expression,Binary,Left
137+
||||||| merged common ancestors
138+
. . . . . . . Roles: Literal,Number,Expression,Expression,Binary,Left
139+
=======
140+
. . . . . . . Roles: Literal,Number,Expression,Expression,Left
141+
>>>>>>> Misc annotation fixes
130142
. . . . . . . TOKEN "1"
131143
. . . . . . . StartPosition: {
132144
. . . . . . . . Offset: 7
@@ -143,7 +155,7 @@ Module {
143155
. . . . . . . }
144156
. . . . . . }
145157
. . . . . . 2: Compare.ops {
146-
. . . . . . . Roles: Expression,Binary,Operator
158+
. . . . . . . Roles: Expression
147159
. . . . . . . Properties: {
148160
. . . . . . . . promotedPropertyList: true
149161
. . . . . . . }
@@ -231,7 +243,7 @@ Module {
231243
. . . . . }
232244
. . . . . Children: {
233245
. . . . . . 0: Compare.comparators {
234-
. . . . . . . Roles: Expression,Binary,Right
246+
. . . . . . . Roles: Expression,Right
235247
. . . . . . . Properties: {
236248
. . . . . . . . promotedPropertyList: true
237249
. . . . . . . }
@@ -267,7 +279,13 @@ Module {
267279
. . . . . . . }
268280
. . . . . . }
269281
. . . . . . 1: Num {
282+
<<<<<<< HEAD
270283
. . . . . . . Roles: Literal,Number,Expression,Primitive,Expression,Binary,Left
284+
||||||| merged common ancestors
285+
. . . . . . . Roles: Literal,Number,Expression,Expression,Binary,Left
286+
=======
287+
. . . . . . . Roles: Literal,Number,Expression,Expression,Left
288+
>>>>>>> Misc annotation fixes
271289
. . . . . . . TOKEN "1"
272290
. . . . . . . StartPosition: {
273291
. . . . . . . . Offset: 20
@@ -284,7 +302,7 @@ Module {
284302
. . . . . . . }
285303
. . . . . . }
286304
. . . . . . 2: Compare.ops {
287-
. . . . . . . Roles: Expression,Binary,Operator
305+
. . . . . . . Roles: Expression
288306
. . . . . . . Properties: {
289307
. . . . . . . . promotedPropertyList: true
290308
. . . . . . . }
@@ -326,7 +344,7 @@ Module {
326344
. . . . . }
327345
. . . . . Children: {
328346
. . . . . . 0: Compare.comparators {
329-
. . . . . . . Roles: Expression,Binary,Right
347+
. . . . . . . Roles: Expression,Right
330348
. . . . . . . Properties: {
331349
. . . . . . . . promotedPropertyList: true
332350
. . . . . . . }
@@ -362,7 +380,13 @@ Module {
362380
. . . . . . . }
363381
. . . . . . }
364382
. . . . . . 1: Num {
383+
<<<<<<< HEAD
365384
. . . . . . . Roles: Literal,Number,Expression,Primitive,Expression,Binary,Left
385+
||||||| merged common ancestors
386+
. . . . . . . Roles: Literal,Number,Expression,Expression,Binary,Left
387+
=======
388+
. . . . . . . Roles: Literal,Number,Expression,Expression,Left
389+
>>>>>>> Misc annotation fixes
366390
. . . . . . . TOKEN "1"
367391
. . . . . . . StartPosition: {
368392
. . . . . . . . Offset: 32
@@ -379,7 +403,7 @@ Module {
379403
. . . . . . . }
380404
. . . . . . }
381405
. . . . . . 2: Compare.ops {
382-
. . . . . . . Roles: Expression,Binary,Operator
406+
. . . . . . . Roles: Expression
383407
. . . . . . . Properties: {
384408
. . . . . . . . promotedPropertyList: true
385409
. . . . . . . }
@@ -421,7 +445,7 @@ Module {
421445
. . . . . }
422446
. . . . . Children: {
423447
. . . . . . 0: Compare.comparators {
424-
. . . . . . . Roles: Expression,Binary,Right
448+
. . . . . . . Roles: Expression,Right
425449
. . . . . . . Properties: {
426450
. . . . . . . . promotedPropertyList: true
427451
. . . . . . . }
@@ -457,7 +481,13 @@ Module {
457481
. . . . . . . }
458482
. . . . . . }
459483
. . . . . . 1: Num {
484+
<<<<<<< HEAD
460485
. . . . . . . Roles: Literal,Number,Expression,Primitive,Expression,Binary,Left
486+
||||||| merged common ancestors
487+
. . . . . . . Roles: Literal,Number,Expression,Expression,Binary,Left
488+
=======
489+
. . . . . . . Roles: Literal,Number,Expression,Expression,Left
490+
>>>>>>> Misc annotation fixes
461491
. . . . . . . TOKEN "1"
462492
. . . . . . . StartPosition: {
463493
. . . . . . . . Offset: 42
@@ -474,7 +504,7 @@ Module {
474504
. . . . . . . }
475505
. . . . . . }
476506
. . . . . . 2: Compare.ops {
477-
. . . . . . . Roles: Expression,Binary,Operator
507+
. . . . . . . Roles: Expression
478508
. . . . . . . Properties: {
479509
. . . . . . . . promotedPropertyList: true
480510
. . . . . . . }

fixtures/comprehension_dict.py.uast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Module {
3434
. . . . . . . }
3535
. . . . . . . Children: {
3636
. . . . . . . . 0: Compare {
37-
. . . . . . . . . Roles: Expression,Binary,If,Condition,Expression,Binary
37+
. . . . . . . . . Roles: Expression,Binary,If,Condition
3838
. . . . . . . . . StartPosition: {
3939
. . . . . . . . . . Offset: 29
4040
. . . . . . . . . . Line: 1
@@ -45,7 +45,7 @@ Module {
4545
. . . . . . . . . }
4646
. . . . . . . . . Children: {
4747
. . . . . . . . . . 0: Compare.comparators {
48-
. . . . . . . . . . . Roles: Expression,Binary,Right
48+
. . . . . . . . . . . Roles: Expression,Right
4949
. . . . . . . . . . . Properties: {
5050
. . . . . . . . . . . . promotedPropertyList: true
5151
. . . . . . . . . . . }
@@ -67,7 +67,7 @@ Module {
6767
. . . . . . . . . . . }
6868
. . . . . . . . . . }
6969
. . . . . . . . . . 1: Name {
70-
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Binary,Left,Expression,Binary,Left
70+
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Left
7171
. . . . . . . . . . . TOKEN "n"
7272
. . . . . . . . . . . StartPosition: {
7373
. . . . . . . . . . . . Offset: 29
@@ -85,7 +85,7 @@ Module {
8585
. . . . . . . . . . . }
8686
. . . . . . . . . . }
8787
. . . . . . . . . . 2: Compare.ops {
88-
. . . . . . . . . . . Roles: Expression,Binary,Operator,Expression,Binary,Operator
88+
. . . . . . . . . . . Roles: Expression
8989
. . . . . . . . . . . Properties: {
9090
. . . . . . . . . . . . promotedPropertyList: true
9191
. . . . . . . . . . . }

fixtures/comprehension_list.py.uast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Module {
8989
. . . . . . . }
9090
. . . . . . . Children: {
9191
. . . . . . . . 0: Compare {
92-
. . . . . . . . . Roles: Expression,Binary,If,Condition,Expression,Binary
92+
. . . . . . . . . Roles: Expression,Binary,If,Condition
9393
. . . . . . . . . StartPosition: {
9494
. . . . . . . . . . Offset: 26
9595
. . . . . . . . . . Line: 1
@@ -100,7 +100,7 @@ Module {
100100
. . . . . . . . . }
101101
. . . . . . . . . Children: {
102102
. . . . . . . . . . 0: Compare.comparators {
103-
. . . . . . . . . . . Roles: Expression,Binary,Right
103+
. . . . . . . . . . . Roles: Expression,Right
104104
. . . . . . . . . . . Properties: {
105105
. . . . . . . . . . . . promotedPropertyList: true
106106
. . . . . . . . . . . }
@@ -122,7 +122,7 @@ Module {
122122
. . . . . . . . . . . }
123123
. . . . . . . . . . }
124124
. . . . . . . . . . 1: Name {
125-
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Binary,Left,Expression,Binary,Left
125+
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Left
126126
. . . . . . . . . . . TOKEN "i"
127127
. . . . . . . . . . . StartPosition: {
128128
. . . . . . . . . . . . Offset: 26
@@ -140,7 +140,7 @@ Module {
140140
. . . . . . . . . . . }
141141
. . . . . . . . . . }
142142
. . . . . . . . . . 2: Compare.ops {
143-
. . . . . . . . . . . Roles: Expression,Binary,Operator,Expression,Binary,Operator
143+
. . . . . . . . . . . Roles: Expression
144144
. . . . . . . . . . . Properties: {
145145
. . . . . . . . . . . . promotedPropertyList: true
146146
. . . . . . . . . . . }

fixtures/comprehension_set.py.uast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Module {
8989
. . . . . . . }
9090
. . . . . . . Children: {
9191
. . . . . . . . 0: Compare {
92-
. . . . . . . . . Roles: Expression,Binary,If,Condition,Expression,Binary
92+
. . . . . . . . . Roles: Expression,Binary,If,Condition
9393
. . . . . . . . . StartPosition: {
9494
. . . . . . . . . . Offset: 26
9595
. . . . . . . . . . Line: 1
@@ -100,7 +100,7 @@ Module {
100100
. . . . . . . . . }
101101
. . . . . . . . . Children: {
102102
. . . . . . . . . . 0: Compare.comparators {
103-
. . . . . . . . . . . Roles: Expression,Binary,Right
103+
. . . . . . . . . . . Roles: Expression,Right
104104
. . . . . . . . . . . Properties: {
105105
. . . . . . . . . . . . promotedPropertyList: true
106106
. . . . . . . . . . . }
@@ -122,7 +122,7 @@ Module {
122122
. . . . . . . . . . . }
123123
. . . . . . . . . . }
124124
. . . . . . . . . . 1: Name {
125-
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Binary,Left,Expression,Binary,Left
125+
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Left
126126
. . . . . . . . . . . TOKEN "n"
127127
. . . . . . . . . . . StartPosition: {
128128
. . . . . . . . . . . . Offset: 26
@@ -140,7 +140,7 @@ Module {
140140
. . . . . . . . . . . }
141141
. . . . . . . . . . }
142142
. . . . . . . . . . 2: Compare.ops {
143-
. . . . . . . . . . . Roles: Expression,Binary,Operator,Expression,Binary,Operator
143+
. . . . . . . . . . . Roles: Expression
144144
. . . . . . . . . . . Properties: {
145145
. . . . . . . . . . . . promotedPropertyList: true
146146
. . . . . . . . . . . }

fixtures/continue_break.py.uast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Module {
7575
. . . . . . . . . }
7676
. . . . . . . . . Children: {
7777
. . . . . . . . . . 0: Compare.comparators {
78-
. . . . . . . . . . . Roles: Expression,Binary,Right
78+
. . . . . . . . . . . Roles: Expression,Right
7979
. . . . . . . . . . . Properties: {
8080
. . . . . . . . . . . . promotedPropertyList: true
8181
. . . . . . . . . . . }
@@ -97,7 +97,7 @@ Module {
9797
. . . . . . . . . . . }
9898
. . . . . . . . . . }
9999
. . . . . . . . . . 1: Name {
100-
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Binary,Left
100+
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Left
101101
. . . . . . . . . . . TOKEN "i"
102102
. . . . . . . . . . . StartPosition: {
103103
. . . . . . . . . . . . Offset: 25
@@ -115,7 +115,7 @@ Module {
115115
. . . . . . . . . . . }
116116
. . . . . . . . . . }
117117
. . . . . . . . . . 2: Compare.ops {
118-
. . . . . . . . . . . Roles: Expression,Binary,Operator
118+
. . . . . . . . . . . Roles: Expression
119119
. . . . . . . . . . . Properties: {
120120
. . . . . . . . . . . . promotedPropertyList: true
121121
. . . . . . . . . . . }
@@ -178,7 +178,7 @@ Module {
178178
. . . . . . . . . }
179179
. . . . . . . . . Children: {
180180
. . . . . . . . . . 0: Compare.comparators {
181-
. . . . . . . . . . . Roles: Expression,Binary,Right
181+
. . . . . . . . . . . Roles: Expression,Right
182182
. . . . . . . . . . . Properties: {
183183
. . . . . . . . . . . . promotedPropertyList: true
184184
. . . . . . . . . . . }
@@ -200,7 +200,7 @@ Module {
200200
. . . . . . . . . . . }
201201
. . . . . . . . . . }
202202
. . . . . . . . . . 1: Name {
203-
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Binary,Left
203+
. . . . . . . . . . . Roles: Identifier,Expression,Expression,Left
204204
. . . . . . . . . . . TOKEN "i"
205205
. . . . . . . . . . . StartPosition: {
206206
. . . . . . . . . . . . Offset: 57
@@ -218,7 +218,7 @@ Module {
218218
. . . . . . . . . . . }
219219
. . . . . . . . . . }
220220
. . . . . . . . . . 2: Compare.ops {
221-
. . . . . . . . . . . Roles: Expression,Binary,Operator
221+
. . . . . . . . . . . Roles: Expression
222222
. . . . . . . . . . . Properties: {
223223
. . . . . . . . . . . . promotedPropertyList: true
224224
. . . . . . . . . . . }

0 commit comments

Comments
 (0)