Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ var AnnotationRules = On(Any).Self(
On(pyast.Name).Roles(uast.Identifier, uast.Expression),
// Comments and non significative whitespace
On(pyast.SameLineNoops).Roles(uast.Comment),
On(pyast.PreviousNoops).Roles(uast.Whitespace).Children(
On(HasInternalRole("lines")).Roles(uast.Comment),
On(pyast.PreviousNoops).Roles(uast.Noop).Children(
On(HasInternalRole("lines")).Self(
On(HasProperty("noop_line", "\n")).Roles(uast.Noop, uast.Whitespace),
On(Not(HasProperty("noop_line", "\n"))).Roles(uast.Noop, uast.Comment),
),
),
On(pyast.RemainderNoops).Roles(uast.Whitespace).Children(
On(HasInternalRole("lines")).Roles(uast.Comment),
On(pyast.RemainderNoops).Roles(uast.Noop).Children(
On(HasInternalRole("lines")).Self(
On(HasProperty("noop_line", "\n")).Roles(uast.Noop, uast.Whitespace),
On(Not(HasProperty("noop_line", "\n"))).Roles(uast.Noop, uast.Comment),
),
),

// TODO: check what Constant nodes are generated in the python AST and improve this
Expand Down
3 changes: 0 additions & 3 deletions fixtures/annotations.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Module {
. . . Properties: {
. . . . internalRole: body
. . . . simple: 1
. . . . value: <nil>
. . . }
. . . Children: {
. . . . 0: Name {
Expand Down Expand Up @@ -144,8 +143,6 @@ Module {
. . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . Properties: {
. . . . . . internalRole: args
. . . . . . kwarg: <nil>
. . . . . . vararg: <nil>
. . . . . }
. . . . . Children: {
. . . . . . 0: arg {
Expand Down
2 changes: 1 addition & 1 deletion fixtures/aritmeticops.py.native
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 8,
"noop_line": "# 1@2 FIXME: matmul\n"
"noop_line": " 1@2 FIXME: matmul\n"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions fixtures/aritmeticops.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ Module {
. . . }
. . }
. . 7: RemainderNoops {
. . . Roles: Whitespace
. . . Roles: Noop
. . . StartPosition: {
. . . . Offset: 30
. . . . Line: 8
Expand All @@ -491,8 +491,8 @@ Module {
. . . }
. . . Children: {
. . . . 0: NoopLine {
. . . . . Roles: Comment
. . . . . TOKEN "# 1@2 FIXME: matmul
. . . . . Roles: Noop,Comment
. . . . . TOKEN " 1@2 FIXME: matmul
"
. . . . . StartPosition: {
. . . . . . Offset: 30
Expand Down
2 changes: 0 additions & 2 deletions fixtures/assert_constant.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Module {
. . . }
. . . Properties: {
. . . . internalRole: body
. . . . msg: <nil>
. . . }
. . . Children: {
. . . . 0: BoolLiteral {
Expand Down Expand Up @@ -58,7 +57,6 @@ Module {
. . . }
. . . Properties: {
. . . . internalRole: body
. . . . msg: <nil>
. . . }
. . . Children: {
. . . . 0: BoolLiteral {
Expand Down
36 changes: 4 additions & 32 deletions fixtures/classdef.py.native
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,7 @@
"end_col_offset": 1,
"end_lineno": 5,
"lineno": 5,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 5,
"noop_line": "\n"
}
]
"lines": []
}
},
{
Expand Down Expand Up @@ -200,14 +193,7 @@
"end_col_offset": 1,
"end_lineno": 8,
"lineno": 8,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 8,
"noop_line": "\n"
}
]
"lines": []
}
}
}
Expand Down Expand Up @@ -246,14 +232,7 @@
"end_col_offset": 1,
"end_lineno": 12,
"lineno": 12,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 12,
"noop_line": "\n"
}
]
"lines": []
}
}
],
Expand Down Expand Up @@ -354,14 +333,7 @@
"end_col_offset": 1,
"end_lineno": 16,
"lineno": 16,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 16,
"noop_line": "\n"
}
]
"lines": []
}
}
],
Expand Down
92 changes: 4 additions & 88 deletions fixtures/classdef.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ Module {
. . . . . . . . Line: 2
. . . . . . . . Col: 16
. . . . . . . }
. . . . . . . Properties: {
. . . . . . . . returns: <nil>
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: arguments {
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . . . . . Properties: {
. . . . . . . . . . internalRole: args
. . . . . . . . . . kwarg: <nil>
. . . . . . . . . . vararg: <nil>
. . . . . . . . . }
. . . . . . . . . Children: {
. . . . . . . . . . 0: arg {
Expand All @@ -67,7 +62,6 @@ Module {
. . . . . . . . . . . . Col: 21
. . . . . . . . . . . }
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . annotation: <nil>
. . . . . . . . . . . . internalRole: args
. . . . . . . . . . . }
. . . . . . . . . . }
Expand Down Expand Up @@ -206,16 +200,11 @@ Module {
. . . . . . . . Line: 6
. . . . . . . . Col: 14
. . . . . . . }
. . . . . . . Properties: {
. . . . . . . . returns: <nil>
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: arguments {
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . . . . . Properties: {
. . . . . . . . . . internalRole: args
. . . . . . . . . . kwarg: <nil>
. . . . . . . . . . vararg: <nil>
. . . . . . . . . }
. . . . . . . . . Children: {
. . . . . . . . . . 0: arg {
Expand All @@ -232,12 +221,11 @@ Module {
. . . . . . . . . . . . Col: 19
. . . . . . . . . . . }
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . annotation: <nil>
. . . . . . . . . . . . internalRole: args
. . . . . . . . . . . }
. . . . . . . . . . . Children: {
. . . . . . . . . . . . 0: PreviousNoops {
. . . . . . . . . . . . . Roles: Whitespace
. . . . . . . . . . . . . Roles: Noop
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 72
. . . . . . . . . . . . . . Line: 5
Expand All @@ -251,21 +239,6 @@ Module {
. . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . internalRole: noops_previous
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: NoopLine {
. . . . . . . . . . . . . . . Roles: Comment
. . . . . . . . . . . . . . . TOKEN "
"
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 72
. . . . . . . . . . . . . . . . Line: 5
. . . . . . . . . . . . . . . . Col: 1
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . internalRole: lines
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . }
. . . . . . . . . . }
Expand All @@ -283,7 +256,6 @@ Module {
. . . . . . . . . . . . Col: 25
. . . . . . . . . . . }
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . annotation: <nil>
. . . . . . . . . . . . internalRole: args
. . . . . . . . . . . }
. . . . . . . . . . }
Expand Down Expand Up @@ -321,16 +293,11 @@ Module {
. . . . . . . . Line: 9
. . . . . . . . Col: 5
. . . . . . . }
. . . . . . . Properties: {
. . . . . . . . returns: <nil>
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: arguments {
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . . . . . Properties: {
. . . . . . . . . . internalRole: args
. . . . . . . . . . kwarg: <nil>
. . . . . . . . . . vararg: <nil>
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: FunctionDef.body {
Expand Down Expand Up @@ -390,7 +357,7 @@ Module {
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . . . 0: PreviousNoops {
. . . . . . . . . . . . . . . . . Roles: Whitespace
. . . . . . . . . . . . . . . . . Roles: Noop
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 114
. . . . . . . . . . . . . . . . . . Line: 8
Expand All @@ -404,21 +371,6 @@ Module {
. . . . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . . . internalRole: noops_previous
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . . . . . 0: NoopLine {
. . . . . . . . . . . . . . . . . . . Roles: Comment
. . . . . . . . . . . . . . . . . . . TOKEN "
"
. . . . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . . . Offset: 114
. . . . . . . . . . . . . . . . . . . . Line: 8
. . . . . . . . . . . . . . . . . . . . Col: 1
. . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . . . . . internalRole: lines
. . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
Expand Down Expand Up @@ -463,16 +415,11 @@ Module {
. . . . . . . . Line: 13
. . . . . . . . Col: 5
. . . . . . . }
. . . . . . . Properties: {
. . . . . . . . returns: <nil>
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: arguments {
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . . . . . Properties: {
. . . . . . . . . . internalRole: args
. . . . . . . . . . kwarg: <nil>
. . . . . . . . . . vararg: <nil>
. . . . . . . . . }
. . . . . . . . . Children: {
. . . . . . . . . . 0: arg {
Expand All @@ -489,12 +436,11 @@ Module {
. . . . . . . . . . . . Col: 14
. . . . . . . . . . . }
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . annotation: <nil>
. . . . . . . . . . . . internalRole: args
. . . . . . . . . . . }
. . . . . . . . . . . Children: {
. . . . . . . . . . . . 0: PreviousNoops {
. . . . . . . . . . . . . Roles: Whitespace
. . . . . . . . . . . . . Roles: Noop
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 165
. . . . . . . . . . . . . . Line: 12
Expand All @@ -508,21 +454,6 @@ Module {
. . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . internalRole: noops_previous
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: NoopLine {
. . . . . . . . . . . . . . . Roles: Comment
. . . . . . . . . . . . . . . TOKEN "
"
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 165
. . . . . . . . . . . . . . . . Line: 12
. . . . . . . . . . . . . . . . Col: 1
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . internalRole: lines
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . }
. . . . . . . . . . }
Expand Down Expand Up @@ -683,7 +614,7 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: PreviousNoops {
. . . . . . . Roles: Whitespace
. . . . . . . Roles: Noop
. . . . . . . StartPosition: {
. . . . . . . . Offset: 220
. . . . . . . . Line: 16
Expand All @@ -697,21 +628,6 @@ Module {
. . . . . . . Properties: {
. . . . . . . . internalRole: noops_previous
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: NoopLine {
. . . . . . . . . Roles: Comment
. . . . . . . . . TOKEN "
"
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 220
. . . . . . . . . . Line: 16
. . . . . . . . . . Col: 1
. . . . . . . . . }
. . . . . . . . . Properties: {
. . . . . . . . . . internalRole: lines
. . . . . . . . . }
. . . . . . . . }
. . . . . . . }
. . . . . . }
. . . . . }
. . . . }
Expand Down
18 changes: 2 additions & 16 deletions fixtures/classdef_inheritance.py.native
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@
"end_col_offset": 1,
"end_lineno": 3,
"lineno": 3,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 3,
"noop_line": "\n"
}
]
"lines": []
}
},
{
Expand Down Expand Up @@ -97,14 +90,7 @@
"end_col_offset": 1,
"end_lineno": 6,
"lineno": 6,
"lines": [
{
"ast_type": "NoopLine",
"col_offset": 1,
"lineno": 6,
"noop_line": "\n"
}
]
"lines": []
}
}
}
Expand Down
Loading