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

Commit c968ad1

Browse files
authored
Merge pull request #112 from juanjux/fix/misc_annotations
Fix/misc annotations
2 parents 3b104f5 + f09a524 commit c968ad1

File tree

71 files changed

+3772
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3772
-359
lines changed

ANNOTATION.md

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.

driver/normalizer/annotation.go

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var Transformers = []transformer.Tranformer{
5353
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/ann
5454
var AnnotationRules = On(Any).Self(
5555
On(Not(pyast.Module)).Error(errors.New("root must be uast.Module")),
56-
On(pyast.Module).Roles(uast.File).Descendants(
56+
On(pyast.Module).Roles(uast.File, uast.Module).Descendants(
5757

5858
// Binary Expressions
5959
On(pyast.BinOp).Roles(uast.Expression, uast.Binary).Children(
@@ -127,16 +127,17 @@ var AnnotationRules = On(Any).Self(
127127

128128
// FIXME: the FunctionDeclarationReceiver is not set for methods; it should be taken from the parent
129129
// 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),
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+
),
131138
On(pyast.AsyncFunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier, uast.Incomplete),
132139
On(pyast.FuncDecorators).Roles(uast.Function, uast.Declaration, uast.Call, uast.Incomplete),
133140
On(pyast.FuncDefBody).Roles(uast.Function, uast.Declaration, uast.Body),
134-
// FIXME: arguments is a Groping node, update it we get a "Grouper" or "Container" role
135-
On(HasInternalRole("arguments")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Incomplete),
136-
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
137-
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
138-
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
139-
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
140141
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
141142
// arguments that must be mapped to the arguments right-aligned like:
142143
// a, b=2, c=3 ->
@@ -155,9 +156,9 @@ var AnnotationRules = On(Any).Self(
155156
On(pyast.Name).Roles(uast.Identifier, uast.Qualified)),
156157

157158
On(pyast.Call).Roles(uast.Function, uast.Call, uast.Expression).Children(
158-
On(HasInternalRole("args")).Roles(uast.Call, uast.Argument, uast.Positional),
159-
On(HasInternalRole("keywords")).Roles(uast.Call, uast.Argument, uast.Name).Children(
160-
On(HasInternalRole("value")).Roles(uast.Call, uast.Argument, uast.Value),
159+
On(HasInternalRole("args")).Roles(uast.Function, uast.Call, uast.Positional, uast.Argument, uast.Name),
160+
On(HasInternalRole("keywords")).Roles(uast.Function, uast.Call, uast.Argument, uast.Name).Children(
161+
On(HasInternalRole("value")).Roles(uast.Argument, uast.Value),
161162
),
162163
On(HasInternalRole("func")).Self(
163164
On(pyast.Name).Roles(uast.Call, uast.Callee),
@@ -217,21 +218,19 @@ var AnnotationRules = On(Any).Self(
217218
On(pyast.Break).Roles(uast.Break, uast.Statement),
218219
On(pyast.Continue).Roles(uast.Continue, uast.Statement),
219220

220-
// - Compare.ops (internaluast.Type): [uast.LessThan, uast.LessThan]
221-
// - Compare.comparators (internaluast.Type): ['a', 10]
222-
// The current mapping is:
223-
// - left: uast.Expression, uast.Binary, uast.Left
224-
// - Compare.ops: uast.Expression, uast.Binary, uast.Operator
225-
// - Compare.comparators: uast.Expression, uast.Binary, uast.Right
226-
// But this is obviously not correct. To fix this properly we would need
227-
// and SDK feature to mix lists (also needed for default and keyword arguments and
228-
// boolean operators).
229-
// "uast.If that sounds awkward is because it is" (their words)
221+
// Comparison nodes in Python are oddly structured. Probably one if the first
222+
// things that could be changed once we can normalize tree structures. Check:
223+
// https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare
224+
225+
// Parent of all comparisons
230226
On(pyast.Compare).Roles(uast.Expression, uast.Binary).Children(
231-
On(pyast.CompareOps).Roles(uast.Expression, uast.Binary, uast.Operator),
232-
On(HasInternalRole("left")).Roles(uast.Expression, uast.Binary, uast.Left),
227+
// Operators
228+
On(pyast.CompareOps).Roles(uast.Expression),
229+
// Leftmost element (the others are the comparators below)
230+
On(HasInternalRole("left")).Roles(uast.Expression, uast.Left),
231+
// These hold the members of the comparison (not the operators)
232+
On(pyast.CompareComparators).Roles(uast.Expression, uast.Right),
233233
),
234-
On(pyast.CompareComparators).Roles(uast.Expression, uast.Binary, uast.Right),
235234
On(pyast.If).Roles(uast.If, uast.Statement).Children(
236235
On(pyast.IfBody).Roles(uast.If, uast.Body, uast.Then),
237236
On(HasInternalRole("test")).Roles(uast.If, uast.Condition),
@@ -320,10 +319,7 @@ var AnnotationRules = On(Any).Self(
320319
On(HasInternalRole("iter")).Roles(uast.For, uast.Update, uast.Statement),
321320
On(HasInternalRole("target")).Roles(uast.For, uast.Expression),
322321
// FIXME: see the comment on uast.If, uast.Condition above
323-
On(pyast.Compare).Roles(uast.If, uast.Condition, uast.Expression, uast.Binary).Children(
324-
On(pyast.CompareOps).Roles(uast.Expression, uast.Binary, uast.Operator),
325-
On(HasInternalRole("left")).Roles(uast.Expression, uast.Binary, uast.Left),
326-
),
322+
On(pyast.Compare).Roles(uast.If, uast.Condition),
327323
),
328324

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

fixtures/annotations.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: AnnAssign {
88
. . . Roles: Operator,Binary,Assignment,Comment,Incomplete
@@ -140,7 +140,7 @@ Module {
140140
. . . }
141141
. . . Children: {
142142
. . . . 0: arguments {
143-
. . . . . Roles: Function,Declaration,Argument,Name,Identifier
143+
. . . . . Roles: Function,Declaration,Incomplete,Argument
144144
. . . . . Properties: {
145145
. . . . . . internalRole: args
146146
. . . . . . kwarg: <nil>

fixtures/aritmeticops.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: Expr {
88
. . . Roles: Expression

fixtures/assert_constant.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: Assert {
88
. . . Roles: Assert,Statement

fixtures/augassign.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: AugAssign {
88
. . . Roles: Operator,Binary,Assignment,Statement

fixtures/bitwise.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: Expr {
88
. . . Roles: Expression

fixtures/classdef.py.uast

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ Module {
4545
. . . . . . . }
4646
. . . . . . . Children: {
4747
. . . . . . . . 0: arguments {
48+
<<<<<<< HEAD
4849
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
50+
||||||| merged common ancestors
51+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument,Name,Identifier
52+
=======
53+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
54+
>>>>>>> Remove Identifier from the arguments grouping node. Remove dups
4955
. . . . . . . . . Properties: {
5056
. . . . . . . . . . internalRole: args
5157
. . . . . . . . . . kwarg: <nil>
@@ -210,7 +216,13 @@ Module {
210216
. . . . . . . }
211217
. . . . . . . Children: {
212218
. . . . . . . . 0: arguments {
219+
<<<<<<< HEAD
213220
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
221+
||||||| merged common ancestors
222+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument,Name,Identifier
223+
=======
224+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
225+
>>>>>>> Remove Identifier from the arguments grouping node. Remove dups
214226
. . . . . . . . . Properties: {
215227
. . . . . . . . . . internalRole: args
216228
. . . . . . . . . . kwarg: <nil>
@@ -445,7 +457,13 @@ Module {
445457
. . . . . . . . . }
446458
. . . . . . . . }
447459
. . . . . . . . 2: arguments {
460+
<<<<<<< HEAD
448461
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
462+
||||||| merged common ancestors
463+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument,Name,Identifier
464+
=======
465+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
466+
>>>>>>> Remove Identifier from the arguments grouping node. Remove dups
449467
. . . . . . . . . Properties: {
450468
. . . . . . . . . . internalRole: args
451469
. . . . . . . . . . kwarg: <nil>
@@ -467,7 +485,13 @@ Module {
467485
. . . . . . . }
468486
. . . . . . . Children: {
469487
. . . . . . . . 0: arguments {
488+
<<<<<<< HEAD
470489
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
490+
||||||| merged common ancestors
491+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument,Name,Identifier
492+
=======
493+
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
494+
>>>>>>> Remove Identifier from the arguments grouping node. Remove dups
471495
. . . . . . . . . Properties: {
472496
. . . . . . . . . . internalRole: args
473497
. . . . . . . . . . kwarg: <nil>
@@ -1006,7 +1030,13 @@ Module {
10061030
. . . . . }
10071031
. . . . . Children: {
10081032
. . . . . . 0: Num {
1033+
<<<<<<< HEAD
10091034
. . . . . . . Roles: Literal,Number,Expression,Primitive,Function,Declaration,Argument,Name,Identifier,Call,Argument,Positional
1035+
||||||| merged common ancestors
1036+
. . . . . . . Roles: Literal,Number,Expression,Argument,Name,Identifier,Function,Call,Positional
1037+
=======
1038+
. . . . . . . Roles: Literal,Number,Expression,Function,Call,Positional,Argument,Name
1039+
>>>>>>> Remove Identifier from the arguments grouping node. Remove dups
10101040
. . . . . . . TOKEN "5"
10111041
. . . . . . . StartPosition: {
10121042
. . . . . . . . Offset: 269

fixtures/classdef_decorated.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: ClassDef {
88
. . . Roles: Type,Declaration,Identifier,Statement

fixtures/classdef_inheritance.py.uast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Status: ok
22
Errors:
33
UAST:
44
Module {
5-
. Roles: File
5+
. Roles: File,Module
66
. Children: {
77
. . 0: ClassDef {
88
. . . Roles: Type,Declaration,Identifier,Statement

0 commit comments

Comments
 (0)