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
40 changes: 18 additions & 22 deletions ANNOTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,25 @@
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Dict'\]/\*\[@internalRole\]\[@internalRole='values'\] | MapValue |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Tuple'\] | TupleLiteral, Expression |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\] | FunctionDeclaration, FunctionDeclarationName, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='FunctionDef\.decorator\_list'\] | Call, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='FunctionDef\.body'\] | FunctionDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\] | FunctionDeclarationArgument, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='args'\] | FunctionDeclarationArgument, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='vararg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='kwarg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.defaults'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.keywords'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\] | FunctionDeclaration, FunctionDeclarationName, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='AsyncFunctionDef\.decorator\_list'\] | Call, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='AsyncFunctionDef\.body'\] | FunctionDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\] | FunctionDeclarationArgument, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='args'\] | FunctionDeclarationArgument, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='vararg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='kwarg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.defaults'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='AsyncFunctionDef'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.keywords'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef\.decorator\_list'\] | Call, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='FunctionDef\.body'\] | FunctionDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\] | FunctionDeclarationArgument, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='args'\] | FunctionDeclarationArgument, FunctionDeclarationArgumentName, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='vararg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='kwarg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, Incomplete, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.defaults'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.keywords'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@InternalType='AsyncFunctionDef\.decorator\_list'\] | Call, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='arguments'\]/\*\[@InternalType='AsyncFunctionDef\.body'\] | FunctionDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\] | FunctionDeclaration, SimpleIdentifier, Expression, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='Lambda\.body'\] | FunctionDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\] | FunctionDeclarationArgument, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='args'\] | FunctionDeclarationArgument, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='vararg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='kwarg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.defaults'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.keywords'\] | FunctionDeclarationArgumentDefaultValue, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='args'\] | FunctionDeclarationArgument, FunctionDeclarationArgumentName, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='vararg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@internalRole\]\[@internalRole='kwarg'\] | FunctionDeclarationArgument, FunctionDeclarationVarArgsList, FunctionDeclarationArgumentName, Incomplete, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.defaults'\] | FunctionDeclarationArgumentDefaultValue, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Lambda'\]/\*\[@InternalType='arguments'\]/\*\[@InternalType='arguments\.keywords'\] | FunctionDeclarationArgumentDefaultValue, SimpleIdentifier, Incomplete |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Attribute'\] | SimpleIdentifier, Expression |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Attribute'\]/\*\[@InternalType='Name'\] | QualifiedIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Call'\] | Call, Expression |
Expand Down Expand Up @@ -129,8 +123,10 @@
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='IfExp'\]/\*\[@internalRole\]\[@internalRole='test'\] | IfCondition |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='IfExp'\]/\*\[@internalRole\]\[@internalRole='orelse'\] | IfElse |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Import'\] | ImportDeclaration, Statement |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='alias'\] | ImportPath, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ImportFrom\.module'\] | ImportPath, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='alias\.asname'\] | ImportAlias, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ImportFrom'\] | ImportDeclaration, Statement |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='alias'\] | ImportAlias, SimpleIdentifier |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ClassDef'\] | TypeDeclaration, SimpleIdentifier, Statement |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ClassDef'\]/\*\[@InternalType='ClassDef\.body'\] | TypeDeclarationBody |
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ClassDef'\]/\*\[@InternalType='ClassDef\.bases'\] | TypeDeclarationBases |
Expand Down
90 changes: 39 additions & 51 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,71 +109,56 @@ var AnnotationRules = On(Any).Self(
// Type node Token (2 levels up) but the SDK doesn't allow this
// TODO: create an issue for the SDK
On(HasInternalType(pyast.FunctionDef)).Roles(FunctionDeclaration, FunctionDeclarationName,
SimpleIdentifier).Children(
On(HasInternalType("FunctionDef.decorator_list")).Roles(Call, SimpleIdentifier, Incomplete),
On(HasInternalType("FunctionDef.body")).Roles(FunctionDeclarationBody),
// FIXME: change to FunctionDeclarationArgumentS once the PR has been merged
On(HasInternalType(pyast.Arguments)).Roles(FunctionDeclarationArgument, Incomplete).Children(
On(HasInternalRole("args")).Roles(FunctionDeclarationArgument, FunctionDeclarationArgumentName),
On(HasInternalRole("vararg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName),
// FIXME: this is really different from vararg, change it when we have FunctionDeclarationMap
// or something similar in the UAST
On(HasInternalRole("kwarg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName, Incomplete),
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
// arguments that must be mapped to the arguments right-aligned like:
// a, b=2, c=3 ->
// args [a,b,c],
// defaults [2,3]
// TODO: create an issue for the SDK
On(HasInternalType("arguments.defaults")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("arguments.keywords")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
),
),
On(HasInternalType(pyast.AsyncFunctionDef)).Roles(FunctionDeclaration, FunctionDeclarationName, SimpleIdentifier,
Incomplete).Children(
SimpleIdentifier),
On(HasInternalType(pyast.AsyncFunctionDef)).Roles(FunctionDeclaration,
FunctionDeclarationName, SimpleIdentifier, Incomplete),
On(HasInternalType("FunctionDef.decorator_list")).Roles(Call, SimpleIdentifier, Incomplete),
On(HasInternalType("FunctionDef.body")).Roles(FunctionDeclarationBody),
// FIXME: change to FunctionDeclarationArgumentS once the PR has been merged
On(HasInternalType(pyast.Arguments)).Roles(FunctionDeclarationArgument, Incomplete).Children(
On(HasInternalRole("args")).Roles(FunctionDeclarationArgument, FunctionDeclarationArgumentName,
SimpleIdentifier),
On(HasInternalRole("vararg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName, SimpleIdentifier),
// FIXME: this is really different from vararg, change it when we have FunctionDeclarationMap
// or something similar in the UAST
On(HasInternalRole("kwarg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName, Incomplete, SimpleIdentifier),
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
// arguments that must be mapped to the arguments right-aligned like:
// a, b=2, c=3 ->
// args [a,b,c],
// defaults [2,3]
// TODO: create an issue for the SDK
On(HasInternalType("arguments.defaults")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("arguments.keywords")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("AsyncFunctionDef.decorator_list")).Roles(Call, SimpleIdentifier, Incomplete),
On(HasInternalType("AsyncFunctionDef.body")).Roles(FunctionDeclarationBody),
// FIXME: change to FunctionDeclarationArgumentS once the PR has been merged
On(HasInternalType(pyast.Arguments)).Roles(FunctionDeclarationArgument, Incomplete).Children(
On(HasInternalRole("args")).Roles(FunctionDeclarationArgument, FunctionDeclarationArgumentName),
On(HasInternalRole("vararg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName),
// FIXME: this is really different from vararg, change it when we have FunctionDeclarationMap
// or something similar in the UAST
On(HasInternalRole("kwarg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName, Incomplete),
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
// arguments that must be mapped to the arguments right-aligned like:
// a, b=2, c=3 ->
// args [a,b,c],
// defaults [2,3]
// TODO: create an issue for the SDK
On(HasInternalType("arguments.defaults")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("arguments.keywords")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
),
),
On(HasInternalType(pyast.Lambda)).Roles(FunctionDeclaration, SimpleIdentifier, Expression,
Incomplete).Children(
Incomplete).Children(
On(HasInternalType("Lambda.body")).Roles(FunctionDeclarationBody),
// FIXME: change to FunctionDeclarationArgumentS once the PR has been merged
On(HasInternalType(pyast.Arguments)).Roles(FunctionDeclarationArgument, Incomplete).Children(
On(HasInternalRole("args")).Roles(FunctionDeclarationArgument, FunctionDeclarationArgumentName),
On(HasInternalRole("args")).Roles(FunctionDeclarationArgument, FunctionDeclarationArgumentName,
SimpleIdentifier),
On(HasInternalRole("vararg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName),
FunctionDeclarationArgumentName, SimpleIdentifier),
// FIXME: this is really different from vararg, change it when we have FunctionDeclarationMap
// or something similar in the UAST
On(HasInternalRole("kwarg")).Roles(FunctionDeclarationArgument, FunctionDeclarationVarArgsList,
FunctionDeclarationArgumentName, Incomplete),
FunctionDeclarationArgumentName, Incomplete, SimpleIdentifier),
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
// arguments that must be mapped to the arguments right-aligned like:
// a, b=2, c=3 ->
// args [a,b,c],
// defaults [2,3]
// TODO: create an issue for the SDK
On(HasInternalType("arguments.defaults")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("arguments.keywords")).Roles(FunctionDeclarationArgumentDefaultValue, Incomplete),
On(HasInternalType("arguments.defaults")).Roles(FunctionDeclarationArgumentDefaultValue,
SimpleIdentifier, Incomplete),
On(HasInternalType("arguments.keywords")).Roles(FunctionDeclarationArgumentDefaultValue,
SimpleIdentifier, Incomplete),
),
),

Expand All @@ -189,7 +174,7 @@ var AnnotationRules = On(Any).Self(
On(HasInternalType(pyast.Name)).Roles(Call),
On(HasInternalType(pyast.Attribute)).Roles(CallCallee).Children(
On(HasInternalRole("value")).Roles(CallReceiver),
)),
)),
),

//
Expand All @@ -208,7 +193,6 @@ var AnnotationRules = On(Any).Self(
On(HasInternalRole("value")).Roles(AugmentedAssignmentValue),
),


On(HasInternalType(pyast.Expression)).Roles(Expression),
On(HasInternalType(pyast.Expr)).Roles(Expression),
On(HasInternalType(pyast.Name)).Roles(SimpleIdentifier, Expression),
Expand Down Expand Up @@ -270,8 +254,13 @@ var AnnotationRules = On(Any).Self(
On(HasInternalRole("orelse")).Roles(IfElse),
),
On(HasInternalType(pyast.Import)).Roles(ImportDeclaration, Statement),
// "y" in "from x import y" or "import y"
On(HasInternalType(pyast.Alias)).Roles(ImportPath, SimpleIdentifier),
// "x" in "from x import y"
On(HasInternalType("ImportFrom.module")).Roles(ImportPath, SimpleIdentifier),
// "y" in "import x as y"
On(HasInternalType("alias.asname")).Roles(ImportAlias, SimpleIdentifier),
On(HasInternalType(pyast.ImportFrom)).Roles(ImportDeclaration, Statement),
On(HasInternalType(pyast.Alias)).Roles(ImportAlias, SimpleIdentifier),
On(HasInternalType(pyast.ClassDef)).Roles(TypeDeclaration, SimpleIdentifier, Statement).Children(
On(HasInternalType("ClassDef.body")).Roles(TypeDeclarationBody),
On(HasInternalType("ClassDef.bases")).Roles(TypeDeclarationBases),
Expand Down Expand Up @@ -360,6 +349,5 @@ var AnnotationRules = On(Any).Self(
On(HasInternalType(pyast.Index)).Roles(Expression, Incomplete),
On(HasInternalType(pyast.Slice)).Roles(Expression, Incomplete),
On(HasInternalType(pyast.ExtSlice)).Roles(Expression, Incomplete),

),
)
4 changes: 4 additions & 0 deletions driver/normalizer/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ var ToNoder = &native.ObjectToNoder{
"ListComp.generators": {"ifs": true},
"ListComp.generators.ifs": {"comparators": true, "ops": true},
},
PromotedPropertyStrings: map[string]map[string]bool{
"alias": {"asname": true},
"ImportFrom": {"module": true},
},
// FIXME: test[ast_type=Compare].comparators is a list?? (should be "right")
}

Expand Down
4 changes: 2 additions & 2 deletions tests/annotations.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: arg {
. . . . . . . Roles: FunctionDeclarationArgument,FunctionDeclarationArgumentName
. . . . . . . Roles: FunctionDeclarationArgument,FunctionDeclarationArgumentName,SimpleIdentifier
. . . . . . . TOKEN "a"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 33
Expand Down Expand Up @@ -216,7 +216,7 @@ Module {
. . . . . . . }
. . . . . . }
. . . . . . 1: arg {
. . . . . . . Roles: FunctionDeclarationArgument,FunctionDeclarationArgumentName
. . . . . . . Roles: FunctionDeclarationArgument,FunctionDeclarationArgumentName,SimpleIdentifier
. . . . . . . TOKEN "b"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 41
Expand Down
Loading