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
363 changes: 0 additions & 363 deletions ANNOTATION.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To initialize the build system execute: `bblfsh-sdk prepare-build`, at the root
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.

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


License
Expand Down
22 changes: 13 additions & 9 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ var Transformers = []transformer.Tranformer{
positioner.NewFillOffsetFromLineCol(),
}

// Common for FunctionDef, AsyncFunctionDef and Lambda
var argumentsAnn = On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
)

// AnnotationRules describes how a UAST should be annotated with `uast.Role`.
//
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/ann
Expand Down Expand Up @@ -113,6 +121,8 @@ var AnnotationRules = On(Any).Self(
On(HasInternalRole("n")).Roles(uast.Literal, uast.Number, uast.Expression),
),
On(pyast.BoolLiteral).Roles(uast.Literal, uast.Boolean, uast.Expression, uast.Primitive),
// another grouping node like "arguments"
On(pyast.BoolOp).Roles(uast.Expression, uast.Boolean, uast.Incomplete),
On(pyast.JoinedStr).Roles(uast.Literal, uast.String, uast.Expression, uast.Primitive).Children(
On(pyast.FormattedValue).Roles(uast.Expression, uast.Incomplete),
),
Expand All @@ -127,15 +137,8 @@ var AnnotationRules = On(Any).Self(

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

On(pyast.Attribute).Roles(uast.Identifier, uast.Expression).Children(
Expand Down
4 changes: 2 additions & 2 deletions fixtures/functiondef_simple.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ Module {
. . . }
. . . Children: {
. . . . 0: arguments {
. . . . . Roles: Unannotated
. . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . Properties: {
. . . . . . internalRole: args
. . . . . . kwarg: <nil>
. . . . . . vararg: <nil>
. . . . . }
. . . . . Children: {
. . . . . . 0: arg {
. . . . . . . Roles: Unannotated
. . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
. . . . . . . TOKEN "arg1"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 125
Expand Down
44 changes: 22 additions & 22 deletions fixtures/issue_server101.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 4120
. . . . . . . . . . . . . . . . . . Line: 107
Expand Down Expand Up @@ -2339,7 +2339,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 3899
. . . . . . . . . . . . . . Line: 102
Expand Down Expand Up @@ -2566,7 +2566,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 2: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 3779
. . . . . . . . . . Line: 100
Expand Down Expand Up @@ -3150,7 +3150,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 4605
. . . . . . . . . . . . . . Line: 120
Expand Down Expand Up @@ -4058,7 +4058,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 5124
. . . . . . . . . . Line: 134
Expand Down Expand Up @@ -4468,7 +4468,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 5291
. . . . . . . . . . Line: 138
Expand Down Expand Up @@ -5024,7 +5024,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 5421
. . . . . . . . . . Line: 141
Expand Down Expand Up @@ -6619,7 +6619,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 6974
. . . . . . . . . . . . . . . . . . Line: 175
Expand Down Expand Up @@ -13238,7 +13238,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 11161
. . . . . . . . . . . . . . . . . . Line: 282
Expand Down Expand Up @@ -13417,7 +13417,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 10503
. . . . . . . . . . . . . . Line: 270
Expand All @@ -13428,7 +13428,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: BoolOp {
. . . . . . . . . . . . . . . Roles: Unannotated
. . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 10504
. . . . . . . . . . . . . . . . Line: 270
Expand Down Expand Up @@ -13583,7 +13583,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . . . Roles: Unannotated
. . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 10593
. . . . . . . . . . . . . . . . Line: 272
Expand Down Expand Up @@ -17516,7 +17516,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 15326
. . . . . . . . . . Line: 384
Expand Down Expand Up @@ -18115,7 +18115,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 15717
. . . . . . . . . . . . . . . . . . Line: 392
Expand Down Expand Up @@ -22242,7 +22242,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 18014
. . . . . . . . . . . . . . Line: 450
Expand Down Expand Up @@ -32161,7 +32161,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . . . . . . . . . Offset: 25811
. . . . . . . . . . . . . . . . . . . . . . . . . . Line: 644
Expand Down Expand Up @@ -32363,7 +32363,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . . . . . Offset: 25545
. . . . . . . . . . . . . . . . . . . . . . Line: 639
Expand Down Expand Up @@ -32567,7 +32567,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 25192
. . . . . . . . . . . . . . . . . . Line: 633
Expand Down Expand Up @@ -33640,7 +33640,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 26372
. . . . . . . . . . Line: 660
Expand Down Expand Up @@ -36128,7 +36128,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . . 2: BoolOp {
. . . . . . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . . . Offset: 27328
. . . . . . . . . . . . . . . . . . Line: 692
Expand Down Expand Up @@ -37202,7 +37202,7 @@ pyid to C{bool}."
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: BoolOp {
. . . . . . . . . . . . . Roles: If,Condition
. . . . . . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 28512
. . . . . . . . . . . . . . Line: 724
Expand Down Expand Up @@ -51241,7 +51241,7 @@ pyid to C{bool}."
. . . . . . . . . }
. . . . . . . . }
. . . . . . . . 1: BoolOp {
. . . . . . . . . Roles: If,Condition
. . . . . . . . . Roles: Expression,Boolean,Incomplete,If,Condition
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 37438
. . . . . . . . . . Line: 953
Expand Down
4 changes: 2 additions & 2 deletions fixtures/lambda.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: arguments {
. . . . . . . Roles: Unannotated
. . . . . . . Roles: Function,Declaration,Incomplete,Argument
. . . . . . . Properties: {
. . . . . . . . internalRole: args
. . . . . . . . kwarg: <nil>
. . . . . . . . vararg: <nil>
. . . . . . . }
. . . . . . . Children: {
. . . . . . . . 0: arg {
. . . . . . . . . Roles: Unannotated
. . . . . . . . . Roles: Function,Declaration,Argument,Name,Identifier
. . . . . . . . . TOKEN "x"
. . . . . . . . . StartPosition: {
. . . . . . . . . . Offset: 7
Expand Down