1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Merge pull request #2082 from github/add-python

Add python and typescript support to semanticd
This commit is contained in:
Josh Vera 2018-07-23 19:44:08 -04:00 committed by GitHub
commit d21e988453
11 changed files with 2056 additions and 27 deletions

View File

@ -6,6 +6,9 @@ import "ruby-terms.proto";
import "ruby-diffs.proto";
import "json-terms.proto";
import "typescript-terms.proto";
import "typescript-diffs.proto";
import "python-terms.proto";
import "python-diffs.proto";
import "types.proto";
import "error_details.proto";
@ -48,6 +51,7 @@ message ParseTreeResponse {
RubyResponse ruby = 1;
JSONResponse json = 2;
TypeScriptResponse typescript = 3;
PythonResponse python = 4;
}
}
@ -63,6 +67,10 @@ message TypeScriptResponse {
repeated typescript_terms.TypeScriptTerm terms = 1;
}
message PythonResponse {
repeated python_terms.PythonTerm terms = 1;
}
message SummarizeDiffRequest {
repeated BlobPair blobPairs = 1;
}
@ -79,6 +87,8 @@ message DiffTreeRequest {
message DiffTreeResponse {
oneof response_type {
RubyDiffResponse ruby = 1;
PythonDiffResponse python = 2;
TypeScriptDiffResponse typescript = 3;
}
}
@ -86,6 +96,14 @@ message RubyDiffResponse {
repeated ruby_diffs.RubyDiff diffs = 1;
}
message PythonDiffResponse {
repeated python_diffs.PythonDiff diffs = 1;
}
message TypeScriptDiffResponse {
repeated typescript_diffs.TypeScriptDiff diffs = 1;
}
message CallGraphRequest {
Project project = 1;
}

486
proto/python-diffs.proto Normal file
View File

@ -0,0 +1,486 @@
// This file was generated by proto-gen. Do not edit by hand.
syntax = "proto3";
package github.semantic.python_diffs;
import "types.proto";
option java_package = "com.github.semantic.python_diffs";
option go_package = "github.com/semantic/python_diffs;python";
message PythonDiff {
oneof diff {
Merge merge = 1;
Delete delete = 2;
Insert insert = 3;
Replace replace = 4;
}
message Merge {
PythonSyntax syntax = 1;
}
message Delete {
PythonSyntax before = 1;
}
message Insert {
PythonSyntax after = 1;
}
message Replace {
PythonSyntax before = 1;
PythonSyntax after = 2;
}
}
message QualifiedName {
oneof sum {
QualifiedName qualifiedName = 1;
RelativeQualifiedName relativeQualifiedName = 2;
}
message QualifiedName {
repeated string paths = 1;
}
message RelativeQualifiedName {
string path = 1;
QualifiedName maybeQualifiedName = 2;
}
}
message Alias {
bytes aliasValue = 1;
bytes aliasName = 2;
}
message PythonSyntax {
oneof syntax {
Comment comment = 1;
Class class = 2;
Comprehension comprehension = 3;
Decorator decorator = 4;
Function function = 5;
Variable variable = 6;
Plus plus = 7;
Minus minus = 8;
Times times = 9;
DividedBy dividedBy = 10;
Modulo modulo = 11;
Power power = 12;
Negate negate = 13;
FloorDivision floorDivision = 14;
And and = 15;
Not not = 16;
Or or = 17;
XOr xOr = 18;
BAnd bAnd = 19;
BOr bOr = 20;
BXOr bXOr = 21;
LShift lShift = 22;
RShift rShift = 23;
Complement complement = 24;
Call call = 25;
LessThan lessThan = 26;
LessThanEqual lessThanEqual = 27;
GreaterThan greaterThan = 28;
GreaterThanEqual greaterThanEqual = 29;
Equal equal = 30;
StrictEqual strictEqual = 31;
Comparison comparison = 32;
Enumeration enumeration = 33;
ScopeResolution scopeResolution = 34;
MemberAccess memberAccess = 35;
Subscript subscript = 36;
Member member = 37;
Array array = 38;
Boolean boolean = 39;
Float float = 40;
Hash hash = 41;
Integer integer = 42;
KeyValue keyValue = 43;
Null null = 44;
Set set = 45;
String string = 46;
TextElement textElement = 47;
Tuple tuple = 48;
Redirect redirect = 49;
Assignment assignment = 50;
Break break = 51;
Catch catch = 52;
Continue continue = 53;
Else else = 54;
Finally finally = 55;
ForEach forEach = 56;
If if = 57;
Let let = 58;
NoOp noOp = 59;
Return return = 60;
Statements statements = 61;
Throw throw = 62;
Try try = 63;
While while = 64;
Yield yield = 65;
Ellipsis ellipsis = 66;
Import import = 67;
QualifiedImport qualifiedImport = 68;
QualifiedAliasedImport qualifiedAliasedImport = 69;
Context context = 70;
Empty empty = 71;
Error error = 72;
Identifier identifier = 73;
Annotation annotation = 74;
List list = 75;
}
}
message Comment {
string commentContent = 1;
}
message Class {
repeated PythonDiff classContext = 1;
PythonDiff classIdentifier = 2;
repeated PythonDiff classSuperclasses = 3;
PythonDiff classBody = 4;
}
message Comprehension {
PythonDiff comprehensionValue = 1;
PythonDiff comprehensionBody = 2;
}
message Decorator {
PythonDiff decoratorIdentifier = 1;
repeated PythonDiff decoratorParamaters = 2;
PythonDiff decoratorBody = 3;
}
message Function {
repeated PythonDiff functionContext = 1;
PythonDiff functionName = 2;
repeated PythonDiff functionParameters = 3;
PythonDiff functionBody = 4;
}
message Variable {
PythonDiff variableName = 1;
PythonDiff variableType = 2;
PythonDiff variableValue = 3;
}
message Plus {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Minus {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Times {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message DividedBy {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Modulo {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Power {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Negate {
PythonDiff term = 1;
}
message FloorDivision {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message And {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Not {
PythonDiff term = 1;
}
message Or {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message XOr {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message BAnd {
PythonDiff left = 1;
PythonDiff right = 2;
}
message BOr {
PythonDiff left = 1;
PythonDiff right = 2;
}
message BXOr {
PythonDiff left = 1;
PythonDiff right = 2;
}
message LShift {
PythonDiff left = 1;
PythonDiff right = 2;
}
message RShift {
PythonDiff left = 1;
PythonDiff right = 2;
}
message Complement {
PythonDiff value = 1;
}
message Call {
repeated PythonDiff callContext = 1;
PythonDiff callFunction = 2;
repeated PythonDiff callParams = 3;
PythonDiff callBlock = 4;
}
message LessThan {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message LessThanEqual {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message GreaterThan {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message GreaterThanEqual {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Equal {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message StrictEqual {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Comparison {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Enumeration {
PythonDiff enumerationStart = 1;
PythonDiff enumerationEnd = 2;
PythonDiff enumerationStep = 3;
}
message ScopeResolution {
repeated PythonDiff scopes = 1;
}
message MemberAccess {
PythonDiff lhs = 1;
bytes rhs = 2;
}
message Subscript {
PythonDiff lhs = 1;
repeated PythonDiff rhs = 2;
}
message Member {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Array {
repeated PythonDiff arrayElements = 1;
}
message Boolean {
bool booleanContent = 1;
}
message Float {
string floatContent = 1;
}
message Hash {
repeated PythonDiff hashElements = 1;
}
message Integer {
string integerContent = 1;
}
message KeyValue {
PythonDiff key = 1;
PythonDiff value = 2;
}
message Null { }
message Set {
repeated PythonDiff setElements = 1;
}
message String {
repeated PythonDiff stringElements = 1;
}
message TextElement {
string textElementContent = 1;
}
message Tuple {
repeated PythonDiff tupleContents = 1;
}
message Redirect {
PythonDiff lhs = 1;
PythonDiff rhs = 2;
}
message Assignment {
repeated PythonDiff assignmentContext = 1;
PythonDiff assignmentTarget = 2;
PythonDiff assignmentValue = 3;
}
message Break {
PythonDiff term = 1;
}
message Catch {
PythonDiff catchException = 1;
PythonDiff catchBody = 2;
}
message Continue {
PythonDiff term = 1;
}
message Else {
PythonDiff elseCondition = 1;
PythonDiff elseBody = 2;
}
message Finally {
PythonDiff term = 1;
}
message ForEach {
PythonDiff forEachBinding = 1;
PythonDiff forEachSubject = 2;
PythonDiff forEachBody = 3;
}
message If {
PythonDiff ifCondition = 1;
PythonDiff ifThenBody = 2;
PythonDiff ifElseBody = 3;
}
message Let {
PythonDiff letVariable = 1;
PythonDiff letValue = 2;
PythonDiff letBody = 3;
}
message NoOp {
PythonDiff value = 1;
}
message Return {
PythonDiff term = 1;
}
message Statements {
repeated PythonDiff statements = 1;
}
message Throw {
PythonDiff value = 1;
}
message Try {
PythonDiff tryBody = 1;
repeated PythonDiff tryCatch = 2;
}
message While {
PythonDiff whileCondition = 1;
PythonDiff whileBody = 2;
}
message Yield {
PythonDiff term = 1;
}
message Ellipsis { }
message Import {
QualifiedName importFrom = 1;
repeated Alias importSymbols = 2;
}
message QualifiedImport {
repeated string qualifiedImportFrom = 1;
}
message QualifiedAliasedImport {
QualifiedName qualifiedAliasedImportFrom = 1;
PythonDiff qualifiedAliasedImportAlias = 2;
}
message Context {
repeated PythonDiff contextTerms = 1;
PythonDiff contextSubject = 2;
}
message Empty { }
message Error {
repeated ErrorSite errorCallStack = 1;
repeated string errorExpected = 2;
string errorActual = 3;
repeated PythonDiff errorChildren = 4;
}
message Identifier {
bytes name = 1;
}
message Annotation {
PythonDiff annotationSubject = 1;
PythonDiff annotationType = 2;
}
message List {
repeated PythonDiff listContent = 1;
}

468
proto/python-terms.proto Normal file
View File

@ -0,0 +1,468 @@
// This file was generated by proto-gen. Do not edit by hand.
syntax = "proto3";
package github.semantic.python_terms;
import "types.proto";
option java_package = "com.github.semantic.python_terms";
option go_package = "github.com/semantic/python_terms;python";
message PythonTerm {
PythonSyntax syntax = 1;
}
message QualifiedName {
oneof sum {
QualifiedName qualifiedName = 1;
RelativeQualifiedName relativeQualifiedName = 2;
}
message QualifiedName {
repeated string paths = 1;
}
message RelativeQualifiedName {
string path = 1;
QualifiedName maybeQualifiedName = 2;
}
}
message Alias {
bytes aliasValue = 1;
bytes aliasName = 2;
}
message PythonSyntax {
oneof syntax {
Comment comment = 1;
Class class = 2;
Comprehension comprehension = 3;
Decorator decorator = 4;
Function function = 5;
Variable variable = 6;
Plus plus = 7;
Minus minus = 8;
Times times = 9;
DividedBy dividedBy = 10;
Modulo modulo = 11;
Power power = 12;
Negate negate = 13;
FloorDivision floorDivision = 14;
And and = 15;
Not not = 16;
Or or = 17;
XOr xOr = 18;
BAnd bAnd = 19;
BOr bOr = 20;
BXOr bXOr = 21;
LShift lShift = 22;
RShift rShift = 23;
Complement complement = 24;
Call call = 25;
LessThan lessThan = 26;
LessThanEqual lessThanEqual = 27;
GreaterThan greaterThan = 28;
GreaterThanEqual greaterThanEqual = 29;
Equal equal = 30;
StrictEqual strictEqual = 31;
Comparison comparison = 32;
Enumeration enumeration = 33;
ScopeResolution scopeResolution = 34;
MemberAccess memberAccess = 35;
Subscript subscript = 36;
Member member = 37;
Array array = 38;
Boolean boolean = 39;
Float float = 40;
Hash hash = 41;
Integer integer = 42;
KeyValue keyValue = 43;
Null null = 44;
Set set = 45;
String string = 46;
TextElement textElement = 47;
Tuple tuple = 48;
Redirect redirect = 49;
Assignment assignment = 50;
Break break = 51;
Catch catch = 52;
Continue continue = 53;
Else else = 54;
Finally finally = 55;
ForEach forEach = 56;
If if = 57;
Let let = 58;
NoOp noOp = 59;
Return return = 60;
Statements statements = 61;
Throw throw = 62;
Try try = 63;
While while = 64;
Yield yield = 65;
Ellipsis ellipsis = 66;
Import import = 67;
QualifiedImport qualifiedImport = 68;
QualifiedAliasedImport qualifiedAliasedImport = 69;
Context context = 70;
Empty empty = 71;
Error error = 72;
Identifier identifier = 73;
Annotation annotation = 74;
List list = 75;
}
}
message Comment {
string commentContent = 1;
}
message Class {
repeated PythonTerm classContext = 1;
PythonTerm classIdentifier = 2;
repeated PythonTerm classSuperclasses = 3;
PythonTerm classBody = 4;
}
message Comprehension {
PythonTerm comprehensionValue = 1;
PythonTerm comprehensionBody = 2;
}
message Decorator {
PythonTerm decoratorIdentifier = 1;
repeated PythonTerm decoratorParamaters = 2;
PythonTerm decoratorBody = 3;
}
message Function {
repeated PythonTerm functionContext = 1;
PythonTerm functionName = 2;
repeated PythonTerm functionParameters = 3;
PythonTerm functionBody = 4;
}
message Variable {
PythonTerm variableName = 1;
PythonTerm variableType = 2;
PythonTerm variableValue = 3;
}
message Plus {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Minus {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Times {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message DividedBy {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Modulo {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Power {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Negate {
PythonTerm term = 1;
}
message FloorDivision {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message And {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Not {
PythonTerm term = 1;
}
message Or {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message XOr {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message BAnd {
PythonTerm left = 1;
PythonTerm right = 2;
}
message BOr {
PythonTerm left = 1;
PythonTerm right = 2;
}
message BXOr {
PythonTerm left = 1;
PythonTerm right = 2;
}
message LShift {
PythonTerm left = 1;
PythonTerm right = 2;
}
message RShift {
PythonTerm left = 1;
PythonTerm right = 2;
}
message Complement {
PythonTerm value = 1;
}
message Call {
repeated PythonTerm callContext = 1;
PythonTerm callFunction = 2;
repeated PythonTerm callParams = 3;
PythonTerm callBlock = 4;
}
message LessThan {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message LessThanEqual {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message GreaterThan {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message GreaterThanEqual {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Equal {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message StrictEqual {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Comparison {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Enumeration {
PythonTerm enumerationStart = 1;
PythonTerm enumerationEnd = 2;
PythonTerm enumerationStep = 3;
}
message ScopeResolution {
repeated PythonTerm scopes = 1;
}
message MemberAccess {
PythonTerm lhs = 1;
bytes rhs = 2;
}
message Subscript {
PythonTerm lhs = 1;
repeated PythonTerm rhs = 2;
}
message Member {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Array {
repeated PythonTerm arrayElements = 1;
}
message Boolean {
bool booleanContent = 1;
}
message Float {
string floatContent = 1;
}
message Hash {
repeated PythonTerm hashElements = 1;
}
message Integer {
string integerContent = 1;
}
message KeyValue {
PythonTerm key = 1;
PythonTerm value = 2;
}
message Null { }
message Set {
repeated PythonTerm setElements = 1;
}
message String {
repeated PythonTerm stringElements = 1;
}
message TextElement {
string textElementContent = 1;
}
message Tuple {
repeated PythonTerm tupleContents = 1;
}
message Redirect {
PythonTerm lhs = 1;
PythonTerm rhs = 2;
}
message Assignment {
repeated PythonTerm assignmentContext = 1;
PythonTerm assignmentTarget = 2;
PythonTerm assignmentValue = 3;
}
message Break {
PythonTerm term = 1;
}
message Catch {
PythonTerm catchException = 1;
PythonTerm catchBody = 2;
}
message Continue {
PythonTerm term = 1;
}
message Else {
PythonTerm elseCondition = 1;
PythonTerm elseBody = 2;
}
message Finally {
PythonTerm term = 1;
}
message ForEach {
PythonTerm forEachBinding = 1;
PythonTerm forEachSubject = 2;
PythonTerm forEachBody = 3;
}
message If {
PythonTerm ifCondition = 1;
PythonTerm ifThenBody = 2;
PythonTerm ifElseBody = 3;
}
message Let {
PythonTerm letVariable = 1;
PythonTerm letValue = 2;
PythonTerm letBody = 3;
}
message NoOp {
PythonTerm value = 1;
}
message Return {
PythonTerm term = 1;
}
message Statements {
repeated PythonTerm statements = 1;
}
message Throw {
PythonTerm value = 1;
}
message Try {
PythonTerm tryBody = 1;
repeated PythonTerm tryCatch = 2;
}
message While {
PythonTerm whileCondition = 1;
PythonTerm whileBody = 2;
}
message Yield {
PythonTerm term = 1;
}
message Ellipsis { }
message Import {
QualifiedName importFrom = 1;
repeated Alias importSymbols = 2;
}
message QualifiedImport {
repeated string qualifiedImportFrom = 1;
}
message QualifiedAliasedImport {
QualifiedName qualifiedAliasedImportFrom = 1;
PythonTerm qualifiedAliasedImportAlias = 2;
}
message Context {
repeated PythonTerm contextTerms = 1;
PythonTerm contextSubject = 2;
}
message Empty { }
message Error {
repeated ErrorSite errorCallStack = 1;
repeated string errorExpected = 2;
string errorActual = 3;
repeated PythonTerm errorChildren = 4;
}
message Identifier {
bytes name = 1;
}
message Annotation {
PythonTerm annotationSubject = 1;
PythonTerm annotationType = 2;
}
message List {
repeated PythonTerm listContent = 1;
}

View File

@ -0,0 +1,981 @@
// This file was generated by proto-gen. Do not edit by hand.
syntax = "proto3";
package github.semantic.typescript_diffs;
import "types.proto";
option java_package = "com.github.semantic.typescript_diffs";
option go_package = "github.com/semantic/typescript_diffs;typescript";
message TypeScriptDiff {
oneof diff {
Merge merge = 1;
Delete delete = 2;
Insert insert = 3;
Replace replace = 4;
}
message Merge {
TypeScriptSyntax syntax = 1;
}
message Delete {
TypeScriptSyntax before = 1;
}
message Insert {
TypeScriptSyntax after = 1;
}
message Replace {
TypeScriptSyntax before = 1;
TypeScriptSyntax after = 2;
}
}
message Alias {
bytes aliasValue = 1;
bytes aliasName = 2;
}
message ImportPath {
string unPath = 1;
IsRelative pathIsRelative = 2;
}
enum IsRelative {
Unknown = 0;
Relative = 1;
NonRelative = 2;
}
message TypeScriptSyntax {
oneof syntax {
Comment comment = 1;
HashBang hashBang = 2;
Class class = 3;
Function function = 4;
Method method = 5;
MethodSignature methodSignature = 6;
InterfaceDeclaration interfaceDeclaration = 7;
PublicFieldDefinition publicFieldDefinition = 8;
VariableDeclaration variableDeclaration = 9;
TypeAlias typeAlias = 10;
Plus plus = 11;
Minus minus = 12;
Times times = 13;
DividedBy dividedBy = 14;
Modulo modulo = 15;
Power power = 16;
Negate negate = 17;
FloorDivision floorDivision = 18;
BAnd bAnd = 19;
BOr bOr = 20;
BXOr bXOr = 21;
LShift lShift = 22;
RShift rShift = 23;
UnsignedRShift unsignedRShift = 24;
Complement complement = 25;
And and = 26;
Not not = 27;
Or or = 28;
XOr xOr = 29;
Call call = 30;
Cast cast = 31;
LessThan lessThan = 32;
LessThanEqual lessThanEqual = 33;
GreaterThan greaterThan = 34;
GreaterThanEqual greaterThanEqual = 35;
Equal equal = 36;
StrictEqual strictEqual = 37;
Comparison comparison = 38;
Enumeration enumeration = 39;
MemberAccess memberAccess = 40;
NonNullExpression nonNullExpression = 41;
ScopeResolution scopeResolution = 42;
SequenceExpression sequenceExpression = 43;
Subscript subscript = 44;
Member member = 45;
Delete delete = 46;
Void void = 47;
Typeof typeof = 48;
InstanceOf instanceOf = 49;
New new = 50;
Await await = 51;
Array array = 52;
Boolean boolean = 53;
Float float = 54;
Hash hash = 55;
Integer integer = 56;
KeyValue keyValue = 57;
Null null = 58;
String string = 59;
TextElement textElement = 60;
Regex regex = 61;
Assignment assignment = 62;
Break break = 63;
Catch catch = 64;
Continue continue = 65;
DoWhile doWhile = 66;
Else else = 67;
Finally finally = 68;
For for = 69;
ForEach forEach = 70;
If if = 71;
Match match = 72;
Pattern pattern = 73;
Retry retry = 74;
Return return = 75;
ScopeEntry scopeEntry = 76;
ScopeExit scopeExit = 77;
Statements statements = 78;
Throw throw = 79;
Try try = 80;
While while = 81;
Yield yield = 82;
AccessibilityModifier accessibilityModifier = 83;
Empty empty = 84;
Error error = 85;
Identifier identifier = 86;
Context context = 87;
Readonly readonly = 88;
TypeParameters typeParameters = 89;
TypeParameter typeParameter = 90;
Constraint constraint = 91;
ParenthesizedType parenthesizedType = 92;
DefaultType defaultType = 93;
PredefinedType predefinedType = 94;
TypeIdentifier typeIdentifier = 95;
NestedIdentifier nestedIdentifier = 96;
NestedTypeIdentifier nestedTypeIdentifier = 97;
GenericType genericType = 98;
TypeArguments typeArguments = 99;
TypePredicate typePredicate = 100;
CallSignature callSignature = 101;
ConstructSignature constructSignature = 102;
ArrayType arrayType = 103;
LookupType lookupType = 104;
FlowMaybeType flowMaybeType = 105;
TypeQuery typeQuery = 106;
IndexTypeQuery indexTypeQuery = 107;
ThisType thisType = 108;
ExistentialType existentialType = 109;
AbstractMethodSignature abstractMethodSignature = 110;
IndexSignature indexSignature = 111;
ObjectType objectType = 112;
LiteralType literalType = 113;
Union union = 114;
Intersection intersection = 115;
Module module = 116;
InternalModule internalModule = 117;
FunctionType functionType = 118;
Tuple tuple = 119;
Constructor constructor = 120;
TypeAssertion typeAssertion = 121;
ImportAlias importAlias = 122;
Debugger debugger = 123;
ShorthandPropertyIdentifier shorthandPropertyIdentifier = 124;
Super super = 125;
Undefined undefined = 126;
ClassHeritage classHeritage = 127;
AbstractClass abstractClass = 128;
ImplementsClause implementsClause = 129;
JsxElement jsxElement = 130;
JsxSelfClosingElement jsxSelfClosingElement = 131;
JsxOpeningElement jsxOpeningElement = 132;
JsxText jsxText = 133;
JsxClosingElement jsxClosingElement = 134;
JsxExpression jsxExpression = 135;
JsxAttribute jsxAttribute = 136;
JsxFragment jsxFragment = 137;
JsxNamespaceName jsxNamespaceName = 138;
OptionalParameter optionalParameter = 139;
RequiredParameter requiredParameter = 140;
RestParameter restParameter = 141;
PropertySignature propertySignature = 142;
AmbientDeclaration ambientDeclaration = 143;
EnumDeclaration enumDeclaration = 144;
ExtendsClause extendsClause = 145;
AmbientFunction ambientFunction = 146;
ImportRequireClause importRequireClause = 147;
ImportClause importClause = 148;
LabeledStatement labeledStatement = 149;
Annotation annotation = 150;
With with = 151;
ForOf forOf = 152;
This this = 153;
Update update = 154;
ComputedPropertyName computedPropertyName = 155;
Decorator decorator = 156;
Import import = 157;
QualifiedAliasedImport qualifiedAliasedImport = 158;
SideEffectImport sideEffectImport = 159;
DefaultExport defaultExport = 160;
QualifiedExport qualifiedExport = 161;
QualifiedExportFrom qualifiedExportFrom = 162;
JavaScriptRequire javaScriptRequire = 163;
List list = 164;
}
}
message Comment {
string commentContent = 1;
}
message HashBang {
string value = 1;
}
message Class {
repeated TypeScriptDiff classContext = 1;
TypeScriptDiff classIdentifier = 2;
repeated TypeScriptDiff classSuperclasses = 3;
TypeScriptDiff classBody = 4;
}
message Function {
repeated TypeScriptDiff functionContext = 1;
TypeScriptDiff functionName = 2;
repeated TypeScriptDiff functionParameters = 3;
TypeScriptDiff functionBody = 4;
}
message Method {
repeated TypeScriptDiff methodContext = 1;
TypeScriptDiff methodReceiver = 2;
TypeScriptDiff methodName = 3;
repeated TypeScriptDiff methodParameters = 4;
TypeScriptDiff methodBody = 5;
}
message MethodSignature {
repeated TypeScriptDiff methodSignatureContext = 1;
TypeScriptDiff methodSignatureName = 2;
repeated TypeScriptDiff methodSignatureParameters = 3;
}
message InterfaceDeclaration {
repeated TypeScriptDiff interfaceDeclarationContext = 1;
TypeScriptDiff interfaceDeclarationIdentifier = 2;
TypeScriptDiff interfaceDeclarationBody = 3;
}
message PublicFieldDefinition {
repeated TypeScriptDiff publicFieldContext = 1;
TypeScriptDiff publicFieldPropertyName = 2;
TypeScriptDiff publicFieldValue = 3;
}
message VariableDeclaration {
repeated TypeScriptDiff variableDeclarations = 1;
}
message TypeAlias {
repeated TypeScriptDiff typeAliasContext = 1;
TypeScriptDiff typeAliasIdentifier = 2;
TypeScriptDiff typeAliasKind = 3;
}
message Plus {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Minus {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Times {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message DividedBy {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Modulo {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Power {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Negate {
TypeScriptDiff term = 1;
}
message FloorDivision {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message BAnd {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message BOr {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message BXOr {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message LShift {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message RShift {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message UnsignedRShift {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message Complement {
TypeScriptDiff value = 1;
}
message And {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Not {
TypeScriptDiff term = 1;
}
message Or {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message XOr {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Call {
repeated TypeScriptDiff callContext = 1;
TypeScriptDiff callFunction = 2;
repeated TypeScriptDiff callParams = 3;
TypeScriptDiff callBlock = 4;
}
message Cast {
TypeScriptDiff castSubject = 1;
TypeScriptDiff castType = 2;
}
message LessThan {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message LessThanEqual {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message GreaterThan {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message GreaterThanEqual {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Equal {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message StrictEqual {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Comparison {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Enumeration {
TypeScriptDiff enumerationStart = 1;
TypeScriptDiff enumerationEnd = 2;
TypeScriptDiff enumerationStep = 3;
}
message MemberAccess {
TypeScriptDiff lhs = 1;
bytes rhs = 2;
}
message NonNullExpression {
TypeScriptDiff nonNullExpression = 1;
}
message ScopeResolution {
repeated TypeScriptDiff scopes = 1;
}
message SequenceExpression {
TypeScriptDiff firstExpression = 1;
TypeScriptDiff secondExpression = 2;
}
message Subscript {
TypeScriptDiff lhs = 1;
repeated TypeScriptDiff rhs = 2;
}
message Member {
TypeScriptDiff lhs = 1;
TypeScriptDiff rhs = 2;
}
message Delete {
TypeScriptDiff value = 1;
}
message Void {
TypeScriptDiff value = 1;
}
message Typeof {
TypeScriptDiff value = 1;
}
message InstanceOf {
TypeScriptDiff instanceOfSubject = 1;
TypeScriptDiff instanceOfObject = 2;
}
message New {
repeated TypeScriptDiff newSubject = 1;
}
message Await {
TypeScriptDiff awaitSubject = 1;
}
message Array {
repeated TypeScriptDiff arrayElements = 1;
}
message Boolean {
bool booleanContent = 1;
}
message Float {
string floatContent = 1;
}
message Hash {
repeated TypeScriptDiff hashElements = 1;
}
message Integer {
string integerContent = 1;
}
message KeyValue {
TypeScriptDiff key = 1;
TypeScriptDiff value = 2;
}
message Null { }
message String {
repeated TypeScriptDiff stringElements = 1;
}
message TextElement {
string textElementContent = 1;
}
message Regex {
string regexContent = 1;
}
message Assignment {
repeated TypeScriptDiff assignmentContext = 1;
TypeScriptDiff assignmentTarget = 2;
TypeScriptDiff assignmentValue = 3;
}
message Break {
TypeScriptDiff term = 1;
}
message Catch {
TypeScriptDiff catchException = 1;
TypeScriptDiff catchBody = 2;
}
message Continue {
TypeScriptDiff term = 1;
}
message DoWhile {
TypeScriptDiff doWhileCondition = 1;
TypeScriptDiff doWhileBody = 2;
}
message Else {
TypeScriptDiff elseCondition = 1;
TypeScriptDiff elseBody = 2;
}
message Finally {
TypeScriptDiff term = 1;
}
message For {
TypeScriptDiff forBefore = 1;
TypeScriptDiff forCondition = 2;
TypeScriptDiff forStep = 3;
TypeScriptDiff forBody = 4;
}
message ForEach {
TypeScriptDiff forEachBinding = 1;
TypeScriptDiff forEachSubject = 2;
TypeScriptDiff forEachBody = 3;
}
message If {
TypeScriptDiff ifCondition = 1;
TypeScriptDiff ifThenBody = 2;
TypeScriptDiff ifElseBody = 3;
}
message Match {
TypeScriptDiff matchSubject = 1;
TypeScriptDiff matchPatterns = 2;
}
message Pattern {
TypeScriptDiff value = 1;
TypeScriptDiff patternBody = 2;
}
message Retry {
TypeScriptDiff term = 1;
}
message Return {
TypeScriptDiff term = 1;
}
message ScopeEntry {
repeated TypeScriptDiff terms = 1;
}
message ScopeExit {
repeated TypeScriptDiff terms = 1;
}
message Statements {
repeated TypeScriptDiff statements = 1;
}
message Throw {
TypeScriptDiff value = 1;
}
message Try {
TypeScriptDiff tryBody = 1;
repeated TypeScriptDiff tryCatch = 2;
}
message While {
TypeScriptDiff whileCondition = 1;
TypeScriptDiff whileBody = 2;
}
message Yield {
TypeScriptDiff term = 1;
}
message AccessibilityModifier {
string contents = 1;
}
message Empty { }
message Error {
repeated ErrorSite errorCallStack = 1;
repeated string errorExpected = 2;
string errorActual = 3;
repeated TypeScriptDiff errorChildren = 4;
}
message Identifier {
bytes name = 1;
}
message Context {
repeated TypeScriptDiff contextTerms = 1;
TypeScriptDiff contextSubject = 2;
}
message Readonly { }
message TypeParameters {
repeated TypeScriptDiff terms = 1;
}
message TypeParameter {
TypeScriptDiff typeParameter = 1;
TypeScriptDiff typeParameterConstraint = 2;
TypeScriptDiff typeParameterDefaultType = 3;
}
message Constraint {
TypeScriptDiff constraintType = 1;
}
message ParenthesizedType {
TypeScriptDiff parenthesizedType = 1;
}
message DefaultType {
TypeScriptDiff defaultType = 1;
}
message PredefinedType {
string predefinedType = 1;
}
message TypeIdentifier {
string contents = 1;
}
message NestedIdentifier {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message NestedTypeIdentifier {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message GenericType {
TypeScriptDiff genericTypeIdentifier = 1;
TypeScriptDiff genericTypeArguments = 2;
}
message TypeArguments {
repeated TypeScriptDiff typeArguments = 1;
}
message TypePredicate {
TypeScriptDiff typePredicateIdentifier = 1;
TypeScriptDiff typePredicateType = 2;
}
message CallSignature {
TypeScriptDiff callSignatureTypeParameters = 1;
repeated TypeScriptDiff callSignatureParameters = 2;
TypeScriptDiff callSignatureType = 3;
}
message ConstructSignature {
TypeScriptDiff constructSignatureTypeParameters = 1;
repeated TypeScriptDiff constructSignatureParameters = 2;
TypeScriptDiff constructSignatureType = 3;
}
message ArrayType {
TypeScriptDiff arrayType = 1;
}
message LookupType {
TypeScriptDiff lookupTypeIdentifier = 1;
TypeScriptDiff lookupTypeKey = 2;
}
message FlowMaybeType {
TypeScriptDiff flowMaybeType = 1;
}
message TypeQuery {
TypeScriptDiff typeQuerySubject = 1;
}
message IndexTypeQuery {
TypeScriptDiff indexTypeQuerySubject = 1;
}
message ThisType {
string contents = 1;
}
message ExistentialType {
string contents = 1;
}
message AbstractMethodSignature {
repeated TypeScriptDiff abstractMethodSignatureContext = 1;
TypeScriptDiff abstractMethodSignatureName = 2;
repeated TypeScriptDiff abstractMethodSignatureParameters = 3;
}
message IndexSignature {
TypeScriptDiff indexSignatureSubject = 1;
TypeScriptDiff indexSignatureType = 2;
}
message ObjectType {
repeated TypeScriptDiff objectTypeElements = 1;
}
message LiteralType {
TypeScriptDiff literalTypeSubject = 1;
}
message Union {
TypeScriptDiff unionLeft = 1;
TypeScriptDiff unionRight = 2;
}
message Intersection {
TypeScriptDiff intersectionLeft = 1;
TypeScriptDiff intersectionRight = 2;
}
message Module {
TypeScriptDiff moduleIdentifier = 1;
repeated TypeScriptDiff moduleStatements = 2;
}
message InternalModule {
TypeScriptDiff internalModuleIdentifier = 1;
repeated TypeScriptDiff internalModuleStatements = 2;
}
message FunctionType {
TypeScriptDiff functionTypeParameters = 1;
repeated TypeScriptDiff functionFormalParameters = 2;
TypeScriptDiff functionType = 3;
}
message Tuple {
repeated TypeScriptDiff tupleElements = 1;
}
message Constructor {
TypeScriptDiff constructorTypeParameters = 1;
repeated TypeScriptDiff constructorFormalParameters = 2;
TypeScriptDiff constructorType = 3;
}
message TypeAssertion {
TypeScriptDiff typeAssertionParameters = 1;
TypeScriptDiff typeAssertionExpression = 2;
}
message ImportAlias {
TypeScriptDiff importAliasSubject = 1;
TypeScriptDiff importAlias = 2;
}
message Debugger { }
message ShorthandPropertyIdentifier {
string contents = 1;
}
message Super { }
message Undefined { }
message ClassHeritage {
TypeScriptDiff classHeritageExtendsClause = 1;
TypeScriptDiff implementsClause = 2;
}
message AbstractClass {
TypeScriptDiff abstractClassIdentifier = 1;
TypeScriptDiff abstractClassTypeParameters = 2;
repeated TypeScriptDiff classHeritage = 3;
TypeScriptDiff classBody = 4;
}
message ExtendsClause {
repeated TypeScriptDiff extendsClauses = 1;
}
message ImplementsClause {
repeated TypeScriptDiff implementsClauseTypes = 1;
}
message JsxElement {
TypeScriptDiff jsxOpeningElement = 1;
repeated TypeScriptDiff jsxElements = 2;
TypeScriptDiff jsxClosingElement = 3;
}
message JsxSelfClosingElement {
TypeScriptDiff jsxSelfClosingElementIdentifier = 1;
repeated TypeScriptDiff jsxSelfClosingElementAttributes = 2;
}
message JsxOpeningElement {
TypeScriptDiff jsxOpeningElementIdentifier = 1;
repeated TypeScriptDiff jsxAttributes = 2;
}
message JsxText {
string contents = 1;
}
message JsxClosingElement {
TypeScriptDiff jsxClosingElementIdentifier = 1;
}
message JsxExpression {
TypeScriptDiff jsxExpression = 1;
}
message JsxAttribute {
TypeScriptDiff jsxAttributeTarget = 1;
TypeScriptDiff jsxAttributeValue = 2;
}
message JsxFragment {
repeated TypeScriptDiff terms = 1;
}
message JsxNamespaceName {
TypeScriptDiff left = 1;
TypeScriptDiff right = 2;
}
message OptionalParameter {
repeated TypeScriptDiff optionalParameterContext = 1;
TypeScriptDiff optionalParameterSubject = 2;
}
message RequiredParameter {
repeated TypeScriptDiff requiredParameterContext = 1;
TypeScriptDiff requiredParameterSubject = 2;
}
message RestParameter {
repeated TypeScriptDiff restParameterContext = 1;
TypeScriptDiff restParameterSubject = 2;
}
message PropertySignature {
repeated TypeScriptDiff modifiers = 1;
TypeScriptDiff propertySignaturePropertyName = 2;
}
message AmbientDeclaration {
TypeScriptDiff ambientDeclarationBody = 1;
}
message EnumDeclaration {
TypeScriptDiff enumDeclarationIdentifier = 1;
repeated TypeScriptDiff enumDeclarationBody = 2;
}
message AmbientFunction {
repeated TypeScriptDiff ambientFunctionContext = 1;
TypeScriptDiff ambientFunctionIdentifier = 2;
repeated TypeScriptDiff ambientFunctionParameters = 3;
}
message ImportRequireClause {
TypeScriptDiff importRequireIdentifier = 1;
TypeScriptDiff importRequireSubject = 2;
}
message ImportClause {
repeated TypeScriptDiff importClauseElements = 1;
}
message LabeledStatement {
TypeScriptDiff labeledStatementIdentifier = 1;
TypeScriptDiff labeledStatementSubject = 2;
}
message Annotation {
TypeScriptDiff annotationType = 1;
}
message With {
TypeScriptDiff withExpression = 1;
TypeScriptDiff withBody = 2;
}
message ForOf {
TypeScriptDiff forOfBinding = 1;
TypeScriptDiff forOfSubject = 2;
TypeScriptDiff forOfBody = 3;
}
message This { }
message Update {
TypeScriptDiff updateSubject = 1;
}
message ComputedPropertyName {
TypeScriptDiff propertyName = 1;
}
message Decorator {
TypeScriptDiff decoratorTerm = 1;
}
message Import {
repeated Alias importSymbols = 1;
ImportPath importFrom = 2;
}
message QualifiedAliasedImport {
TypeScriptDiff qualifiedAliasedImportAlias = 1;
ImportPath qualifiedAliasedImportFrom = 2;
}
message SideEffectImport {
ImportPath sideEffectImportFrom = 1;
}
message DefaultExport {
TypeScriptDiff defaultExport = 1;
}
message QualifiedExport {
repeated Alias qualifiedExportSymbols = 1;
}
message QualifiedExportFrom {
ImportPath qualifiedExportFrom = 1;
repeated Alias qualifiedExportFromSymbols = 2;
}
message JavaScriptRequire {
TypeScriptDiff javascriptRequireIden = 1;
ImportPath javascriptRequireFrom = 2;
}
message List {
repeated TypeScriptDiff listContent = 1;
}

View File

@ -235,7 +235,7 @@ instance Show1 Retry where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Retry
newtype NoOp a = NoOp a
newtype NoOp a = NoOp { value :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)
instance Eq1 NoOp where liftEq = genericLiftEq

View File

@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME
module Language.Python.Assignment
( assignment
, Syntax
@ -6,10 +7,14 @@ module Language.Python.Assignment
, Term
) where
import Assigning.Assignment hiding (Assignment, Error)
import Data.Abstract.Name (Name, name)
import Data.Record
import Data.Syntax
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import Data.Abstract.Name (Name, name)
import qualified Data.Diff as Diff
import qualified Data.List.NonEmpty as NonEmpty
import Data.Record
import Data.Sum
import Data.Syntax
( contextualize
, emptyTerm
, handleError
@ -21,11 +26,6 @@ import Data.Syntax
, parseError
, postContextualize
)
import Language.Python.Grammar as Grammar
import Language.Python.Syntax as Python.Syntax
import qualified Assigning.Assignment as Assignment
import qualified Data.List.NonEmpty as NonEmpty
import Data.Sum
import qualified Data.Syntax as Syntax
import qualified Data.Syntax.Comment as Comment
import qualified Data.Syntax.Declaration as Declaration
@ -35,7 +35,10 @@ import qualified Data.Syntax.Statement as Statement
import qualified Data.Syntax.Type as Type
import qualified Data.Term as Term
import qualified Data.Text as T
import Prologue
import Language.Python.Grammar as Grammar
import Language.Python.Syntax as Python.Syntax
import Prologue
import Proto3.Suite (Named (..), Named1 (..))
-- | The type of Python syntax.
@ -120,6 +123,15 @@ type Syntax =
type Term = Term.Term (Sum Syntax) (Record Location)
type Assignment = Assignment.Assignment [] Grammar
instance Named1 (Sum Syntax) where
nameOf1 _ = "PythonSyntax"
instance Named (Term.Term (Sum Syntax) ()) where
nameOf _ = "PythonTerm"
instance Named (Diff.Diff (Sum Syntax) () ()) where
nameOf _ = "PythonDiff"
-- | Assignment from AST in Python's grammar onto a program in Python's syntax.
assignment :: Assignment Term
assignment = handleError $ makeTerm <$> symbol Module <*> children (Statement.Statements <$> manyTerm expression) <|> parseError
@ -415,8 +427,8 @@ import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliase
identifierSource = (symbol Identifier <|> symbol Identifier') *> source
aliasIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source) <|> symbol DottedName *> (name <$> source)
makeNameAliasPair from (Just alias) = (from, alias)
makeNameAliasPair from Nothing = (from, from)
makeNameAliasPair from (Just alias) = Python.Syntax.Alias from alias
makeNameAliasPair from Nothing = Python.Syntax.Alias from from
assertStatement :: Assignment Term
assertStatement = makeTerm <$> symbol AssertStatement <*> children (Expression.Call [] <$> (makeTerm <$> symbol AnonAssert <*> (Syntax.Identifier . name <$> source)) <*> manyTerm expression <*> emptyTerm)

View File

@ -1,5 +1,6 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# OPTIONS_GHC -Wno-missing-export-lists #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME
module Language.Python.Syntax where
import Data.Abstract.Environment as Env
@ -15,11 +16,24 @@ import Diffing.Algorithm
import GHC.Generics
import Prologue
import System.FilePath.Posix
import Proto3.Suite (Primitive(..), Message(..), Message1(..), Named1(..), Named(..), MessageField(..), DotProtoIdentifier(..), DotProtoPrimType(..), DotProtoType(..), messageField)
import qualified Proto3.Suite as Proto
import qualified Proto3.Wire.Encode as Encode
import qualified Proto3.Wire.Decode as Decode
data QualifiedName
= QualifiedName (NonEmpty FilePath)
| RelativeQualifiedName FilePath (Maybe QualifiedName)
deriving (Eq, Generic, Hashable, Ord, Show, ToJSON)
= QualifiedName { paths :: NonEmpty FilePath }
| RelativeQualifiedName { path :: FilePath, maybeQualifiedName :: Maybe QualifiedName }
deriving (Eq, Generic, Hashable, Ord, Show, ToJSON, Named, Message)
instance MessageField QualifiedName where
encodeMessageField num QualifiedName{..} = Encode.embedded num (encodeMessageField 1 paths)
encodeMessageField num RelativeQualifiedName{..} = Encode.embedded num (encodeMessageField 1 path <> encodeMessageField 2 maybeQualifiedName)
decodeMessageField = Decode.embedded'' (qualifiedName <|> relativeQualifiedName)
where
qualifiedName = QualifiedName <$> Decode.at decodeMessageField 1
relativeQualifiedName = RelativeQualifiedName <$> Decode.at decodeMessageField 1 <*> Decode.at decodeMessageField 2
protoType _ = messageField (Prim $ Named (Single (nameOf (Proxy @QualifiedName)))) Nothing
qualifiedName :: NonEmpty Text -> QualifiedName
qualifiedName xs = QualifiedName (T.unpack <$> xs)
@ -86,20 +100,27 @@ resolvePythonModules q = do
-- | Import declarations (symbols are added directly to the calling environment).
--
-- If the list of symbols is empty copy everything to the calling environment.
data Import a = Import { importFrom :: QualifiedName, importSymbols :: ![(Name, Name)] }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable)
data Import a = Import { importFrom :: QualifiedName, importSymbols :: ![Alias] }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 Import where liftEq = genericLiftEq
instance Ord1 Import where liftCompare = genericLiftCompare
instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
data Alias = Alias { aliasValue :: Name, aliasName :: Name }
deriving (Eq, Generic, Hashable, Ord, Show, Message, Named, ToJSON)
toTuple :: Alias -> (Name, Name)
toTuple Alias{..} = (aliasValue, aliasName)
-- from a import b
instance Evaluatable Import where
-- from . import moduleY
-- This is a bit of a special case in the syntax as this actually behaves like a qualified relative import.
eval (Import (RelativeQualifiedName n Nothing) [(name, _)]) = do
path <- NonEmpty.last <$> resolvePythonModules (RelativeQualifiedName n (Just (qualifiedName (formatName name :| []))))
rvalBox =<< evalQualifiedImport name path
eval (Import (RelativeQualifiedName n Nothing) [Alias{..}]) = do
path <- NonEmpty.last <$> resolvePythonModules (RelativeQualifiedName n (Just (qualifiedName (formatName aliasValue :| []))))
rvalBox =<< evalQualifiedImport aliasValue path
-- from a import b
-- from a import b as c
@ -119,7 +140,7 @@ instance Evaluatable Import where
where
select importedEnv
| Prologue.null xs = importedEnv
| otherwise = Env.overwrite xs importedEnv
| otherwise = Env.overwrite (toTuple <$> xs) importedEnv
-- Evaluate a qualified import
@ -135,7 +156,19 @@ evalQualifiedImport name path = letrec' name $ \addr -> do
unit <$ makeNamespace name addr Nothing
newtype QualifiedImport a = QualifiedImport { qualifiedImportFrom :: NonEmpty FilePath }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable)
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Message1 QualifiedImport where
liftEncodeMessage _ _ QualifiedImport{..} = encodeMessageField 1 qualifiedImportFrom
liftDecodeMessage _ _ = QualifiedImport <$> Decode.at decodeMessageField 1
liftDotProto _ = [ Proto.DotProtoMessageField $ Proto.DotProtoField 1 (Repeated Proto.String) (Single "qualifiedImportFrom") [] Nothing ]
instance Named Prelude.String where nameOf _ = "string"
instance Message Prelude.String where
encodeMessage _ = encodePrimitive 1
decodeMessage _ = Decode.at (Decode.one decodePrimitive mempty) 1
dotProto = undefined
instance Eq1 QualifiedImport where liftEq = genericLiftEq
instance Ord1 QualifiedImport where liftCompare = genericLiftCompare
@ -156,7 +189,7 @@ instance Evaluatable QualifiedImport where
makeNamespace name addr Nothing
data QualifiedAliasedImport a = QualifiedAliasedImport { qualifiedAliasedImportFrom :: QualifiedName, qualifiedAliasedImportAlias :: !a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable)
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 QualifiedAliasedImport where liftEq = genericLiftEq
instance Ord1 QualifiedAliasedImport where liftCompare = genericLiftCompare
@ -180,7 +213,7 @@ instance Evaluatable QualifiedAliasedImport where
-- | Ellipsis (used in splice expressions and alternatively can be used as a fill in expression, like `undefined` in Haskell)
data Ellipsis a = Ellipsis
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable)
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 Ellipsis where liftEq = genericLiftEq
instance Ord1 Ellipsis where liftCompare = genericLiftCompare
@ -190,8 +223,8 @@ instance Show1 Ellipsis where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Ellipsis
data Redirect a = Redirect !a !a
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable)
data Redirect a = Redirect { lhs :: a, rhs :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 Redirect where liftEq = genericLiftEq
instance Ord1 Redirect where liftCompare = genericLiftCompare

View File

@ -1,6 +1,7 @@
{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, ScopedTypeVariables #-}
module Semantic.Diff
( runDiff
, runPythonDiff
, runRubyDiff
, runTypeScriptDiff
, runJSONDiff
@ -27,6 +28,7 @@ import Serializing.Format
import qualified Language.TypeScript.Assignment as TypeScript
import qualified Language.Ruby.Assignment as Ruby
import qualified Language.JSON.Assignment as JSON
import qualified Language.Python.Assignment as Python
runDiff :: (Member Distribute effs, Member (Exc SomeException) effs, Member (Lift IO) effs, Member Task effs, Member Telemetry effs) => DiffRenderer output -> [BlobPair] -> Eff effs Builder
runDiff ToCDiffRenderer = withParsedBlobPairs (decorate . declarationAlgebra) (render . renderToCDiff) >=> serialize JSON
@ -57,6 +59,17 @@ runTypeScriptDiff = flip distributeFor (\ (blobs :: BlobPair) -> do
diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag)
where languageTag = languageTagForBlobPair blobs
runPythonDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum Python.Syntax) () ()]
runPythonDiff = flip distributeFor (\ (blobs :: BlobPair) -> do
terms <- distributeFor blobs (parse pythonParser)
diffs <- diffTerms blobs terms
pure (bimap (const ()) (const ()) diffs))
where
diffTerms blobs terms = time "diff" languageTag $ do
diff <- diff (runJoin terms)
diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag)
where languageTag = languageTagForBlobPair blobs
runJSONDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum JSON.Syntax) () ()]
runJSONDiff = flip distributeFor (\ (blobs :: BlobPair) -> do
terms <- distributeFor blobs (parse jsonParser)

View File

@ -1,6 +1,7 @@
{-# LANGUAGE GADTs, RankNTypes #-}
module Semantic.Parse
( runParse
, runPythonParse
, runRubyParse
, runTypeScriptParse
, runJSONParse
@ -24,6 +25,7 @@ import Serializing.Format
import qualified Language.Ruby.Assignment as Ruby
import qualified Language.TypeScript.Assignment as TypeScript
import qualified Language.JSON.Assignment as JSON
import qualified Language.Python.Assignment as Python
runParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => TermRenderer output -> [Blob] -> Eff effs Builder
runParse JSONTermRenderer = withParsedBlobs (render . renderJSONTerm) >=> serialize JSON
@ -42,6 +44,11 @@ runTypeScriptParse = flip distributeFor (\ blob -> do
term <- parse typescriptParser blob
pure (() <$ term))
runPythonParse :: (Member Distribute effs, Member Task effs) => [Blob] -> Eff effs [Term (Sum Python.Syntax) ()]
runPythonParse = flip distributeFor (\ blob -> do
term <- parse pythonParser blob
pure (() <$ term))
runJSONParse :: (Member Distribute effs, Member Task effs) => [Blob] -> Eff effs [Term (Sum JSON.Syntax) ()]
runJSONParse = flip distributeFor (\ blob -> do
term <- parse jsonParser blob

View File

@ -53,6 +53,7 @@ import qualified Data.Syntax.Directive as Directive
import qualified Data.Syntax.Statement as Statement
import qualified Data.Syntax.Expression as Expression
import qualified Language.Ruby.Syntax as Ruby.Syntax
import qualified Language.Python.Syntax as Python.Syntax
import qualified Data.Abstract.Name as Name
import Data.Term
import Data.Text as T (Text, pack)
@ -478,6 +479,15 @@ instance Listable1 Ruby.Syntax.Require where
instance Listable1 Ruby.Syntax.Send where
liftTiers tiers = liftCons4 (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) Ruby.Syntax.Send
instance Listable Python.Syntax.QualifiedName where
tiers = liftCons1 tiers1 Python.Syntax.QualifiedName \/ liftCons2 tiers tiers1 Python.Syntax.RelativeQualifiedName
instance Listable1 Python.Syntax.Import where
liftTiers tiers = cons2 Python.Syntax.Import
instance Listable Python.Syntax.Alias where
tiers = cons2 Python.Syntax.Alias
type ListableSyntax = Sum
'[ Comment.Comment

View File

@ -19,6 +19,7 @@ import Data.Diff (Diff)
import Data.Sum
import Language.Ruby.Assignment (Syntax)
import qualified Language.Ruby.Assignment as Ruby
import qualified Language.Python.Syntax as Python
import Data.Functor.Classes
import qualified Data.Syntax.Expression as Expression