import { CaseStyle } from "./Casing/CaseStyle" ; import { Import } from "./Imports/Import" ; import { ImportRelativity } from "./Imports/ImportRelativity" ; import { Language } from "./Language" ; import { GeneralProperties } from "./Properties/GeneralProperties" ; import { ProjectProperties } from "./Properties/ProjectProperties" ; import { ArrayNewSizedSyntax } from "./Properties/Syntax/ArrayNewSizedSyntax" ; import { ArraySyntax } from "./Properties/Syntax/ArraySyntax" ; import { BooleanSyntax } from "./Properties/Syntax/BooleanSyntax" ; import { ClassGenericSyntax } from "./Properties/Syntax/ClassGenericSyntax" ; import { ClassMemberFunctionSyntax } from "./Properties/Syntax/ClassMemberFunctionSyntax" ; import { ClassMemberVariableSyntax } from "./Properties/Syntax/ClassMemberVariableSyntax" ; import { ClassStaticFunctionSyntax } from "./Properties/Syntax/ClassStaticFunctionSyntax" ; import { ClassStaticVariableSyntax } from "./Properties/Syntax/ClassStaticVariableSyntax" ; import { ClassSyntax } from "./Properties/Syntax/ClassSyntax" ; import { CommentSyntax } from "./Properties/Syntax/CommentSyntax" ; import { ConditionalSyntax } from "./Properties/Syntax/ConditionalSyntax" ; import { DictionarySyntax } from "./Properties/Syntax/DictionarySyntax" ; import { EnumSyntax } from "./Properties/Syntax/EnumSyntax" ; import { ExceptionSyntax } from "./Properties/Syntax/ExceptionSyntax" ; import { ExportSyntax } from "./Properties/Syntax/ExportSyntax" ; import { FileSyntax } from "./Properties/Syntax/FileSyntax" ; import { FunctionSyntax } from "./Properties/Syntax/FunctionSyntax" ; import { ImportSyntax } from "./Properties/Syntax/ImportSyntax" ; import { InterfaceSyntax } from "./Properties/Syntax/InterfaceSyntax" ; import { LambdaSyntax } from "./Properties/Syntax/LambdaSyntax" ; import { LambdaTypeInlineSyntax } from "./Properties/Syntax/LambdaTypeInlineSyntax" ; import { ListNewItemsSyntax } from "./Properties/Syntax/ListNewItemsSyntax" ; import { ListNewSizedSyntax } from "./Properties/Syntax/ListNewSizedSyntax" ; import { ListSliceSupport , ListSliceSyntax } from "./Properties/Syntax/ListSliceSyntax" ; import { ListSortMembersSyntax , ListSortMemberType } from "./Properties/Syntax/ListSortMembersSyntax" ; import { ListSyntax } from "./Properties/Syntax/ListSyntax" ; import { LoopSyntax } from "./Properties/Syntax/LoopSyntax" ; import { MainSyntax } from "./Properties/Syntax/MainSyntax" ; import { MathSyntax } from "./Properties/Syntax/MathSyntax" ; import { NativeCallScope , NativeCallSyntax , NativeCallType } from "./Properties/Syntax/NativeCallSyntax" ; import { NewInstantiationSyntaxKind , NewSyntax } from "./Properties/Syntax/NewSyntax" ; import { OperatorSyntax } from "./Properties/Syntax/OperatorSyntax" ; import { ParameterSyntax } from "./Properties/Syntax/ParameterSyntax" ; import { PrintingSyntax } from "./Properties/Syntax/PrintingSyntax" ; import { SetSyntax } from "./Properties/Syntax/SetSyntax" ; import { StandaloneFunctionSyntax } from "./Properties/Syntax/StandaloneFunctionSyntax" ; import { StringFormatSyntax } from "./Properties/Syntax/StringFormatSyntax" ; import { StringSubstringSupport , StringSubstringSyntax } from "./Properties/Syntax/StringSubstringSyntax" ; import { StringSyntax } from "./Properties/Syntax/StringSyntax" ; import { StringToNumberStartConversionType , StringToNumberSyntax } from "./Properties/Syntax/StringToNumberSyntax" ; import { StyleSyntax } from "./Properties/Syntax/StyleSyntax" ; import { UnsupportedSyntax } from "./Properties/Syntax/UnsupportedSyntax" ; import { VariableSyntax } from "./Properties/Syntax/VariableSyntax" ; /**
 * A summary of information for the Python language.
 */ export class Python extends Language { param general protected generateGeneralProperties ( general ) { general . directoryCase = CaseStyle . SnakeCase ; general . extension = ".py" ; general . fileCase = CaseStyle . SnakeCase ; general . name = "Python" ; } param projects protected generateProjectProperties ( projects ) { projects . mainFile = "main.py" ; projects . metadataFiles = { } ; projects . nameFormat = CaseStyle . DashLowerCase ; } param generics protected generateClassGenericSyntax ( generics ) { } param arrays protected generateArraySyntax ( arrays ) { arrays . className = "list" ; arrays . length = new NativeCallSyntax ( "len" , NativeCallScope . Static , NativeCallType . Function ) ; arrays . newGenericCastRequired = false ; arrays . requiredImports = [ ] ; } param arrays protected generateArrayNewSizedSyntax ( newSized ) { newSized . includeType = false ; newSized . left = "[None] * " ; newSized . right = "" ; } param booleans protected generateBooleanSyntax ( booleans ) { booleans . className = "bool" ; } param members protected generateClassMemberFunctionSyntax ( functions ) { functions . includeThisReference = true ; functions . private = "def " ; functions . privateCase = CaseStyle . SnakeCase ; functions . privatePrefix = "__" ; functions . protected = "def " ; functions . protectedCase = CaseStyle . SnakeCase ; functions . protectedPrefix = "_" ; functions . public = "def " ; functions . publicCase = CaseStyle . SnakeCase ; functions . publicPrefix = "" ; } param members protected generateClassMemberVariableSyntax ( variables ) { variables . publicPrefix = "" ; variables . skipMemberVariables = true ; variables . privateCase = CaseStyle . SnakeCase ; variables . privatePrefix = "__" ; variables . protectedCase = CaseStyle . SnakeCase ; variables . protectedPrefix = "_" ; variables . publicCase = CaseStyle . CamelCase ; } param classes protected generateClassSyntax ( classes ) { classes . constructors . private = "" ; classes . constructors . protected = "" ; classes . constructors . public = "" ; classes . constructors . useKeyword = true ; classes . newStart = "new " ; classes . this = "self" ; classes . abstractDeclaration = "" ; classes . aliases = { char : "string" , dictionary : "dict" , number : "double" , } ; classes . constructors . baseConstructor = "super().__init__" ; classes . constructors . keyword = "def __init__" ; classes . constructors . takeThis = true ; classes . declareEnd = "\0" ; classes . declareExtendsLeft = "(" ; classes . declareExtendsRight = ")" ; classes . declareStartLeft = "class " ; classes . declareStartRight = ":" ; classes . instanceOf = new NativeCallSyntax ( "isinstance" , NativeCallScope . Static , NativeCallType . Function ) ; classes . statics . labelBeforePublicity = true ; } param functions protected generateClassStaticFunctionSyntax ( functions ) { functions . label = "@staticmethod\n" ; functions . private = "def " ; functions . privateCase = CaseStyle . SnakeCase ; functions . privatePrefix = "__" ; functions . protected = "def " ; functions . protectedCase = CaseStyle . SnakeCase ; functions . protectedPrefix = "_" ; functions . public = "def " ; functions . publicCase = CaseStyle . SnakeCase ; functions . publicPrefix = "" ; } param members protected generateClassStaticVariableSyntax ( variables ) { variables . private = "" ; variables . protected = "" ; variables . public = "" ; variables . skipStaticVariables = true ; variables . label = "" ; variables . privateCase = CaseStyle . SnakeCase ; variables . privatePrefix = "__" ; variables . protectedCase = CaseStyle . SnakeCase ; variables . protectedPrefix = "_" ; variables . publicCase = CaseStyle . CamelCase ; variables . publicPrefix = "" ; } param comments protected generateCommentSyntax ( comments ) { comments . blockEnd = '"""' ; comments . blockLineLeft = "" ; comments . blockLineRight = "" ; comments . blockStart = '"""' ; comments . docEnd = '"""' ; comments . docLineEnd = "" ; comments . docLineStart = "" ; comments . docStart = '"""' ; comments . docTagAliases = { note : "remarks" , parameter : "param" , returns : "returns" , summary : "" , todo : "todo" , } ; comments . docTagsWithParameters = { parameter : "" , } ; comments . docTagEnd = " " ; comments . docTagSpaceAfter = "  " ; comments . docTagStart = ":" ; comments . lineLeft = "# " ; comments . lineRight = "" ; } param conditionals protected generateConditionalSyntax ( conditionals ) { conditionals . continueLeft = "" ; conditionals . else = "else" ; conditionals . end = "\0" ; conditionals . if = "if" ; conditionals . startLeft = " " ; conditionals . continueRight = ":" ; conditionals . elif = "elif" ; conditionals . startRight = ":" ; } param dictionaries protected generateDictionarySyntax ( dictionaries ) { dictionaries . className = "dict" ; dictionaries . containsKey = new NativeCallSyntax ( " in " , NativeCallScope . Operator , NativeCallType . FloatingLeft ) ; dictionaries . getLeft = "[" ; dictionaries . getRight = "]" ; dictionaries . initializeAsLiteral = "{}" ; dictionaries . initializeEnd = "}" ; dictionaries . initializePairComma = "," ; dictionaries . initializePairLeft = "" ; dictionaries . initializePairMiddle = ": " ; dictionaries . initializePairRight = "" ; dictionaries . initializeStart = "{" ; dictionaries . keys = new NativeCallSyntax ( "keys" , NativeCallScope . Member , NativeCallType . Function ) ; dictionaries . setLeft = "[" ; dictionaries . setMiddle = "] = " ; dictionaries . setRight = "" ; } param enums protected generateEnumSyntax ( enums ) { enums . declareCommaRight = "" ; enums . declareLastRight = "" ; enums . declareExternal = "class {0}(Enum):" ; enums . declareInternal = "class {0}(Enum):" ; enums . declareValueLeft = " = " ; enums . declareValueRight = "" ; enums . declareValues = true ; enums . isObject = false ; enums . requiredImports = [ new Import ( [ "enum" ] , [ "Enum" ] , ImportRelativity . Absolute ) ] ; enums . valueLeft = "" ; enums . valueMiddle = "." ; enums . valueRight = "" ; } param exceptions protected generateExceptionSyntax ( exceptions ) { exceptions . blockEnd = "" ; exceptions . catch = "except" ; exceptions . className = "Exception" ; exceptions . catchStartLink = " as " ; exceptions . catchStartMiddle = " " ; exceptions . catchStartRight = ":" ; exceptions . finally = "finally" ; exceptions . finallyStartRight = ":" ; exceptions . requiredImports = [ ] ; exceptions . requiresExceptionType = true ; exceptions . throw = "raise" ; exceptions . throwMiddle = "(" ; exceptions . throwRight = ")" ; exceptions . try = "try" ; exceptions . tryStartRight = ":" ; exceptions . variablePrefix = "" ; } param members protected generateExportSyntax ( exports ) { exports . exportedLeft = "" ; exports . internal = "" ; } param file protected generateFileSyntax ( files ) { files . endLines = [ ] ; files . indentation = 0 ; files . startCase = CaseStyle . FileSystemLowerCase ; files . startLines = [ ] ; } param functions protected generateFunctionSyntax ( functions ) { functions . case = CaseStyle . SnakeCase ; functions . defineStartLeft = "def " ; functions . defineStartRight = ":" ; functions . requiresExceptions = false ; functions . defineStartRight = ":" ; functions . defineEnd = "\0" ; } param imports protected generateImportSyntax ( imports ) { imports . case = CaseStyle . PythonImportCase ; imports . explicitAbsoluteFileName = true ; imports . explicitItems = true ; imports . leftAbsolute = "from " ; imports . leftLocal = "from " ; imports . middle = " import " ; imports . right = "" ; imports . transformFileNames = true ; imports . removeFirstPathComponent = true ; imports . useLocalRelativeImports = false ; } param interfaces protected generateInterfaceSyntax ( interfaces ) { interfaces . supported = false ; } param lambdas protected generateLambdaSyntax ( lambdas ) { lambdas . callLeft = "(" ; lambdas . callRight = ")" ; lambdas . functionLeft = "lambda " ; lambdas . functionMiddle = ": " ; lambdas . functionRight = "" ; lambdas . parameterTypeRequired = false ; lambdas . returnTypeRequired = false ; } param typeInline protected generateLambdaTypeInlineSyntax ( typeInline ) { } param lists protected generateListSyntax ( lists ) { lists . addList = new NativeCallSyntax ( "extend" , NativeCallScope . Member , NativeCallType . Function ) ; lists . asArray = true ; lists . getLeft = "[" ; lists . getRight = "]" ; lists . insert = new NativeCallSyntax ( "insert" , NativeCallScope . Member , NativeCallType . Function ) ; lists . length = new NativeCallSyntax ( "len" , NativeCallScope . Static , NativeCallType . Function ) ; lists . pop = new NativeCallSyntax ( "pop" , NativeCallScope . Member , NativeCallType . Function ) ; lists . popFront = new NativeCallSyntax ( "pop" , NativeCallScope . Member , NativeCallType . Function ) ; lists . popFront . withArguments ( [ "0" ] ) ; lists . push = new NativeCallSyntax ( "append" , NativeCallScope . Member , NativeCallType . Function ) ; lists . requiredImports = [ ] ; lists . setLeft = "[" ; lists . setMiddle = "] = " ; lists . setRight = "" ; lists . sortNumbers = new NativeCallSyntax ( "sort" , NativeCallScope . Member , NativeCallType . Function ) ; lists . sortStrings = lists . sortNumbers ; } /**
     * Fills out metadata on list creation with items.
     */ protected generateListNewItemsSyntax ( newItems ) { } param arrays protected generateListNewSizedSyntax ( newSized ) { newSized . includeType = false ; newSized . left = "[None] * " ; newSized . right = "" ; } /**
     * Fills out metadata on list slicing.
     */ protected generateListSliceSyntax ( slices ) { slices . before = "" ; slices . left = "[" ; slices . middle = ":" ; slices . right = "]" ; slices . support = ListSliceSupport . Index ; slices . untilEndDefaultStart = "" ; slices . untilEndLeft = "[" ; slices . untilEndMiddle = ":" ; slices . untilEndRightFromIndex = "]" ; slices . untilEndRightFromStart = "]" ; } /**
     * Fills out metadata on list sorting by keyed member numbers.
     */ protected generateListSortMemberNumbersSyntax ( sortMembers ) { sortMembers . lambdaLeft = ".sort(key = lambda " ; sortMembers . lambdaMiddleLeft = ": " ; sortMembers . lambdaRight = ")" ; sortMembers . requiredImports = [ ] ; sortMembers . type = ListSortMemberType . ShorthandLambda ; } /**
     * Fills out metadata on list sorting by keyed members.
     */ protected generateListSortMemberStringsSyntax ( sortMembers ) { sortMembers . lambdaLeft = ".sort(key = lambda " ; sortMembers . lambdaMiddleLeft = ": " ; sortMembers . lambdaMiddleRight = " < " ; sortMembers . lambdaRight = ")" ; sortMembers . requiredImports = [ ] ; sortMembers . type = ListSortMemberType . ShorthandLambda ; } param loops protected generateLoopSyntax ( loops ) { loops . break = "break" ; loops . continue = "continue" ; loops . for = "for" ; loops . foreach = "for" ; loops . forEachMiddle = " in " ; loops . rangedForLoops = true ; loops . forEachStartIteration = " " ; loops . whileStartLeft = "while" ; loops . whileStartMiddle = " " ; loops . whileStartRight = ":" ; loops . forEachEnd = "\0" ; loops . forEachGetKeys = "" ; loops . forEachGetPairs = ".items()" ; loops . forEachKeyEnd = "\0" ; loops . forEachPairEnd = "\0" ; loops . forEachPairsAsPair = true ; loops . forEachRight = "" ; loops . forNumbersEnd = "\0" ; loops . forEachStartLeft = "for" ; loops . forEachStartSeparator = " in " ; loops . forEachStartRight = ":" ; loops . rangedForLoopsLeft = " in range(" ; loops . rangedForLoopsMiddle = ", " ; loops . rangedForLoopsRight = ")" ; } param main protected generateMainSyntax ( main ) { main . contextEndLines = [ ] ; main . contextIndentation = 0 ; main . contextStartLines = [ ] ; main . group = "" ; main . mainEndLines = [ ] ; main . mainIndentation = 1 ; main . mainStartLines = [ 'if __name__ == "__main__":' ] ; } param math protected generateMathSyntax ( math ) { math . absolute = new NativeCallSyntax ( "fabs" , NativeCallScope . Static , NativeCallType . Function ) . withImports ( [ new Import ( [ "math" ] , [ "fabs" ] , ImportRelativity . Absolute ) , ] ) ; math . asInt = new NativeCallSyntax ( "floor" , NativeCallScope . Static , NativeCallType . Function ) . withImports ( [ new Import ( [ "math" ] , [ "floor" ] , ImportRelativity . Absolute ) , ] ) ; math . ceiling = new NativeCallSyntax ( "ceil" , NativeCallScope . Static , NativeCallType . Function ) . withImports ( [ new Import ( [ "math" ] , [ "ceil" ] , ImportRelativity . Absolute ) , ] ) ; math . floor = new NativeCallSyntax ( "floor" , NativeCallScope . Static , NativeCallType . Function ) . withImports ( [ new Import ( [ "math" ] , [ "floor" ] , ImportRelativity . Absolute ) , ] ) ; math . max = new NativeCallSyntax ( "max" , NativeCallScope . Static , NativeCallType . Function ) ; math . min = new NativeCallSyntax ( "min" , NativeCallScope . Static , NativeCallType . Function ) ; math . power = new NativeCallSyntax ( "pow" , NativeCallScope . Static , NativeCallType . Function ) . withImports ( [ new Import ( [ "math" ] , [ "pow" ] , ImportRelativity . Absolute ) , ] ) ; math . mathName = "Math" ; } param newProp protected generateNewSyntax ( newProp ) { newProp . instantiationKind = NewInstantiationSyntaxKind . MethodCall ; } param operators protected generateOperatorSyntax ( operators ) { operators . and = "&&" ; operators . decreaseBy = "-=" ; operators . divide = "/" ; operators . divideBy = "/=" ; operators . equals = "=" ; operators . equalTo = "==" ; operators . greaterThan = ">" ; operators . greaterThanOrEqualTo = ">=" ; operators . increaseBy = "+=" ; operators . lessThan = "<" ; operators . lessThanOrEqualTo = "<=" ; operators . minus = "-" ; operators . mod = "%" ; operators . multiplyBy = "*=" ; operators . not = "not " ; operators . notEqualTo = "!=" ; operators . or = "||" ; operators . plus = "+" ; operators . times = "*" ; } param parameters protected generateParameterSyntax ( parameters ) { parameters . restDeclarationAfter = false ; parameters . restDeclarationType = false ; parameters . restKeywordLeft = "*" ; parameters . restKeywordMiddle = "" ; parameters . restKeywordRight = "" ; } param parameters protected generatePrintingSyntax ( printing ) { printing . end = ")" ; printing . requiredImports = [ ] ; printing . start = "print(" ; } param parameters protected generateSetSyntax ( sets ) { sets . add = new NativeCallSyntax ( "add" , NativeCallScope . Member , NativeCallType . Function ) ; sets . className = "set" ; sets . contains = new NativeCallSyntax ( " in " , NativeCallScope . Operator , NativeCallType . FloatingLeft ) ; sets . initializeAsNew = false ; sets . initializeStart = "" ; sets . requiredImports = [ ] ; sets . startItemsLeft = "({" ; sets . startItemsRight = "})" ; sets . startNoItems = "()" ; sets . toArray = new NativeCallSyntax ( "list" , NativeCallScope . Static , NativeCallType . Function ) ; sets . toList = sets . toArray ; } param parameters protected generateStandaloneFunctionSyntax ( standaloneFunctions ) { standaloneFunctions . withinStaticClass = false ; } param strings protected generateStringFormatSyntax ( formatting ) { formatting . formatLeft = '"' ; formatting . formatMiddle = '".format(' ; formatting . formatAbbreviated = '".format(' ; formatting . formatRight = ")" ; formatting . formatInputLeft = "{" ; formatting . formatInputRight = "}" ; formatting . includeIndexInFormatting = true ; formatting . inputTypes = false ; formatting . useInterpolation = false ; } param strings protected generateStringSubstringSyntax ( substrings ) { substrings . defaultEnd = ":" ; substrings . leftIndex = "[" ; substrings . leftLength = "[" ; substrings . middle = ":" ; substrings . right = "]" ; substrings . support = StringSubstringSupport . Index ; } param strings protected generateStringSyntax ( strings ) { strings . caseLower = new NativeCallSyntax ( "lower" , NativeCallScope . Member , NativeCallType . Function ) ; strings . caseUpper = new NativeCallSyntax ( "upper" , NativeCallScope . Member , NativeCallType . Function ) ; strings . className = "string" ; strings . concatenate = " + " ; strings . indexLeft = "[" ; strings . indexOf = new NativeCallSyntax ( "find" , NativeCallScope . Member , NativeCallType . Function ) ; strings . indexOfNotFound = "-1" ; strings . indexRight = "]" ; strings . length = new NativeCallSyntax ( "len" , NativeCallScope . Static , NativeCallType . Function ) ; strings . trim = new NativeCallSyntax ( "strip" , NativeCallScope . Member , NativeCallType . Function ) ; } param toDouble protected generateStringToDoubleSyntax ( toDouble ) { toDouble . conversionType = StringToNumberStartConversionType . PredeclareConvertAndValidate ; toDouble . initialVariableValues = "None" ; toDouble . initializeVariablesEnd = "\n\ntry:\n" ; toDouble . perVariableConversionStartLeft = "    " ; toDouble . perVariableConversionStartMiddle = " = float(" ; toDouble . perVariableConversionStartRight = ")\n" ; toDouble . validationBlockComparison = "{1} is not None" ; toDouble . validationBlockLeft = "except:\n    pass\n\nif " ; toDouble . validationBlockMiddle = " and " ; toDouble . validationBlockRight = ":" ; } param toInt protected generateStringToIntSyntax ( toInt ) { toInt . conversionType = StringToNumberStartConversionType . PredeclareConvertAndValidate ; toInt . initialVariableValues = "None" ; toInt . initializeVariablesEnd = "\n\ntry:\n" ; toInt . perVariableConversionStartLeft = "    " ; toInt . perVariableConversionStartMiddle = " = int(" ; toInt . perVariableConversionStartRight = ")\n" ; toInt . validationBlockComparison = "{1} is not None" ; toInt . validationBlockLeft = "except:\n    pass\n\nif " ; toInt . validationBlockMiddle = " and " ; toInt . validationBlockRight = ":" ; } param style protected generateStyleSyntax ( style ) { style . semicolon = "" ; } param style protected generateUnsupportedSyntax ( unsupported ) { unsupported . complaintEnd = "'''" ; unsupported . complaintStart = "'''" ; } param variables protected generateVariableSyntax ( variables ) { variables . declaration = "" ; variables . aliases = { false : "False" , infinity : "inf" , true : "True" , } ; variables . null = "None" ; variables . isNullLeft = "" ; variables . isNotNullLeft = "" ; variables . isNotNullMiddle = " is not " ; variables . isNullMiddle = " is " ; variables . nullRight = "None" ; } }