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

Commit e4fb9eb

Browse files
author
Juanjo Alvarez
committed
Factorize the common annotation for function children arguments
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 82e1dea commit e4fb9eb

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

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: 11 additions & 22 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
@@ -129,22 +137,8 @@ var AnnotationRules = On(Any).Self(
129137

130138
// FIXME: the FunctionDeclarationReceiver is not set for methods; it should be taken from the parent
131139
// Type node Token (2 levels up) but the SDK doesn't allow this
132-
On(pyast.FunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier).Children(
133-
On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
134-
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
135-
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
136-
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
137-
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
138-
),
139-
),
140-
On(pyast.AsyncFunctionDef).Roles(uast.Function, uast.Declaration, uast.Name, uast.Identifier, uast.Incomplete).Children(
141-
On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
142-
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
143-
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
144-
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
145-
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
146-
),
147-
),
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),
148142
On(pyast.FuncDecorators).Roles(uast.Function, uast.Declaration, uast.Call, uast.Incomplete),
149143
On(pyast.FuncDefBody).Roles(uast.Function, uast.Declaration, uast.Body),
150144
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
@@ -159,12 +153,7 @@ var AnnotationRules = On(Any).Self(
159153
// FIXME: change to Function, Declaration, ArgumentS once the PR has been merged
160154
On(pyast.Lambda).Roles(uast.Function, uast.Declaration, uast.Expression, uast.Incomplete).Children(
161155
On(pyast.LambdaBody).Roles(uast.Function, uast.Declaration, uast.Body),
162-
On(pyast.Arguments).Roles(uast.Function, uast.Declaration, uast.Incomplete, uast.Argument).Children(
163-
On(HasInternalRole("args")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.Name, uast.Identifier),
164-
On(HasInternalRole("vararg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Name, uast.Identifier),
165-
On(HasInternalRole("kwarg")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
166-
On(HasInternalRole("kwonlyargs")).Roles(uast.Function, uast.Declaration, uast.Argument, uast.ArgsList, uast.Map, uast.Name, uast.Identifier),
167-
),
156+
argumentsAnn,
168157
),
169158

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

0 commit comments

Comments
 (0)