@zzzen/pyright-internal 1.1.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/aliasDeclarationUtils.d.ts +9 -0
- package/dist/analyzer/aliasDeclarationUtils.js +128 -0
- package/dist/analyzer/aliasDeclarationUtils.js.map +1 -0
- package/dist/analyzer/analysis.d.ts +18 -0
- package/dist/analyzer/analysis.js +81 -0
- package/dist/analyzer/analysis.js.map +1 -0
- package/dist/analyzer/analyzerFileInfo.d.ts +39 -0
- package/dist/analyzer/analyzerFileInfo.js +17 -0
- package/dist/analyzer/analyzerFileInfo.js.map +1 -0
- package/dist/analyzer/analyzerNodeInfo.d.ts +32 -0
- package/dist/analyzer/analyzerNodeInfo.js +138 -0
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +54 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +222 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -0
- package/dist/analyzer/binder.d.ts +149 -0
- package/dist/analyzer/binder.js +3195 -0
- package/dist/analyzer/binder.js.map +1 -0
- package/dist/analyzer/checker.d.ts +116 -0
- package/dist/analyzer/checker.js +3828 -0
- package/dist/analyzer/checker.js.map +1 -0
- package/dist/analyzer/circularDependency.d.ts +7 -0
- package/dist/analyzer/circularDependency.js +51 -0
- package/dist/analyzer/circularDependency.js.map +1 -0
- package/dist/analyzer/codeFlowEngine.d.ts +21 -0
- package/dist/analyzer/codeFlowEngine.js +1132 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -0
- package/dist/analyzer/codeFlowTypes.d.ts +82 -0
- package/dist/analyzer/codeFlowTypes.js +134 -0
- package/dist/analyzer/codeFlowTypes.js.map +1 -0
- package/dist/analyzer/codeFlowUtils.d.ts +2 -0
- package/dist/analyzer/codeFlowUtils.js +348 -0
- package/dist/analyzer/codeFlowUtils.js.map +1 -0
- package/dist/analyzer/commentUtils.d.ts +4 -0
- package/dist/analyzer/commentUtils.js +131 -0
- package/dist/analyzer/commentUtils.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +7 -0
- package/dist/analyzer/constraintSolver.js +605 -0
- package/dist/analyzer/constraintSolver.js.map +1 -0
- package/dist/analyzer/constructorTransform.d.ts +4 -0
- package/dist/analyzer/constructorTransform.js +219 -0
- package/dist/analyzer/constructorTransform.js.map +1 -0
- package/dist/analyzer/dataClasses.d.ts +9 -0
- package/dist/analyzer/dataClasses.js +762 -0
- package/dist/analyzer/dataClasses.js.map +1 -0
- package/dist/analyzer/declaration.d.ts +90 -0
- package/dist/analyzer/declaration.js +42 -0
- package/dist/analyzer/declaration.js.map +1 -0
- package/dist/analyzer/declarationUtils.d.ts +12 -0
- package/dist/analyzer/declarationUtils.js +212 -0
- package/dist/analyzer/declarationUtils.js.map +1 -0
- package/dist/analyzer/docStringConversion.d.ts +2 -0
- package/dist/analyzer/docStringConversion.js +699 -0
- package/dist/analyzer/docStringConversion.js.map +1 -0
- package/dist/analyzer/docStringUtils.d.ts +3 -0
- package/dist/analyzer/docStringUtils.js +103 -0
- package/dist/analyzer/docStringUtils.js.map +1 -0
- package/dist/analyzer/functionTransform.d.ts +4 -0
- package/dist/analyzer/functionTransform.js +96 -0
- package/dist/analyzer/functionTransform.js.map +1 -0
- package/dist/analyzer/importResolver.d.ts +97 -0
- package/dist/analyzer/importResolver.js +1617 -0
- package/dist/analyzer/importResolver.js.map +1 -0
- package/dist/analyzer/importResult.d.ts +33 -0
- package/dist/analyzer/importResult.js +11 -0
- package/dist/analyzer/importResult.js.map +1 -0
- package/dist/analyzer/importStatementUtils.d.ts +46 -0
- package/dist/analyzer/importStatementUtils.js +618 -0
- package/dist/analyzer/importStatementUtils.js.map +1 -0
- package/dist/analyzer/namedTuples.d.ts +5 -0
- package/dist/analyzer/namedTuples.js +342 -0
- package/dist/analyzer/namedTuples.js.map +1 -0
- package/dist/analyzer/packageTypeReport.d.ts +52 -0
- package/dist/analyzer/packageTypeReport.js +45 -0
- package/dist/analyzer/packageTypeReport.js.map +1 -0
- package/dist/analyzer/packageTypeVerifier.d.ts +37 -0
- package/dist/analyzer/packageTypeVerifier.js +908 -0
- package/dist/analyzer/packageTypeVerifier.js.map +1 -0
- package/dist/analyzer/parentDirectoryCache.d.ts +23 -0
- package/dist/analyzer/parentDirectoryCache.js +71 -0
- package/dist/analyzer/parentDirectoryCache.js.map +1 -0
- package/dist/analyzer/parseTreeCleaner.d.ts +8 -0
- package/dist/analyzer/parseTreeCleaner.js +51 -0
- package/dist/analyzer/parseTreeCleaner.js.map +1 -0
- package/dist/analyzer/parseTreeUtils.d.ts +98 -0
- package/dist/analyzer/parseTreeUtils.js +1753 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -0
- package/dist/analyzer/parseTreeWalker.d.ts +81 -0
- package/dist/analyzer/parseTreeWalker.js +437 -0
- package/dist/analyzer/parseTreeWalker.js.map +1 -0
- package/dist/analyzer/patternMatching.d.ts +6 -0
- package/dist/analyzer/patternMatching.js +866 -0
- package/dist/analyzer/patternMatching.js.map +1 -0
- package/dist/analyzer/program.d.ts +158 -0
- package/dist/analyzer/program.js +1902 -0
- package/dist/analyzer/program.js.map +1 -0
- package/dist/analyzer/properties.d.ts +10 -0
- package/dist/analyzer/properties.js +368 -0
- package/dist/analyzer/properties.js.map +1 -0
- package/dist/analyzer/protocols.d.ts +8 -0
- package/dist/analyzer/protocols.js +409 -0
- package/dist/analyzer/protocols.js.map +1 -0
- package/dist/analyzer/pyTypedUtils.d.ts +6 -0
- package/dist/analyzer/pyTypedUtils.js +42 -0
- package/dist/analyzer/pyTypedUtils.js.map +1 -0
- package/dist/analyzer/pythonPathUtils.d.ts +14 -0
- package/dist/analyzer/pythonPathUtils.js +173 -0
- package/dist/analyzer/pythonPathUtils.js.map +1 -0
- package/dist/analyzer/scope.d.ts +39 -0
- package/dist/analyzer/scope.js +110 -0
- package/dist/analyzer/scope.js.map +1 -0
- package/dist/analyzer/scopeUtils.d.ts +6 -0
- package/dist/analyzer/scopeUtils.js +72 -0
- package/dist/analyzer/scopeUtils.js.map +1 -0
- package/dist/analyzer/service.d.ts +144 -0
- package/dist/analyzer/service.js +1197 -0
- package/dist/analyzer/service.js.map +1 -0
- package/dist/analyzer/sourceFile.d.ts +123 -0
- package/dist/analyzer/sourceFile.js +908 -0
- package/dist/analyzer/sourceFile.js.map +1 -0
- package/dist/analyzer/sourceMapper.d.ts +47 -0
- package/dist/analyzer/sourceMapper.js +543 -0
- package/dist/analyzer/sourceMapper.js.map +1 -0
- package/dist/analyzer/staticExpressions.d.ts +4 -0
- package/dist/analyzer/staticExpressions.js +242 -0
- package/dist/analyzer/staticExpressions.js.map +1 -0
- package/dist/analyzer/symbol.d.ts +50 -0
- package/dist/analyzer/symbol.js +160 -0
- package/dist/analyzer/symbol.js.map +1 -0
- package/dist/analyzer/symbolNameUtils.d.ts +8 -0
- package/dist/analyzer/symbolNameUtils.js +53 -0
- package/dist/analyzer/symbolNameUtils.js.map +1 -0
- package/dist/analyzer/symbolUtils.d.ts +7 -0
- package/dist/analyzer/symbolUtils.js +46 -0
- package/dist/analyzer/symbolUtils.js.map +1 -0
- package/dist/analyzer/testWalker.d.ts +14 -0
- package/dist/analyzer/testWalker.js +92 -0
- package/dist/analyzer/testWalker.js.map +1 -0
- package/dist/analyzer/tracePrinter.d.ts +11 -0
- package/dist/analyzer/tracePrinter.js +222 -0
- package/dist/analyzer/tracePrinter.js.map +1 -0
- package/dist/analyzer/typeCache.d.ts +40 -0
- package/dist/analyzer/typeCache.js +134 -0
- package/dist/analyzer/typeCache.js.map +1 -0
- package/dist/analyzer/typeDocStringUtils.d.ts +12 -0
- package/dist/analyzer/typeDocStringUtils.js +293 -0
- package/dist/analyzer/typeDocStringUtils.js.map +1 -0
- package/dist/analyzer/typeEvaluator.d.ts +18 -0
- package/dist/analyzer/typeEvaluator.js +16598 -0
- package/dist/analyzer/typeEvaluator.js.map +1 -0
- package/dist/analyzer/typeEvaluatorTypes.d.ts +220 -0
- package/dist/analyzer/typeEvaluatorTypes.js +16 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -0
- package/dist/analyzer/typeEvaluatorWithTracker.d.ts +6 -0
- package/dist/analyzer/typeEvaluatorWithTracker.js +121 -0
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -0
- package/dist/analyzer/typeGuards.d.ts +6 -0
- package/dist/analyzer/typeGuards.js +1293 -0
- package/dist/analyzer/typeGuards.js.map +1 -0
- package/dist/analyzer/typePrinter.d.ts +17 -0
- package/dist/analyzer/typePrinter.js +603 -0
- package/dist/analyzer/typePrinter.js.map +1 -0
- package/dist/analyzer/typeStubWriter.d.ts +48 -0
- package/dist/analyzer/typeStubWriter.js +605 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -0
- package/dist/analyzer/typeUtils.d.ts +134 -0
- package/dist/analyzer/typeUtils.js +2380 -0
- package/dist/analyzer/typeUtils.js.map +1 -0
- package/dist/analyzer/typeVarContext.d.ts +50 -0
- package/dist/analyzer/typeVarContext.js +250 -0
- package/dist/analyzer/typeVarContext.js.map +1 -0
- package/dist/analyzer/typedDicts.d.ts +12 -0
- package/dist/analyzer/typedDicts.js +695 -0
- package/dist/analyzer/typedDicts.js.map +1 -0
- package/dist/analyzer/types.d.ts +484 -0
- package/dist/analyzer/types.js +1844 -0
- package/dist/analyzer/types.js.map +1 -0
- package/dist/backgroundAnalysis.d.ts +14 -0
- package/dist/backgroundAnalysis.js +42 -0
- package/dist/backgroundAnalysis.js.map +1 -0
- package/dist/backgroundAnalysisBase.d.ts +83 -0
- package/dist/backgroundAnalysisBase.js +429 -0
- package/dist/backgroundAnalysisBase.js.map +1 -0
- package/dist/backgroundThreadBase.d.ts +34 -0
- package/dist/backgroundThreadBase.js +134 -0
- package/dist/backgroundThreadBase.js.map +1 -0
- package/dist/commands/commandController.d.ts +13 -0
- package/dist/commands/commandController.js +48 -0
- package/dist/commands/commandController.js.map +1 -0
- package/dist/commands/commandResult.d.ts +9 -0
- package/dist/commands/commandResult.js +19 -0
- package/dist/commands/commandResult.js.map +1 -0
- package/dist/commands/commands.d.ts +7 -0
- package/dist/commands/commands.js +11 -0
- package/dist/commands/commands.js.map +1 -0
- package/dist/commands/createTypeStub.d.ts +8 -0
- package/dist/commands/createTypeStub.js +50 -0
- package/dist/commands/createTypeStub.js.map +1 -0
- package/dist/commands/quickActionCommand.d.ts +8 -0
- package/dist/commands/quickActionCommand.js +31 -0
- package/dist/commands/quickActionCommand.js.map +1 -0
- package/dist/commands/restartServer.d.ts +8 -0
- package/dist/commands/restartServer.js +20 -0
- package/dist/commands/restartServer.js.map +1 -0
- package/dist/common/cancellationUtils.d.ts +16 -0
- package/dist/common/cancellationUtils.js +60 -0
- package/dist/common/cancellationUtils.js.map +1 -0
- package/dist/common/chokidarFileWatcherProvider.d.ts +9 -0
- package/dist/common/chokidarFileWatcherProvider.js +88 -0
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -0
- package/dist/common/collectionUtils.d.ts +114 -0
- package/dist/common/collectionUtils.js +292 -0
- package/dist/common/collectionUtils.js.map +1 -0
- package/dist/common/commandLineOptions.d.ts +41 -0
- package/dist/common/commandLineOptions.js +46 -0
- package/dist/common/commandLineOptions.js.map +1 -0
- package/dist/common/configOptions.d.ts +144 -0
- package/dist/common/configOptions.js +908 -0
- package/dist/common/configOptions.js.map +1 -0
- package/dist/common/console.d.ts +61 -0
- package/dist/common/console.js +191 -0
- package/dist/common/console.js.map +1 -0
- package/dist/common/core.d.ts +67 -0
- package/dist/common/core.js +118 -0
- package/dist/common/core.js.map +1 -0
- package/dist/common/crypto.d.ts +1 -0
- package/dist/common/crypto.js +37 -0
- package/dist/common/crypto.js.map +1 -0
- package/dist/common/debug.d.ts +13 -0
- package/dist/common/debug.js +131 -0
- package/dist/common/debug.js.map +1 -0
- package/dist/common/deferred.d.ts +11 -0
- package/dist/common/deferred.js +62 -0
- package/dist/common/deferred.js.map +1 -0
- package/dist/common/diagnostic.d.ts +59 -0
- package/dist/common/diagnostic.js +134 -0
- package/dist/common/diagnostic.js.map +1 -0
- package/dist/common/diagnosticRules.d.ts +67 -0
- package/dist/common/diagnosticRules.js +83 -0
- package/dist/common/diagnosticRules.js.map +1 -0
- package/dist/common/diagnosticSink.d.ts +34 -0
- package/dist/common/diagnosticSink.js +110 -0
- package/dist/common/diagnosticSink.js.map +1 -0
- package/dist/common/editAction.d.ts +29 -0
- package/dist/common/editAction.js +11 -0
- package/dist/common/editAction.js.map +1 -0
- package/dist/common/extensibility.d.ts +11 -0
- package/dist/common/extensibility.js +10 -0
- package/dist/common/extensibility.js.map +1 -0
- package/dist/common/extensions.d.ts +3 -0
- package/dist/common/extensions.js +15 -0
- package/dist/common/extensions.js.map +1 -0
- package/dist/common/fileBasedCancellationUtils.d.ts +11 -0
- package/dist/common/fileBasedCancellationUtils.js +259 -0
- package/dist/common/fileBasedCancellationUtils.js.map +1 -0
- package/dist/common/fileSystem.d.ts +72 -0
- package/dist/common/fileSystem.js +69 -0
- package/dist/common/fileSystem.js.map +1 -0
- package/dist/common/fullAccessHost.d.ts +19 -0
- package/dist/common/fullAccessHost.js +193 -0
- package/dist/common/fullAccessHost.js.map +1 -0
- package/dist/common/host.d.ts +21 -0
- package/dist/common/host.js +30 -0
- package/dist/common/host.js.map +1 -0
- package/dist/common/logTracker.d.ts +15 -0
- package/dist/common/logTracker.js +129 -0
- package/dist/common/logTracker.js.map +1 -0
- package/dist/common/lspUtils.d.ts +3 -0
- package/dist/common/lspUtils.js +20 -0
- package/dist/common/lspUtils.js.map +1 -0
- package/dist/common/memUtils.d.ts +3 -0
- package/dist/common/memUtils.js +37 -0
- package/dist/common/memUtils.js.map +1 -0
- package/dist/common/pathConsts.d.ts +8 -0
- package/dist/common/pathConsts.js +19 -0
- package/dist/common/pathConsts.js.map +1 -0
- package/dist/common/pathUtils.d.ts +170 -0
- package/dist/common/pathUtils.js +762 -0
- package/dist/common/pathUtils.js.map +1 -0
- package/dist/common/positionUtils.d.ts +7 -0
- package/dist/common/positionUtils.js +71 -0
- package/dist/common/positionUtils.js.map +1 -0
- package/dist/common/progressReporter.d.ts +15 -0
- package/dist/common/progressReporter.js +44 -0
- package/dist/common/progressReporter.js.map +1 -0
- package/dist/common/pythonVersion.d.ts +20 -0
- package/dist/common/pythonVersion.js +71 -0
- package/dist/common/pythonVersion.js.map +1 -0
- package/dist/common/realFileSystem.d.ts +8 -0
- package/dist/common/realFileSystem.js +368 -0
- package/dist/common/realFileSystem.js.map +1 -0
- package/dist/common/stringUtils.d.ts +47 -0
- package/dist/common/stringUtils.js +160 -0
- package/dist/common/stringUtils.js.map +1 -0
- package/dist/common/textEditUtils.d.ts +3 -0
- package/dist/common/textEditUtils.js +29 -0
- package/dist/common/textEditUtils.js.map +1 -0
- package/dist/common/textRange.d.ts +47 -0
- package/dist/common/textRange.js +211 -0
- package/dist/common/textRange.js.map +1 -0
- package/dist/common/textRangeCollection.d.ts +13 -0
- package/dist/common/textRangeCollection.js +108 -0
- package/dist/common/textRangeCollection.js.map +1 -0
- package/dist/common/timing.d.ts +31 -0
- package/dist/common/timing.js +100 -0
- package/dist/common/timing.js.map +1 -0
- package/dist/common/uriParser.d.ts +12 -0
- package/dist/common/uriParser.js +25 -0
- package/dist/common/uriParser.js.map +1 -0
- package/dist/common/workspaceEditUtils.d.ts +7 -0
- package/dist/common/workspaceEditUtils.js +63 -0
- package/dist/common/workspaceEditUtils.js.map +1 -0
- package/dist/languageServerBase.d.ts +211 -0
- package/dist/languageServerBase.js +923 -0
- package/dist/languageServerBase.js.map +1 -0
- package/dist/languageService/analyzerServiceExecutor.d.ts +8 -0
- package/dist/languageService/analyzerServiceExecutor.js +97 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -0
- package/dist/languageService/autoImporter.d.ts +84 -0
- package/dist/languageService/autoImporter.js +635 -0
- package/dist/languageService/autoImporter.js.map +1 -0
- package/dist/languageService/callHierarchyProvider.d.ts +12 -0
- package/dist/languageService/callHierarchyProvider.js +368 -0
- package/dist/languageService/callHierarchyProvider.js.map +1 -0
- package/dist/languageService/codeActionProvider.d.ts +6 -0
- package/dist/languageService/codeActionProvider.js +53 -0
- package/dist/languageService/codeActionProvider.js.map +1 -0
- package/dist/languageService/completionProvider.d.ts +147 -0
- package/dist/languageService/completionProvider.js +2220 -0
- package/dist/languageService/completionProvider.js.map +1 -0
- package/dist/languageService/definitionProvider.d.ts +17 -0
- package/dist/languageService/definitionProvider.js +206 -0
- package/dist/languageService/definitionProvider.js.map +1 -0
- package/dist/languageService/documentHighlightProvider.d.ts +7 -0
- package/dist/languageService/documentHighlightProvider.js +63 -0
- package/dist/languageService/documentHighlightProvider.js.map +1 -0
- package/dist/languageService/documentSymbolCollector.d.ts +37 -0
- package/dist/languageService/documentSymbolCollector.js +344 -0
- package/dist/languageService/documentSymbolCollector.js.map +1 -0
- package/dist/languageService/documentSymbolProvider.d.ts +37 -0
- package/dist/languageService/documentSymbolProvider.js +308 -0
- package/dist/languageService/documentSymbolProvider.js.map +1 -0
- package/dist/languageService/hoverProvider.d.ts +25 -0
- package/dist/languageService/hoverProvider.js +366 -0
- package/dist/languageService/hoverProvider.js.map +1 -0
- package/dist/languageService/importAdder.d.ts +24 -0
- package/dist/languageService/importAdder.js +296 -0
- package/dist/languageService/importAdder.js.map +1 -0
- package/dist/languageService/importSorter.d.ts +15 -0
- package/dist/languageService/importSorter.js +152 -0
- package/dist/languageService/importSorter.js.map +1 -0
- package/dist/languageService/indentationUtils.d.ts +4 -0
- package/dist/languageService/indentationUtils.js +597 -0
- package/dist/languageService/indentationUtils.js.map +1 -0
- package/dist/languageService/quickActions.d.ts +4 -0
- package/dist/languageService/quickActions.js +97 -0
- package/dist/languageService/quickActions.js.map +1 -0
- package/dist/languageService/referencesProvider.d.ts +36 -0
- package/dist/languageService/referencesProvider.js +236 -0
- package/dist/languageService/referencesProvider.js.map +1 -0
- package/dist/languageService/renameModuleProvider.d.ts +58 -0
- package/dist/languageService/renameModuleProvider.js +884 -0
- package/dist/languageService/renameModuleProvider.js.map +1 -0
- package/dist/languageService/signatureHelpProvider.d.ts +26 -0
- package/dist/languageService/signatureHelpProvider.js +180 -0
- package/dist/languageService/signatureHelpProvider.js.map +1 -0
- package/dist/languageService/tooltipUtils.d.ts +9 -0
- package/dist/languageService/tooltipUtils.js +129 -0
- package/dist/languageService/tooltipUtils.js.map +1 -0
- package/dist/localization/localize.d.ts +1324 -0
- package/dist/localization/localize.js +788 -0
- package/dist/localization/localize.js.map +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.en-us.json +636 -0
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- package/dist/nodeMain.d.ts +1 -0
- package/dist/nodeMain.js +21 -0
- package/dist/nodeMain.js.map +1 -0
- package/dist/nodeServer.d.ts +3 -0
- package/dist/nodeServer.js +31 -0
- package/dist/nodeServer.js.map +1 -0
- package/dist/parser/characterStream.d.ts +27 -0
- package/dist/parser/characterStream.js +120 -0
- package/dist/parser/characterStream.js.map +1 -0
- package/dist/parser/characters.d.ts +17 -0
- package/dist/parser/characters.js +240 -0
- package/dist/parser/characters.js.map +1 -0
- package/dist/parser/parseNodes.d.ts +750 -0
- package/dist/parser/parseNodes.js +1406 -0
- package/dist/parser/parseNodes.js.map +1 -0
- package/dist/parser/parser.d.ts +191 -0
- package/dist/parser/parser.js +3806 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/stringTokenUtils.d.ts +25 -0
- package/dist/parser/stringTokenUtils.js +455 -0
- package/dist/parser/stringTokenUtils.js.map +1 -0
- package/dist/parser/tokenizer.d.ts +71 -0
- package/dist/parser/tokenizer.js +1111 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/tokenizerTypes.d.ts +223 -0
- package/dist/parser/tokenizerTypes.js +164 -0
- package/dist/parser/tokenizerTypes.js.map +1 -0
- package/dist/parser/unicode.d.ts +23 -0
- package/dist/parser/unicode.js +2899 -0
- package/dist/parser/unicode.js.map +1 -0
- package/dist/pyright.d.ts +1 -0
- package/dist/pyright.js +645 -0
- package/dist/pyright.js.map +1 -0
- package/dist/pyrightFileSystem.d.ts +28 -0
- package/dist/pyrightFileSystem.js +196 -0
- package/dist/pyrightFileSystem.js.map +1 -0
- package/dist/readonlyAugmentedFileSystem.d.ts +40 -0
- package/dist/readonlyAugmentedFileSystem.js +155 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +232 -0
- package/dist/server.js.map +1 -0
- package/dist/tests/chainedSourceFiles.test.d.ts +1 -0
- package/dist/tests/chainedSourceFiles.test.js +153 -0
- package/dist/tests/chainedSourceFiles.test.js.map +1 -0
- package/dist/tests/checker.test.d.ts +1 -0
- package/dist/tests/checker.test.js +346 -0
- package/dist/tests/checker.test.js.map +1 -0
- package/dist/tests/collectionUtils.test.d.ts +1 -0
- package/dist/tests/collectionUtils.test.js +153 -0
- package/dist/tests/collectionUtils.test.js.map +1 -0
- package/dist/tests/common.test.d.ts +1 -0
- package/dist/tests/common.test.js +125 -0
- package/dist/tests/common.test.js.map +1 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/dist/tests/config.test.js +230 -0
- package/dist/tests/config.test.js.map +1 -0
- package/dist/tests/debug.test.d.ts +1 -0
- package/dist/tests/debug.test.js +102 -0
- package/dist/tests/debug.test.js.map +1 -0
- package/dist/tests/deferred.test.d.ts +1 -0
- package/dist/tests/deferred.test.js +65 -0
- package/dist/tests/deferred.test.js.map +1 -0
- package/dist/tests/diagnosticOverrides.test.d.ts +1 -0
- package/dist/tests/diagnosticOverrides.test.js +108 -0
- package/dist/tests/diagnosticOverrides.test.js.map +1 -0
- package/dist/tests/docStringConversion.test.d.ts +1 -0
- package/dist/tests/docStringConversion.test.js +695 -0
- package/dist/tests/docStringConversion.test.js.map +1 -0
- package/dist/tests/docStringUtils.test.d.ts +1 -0
- package/dist/tests/docStringUtils.test.js +70 -0
- package/dist/tests/docStringUtils.test.js.map +1 -0
- package/dist/tests/documentSymbolCollector.test.d.ts +1 -0
- package/dist/tests/documentSymbolCollector.test.js +635 -0
- package/dist/tests/documentSymbolCollector.test.js.map +1 -0
- package/dist/tests/filesystem.test.d.ts +1 -0
- package/dist/tests/filesystem.test.js +194 -0
- package/dist/tests/filesystem.test.js.map +1 -0
- package/dist/tests/fourSlashParser.test.d.ts +1 -0
- package/dist/tests/fourSlashParser.test.js +281 -0
- package/dist/tests/fourSlashParser.test.js.map +1 -0
- package/dist/tests/fourSlashRunner.test.d.ts +1 -0
- package/dist/tests/fourSlashRunner.test.js +52 -0
- package/dist/tests/fourSlashRunner.test.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.js +42 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.js +13 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.js +35 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.js +128 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +43 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +116 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.js +21 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.js +54 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js +245 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js +162 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js +132 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.js +37 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.comment.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.comment.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.comment.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.js +18 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.js +26 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.js +15 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.js +36 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.js +147 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.js +131 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +73 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +58 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +154 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +143 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +109 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.js +44 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.js +12 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fourslash.js +51 -0
- package/dist/tests/fourslash/completions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.js +32 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +96 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.d.ts +0 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inList.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inList.fourslash.js +32 -0
- package/dist/tests/fourslash/completions.inList.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.included.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.included.fourslash.js +12 -0
- package/dist/tests/fourslash/completions.included.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +54 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js +26 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js +49 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.js +101 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.js +105 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js +67 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +75 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.literals.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.literals.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.literals.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.js +71 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.js +17 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.js +57 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.js +37 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.importStub.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.importStub.js +49 -0
- package/dist/tests/fourslash/completions.override.default.importStub.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.js +60 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.js +63 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override2.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.params.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.params.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.js +15 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.js +34 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.private.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.private.fourslash.js +61 -0
- package/dist/tests/fourslash/completions.private.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.property.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.property.fourslash.js +28 -0
- package/dist/tests/fourslash/completions.property.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.js +64 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.self.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.self.fourslash.js +43 -0
- package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.js +71 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js +78 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.js +9 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.js +33 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +109 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.with.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.with.fourslash.js +25 -0
- package/dist/tests/fourslash/completions.with.fourslash.js.map +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +64 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js +24 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.js +93 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.js +19 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.js +123 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.js +79 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.js +154 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.js +42 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js +34 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.js +213 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js +154 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.js +29 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.js +30 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.js +26 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.js +28 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.js +33 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.js +26 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.js +59 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.js +59 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.js +94 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.js +79 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js +106 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.js +24 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js +66 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.js +26 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.js +36 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.fourslash.js +30 -0
- package/dist/tests/fourslash/findallreferences.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.js +30 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.js +46 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.js +60 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.js +54 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.js +41 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.js +83 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.js +32 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.js +22 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.js +29 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.js +33 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.js +36 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.js +44 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.js +31 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.js +22 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +301 -0
- package/dist/tests/fourslash/fourslash.js +25 -0
- package/dist/tests/fourslash/fourslash.js.map +1 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.js +30 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +63 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.js +14 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.js +47 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +77 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +22 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +22 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +21 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +25 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +18 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js +12 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.js +23 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.import.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.import.fourslash.js +10 -0
- package/dist/tests/fourslash/hover.import.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +61 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +51 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +40 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js +43 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js +44 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.js +84 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.js +88 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.init.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.init.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +49 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +39 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.js +39 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.js +14 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.js +50 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js +35 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +73 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.js +63 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.js +72 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.js +61 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +35 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +35 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.js +24 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.js.map +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js +13 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.js +18 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +13 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +31 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.js +44 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.js +35 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.js +35 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.js +18 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.js +34 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.js.map +1 -0
- package/dist/tests/fourslash/noerrors.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/noerrors.fourslash.js +9 -0
- package/dist/tests/fourslash/noerrors.fourslash.js.map +1 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.js +17 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.js.map +1 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.js +21 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +23 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +23 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.fourslash.js +26 -0
- package/dist/tests/fourslash/rename.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.library.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.library.fourslash.js +26 -0
- package/dist/tests/fourslash/rename.library.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.js +29 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.d.ts +2 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.js +19 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.js +33 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.js +39 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.string.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.string.fourslash.js +25 -0
- package/dist/tests/fourslash/rename.string.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +62 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js +97 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.js +22 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.js +42 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js +49 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +115 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.overload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.overload.fourslash.js +63 -0
- package/dist/tests/fourslash/signature.overload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js +104 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashParser.d.ts +10 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js +347 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.d.ts +81 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js +65 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -0
- package/dist/tests/harness/fourslash/runner.d.ts +20 -0
- package/dist/tests/harness/fourslash/runner.js +93 -0
- package/dist/tests/harness/fourslash/runner.js.map +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +40 -0
- package/dist/tests/harness/fourslash/testLanguageService.js +120 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +11 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +50 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.d.ts +232 -0
- package/dist/tests/harness/fourslash/testState.js +1381 -0
- package/dist/tests/harness/fourslash/testState.js.map +1 -0
- package/dist/tests/harness/testAccessHost.d.ts +8 -0
- package/dist/tests/harness/testAccessHost.js +26 -0
- package/dist/tests/harness/testAccessHost.js.map +1 -0
- package/dist/tests/harness/testHost.d.ts +16 -0
- package/dist/tests/harness/testHost.js +161 -0
- package/dist/tests/harness/testHost.js.map +1 -0
- package/dist/tests/harness/utils.d.ts +74 -0
- package/dist/tests/harness/utils.js +328 -0
- package/dist/tests/harness/utils.js.map +1 -0
- package/dist/tests/harness/vfs/factory.d.ts +32 -0
- package/dist/tests/harness/vfs/factory.js +173 -0
- package/dist/tests/harness/vfs/factory.js.map +1 -0
- package/dist/tests/harness/vfs/filesystem.d.ts +430 -0
- package/dist/tests/harness/vfs/filesystem.js +1455 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -0
- package/dist/tests/harness/vfs/pathValidation.d.ts +24 -0
- package/dist/tests/harness/vfs/pathValidation.js +123 -0
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -0
- package/dist/tests/importAdder.test.d.ts +1 -0
- package/dist/tests/importAdder.test.js +1192 -0
- package/dist/tests/importAdder.test.js.map +1 -0
- package/dist/tests/importResolver.test.d.ts +1 -0
- package/dist/tests/importResolver.test.js +450 -0
- package/dist/tests/importResolver.test.js.map +1 -0
- package/dist/tests/importStatementUtils.test.d.ts +1 -0
- package/dist/tests/importStatementUtils.test.js +371 -0
- package/dist/tests/importStatementUtils.test.js.map +1 -0
- package/dist/tests/indentationUtils.ptvs.test.d.ts +1 -0
- package/dist/tests/indentationUtils.ptvs.test.js +324 -0
- package/dist/tests/indentationUtils.ptvs.test.js.map +1 -0
- package/dist/tests/indentationUtils.reindent.test.d.ts +1 -0
- package/dist/tests/indentationUtils.reindent.test.js +332 -0
- package/dist/tests/indentationUtils.reindent.test.js.map +1 -0
- package/dist/tests/indentationUtils.test.d.ts +1 -0
- package/dist/tests/indentationUtils.test.js +375 -0
- package/dist/tests/indentationUtils.test.js.map +1 -0
- package/dist/tests/ipythonMode.test.d.ts +1 -0
- package/dist/tests/ipythonMode.test.js +303 -0
- package/dist/tests/ipythonMode.test.js.map +1 -0
- package/dist/tests/localizer.test.d.ts +1 -0
- package/dist/tests/localizer.test.js +64 -0
- package/dist/tests/localizer.test.js.map +1 -0
- package/dist/tests/parseTreeUtils.test.d.ts +1 -0
- package/dist/tests/parseTreeUtils.test.js +228 -0
- package/dist/tests/parseTreeUtils.test.js.map +1 -0
- package/dist/tests/parser.test.d.ts +1 -0
- package/dist/tests/parser.test.js +101 -0
- package/dist/tests/parser.test.js.map +1 -0
- package/dist/tests/pathUtils.test.d.ts +1 -0
- package/dist/tests/pathUtils.test.js +253 -0
- package/dist/tests/pathUtils.test.js.map +1 -0
- package/dist/tests/pyrightFileSystem.test.d.ts +1 -0
- package/dist/tests/pyrightFileSystem.test.js +152 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -0
- package/dist/tests/renameModule.folder.test.d.ts +1 -0
- package/dist/tests/renameModule.folder.test.js +229 -0
- package/dist/tests/renameModule.folder.test.js.map +1 -0
- package/dist/tests/renameModule.fromImports.test.d.ts +1 -0
- package/dist/tests/renameModule.fromImports.test.js +790 -0
- package/dist/tests/renameModule.fromImports.test.js.map +1 -0
- package/dist/tests/renameModule.imports.test.d.ts +1 -0
- package/dist/tests/renameModule.imports.test.js +380 -0
- package/dist/tests/renameModule.imports.test.js.map +1 -0
- package/dist/tests/renameModule.misc.test.d.ts +1 -0
- package/dist/tests/renameModule.misc.test.js +615 -0
- package/dist/tests/renameModule.misc.test.js.map +1 -0
- package/dist/tests/renameModule.relativePath.test.d.ts +1 -0
- package/dist/tests/renameModule.relativePath.test.js +231 -0
- package/dist/tests/renameModule.relativePath.test.js.map +1 -0
- package/dist/tests/renameModuleTestUtils.d.ts +4 -0
- package/dist/tests/renameModuleTestUtils.js +148 -0
- package/dist/tests/renameModuleTestUtils.js.map +1 -0
- package/dist/tests/sourceFile.test.d.ts +1 -0
- package/dist/tests/sourceFile.test.js +25 -0
- package/dist/tests/sourceFile.test.js.map +1 -0
- package/dist/tests/stringUtils.test.d.ts +1 -0
- package/dist/tests/stringUtils.test.js +69 -0
- package/dist/tests/stringUtils.test.js.map +1 -0
- package/dist/tests/symbolNameUtils.test.d.ts +1 -0
- package/dist/tests/symbolNameUtils.test.js +83 -0
- package/dist/tests/symbolNameUtils.test.js.map +1 -0
- package/dist/tests/testState.test.d.ts +1 -0
- package/dist/tests/testState.test.js +521 -0
- package/dist/tests/testState.test.js.map +1 -0
- package/dist/tests/testUtils.d.ts +27 -0
- package/dist/tests/testUtils.js +213 -0
- package/dist/tests/testUtils.js.map +1 -0
- package/dist/tests/tokenizer.test.d.ts +1 -0
- package/dist/tests/tokenizer.test.js +1277 -0
- package/dist/tests/tokenizer.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.d.ts +1 -0
- package/dist/tests/typeEvaluator1.test.js +1023 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -0
- package/dist/tests/typeEvaluator2.test.d.ts +1 -0
- package/dist/tests/typeEvaluator2.test.js +869 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -0
- package/dist/tests/typeEvaluator3.test.d.ts +1 -0
- package/dist/tests/typeEvaluator3.test.js +915 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -0
- package/dist/tests/typeEvaluator4.test.d.ts +1 -0
- package/dist/tests/typeEvaluator4.test.js +901 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -0
- package/dist/tests/updateSymbolReference.test.d.ts +1 -0
- package/dist/tests/updateSymbolReference.test.js +980 -0
- package/dist/tests/updateSymbolReference.test.js.map +1 -0
- package/dist/tests/zipfs.test.d.ts +1 -0
- package/dist/tests/zipfs.test.js +112 -0
- package/dist/tests/zipfs.test.js.map +1 -0
- package/dist/workspaceMap.d.ts +6 -0
- package/dist/workspaceMap.js +73 -0
- package/dist/workspaceMap.js.map +1 -0
- package/package.json +45 -0
@@ -0,0 +1,3806 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
* parser.ts
|
4
|
+
* Copyright (c) Microsoft Corporation.
|
5
|
+
* Licensed under the MIT license.
|
6
|
+
* Author: Eric Traut
|
7
|
+
*
|
8
|
+
* Based on code from python-language-server repository:
|
9
|
+
* https://github.com/Microsoft/python-language-server
|
10
|
+
*
|
11
|
+
* Parser for the Python language. Converts a stream of tokens
|
12
|
+
* into an abstract syntax tree (AST).
|
13
|
+
*/
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
15
|
+
if (k2 === undefined) k2 = k;
|
16
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
17
|
+
}) : (function(o, m, k, k2) {
|
18
|
+
if (k2 === undefined) k2 = k;
|
19
|
+
o[k2] = m[k];
|
20
|
+
}));
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
23
|
+
}) : function(o, v) {
|
24
|
+
o["default"] = v;
|
25
|
+
});
|
26
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
27
|
+
if (mod && mod.__esModule) return mod;
|
28
|
+
var result = {};
|
29
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
30
|
+
__setModuleDefault(result, mod);
|
31
|
+
return result;
|
32
|
+
};
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
34
|
+
exports.Parser = exports.ParseOptions = void 0;
|
35
|
+
const collectionUtils_1 = require("../common/collectionUtils");
|
36
|
+
const debug_1 = require("../common/debug");
|
37
|
+
const diagnostic_1 = require("../common/diagnostic");
|
38
|
+
const diagnosticSink_1 = require("../common/diagnosticSink");
|
39
|
+
const positionUtils_1 = require("../common/positionUtils");
|
40
|
+
const pythonVersion_1 = require("../common/pythonVersion");
|
41
|
+
const timing_1 = require("../common/timing");
|
42
|
+
const localize_1 = require("../localization/localize");
|
43
|
+
const parseNodes_1 = require("./parseNodes");
|
44
|
+
const StringTokenUtils = __importStar(require("./stringTokenUtils"));
|
45
|
+
const tokenizer_1 = require("./tokenizer");
|
46
|
+
const tokenizerTypes_1 = require("./tokenizerTypes");
|
47
|
+
class ParseOptions {
|
48
|
+
constructor() {
|
49
|
+
this.isStubFile = false;
|
50
|
+
this.pythonVersion = pythonVersion_1.latestStablePythonVersion;
|
51
|
+
this.reportInvalidStringEscapeSequence = false;
|
52
|
+
this.skipFunctionAndClassBody = false;
|
53
|
+
this.ipythonMode = false;
|
54
|
+
this.reportErrorsForParsedStringContents = false;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.ParseOptions = ParseOptions;
|
58
|
+
// Limit the max child node depth to prevent stack overflows.
|
59
|
+
const maxChildNodeDepth = 256;
|
60
|
+
class Parser {
|
61
|
+
constructor() {
|
62
|
+
this._tokenIndex = 0;
|
63
|
+
this._areErrorsSuppressed = false;
|
64
|
+
this._parseOptions = new ParseOptions();
|
65
|
+
this._diagSink = new diagnosticSink_1.DiagnosticSink();
|
66
|
+
this._isInLoop = false;
|
67
|
+
this._isInFunction = false;
|
68
|
+
this._isInFinally = false;
|
69
|
+
this._isParsingTypeAnnotation = false;
|
70
|
+
this._isParsingIndexTrailer = false;
|
71
|
+
this._futureImportMap = new Map();
|
72
|
+
this._importedModules = [];
|
73
|
+
this._containsWildcardImport = false;
|
74
|
+
this._assignmentExpressionsAllowed = true;
|
75
|
+
this._typingImportAliases = [];
|
76
|
+
this._typingSymbolAliases = new Map();
|
77
|
+
}
|
78
|
+
parseSourceFile(fileContents, parseOptions, diagSink) {
|
79
|
+
timing_1.timingStats.tokenizeFileTime.timeOperation(() => {
|
80
|
+
this._startNewParse(fileContents, 0, fileContents.length, parseOptions, diagSink);
|
81
|
+
});
|
82
|
+
const moduleNode = parseNodes_1.ModuleNode.create({ start: 0, length: fileContents.length });
|
83
|
+
timing_1.timingStats.parseFileTime.timeOperation(() => {
|
84
|
+
while (!this._atEof()) {
|
85
|
+
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
86
|
+
// Handle a common error case and try to recover.
|
87
|
+
const nextToken = this._peekToken();
|
88
|
+
if (nextToken.type === 3 /* Indent */) {
|
89
|
+
this._getNextToken();
|
90
|
+
const indentToken = nextToken;
|
91
|
+
if (indentToken.isIndentAmbiguous) {
|
92
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), indentToken);
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedIndent(), nextToken);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
const statement = this._parseStatement();
|
99
|
+
if (!statement) {
|
100
|
+
// Perform basic error recovery to get to the next line.
|
101
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
102
|
+
}
|
103
|
+
else {
|
104
|
+
statement.parent = moduleNode;
|
105
|
+
moduleNode.statements.push(statement);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
});
|
110
|
+
(0, debug_1.assert)(this._tokenizerOutput !== undefined);
|
111
|
+
return {
|
112
|
+
text: fileContents,
|
113
|
+
parseTree: moduleNode,
|
114
|
+
importedModules: this._importedModules,
|
115
|
+
futureImports: this._futureImportMap,
|
116
|
+
tokenizerOutput: this._tokenizerOutput,
|
117
|
+
containsWildcardImport: this._containsWildcardImport,
|
118
|
+
typingSymbolAliases: this._typingSymbolAliases,
|
119
|
+
};
|
120
|
+
}
|
121
|
+
parseTextExpression(fileContents, textOffset, textLength, parseOptions, parseTextMode = 0 /* Expression */, initialParenDepth = 0, typingSymbolAliases) {
|
122
|
+
const diagSink = new diagnosticSink_1.DiagnosticSink();
|
123
|
+
this._startNewParse(fileContents, textOffset, textLength, parseOptions, diagSink, initialParenDepth);
|
124
|
+
if (typingSymbolAliases) {
|
125
|
+
this._typingSymbolAliases = new Map(typingSymbolAliases);
|
126
|
+
}
|
127
|
+
let parseTree;
|
128
|
+
if (parseTextMode === 1 /* VariableAnnotation */) {
|
129
|
+
parseTree = this._parseTypeAnnotation();
|
130
|
+
}
|
131
|
+
else if (parseTextMode === 2 /* FunctionAnnotation */) {
|
132
|
+
parseTree = this._parseFunctionTypeAnnotation();
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
const exprListResult = this._parseTestOrStarExpressionList(
|
136
|
+
/* allowAssignmentExpression */ false,
|
137
|
+
/* allowMultipleUnpack */ true);
|
138
|
+
if (exprListResult.parseError) {
|
139
|
+
parseTree = exprListResult.parseError;
|
140
|
+
}
|
141
|
+
else {
|
142
|
+
if (exprListResult.list.length === 0) {
|
143
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedExpr(), this._peekToken());
|
144
|
+
}
|
145
|
+
parseTree = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
if (this._peekTokenType() === 2 /* NewLine */) {
|
149
|
+
this._getNextToken();
|
150
|
+
}
|
151
|
+
if (!this._atEof()) {
|
152
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedExprToken(), this._peekToken());
|
153
|
+
}
|
154
|
+
return {
|
155
|
+
parseTree,
|
156
|
+
lines: this._tokenizerOutput.lines,
|
157
|
+
diagnostics: diagSink.fetchAndClear(),
|
158
|
+
};
|
159
|
+
}
|
160
|
+
_startNewParse(fileContents, textOffset, textLength, parseOptions, diagSink, initialParenDepth = 0) {
|
161
|
+
this._fileContents = fileContents;
|
162
|
+
this._parseOptions = parseOptions;
|
163
|
+
this._diagSink = diagSink;
|
164
|
+
// Tokenize the file contents.
|
165
|
+
const tokenizer = new tokenizer_1.Tokenizer();
|
166
|
+
this._tokenizerOutput = tokenizer.tokenize(fileContents, textOffset, textLength, initialParenDepth, this._parseOptions.ipythonMode);
|
167
|
+
this._tokenIndex = 0;
|
168
|
+
}
|
169
|
+
// stmt: simple_stmt | compound_stmt
|
170
|
+
// compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt
|
171
|
+
// | funcdef | classdef | decorated | async_stmt
|
172
|
+
_parseStatement() {
|
173
|
+
// Handle the errant condition of a dedent token here to provide
|
174
|
+
// better recovery.
|
175
|
+
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
176
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedUnindent(), this._peekToken());
|
177
|
+
}
|
178
|
+
switch (this._peekKeywordType()) {
|
179
|
+
case 20 /* If */:
|
180
|
+
return this._parseIfStatement();
|
181
|
+
case 35 /* While */:
|
182
|
+
return this._parseWhileStatement();
|
183
|
+
case 17 /* For */:
|
184
|
+
return this._parseForStatement();
|
185
|
+
case 34 /* Try */:
|
186
|
+
return this._parseTryStatement();
|
187
|
+
case 36 /* With */:
|
188
|
+
return this._parseWithStatement();
|
189
|
+
case 10 /* Def */:
|
190
|
+
return this._parseFunctionDef();
|
191
|
+
case 7 /* Class */:
|
192
|
+
return this._parseClassDef();
|
193
|
+
case 3 /* Async */:
|
194
|
+
return this._parseAsyncStatement();
|
195
|
+
case 25 /* Match */: {
|
196
|
+
// Match is considered a "soft" keyword, so we will treat
|
197
|
+
// it as an identifier if it is followed by an unexpected
|
198
|
+
// token.
|
199
|
+
const peekToken = this._peekToken(1);
|
200
|
+
let isInvalidMatchToken = false;
|
201
|
+
if (peekToken.type === 10 /* Colon */ ||
|
202
|
+
peekToken.type === 11 /* Semicolon */ ||
|
203
|
+
peekToken.type === 12 /* Comma */ ||
|
204
|
+
peekToken.type === 20 /* Dot */ ||
|
205
|
+
peekToken.type === 2 /* NewLine */ ||
|
206
|
+
peekToken.type === 1 /* EndOfStream */) {
|
207
|
+
isInvalidMatchToken = true;
|
208
|
+
}
|
209
|
+
else if (peekToken.type === 9 /* Operator */) {
|
210
|
+
const operatorToken = peekToken;
|
211
|
+
if (operatorToken.operatorType !== 26 /* Multiply */ &&
|
212
|
+
operatorToken.operatorType !== 33 /* Subtract */) {
|
213
|
+
isInvalidMatchToken = true;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
if (!isInvalidMatchToken) {
|
217
|
+
// Try to parse the match statement. If it doesn't appear to
|
218
|
+
// be a match statement, treat as a non-keyword and reparse.
|
219
|
+
const matchStatement = this._parseMatchStatement();
|
220
|
+
if (matchStatement) {
|
221
|
+
return matchStatement;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
if (this._peekOperatorType() === 22 /* MatrixMultiply */) {
|
227
|
+
return this._parseDecorated();
|
228
|
+
}
|
229
|
+
return this._parseSimpleStatement();
|
230
|
+
}
|
231
|
+
// async_stmt: 'async' (funcdef | with_stmt | for_stmt)
|
232
|
+
_parseAsyncStatement() {
|
233
|
+
const asyncToken = this._getKeywordToken(3 /* Async */);
|
234
|
+
switch (this._peekKeywordType()) {
|
235
|
+
case 10 /* Def */:
|
236
|
+
return this._parseFunctionDef(asyncToken);
|
237
|
+
case 36 /* With */:
|
238
|
+
return this._parseWithStatement(asyncToken);
|
239
|
+
case 17 /* For */:
|
240
|
+
return this._parseForStatement(asyncToken);
|
241
|
+
}
|
242
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedAsyncToken(), asyncToken);
|
243
|
+
return undefined;
|
244
|
+
}
|
245
|
+
// match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT
|
246
|
+
// subject_expr:
|
247
|
+
// | star_named_expression ',' star_named_expressions?
|
248
|
+
// | named_expression
|
249
|
+
_parseMatchStatement() {
|
250
|
+
// Parse the subject expression with errors suppressed. If it's not
|
251
|
+
// followed by a colon, we'll assume this is not a match statement.
|
252
|
+
// We need to do this because "match" is considered a soft keyword,
|
253
|
+
// and we need to distinguish between "match(2)" and "match (2):"
|
254
|
+
// and between "match[2]" and "match [2]:"
|
255
|
+
let smellsLikeMatchStatement = false;
|
256
|
+
this._suppressErrors(() => {
|
257
|
+
const curTokenIndex = this._tokenIndex;
|
258
|
+
this._getKeywordToken(25 /* Match */);
|
259
|
+
const expression = this._parseTestOrStarListAsExpression(
|
260
|
+
/* allowAssignmentExpression */ true,
|
261
|
+
/* allowMultipleUnpack */ true, 12 /* MissingPatternSubject */, localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
262
|
+
smellsLikeMatchStatement =
|
263
|
+
expression.nodeType !== 0 /* Error */ && this._peekToken().type === 10 /* Colon */;
|
264
|
+
// Set the token index back to the start.
|
265
|
+
this._tokenIndex = curTokenIndex;
|
266
|
+
});
|
267
|
+
if (!smellsLikeMatchStatement) {
|
268
|
+
return undefined;
|
269
|
+
}
|
270
|
+
const matchToken = this._getKeywordToken(25 /* Match */);
|
271
|
+
const subjectExpression = this._parseTestOrStarListAsExpression(
|
272
|
+
/* allowAssignmentExpression */ true,
|
273
|
+
/* allowMultipleUnpack */ true, 12 /* MissingPatternSubject */, localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
274
|
+
const matchNode = parseNodes_1.MatchNode.create(matchToken, subjectExpression);
|
275
|
+
const nextToken = this._peekToken();
|
276
|
+
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
277
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), nextToken);
|
278
|
+
// Try to perform parse recovery by consuming tokens until
|
279
|
+
// we find the end of the line.
|
280
|
+
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
281
|
+
this._getNextToken();
|
282
|
+
}
|
283
|
+
}
|
284
|
+
else if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
285
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedNewline(), nextToken);
|
286
|
+
}
|
287
|
+
else {
|
288
|
+
const possibleIndent = this._peekToken();
|
289
|
+
if (!this._consumeTokenIfType(3 /* Indent */)) {
|
290
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
const indentToken = possibleIndent;
|
294
|
+
if (indentToken.isIndentAmbiguous) {
|
295
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), indentToken);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
while (true) {
|
299
|
+
// Handle a common error here and see if we can recover.
|
300
|
+
const nextToken = this._peekToken();
|
301
|
+
if (nextToken.type === 3 /* Indent */) {
|
302
|
+
this._getNextToken();
|
303
|
+
const indentToken = nextToken;
|
304
|
+
if (indentToken.isIndentAmbiguous) {
|
305
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), indentToken);
|
306
|
+
}
|
307
|
+
else {
|
308
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedIndent(), nextToken);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
const caseStatement = this._parseCaseStatement();
|
312
|
+
if (!caseStatement) {
|
313
|
+
// Perform basic error recovery to get to the next line.
|
314
|
+
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
315
|
+
this._getNextToken();
|
316
|
+
}
|
317
|
+
}
|
318
|
+
else {
|
319
|
+
caseStatement.parent = matchNode;
|
320
|
+
matchNode.cases.push(caseStatement);
|
321
|
+
}
|
322
|
+
const dedentToken = this._peekToken();
|
323
|
+
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
324
|
+
if (!dedentToken.matchesIndent) {
|
325
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentIndent(), dedentToken);
|
326
|
+
}
|
327
|
+
if (dedentToken.isDedentAmbiguous) {
|
328
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), dedentToken);
|
329
|
+
}
|
330
|
+
break;
|
331
|
+
}
|
332
|
+
if (this._peekTokenType() === 1 /* EndOfStream */) {
|
333
|
+
break;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
if (matchNode.cases.length > 0) {
|
337
|
+
(0, parseNodes_1.extendRange)(matchNode, matchNode.cases[matchNode.cases.length - 1]);
|
338
|
+
}
|
339
|
+
else {
|
340
|
+
this._addError(localize_1.Localizer.Diagnostic.zeroCaseStatementsFound(), matchToken);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
// This feature requires Python 3.10.
|
344
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_10) {
|
345
|
+
this._addError(localize_1.Localizer.Diagnostic.matchIncompatible(), matchToken);
|
346
|
+
}
|
347
|
+
// Validate that only the last entry uses an irrefutable pattern.
|
348
|
+
for (let i = 0; i < matchNode.cases.length - 1; i++) {
|
349
|
+
const caseNode = matchNode.cases[i];
|
350
|
+
if (!caseNode.guardExpression && caseNode.isIrrefutable) {
|
351
|
+
this._addError(localize_1.Localizer.Diagnostic.casePatternIsIrrefutable(), caseNode.pattern);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
return matchNode;
|
355
|
+
}
|
356
|
+
// case_block: "case" patterns [guard] ':' block
|
357
|
+
// patterns: sequence_pattern | as_pattern
|
358
|
+
// guard: 'if' named_expression
|
359
|
+
_parseCaseStatement() {
|
360
|
+
const caseToken = this._peekToken();
|
361
|
+
if (!this._consumeTokenIfKeyword(6 /* Case */)) {
|
362
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCase(), caseToken);
|
363
|
+
return undefined;
|
364
|
+
}
|
365
|
+
const patternList = this._parsePatternSequence();
|
366
|
+
let casePattern;
|
367
|
+
if (patternList.parseError) {
|
368
|
+
casePattern = patternList.parseError;
|
369
|
+
}
|
370
|
+
else if (patternList.list.length === 0) {
|
371
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
|
372
|
+
casePattern = parseNodes_1.ErrorNode.create(caseToken, 11 /* MissingPattern */);
|
373
|
+
}
|
374
|
+
else if (patternList.list.length === 1 && !patternList.trailingComma) {
|
375
|
+
const pattern = patternList.list[0].orPatterns[0];
|
376
|
+
if (pattern.nodeType === 69 /* PatternCapture */ && pattern.isStar) {
|
377
|
+
casePattern = parseNodes_1.PatternSequenceNode.create(patternList.list[0], patternList.list);
|
378
|
+
}
|
379
|
+
else {
|
380
|
+
casePattern = patternList.list[0];
|
381
|
+
}
|
382
|
+
}
|
383
|
+
else {
|
384
|
+
casePattern = parseNodes_1.PatternSequenceNode.create(patternList.list[0], patternList.list);
|
385
|
+
}
|
386
|
+
let guardExpression;
|
387
|
+
if (this._consumeTokenIfKeyword(20 /* If */)) {
|
388
|
+
guardExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
389
|
+
}
|
390
|
+
const suite = this._parseSuite(this._isInFunction);
|
391
|
+
return parseNodes_1.CaseNode.create(caseToken, casePattern, this._isPatternIrrefutable(casePattern), guardExpression, suite);
|
392
|
+
}
|
393
|
+
// PEP 634 defines the concept of an "irrefutable" pattern - a pattern that
|
394
|
+
// will always be matched.
|
395
|
+
_isPatternIrrefutable(node) {
|
396
|
+
if (node.nodeType === 69 /* PatternCapture */) {
|
397
|
+
return true;
|
398
|
+
}
|
399
|
+
if (node.nodeType === 66 /* PatternAs */) {
|
400
|
+
return node.orPatterns.some((pattern) => this._isPatternIrrefutable(pattern));
|
401
|
+
}
|
402
|
+
return false;
|
403
|
+
}
|
404
|
+
_getPatternTargetNames(node, nameMap) {
|
405
|
+
switch (node.nodeType) {
|
406
|
+
case 65 /* PatternSequence */: {
|
407
|
+
node.entries.forEach((subpattern) => {
|
408
|
+
this._getPatternTargetNames(subpattern, nameMap);
|
409
|
+
});
|
410
|
+
break;
|
411
|
+
}
|
412
|
+
case 68 /* PatternClass */: {
|
413
|
+
node.arguments.forEach((arg) => {
|
414
|
+
this._getPatternTargetNames(arg.pattern, nameMap);
|
415
|
+
});
|
416
|
+
break;
|
417
|
+
}
|
418
|
+
case 66 /* PatternAs */: {
|
419
|
+
if (node.target) {
|
420
|
+
nameMap.set(node.target.value, true);
|
421
|
+
}
|
422
|
+
node.orPatterns.forEach((subpattern) => {
|
423
|
+
this._getPatternTargetNames(subpattern, nameMap);
|
424
|
+
});
|
425
|
+
break;
|
426
|
+
}
|
427
|
+
case 69 /* PatternCapture */: {
|
428
|
+
if (!node.isWildcard) {
|
429
|
+
nameMap.set(node.target.value, true);
|
430
|
+
}
|
431
|
+
break;
|
432
|
+
}
|
433
|
+
case 70 /* PatternMapping */: {
|
434
|
+
node.entries.forEach((mapEntry) => {
|
435
|
+
if (mapEntry.nodeType === 72 /* PatternMappingExpandEntry */) {
|
436
|
+
nameMap.set(mapEntry.target.value, true);
|
437
|
+
}
|
438
|
+
else {
|
439
|
+
this._getPatternTargetNames(mapEntry.keyPattern, nameMap);
|
440
|
+
this._getPatternTargetNames(mapEntry.valuePattern, nameMap);
|
441
|
+
}
|
442
|
+
});
|
443
|
+
break;
|
444
|
+
}
|
445
|
+
case 67 /* PatternLiteral */:
|
446
|
+
case 73 /* PatternValue */:
|
447
|
+
case 0 /* Error */: {
|
448
|
+
break;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
_parsePatternSequence() {
|
453
|
+
const patternList = this._parseExpressionListGeneric(() => this._parsePatternAs());
|
454
|
+
// Check for more than one star entry.
|
455
|
+
const starEntries = patternList.list.filter((entry) => entry.orPatterns.length === 1 &&
|
456
|
+
entry.orPatterns[0].nodeType === 69 /* PatternCapture */ &&
|
457
|
+
entry.orPatterns[0].isStar);
|
458
|
+
if (starEntries.length > 1) {
|
459
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateStarPattern(), starEntries[1].orPatterns[0]);
|
460
|
+
}
|
461
|
+
// Look for redundant capture targets.
|
462
|
+
const captureTargetMap = new Map();
|
463
|
+
patternList.list.forEach((asPattern) => {
|
464
|
+
asPattern.orPatterns.forEach((patternAtom) => {
|
465
|
+
if (patternAtom.nodeType === 69 /* PatternCapture */ &&
|
466
|
+
!patternAtom.isStar &&
|
467
|
+
!patternAtom.isWildcard) {
|
468
|
+
if (captureTargetMap.has(patternAtom.target.value)) {
|
469
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateCapturePatternTarget().format({
|
470
|
+
name: patternAtom.target.value,
|
471
|
+
}), patternAtom);
|
472
|
+
}
|
473
|
+
else {
|
474
|
+
captureTargetMap.set(patternAtom.target.value, patternAtom);
|
475
|
+
}
|
476
|
+
}
|
477
|
+
});
|
478
|
+
});
|
479
|
+
return patternList;
|
480
|
+
}
|
481
|
+
// as_pattern: or_pattern ['as' NAME]
|
482
|
+
// or_pattern: '|'.pattern_atom+
|
483
|
+
_parsePatternAs() {
|
484
|
+
const orPatterns = [];
|
485
|
+
while (true) {
|
486
|
+
const patternAtom = this._parsePatternAtom();
|
487
|
+
orPatterns.push(patternAtom);
|
488
|
+
if (!this._consumeTokenIfOperator(6 /* BitwiseOr */)) {
|
489
|
+
break;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
if (orPatterns.length > 1) {
|
493
|
+
// Star patterns cannot be ORed with other patterns.
|
494
|
+
orPatterns.forEach((patternAtom) => {
|
495
|
+
if (patternAtom.nodeType === 69 /* PatternCapture */ && patternAtom.isStar) {
|
496
|
+
this._addError(localize_1.Localizer.Diagnostic.starPatternInOrPattern(), patternAtom);
|
497
|
+
}
|
498
|
+
});
|
499
|
+
}
|
500
|
+
let target;
|
501
|
+
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
502
|
+
const nameToken = this._getTokenIfIdentifier();
|
503
|
+
if (nameToken) {
|
504
|
+
target = parseNodes_1.NameNode.create(nameToken);
|
505
|
+
}
|
506
|
+
else {
|
507
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedNameAfterAs(), this._peekToken());
|
508
|
+
}
|
509
|
+
}
|
510
|
+
// Star patterns cannot be used with AS pattern.
|
511
|
+
if (target &&
|
512
|
+
orPatterns.length === 1 &&
|
513
|
+
orPatterns[0].nodeType === 69 /* PatternCapture */ &&
|
514
|
+
orPatterns[0].isStar) {
|
515
|
+
this._addError(localize_1.Localizer.Diagnostic.starPatternInAsPattern(), orPatterns[0]);
|
516
|
+
}
|
517
|
+
// Validate that irrefutable patterns are not in any entries other than the last.
|
518
|
+
orPatterns.forEach((orPattern, index) => {
|
519
|
+
if (index < orPatterns.length - 1 && this._isPatternIrrefutable(orPattern)) {
|
520
|
+
this._addError(localize_1.Localizer.Diagnostic.orPatternIrrefutable(), orPattern);
|
521
|
+
}
|
522
|
+
});
|
523
|
+
// Validate that all bound variables are the same within all or patterns.
|
524
|
+
const fullNameMap = new Map();
|
525
|
+
orPatterns.forEach((orPattern) => {
|
526
|
+
this._getPatternTargetNames(orPattern, fullNameMap);
|
527
|
+
});
|
528
|
+
orPatterns.forEach((orPattern) => {
|
529
|
+
const localNameMap = new Map();
|
530
|
+
this._getPatternTargetNames(orPattern, localNameMap);
|
531
|
+
if (localNameMap.size < fullNameMap.size) {
|
532
|
+
const missingNames = Array.from(fullNameMap.keys()).filter((name) => !localNameMap.has(name));
|
533
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
534
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.orPatternMissingName().format({
|
535
|
+
name: missingNames.map((name) => `"${name}"`).join(', '),
|
536
|
+
}));
|
537
|
+
this._addError(localize_1.Localizer.Diagnostic.orPatternMissingName() + diag.getString(), orPattern);
|
538
|
+
}
|
539
|
+
});
|
540
|
+
return parseNodes_1.PatternAsNode.create(orPatterns, target);
|
541
|
+
}
|
542
|
+
// pattern_atom:
|
543
|
+
// | literal_pattern
|
544
|
+
// | name_or_attr
|
545
|
+
// | '(' as_pattern ')'
|
546
|
+
// | '[' [sequence_pattern] ']'
|
547
|
+
// | '(' [sequence_pattern] ')'
|
548
|
+
// | '{' [items_pattern] '}'
|
549
|
+
// | name_or_attr '(' [pattern_arguments ','?] ')'
|
550
|
+
// name_or_attr: attr | NAME
|
551
|
+
// attr: name_or_attr '.' NAME
|
552
|
+
// sequence_pattern: ','.maybe_star_pattern+ ','?
|
553
|
+
// maybe_star_pattern: '*' NAME | pattern
|
554
|
+
// items_pattern: ','.key_value_pattern+ ','?
|
555
|
+
_parsePatternAtom() {
|
556
|
+
const patternLiteral = this._parsePatternLiteral();
|
557
|
+
if (patternLiteral) {
|
558
|
+
return patternLiteral;
|
559
|
+
}
|
560
|
+
const patternCaptureOrValue = this._parsePatternCaptureOrValue();
|
561
|
+
if (patternCaptureOrValue) {
|
562
|
+
const openParenToken = this._peekToken();
|
563
|
+
if (patternCaptureOrValue.nodeType === 0 /* Error */ ||
|
564
|
+
!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
565
|
+
return patternCaptureOrValue;
|
566
|
+
}
|
567
|
+
const args = this._parseClassPatternArgList();
|
568
|
+
const classNameExpr = patternCaptureOrValue.nodeType === 69 /* PatternCapture */
|
569
|
+
? patternCaptureOrValue.target
|
570
|
+
: patternCaptureOrValue.expression;
|
571
|
+
const classPattern = parseNodes_1.PatternClassNode.create(classNameExpr, args);
|
572
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
573
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
574
|
+
// Consume the remainder of tokens on the line for error
|
575
|
+
// recovery.
|
576
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
577
|
+
// Extend the node's range to include the rest of the line.
|
578
|
+
// This helps the signatureHelpProvider.
|
579
|
+
(0, parseNodes_1.extendRange)(classPattern, this._peekToken());
|
580
|
+
}
|
581
|
+
return classPattern;
|
582
|
+
}
|
583
|
+
const nextToken = this._peekToken();
|
584
|
+
const nextOperator = this._peekOperatorType();
|
585
|
+
if (nextOperator === 26 /* Multiply */) {
|
586
|
+
const starToken = this._getNextToken();
|
587
|
+
const identifierToken = this._getTokenIfIdentifier();
|
588
|
+
if (!identifierToken) {
|
589
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
590
|
+
return parseNodes_1.ErrorNode.create(starToken, 2 /* MissingExpression */);
|
591
|
+
}
|
592
|
+
else {
|
593
|
+
return parseNodes_1.PatternCaptureNode.create(parseNodes_1.NameNode.create(identifierToken), starToken);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
if (nextToken.type === 13 /* OpenParenthesis */ || nextToken.type === 15 /* OpenBracket */) {
|
597
|
+
const startToken = this._getNextToken();
|
598
|
+
const patternList = this._parsePatternSequence();
|
599
|
+
let casePattern;
|
600
|
+
if (patternList.parseError) {
|
601
|
+
casePattern = patternList.parseError;
|
602
|
+
}
|
603
|
+
else if (patternList.list.length === 1 &&
|
604
|
+
!patternList.trailingComma &&
|
605
|
+
startToken.type === 13 /* OpenParenthesis */) {
|
606
|
+
const pattern = patternList.list[0].orPatterns[0];
|
607
|
+
if (pattern.nodeType === 69 /* PatternCapture */ && pattern.isStar) {
|
608
|
+
casePattern = parseNodes_1.PatternSequenceNode.create(startToken, patternList.list);
|
609
|
+
}
|
610
|
+
else {
|
611
|
+
casePattern = patternList.list[0];
|
612
|
+
}
|
613
|
+
(0, parseNodes_1.extendRange)(casePattern, nextToken);
|
614
|
+
}
|
615
|
+
else {
|
616
|
+
casePattern = parseNodes_1.PatternSequenceNode.create(startToken, patternList.list);
|
617
|
+
}
|
618
|
+
const endToken = this._peekToken();
|
619
|
+
if (this._consumeTokenIfType(nextToken.type === 13 /* OpenParenthesis */ ? 14 /* CloseParenthesis */ : 16 /* CloseBracket */)) {
|
620
|
+
(0, parseNodes_1.extendRange)(casePattern, endToken);
|
621
|
+
}
|
622
|
+
else {
|
623
|
+
this._addError(nextToken.type === 13 /* OpenParenthesis */
|
624
|
+
? localize_1.Localizer.Diagnostic.expectedCloseParen()
|
625
|
+
: localize_1.Localizer.Diagnostic.expectedCloseBracket(), nextToken);
|
626
|
+
this._consumeTokensUntilType([
|
627
|
+
10 /* Colon */,
|
628
|
+
nextToken.type === 13 /* OpenParenthesis */ ? 14 /* CloseParenthesis */ : 16 /* CloseBracket */,
|
629
|
+
]);
|
630
|
+
}
|
631
|
+
return casePattern;
|
632
|
+
}
|
633
|
+
else if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
634
|
+
const firstToken = this._getNextToken();
|
635
|
+
const mappingPattern = this._parsePatternMapping(firstToken);
|
636
|
+
const lastToken = this._peekToken();
|
637
|
+
if (this._consumeTokenIfType(18 /* CloseCurlyBrace */)) {
|
638
|
+
(0, parseNodes_1.extendRange)(mappingPattern, lastToken);
|
639
|
+
}
|
640
|
+
else {
|
641
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBrace(), nextToken);
|
642
|
+
this._consumeTokensUntilType([10 /* Colon */, 18 /* CloseCurlyBrace */]);
|
643
|
+
}
|
644
|
+
return mappingPattern;
|
645
|
+
}
|
646
|
+
return this._handleExpressionParseError(11 /* MissingPattern */, localize_1.Localizer.Diagnostic.expectedPatternExpr());
|
647
|
+
}
|
648
|
+
// pattern_arguments:
|
649
|
+
// | positional_patterns [',' keyword_patterns]
|
650
|
+
// | keyword_patterns
|
651
|
+
// positional_patterns: ','.as_pattern+
|
652
|
+
// keyword_patterns: ','.keyword_pattern+
|
653
|
+
_parseClassPatternArgList() {
|
654
|
+
const argList = [];
|
655
|
+
let sawKeywordArg = false;
|
656
|
+
while (true) {
|
657
|
+
const nextTokenType = this._peekTokenType();
|
658
|
+
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
659
|
+
nextTokenType === 2 /* NewLine */ ||
|
660
|
+
nextTokenType === 1 /* EndOfStream */) {
|
661
|
+
break;
|
662
|
+
}
|
663
|
+
const arg = this._parseClassPatternArgument();
|
664
|
+
if (arg.name) {
|
665
|
+
sawKeywordArg = true;
|
666
|
+
}
|
667
|
+
else if (sawKeywordArg && !arg.name) {
|
668
|
+
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
|
669
|
+
}
|
670
|
+
argList.push(arg);
|
671
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
672
|
+
break;
|
673
|
+
}
|
674
|
+
}
|
675
|
+
return argList;
|
676
|
+
}
|
677
|
+
// keyword_pattern: NAME '=' as_pattern
|
678
|
+
_parseClassPatternArgument() {
|
679
|
+
const firstToken = this._peekToken();
|
680
|
+
const secondToken = this._peekToken(1);
|
681
|
+
let keywordName;
|
682
|
+
if ((firstToken.type === 7 /* Identifier */ || firstToken.type === 8 /* Keyword */) &&
|
683
|
+
secondToken.type === 9 /* Operator */ &&
|
684
|
+
secondToken.operatorType === 2 /* Assign */) {
|
685
|
+
this._getNextToken();
|
686
|
+
keywordName = parseNodes_1.NameNode.create(firstToken);
|
687
|
+
this._getNextToken();
|
688
|
+
}
|
689
|
+
const pattern = this._parsePatternAs();
|
690
|
+
return parseNodes_1.PatternClassArgumentNode.create(pattern, keywordName);
|
691
|
+
}
|
692
|
+
// literal_pattern:
|
693
|
+
// | signed_number
|
694
|
+
// | signed_number '+' NUMBER
|
695
|
+
// | signed_number '-' NUMBER
|
696
|
+
// | strings
|
697
|
+
// | 'None'
|
698
|
+
// | 'True'
|
699
|
+
// | 'False'
|
700
|
+
_parsePatternLiteral() {
|
701
|
+
const nextToken = this._peekToken();
|
702
|
+
const nextOperator = this._peekOperatorType();
|
703
|
+
if (nextToken.type === 6 /* Number */ || nextOperator === 33 /* Subtract */) {
|
704
|
+
return this._parsePatternLiteralNumber();
|
705
|
+
}
|
706
|
+
if (nextToken.type === 5 /* String */) {
|
707
|
+
const stringList = this._parseAtom();
|
708
|
+
(0, debug_1.assert)(stringList.nodeType === 48 /* StringList */);
|
709
|
+
// Check for f-strings, which are not allowed.
|
710
|
+
stringList.strings.forEach((stringAtom) => {
|
711
|
+
if (stringAtom.token.flags & 64 /* Format */) {
|
712
|
+
this._addError(localize_1.Localizer.Diagnostic.formatStringInPattern(), stringAtom);
|
713
|
+
}
|
714
|
+
});
|
715
|
+
return parseNodes_1.PatternLiteralNode.create(stringList);
|
716
|
+
}
|
717
|
+
if (nextToken.type === 8 /* Keyword */) {
|
718
|
+
const keywordToken = nextToken;
|
719
|
+
if (keywordToken.keywordType === 15 /* False */ ||
|
720
|
+
keywordToken.keywordType === 33 /* True */ ||
|
721
|
+
keywordToken.keywordType === 26 /* None */) {
|
722
|
+
return parseNodes_1.PatternLiteralNode.create(this._parseAtom());
|
723
|
+
}
|
724
|
+
}
|
725
|
+
return undefined;
|
726
|
+
}
|
727
|
+
// signed_number: NUMBER | '-' NUMBER
|
728
|
+
_parsePatternLiteralNumber() {
|
729
|
+
const expression = this._parseArithmeticExpression();
|
730
|
+
let realValue;
|
731
|
+
let imagValue;
|
732
|
+
if (expression.nodeType === 7 /* BinaryOperation */) {
|
733
|
+
if (expression.operator === 33 /* Subtract */ || expression.operator === 0 /* Add */) {
|
734
|
+
realValue = expression.leftExpression;
|
735
|
+
imagValue = expression.rightExpression;
|
736
|
+
}
|
737
|
+
}
|
738
|
+
else {
|
739
|
+
realValue = expression;
|
740
|
+
}
|
741
|
+
if (realValue) {
|
742
|
+
if (realValue.nodeType === 55 /* UnaryOperation */ && realValue.operator === 33 /* Subtract */) {
|
743
|
+
realValue = realValue.expression;
|
744
|
+
}
|
745
|
+
if (realValue.nodeType !== 40 /* Number */ || (imagValue !== undefined && realValue.isImaginary)) {
|
746
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
|
747
|
+
imagValue = undefined;
|
748
|
+
}
|
749
|
+
}
|
750
|
+
if (imagValue) {
|
751
|
+
if (imagValue.nodeType === 55 /* UnaryOperation */ && imagValue.operator === 33 /* Subtract */) {
|
752
|
+
imagValue = imagValue.expression;
|
753
|
+
}
|
754
|
+
if (imagValue.nodeType !== 40 /* Number */ || !imagValue.isImaginary) {
|
755
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
|
756
|
+
}
|
757
|
+
}
|
758
|
+
return parseNodes_1.PatternLiteralNode.create(expression);
|
759
|
+
}
|
760
|
+
_parsePatternMapping(firstToken) {
|
761
|
+
const itemList = this._parseExpressionListGeneric(() => this._parsePatternMappingItem());
|
762
|
+
if (itemList.list.length > 0) {
|
763
|
+
// Verify there's at most one ** entry.
|
764
|
+
const starStarEntries = itemList.list.filter((entry) => entry.nodeType === 72 /* PatternMappingExpandEntry */);
|
765
|
+
if (starStarEntries.length > 1) {
|
766
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateStarStarPattern(), starStarEntries[1]);
|
767
|
+
}
|
768
|
+
return parseNodes_1.PatternMappingNode.create(firstToken, itemList.list);
|
769
|
+
}
|
770
|
+
return itemList.parseError || parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
771
|
+
}
|
772
|
+
// key_value_pattern:
|
773
|
+
// | (literal_pattern | attr) ':' as_pattern
|
774
|
+
// | '**' NAME
|
775
|
+
_parsePatternMappingItem() {
|
776
|
+
let keyExpression;
|
777
|
+
const doubleStar = this._peekToken();
|
778
|
+
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
779
|
+
const identifierToken = this._getTokenIfIdentifier();
|
780
|
+
if (!identifierToken) {
|
781
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
782
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
783
|
+
}
|
784
|
+
const nameNode = parseNodes_1.NameNode.create(identifierToken);
|
785
|
+
if (identifierToken.value === '_') {
|
786
|
+
this._addError(localize_1.Localizer.Diagnostic.starStarWildcardNotAllowed(), nameNode);
|
787
|
+
}
|
788
|
+
return parseNodes_1.PatternMappingExpandEntryNode.create(doubleStar, nameNode);
|
789
|
+
}
|
790
|
+
const patternLiteral = this._parsePatternLiteral();
|
791
|
+
if (patternLiteral) {
|
792
|
+
keyExpression = patternLiteral;
|
793
|
+
}
|
794
|
+
else {
|
795
|
+
const patternCaptureOrValue = this._parsePatternCaptureOrValue();
|
796
|
+
if (patternCaptureOrValue) {
|
797
|
+
if (patternCaptureOrValue.nodeType === 73 /* PatternValue */) {
|
798
|
+
keyExpression = patternCaptureOrValue;
|
799
|
+
}
|
800
|
+
else {
|
801
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedPatternValue(), patternCaptureOrValue);
|
802
|
+
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
803
|
+
}
|
804
|
+
}
|
805
|
+
}
|
806
|
+
if (!keyExpression) {
|
807
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
|
808
|
+
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
809
|
+
}
|
810
|
+
let valuePattern;
|
811
|
+
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
812
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), this._peekToken());
|
813
|
+
valuePattern = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
814
|
+
}
|
815
|
+
else {
|
816
|
+
valuePattern = this._parsePatternAs();
|
817
|
+
}
|
818
|
+
return parseNodes_1.PatternMappingKeyEntryNode.create(keyExpression, valuePattern);
|
819
|
+
}
|
820
|
+
_parsePatternCaptureOrValue() {
|
821
|
+
const nextToken = this._peekToken();
|
822
|
+
if (nextToken.type === 7 /* Identifier */ || nextToken.type === 8 /* Keyword */) {
|
823
|
+
let nameOrMember;
|
824
|
+
while (true) {
|
825
|
+
const identifierToken = this._getTokenIfIdentifier();
|
826
|
+
if (identifierToken) {
|
827
|
+
const nameNode = parseNodes_1.NameNode.create(identifierToken);
|
828
|
+
nameOrMember = nameOrMember ? parseNodes_1.MemberAccessNode.create(nameOrMember, nameNode) : nameNode;
|
829
|
+
}
|
830
|
+
else {
|
831
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
832
|
+
break;
|
833
|
+
}
|
834
|
+
if (!this._consumeTokenIfType(20 /* Dot */)) {
|
835
|
+
break;
|
836
|
+
}
|
837
|
+
}
|
838
|
+
if (!nameOrMember) {
|
839
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
840
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
841
|
+
}
|
842
|
+
if (nameOrMember.nodeType === 35 /* MemberAccess */) {
|
843
|
+
return parseNodes_1.PatternValueNode.create(nameOrMember);
|
844
|
+
}
|
845
|
+
return parseNodes_1.PatternCaptureNode.create(nameOrMember);
|
846
|
+
}
|
847
|
+
return undefined;
|
848
|
+
}
|
849
|
+
// if_stmt: 'if' test_suite ('elif' test_suite)* ['else' suite]
|
850
|
+
// test_suite: test suite
|
851
|
+
// test: or_test ['if' or_test 'else' test] | lambdef
|
852
|
+
_parseIfStatement(keywordType = 20 /* If */) {
|
853
|
+
const ifOrElifToken = this._getKeywordToken(keywordType);
|
854
|
+
const test = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
855
|
+
const suite = this._parseSuite(this._isInFunction);
|
856
|
+
const ifNode = parseNodes_1.IfNode.create(ifOrElifToken, test, suite);
|
857
|
+
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
858
|
+
ifNode.elseSuite = this._parseSuite(this._isInFunction);
|
859
|
+
ifNode.elseSuite.parent = ifNode;
|
860
|
+
(0, parseNodes_1.extendRange)(ifNode, ifNode.elseSuite);
|
861
|
+
}
|
862
|
+
else if (this._peekKeywordType() === 12 /* Elif */) {
|
863
|
+
// Recursively handle an "elif" statement.
|
864
|
+
ifNode.elseSuite = this._parseIfStatement(12 /* Elif */);
|
865
|
+
ifNode.elseSuite.parent = ifNode;
|
866
|
+
(0, parseNodes_1.extendRange)(ifNode, ifNode.elseSuite);
|
867
|
+
}
|
868
|
+
return ifNode;
|
869
|
+
}
|
870
|
+
_parseLoopSuite(disallowTypeComment = false) {
|
871
|
+
const wasInLoop = this._isInLoop;
|
872
|
+
const wasInFinally = this._isInFinally;
|
873
|
+
this._isInLoop = true;
|
874
|
+
this._isInFinally = false;
|
875
|
+
const suite = this._parseSuite(this._isInFunction, /* skipBody */ false, () => {
|
876
|
+
if (disallowTypeComment) {
|
877
|
+
this._detectUnsupportedTypeAnnotationComment();
|
878
|
+
}
|
879
|
+
});
|
880
|
+
this._isInLoop = wasInLoop;
|
881
|
+
this._isInFinally = wasInFinally;
|
882
|
+
return suite;
|
883
|
+
}
|
884
|
+
// suite: ':' (simple_stmt | NEWLINE INDENT stmt+ DEDENT)
|
885
|
+
_parseSuite(isFunction = false, skipBody = false, postColonCallback) {
|
886
|
+
const nextToken = this._peekToken();
|
887
|
+
const suite = parseNodes_1.SuiteNode.create(nextToken);
|
888
|
+
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
889
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), nextToken);
|
890
|
+
// Try to perform parse recovery by consuming tokens.
|
891
|
+
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
892
|
+
if (this._peekTokenType() === 10 /* Colon */) {
|
893
|
+
this._getNextToken();
|
894
|
+
}
|
895
|
+
else if (this._peekToken(1).type !== 3 /* Indent */) {
|
896
|
+
// Bail so we resume the at the next statement.
|
897
|
+
// We can't parse as a simple statement as we've skipped all but the newline.
|
898
|
+
this._getNextToken();
|
899
|
+
return suite;
|
900
|
+
}
|
901
|
+
}
|
902
|
+
}
|
903
|
+
if (skipBody) {
|
904
|
+
if (this._consumeTokenIfType(2 /* NewLine */)) {
|
905
|
+
let indent = 0;
|
906
|
+
while (true) {
|
907
|
+
const nextToken = this._getNextToken();
|
908
|
+
if (nextToken.type === 3 /* Indent */) {
|
909
|
+
indent++;
|
910
|
+
}
|
911
|
+
if (nextToken.type === 4 /* Dedent */) {
|
912
|
+
if (nextToken.isDedentAmbiguous) {
|
913
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), nextToken);
|
914
|
+
}
|
915
|
+
indent--;
|
916
|
+
if (indent === 0) {
|
917
|
+
break;
|
918
|
+
}
|
919
|
+
}
|
920
|
+
if (nextToken.type === 1 /* EndOfStream */) {
|
921
|
+
break;
|
922
|
+
}
|
923
|
+
}
|
924
|
+
}
|
925
|
+
else {
|
926
|
+
// consume tokens
|
927
|
+
this._parseSimpleStatement();
|
928
|
+
}
|
929
|
+
if (this._tokenIndex > 0) {
|
930
|
+
(0, parseNodes_1.extendRange)(suite, this._tokenizerOutput.tokens.getItemAt(this._tokenIndex - 1));
|
931
|
+
}
|
932
|
+
return suite;
|
933
|
+
}
|
934
|
+
if (postColonCallback) {
|
935
|
+
postColonCallback();
|
936
|
+
}
|
937
|
+
const wasFunction = this._isInFunction;
|
938
|
+
this._isInFunction = isFunction;
|
939
|
+
if (this._consumeTokenIfType(2 /* NewLine */)) {
|
940
|
+
if (postColonCallback) {
|
941
|
+
postColonCallback();
|
942
|
+
}
|
943
|
+
const possibleIndent = this._peekToken();
|
944
|
+
if (!this._consumeTokenIfType(3 /* Indent */)) {
|
945
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
|
946
|
+
}
|
947
|
+
else {
|
948
|
+
const indentToken = possibleIndent;
|
949
|
+
if (indentToken.isIndentAmbiguous) {
|
950
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), indentToken);
|
951
|
+
}
|
952
|
+
}
|
953
|
+
while (true) {
|
954
|
+
// Handle a common error here and see if we can recover.
|
955
|
+
const nextToken = this._peekToken();
|
956
|
+
if (nextToken.type === 3 /* Indent */) {
|
957
|
+
this._getNextToken();
|
958
|
+
const indentToken = nextToken;
|
959
|
+
if (indentToken.isIndentAmbiguous) {
|
960
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), indentToken);
|
961
|
+
}
|
962
|
+
else {
|
963
|
+
this._addError(localize_1.Localizer.Diagnostic.unexpectedIndent(), nextToken);
|
964
|
+
}
|
965
|
+
}
|
966
|
+
const statement = this._parseStatement();
|
967
|
+
if (!statement) {
|
968
|
+
// Perform basic error recovery to get to the next line.
|
969
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
970
|
+
}
|
971
|
+
else {
|
972
|
+
statement.parent = suite;
|
973
|
+
suite.statements.push(statement);
|
974
|
+
}
|
975
|
+
const dedentToken = this._peekToken();
|
976
|
+
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
977
|
+
if (!dedentToken.matchesIndent) {
|
978
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentIndent(), dedentToken);
|
979
|
+
}
|
980
|
+
if (dedentToken.isDedentAmbiguous) {
|
981
|
+
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), dedentToken);
|
982
|
+
}
|
983
|
+
break;
|
984
|
+
}
|
985
|
+
if (this._peekTokenType() === 1 /* EndOfStream */) {
|
986
|
+
break;
|
987
|
+
}
|
988
|
+
}
|
989
|
+
}
|
990
|
+
else {
|
991
|
+
const simpleStatement = this._parseSimpleStatement();
|
992
|
+
suite.statements.push(simpleStatement);
|
993
|
+
simpleStatement.parent = suite;
|
994
|
+
}
|
995
|
+
if (suite.statements.length > 0) {
|
996
|
+
(0, parseNodes_1.extendRange)(suite, suite.statements[suite.statements.length - 1]);
|
997
|
+
}
|
998
|
+
this._isInFunction = wasFunction;
|
999
|
+
return suite;
|
1000
|
+
}
|
1001
|
+
// for_stmt: [async] 'for' exprlist 'in' testlist suite ['else' suite]
|
1002
|
+
_parseForStatement(asyncToken) {
|
1003
|
+
const forToken = this._getKeywordToken(17 /* For */);
|
1004
|
+
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1005
|
+
let seqExpr;
|
1006
|
+
let forSuite;
|
1007
|
+
let elseSuite;
|
1008
|
+
if (!this._consumeTokenIfKeyword(22 /* In */)) {
|
1009
|
+
seqExpr = this._handleExpressionParseError(0 /* MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1010
|
+
forSuite = parseNodes_1.SuiteNode.create(this._peekToken());
|
1011
|
+
}
|
1012
|
+
else {
|
1013
|
+
seqExpr = this._parseTestOrStarListAsExpression(
|
1014
|
+
/* allowAssignmentExpression */ false,
|
1015
|
+
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedInExpr());
|
1016
|
+
forSuite = this._parseLoopSuite(/* disallowTypeComment */ true);
|
1017
|
+
// Versions of Python earlier than 3.9 didn't allow unpack operators if the
|
1018
|
+
// tuple wasn't enclosed in parentheses.
|
1019
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_9 && !this._parseOptions.isStubFile) {
|
1020
|
+
if (seqExpr.nodeType === 52 /* Tuple */ && !seqExpr.enclosedInParens) {
|
1021
|
+
let sawStar = false;
|
1022
|
+
seqExpr.expressions.forEach((expr) => {
|
1023
|
+
if (expr.nodeType === 56 /* Unpack */ && !sawStar) {
|
1024
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackOperatorNotAllowed(), expr);
|
1025
|
+
sawStar = true;
|
1026
|
+
}
|
1027
|
+
});
|
1028
|
+
}
|
1029
|
+
}
|
1030
|
+
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1031
|
+
elseSuite = this._parseSuite(this._isInFunction);
|
1032
|
+
}
|
1033
|
+
}
|
1034
|
+
const forNode = parseNodes_1.ForNode.create(forToken, targetExpr, seqExpr, forSuite);
|
1035
|
+
forNode.elseSuite = elseSuite;
|
1036
|
+
if (elseSuite) {
|
1037
|
+
(0, parseNodes_1.extendRange)(forNode, elseSuite);
|
1038
|
+
elseSuite.parent = forNode;
|
1039
|
+
}
|
1040
|
+
if (asyncToken) {
|
1041
|
+
forNode.isAsync = true;
|
1042
|
+
forNode.asyncToken = asyncToken;
|
1043
|
+
(0, parseNodes_1.extendRange)(forNode, asyncToken);
|
1044
|
+
}
|
1045
|
+
return forNode;
|
1046
|
+
}
|
1047
|
+
// comp_iter: comp_for | comp_if
|
1048
|
+
_tryParseListComprehension(target) {
|
1049
|
+
const compFor = this._tryParseCompForStatement();
|
1050
|
+
if (!compFor) {
|
1051
|
+
return undefined;
|
1052
|
+
}
|
1053
|
+
if (target.nodeType === 56 /* Unpack */) {
|
1054
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackIllegalInComprehension(), target);
|
1055
|
+
}
|
1056
|
+
else if (target.nodeType === 16 /* DictionaryExpandEntry */) {
|
1057
|
+
this._addError(localize_1.Localizer.Diagnostic.dictExpandIllegalInComprehension(), target);
|
1058
|
+
}
|
1059
|
+
const listCompNode = parseNodes_1.ListComprehensionNode.create(target);
|
1060
|
+
const forIfList = [compFor];
|
1061
|
+
while (true) {
|
1062
|
+
const compIter = this._tryParseCompForStatement() || this._tryParseCompIfStatement();
|
1063
|
+
if (!compIter) {
|
1064
|
+
break;
|
1065
|
+
}
|
1066
|
+
compIter.parent = listCompNode;
|
1067
|
+
forIfList.push(compIter);
|
1068
|
+
}
|
1069
|
+
listCompNode.forIfNodes = forIfList;
|
1070
|
+
if (forIfList.length > 0) {
|
1071
|
+
forIfList.forEach((comp) => {
|
1072
|
+
comp.parent = listCompNode;
|
1073
|
+
});
|
1074
|
+
(0, parseNodes_1.extendRange)(listCompNode, forIfList[forIfList.length - 1]);
|
1075
|
+
}
|
1076
|
+
return listCompNode;
|
1077
|
+
}
|
1078
|
+
// comp_for: ['async'] 'for' exprlist 'in' or_test [comp_iter]
|
1079
|
+
_tryParseCompForStatement() {
|
1080
|
+
const startTokenKeywordType = this._peekKeywordType();
|
1081
|
+
if (startTokenKeywordType === 3 /* Async */) {
|
1082
|
+
const nextToken = this._peekToken(1);
|
1083
|
+
if (nextToken.type !== 8 /* Keyword */ || nextToken.keywordType !== 17 /* For */) {
|
1084
|
+
return undefined;
|
1085
|
+
}
|
1086
|
+
}
|
1087
|
+
else if (startTokenKeywordType !== 17 /* For */) {
|
1088
|
+
return undefined;
|
1089
|
+
}
|
1090
|
+
let asyncToken;
|
1091
|
+
if (this._peekKeywordType() === 3 /* Async */) {
|
1092
|
+
asyncToken = this._getKeywordToken(3 /* Async */);
|
1093
|
+
}
|
1094
|
+
const forToken = this._getKeywordToken(17 /* For */);
|
1095
|
+
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1096
|
+
let seqExpr;
|
1097
|
+
if (!this._consumeTokenIfKeyword(22 /* In */)) {
|
1098
|
+
seqExpr = this._handleExpressionParseError(0 /* MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1099
|
+
}
|
1100
|
+
else {
|
1101
|
+
this._disallowAssignmentExpression(() => {
|
1102
|
+
seqExpr = this._parseOrTest();
|
1103
|
+
});
|
1104
|
+
}
|
1105
|
+
const compForNode = parseNodes_1.ListComprehensionForNode.create(asyncToken || forToken, targetExpr, seqExpr);
|
1106
|
+
if (asyncToken) {
|
1107
|
+
compForNode.isAsync = true;
|
1108
|
+
compForNode.asyncToken = asyncToken;
|
1109
|
+
}
|
1110
|
+
return compForNode;
|
1111
|
+
}
|
1112
|
+
// comp_if: 'if' test_nocond [comp_iter]
|
1113
|
+
// comp_iter: comp_for | comp_if
|
1114
|
+
_tryParseCompIfStatement() {
|
1115
|
+
if (this._peekKeywordType() !== 20 /* If */) {
|
1116
|
+
return undefined;
|
1117
|
+
}
|
1118
|
+
const ifToken = this._getKeywordToken(20 /* If */);
|
1119
|
+
const ifExpr = this._tryParseLambdaExpression() ||
|
1120
|
+
this._parseAssignmentExpression(/* disallowAssignmentExpression */ true);
|
1121
|
+
const compIfNode = parseNodes_1.ListComprehensionIfNode.create(ifToken, ifExpr);
|
1122
|
+
return compIfNode;
|
1123
|
+
}
|
1124
|
+
// while_stmt: 'while' test suite ['else' suite]
|
1125
|
+
_parseWhileStatement() {
|
1126
|
+
const whileToken = this._getKeywordToken(35 /* While */);
|
1127
|
+
const whileNode = parseNodes_1.WhileNode.create(whileToken, this._parseTestExpression(/* allowAssignmentExpression */ true), this._parseLoopSuite());
|
1128
|
+
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1129
|
+
whileNode.elseSuite = this._parseSuite(this._isInFunction);
|
1130
|
+
whileNode.elseSuite.parent = whileNode;
|
1131
|
+
(0, parseNodes_1.extendRange)(whileNode, whileNode.elseSuite);
|
1132
|
+
}
|
1133
|
+
return whileNode;
|
1134
|
+
}
|
1135
|
+
// try_stmt: ('try' suite
|
1136
|
+
// ((except_clause suite)+
|
1137
|
+
// ['else' suite]
|
1138
|
+
// ['finally' suite] |
|
1139
|
+
// 'finally' suite))
|
1140
|
+
// except_clause: 'except' [test ['as' NAME]]
|
1141
|
+
_parseTryStatement() {
|
1142
|
+
const tryToken = this._getKeywordToken(34 /* Try */);
|
1143
|
+
const trySuite = this._parseSuite(this._isInFunction);
|
1144
|
+
const tryNode = parseNodes_1.TryNode.create(tryToken, trySuite);
|
1145
|
+
let sawCatchAllExcept = false;
|
1146
|
+
while (true) {
|
1147
|
+
const exceptToken = this._peekToken();
|
1148
|
+
if (!this._consumeTokenIfKeyword(14 /* Except */)) {
|
1149
|
+
break;
|
1150
|
+
}
|
1151
|
+
// See if this is a Python 3.11 exception group.
|
1152
|
+
const possibleStarToken = this._peekToken();
|
1153
|
+
let isExceptGroup = false;
|
1154
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1155
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_11 && !this._parseOptions.isStubFile) {
|
1156
|
+
this._addError(localize_1.Localizer.Diagnostic.exceptionGroupIncompatible(), possibleStarToken);
|
1157
|
+
}
|
1158
|
+
isExceptGroup = true;
|
1159
|
+
}
|
1160
|
+
let typeExpr;
|
1161
|
+
let symbolName;
|
1162
|
+
if (this._peekTokenType() !== 10 /* Colon */) {
|
1163
|
+
typeExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1164
|
+
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1165
|
+
symbolName = this._getTokenIfIdentifier();
|
1166
|
+
if (!symbolName) {
|
1167
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedNameAfterAs(), this._peekToken());
|
1168
|
+
}
|
1169
|
+
}
|
1170
|
+
else {
|
1171
|
+
// Handle the python 2.x syntax in a graceful manner.
|
1172
|
+
const peekToken = this._peekToken();
|
1173
|
+
if (this._consumeTokenIfType(12 /* Comma */)) {
|
1174
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedAsAfterException(), peekToken);
|
1175
|
+
// Parse the expression expected in python 2.x, but discard it.
|
1176
|
+
this._parseTestExpression(/* allowAssignmentExpression */ false);
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
}
|
1180
|
+
if (!typeExpr) {
|
1181
|
+
if (sawCatchAllExcept) {
|
1182
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateCatchAll(), exceptToken);
|
1183
|
+
}
|
1184
|
+
sawCatchAllExcept = true;
|
1185
|
+
}
|
1186
|
+
else {
|
1187
|
+
if (sawCatchAllExcept) {
|
1188
|
+
this._addError(localize_1.Localizer.Diagnostic.namedExceptAfterCatchAll(), typeExpr);
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
const exceptSuite = this._parseSuite(this._isInFunction);
|
1192
|
+
const exceptNode = parseNodes_1.ExceptNode.create(exceptToken, exceptSuite, isExceptGroup);
|
1193
|
+
if (typeExpr) {
|
1194
|
+
exceptNode.typeExpression = typeExpr;
|
1195
|
+
exceptNode.typeExpression.parent = exceptNode;
|
1196
|
+
}
|
1197
|
+
if (symbolName) {
|
1198
|
+
exceptNode.name = parseNodes_1.NameNode.create(symbolName);
|
1199
|
+
exceptNode.name.parent = exceptNode;
|
1200
|
+
}
|
1201
|
+
tryNode.exceptClauses.push(exceptNode);
|
1202
|
+
exceptNode.parent = tryNode;
|
1203
|
+
}
|
1204
|
+
if (tryNode.exceptClauses.length > 0) {
|
1205
|
+
(0, parseNodes_1.extendRange)(tryNode, tryNode.exceptClauses[tryNode.exceptClauses.length - 1]);
|
1206
|
+
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1207
|
+
tryNode.elseSuite = this._parseSuite(this._isInFunction);
|
1208
|
+
tryNode.elseSuite.parent = tryNode;
|
1209
|
+
(0, parseNodes_1.extendRange)(tryNode, tryNode.elseSuite);
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
if (this._consumeTokenIfKeyword(16 /* Finally */)) {
|
1213
|
+
tryNode.finallySuite = this._parseSuite(this._isInFunction);
|
1214
|
+
tryNode.finallySuite.parent = tryNode;
|
1215
|
+
(0, parseNodes_1.extendRange)(tryNode, tryNode.finallySuite);
|
1216
|
+
}
|
1217
|
+
if (!tryNode.finallySuite && tryNode.exceptClauses.length === 0) {
|
1218
|
+
this._addError(localize_1.Localizer.Diagnostic.tryWithoutExcept(), tryToken);
|
1219
|
+
}
|
1220
|
+
return tryNode;
|
1221
|
+
}
|
1222
|
+
// funcdef: 'def' NAME parameters ['->' test] ':' suite
|
1223
|
+
// parameters: '(' [typedargslist] ')'
|
1224
|
+
_parseFunctionDef(asyncToken, decorators) {
|
1225
|
+
const defToken = this._getKeywordToken(10 /* Def */);
|
1226
|
+
const nameToken = this._getTokenIfIdentifier();
|
1227
|
+
if (!nameToken) {
|
1228
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedFunctionName(), defToken);
|
1229
|
+
return parseNodes_1.ErrorNode.create(defToken, 10 /* MissingFunctionParameterList */, undefined, decorators);
|
1230
|
+
}
|
1231
|
+
const openParenToken = this._peekToken();
|
1232
|
+
if (!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
1233
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
|
1234
|
+
return parseNodes_1.ErrorNode.create(nameToken, 10 /* MissingFunctionParameterList */, parseNodes_1.NameNode.create(nameToken), decorators);
|
1235
|
+
}
|
1236
|
+
const paramList = this._parseVarArgsList(14 /* CloseParenthesis */, /* allowAnnotations */ true);
|
1237
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1238
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1239
|
+
this._consumeTokensUntilType([10 /* Colon */]);
|
1240
|
+
}
|
1241
|
+
let returnType;
|
1242
|
+
if (this._consumeTokenIfType(21 /* Arrow */)) {
|
1243
|
+
returnType = this._parseTypeAnnotation();
|
1244
|
+
}
|
1245
|
+
let functionTypeAnnotationToken;
|
1246
|
+
const suite = this._parseSuite(/* isFunction */ true, this._parseOptions.skipFunctionAndClassBody, () => {
|
1247
|
+
if (!functionTypeAnnotationToken) {
|
1248
|
+
functionTypeAnnotationToken = this._getTypeAnnotationCommentText();
|
1249
|
+
}
|
1250
|
+
});
|
1251
|
+
const functionNode = parseNodes_1.FunctionNode.create(defToken, parseNodes_1.NameNode.create(nameToken), suite);
|
1252
|
+
if (asyncToken) {
|
1253
|
+
functionNode.isAsync = true;
|
1254
|
+
(0, parseNodes_1.extendRange)(functionNode, asyncToken);
|
1255
|
+
}
|
1256
|
+
functionNode.parameters = paramList;
|
1257
|
+
paramList.forEach((param) => {
|
1258
|
+
param.parent = functionNode;
|
1259
|
+
});
|
1260
|
+
if (decorators) {
|
1261
|
+
functionNode.decorators = decorators;
|
1262
|
+
decorators.forEach((decorator) => {
|
1263
|
+
decorator.parent = functionNode;
|
1264
|
+
});
|
1265
|
+
if (decorators.length > 0) {
|
1266
|
+
(0, parseNodes_1.extendRange)(functionNode, decorators[0]);
|
1267
|
+
}
|
1268
|
+
}
|
1269
|
+
if (returnType) {
|
1270
|
+
functionNode.returnTypeAnnotation = returnType;
|
1271
|
+
functionNode.returnTypeAnnotation.parent = functionNode;
|
1272
|
+
(0, parseNodes_1.extendRange)(functionNode, returnType);
|
1273
|
+
}
|
1274
|
+
// If there was a type annotation comment for the function,
|
1275
|
+
// parse it now.
|
1276
|
+
if (functionTypeAnnotationToken) {
|
1277
|
+
this._parseFunctionTypeAnnotationComment(functionTypeAnnotationToken, functionNode);
|
1278
|
+
}
|
1279
|
+
return functionNode;
|
1280
|
+
}
|
1281
|
+
// typedargslist: (
|
1282
|
+
// tfpdef ['=' test] (',' tfpdef ['=' test])*
|
1283
|
+
// [ ','
|
1284
|
+
// [
|
1285
|
+
// '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
1286
|
+
// | '**' tfpdef [',']
|
1287
|
+
// ]
|
1288
|
+
// ]
|
1289
|
+
// | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
1290
|
+
// | '**' tfpdef [','])
|
1291
|
+
// tfpdef: NAME [':' test]
|
1292
|
+
// vfpdef: NAME;
|
1293
|
+
_parseVarArgsList(terminator, allowAnnotations) {
|
1294
|
+
const paramMap = new Map();
|
1295
|
+
const paramList = [];
|
1296
|
+
let sawDefaultParam = false;
|
1297
|
+
let reportedNonDefaultParamErr = false;
|
1298
|
+
let sawKeywordOnlySeparator = false;
|
1299
|
+
let sawPositionOnlySeparator = false;
|
1300
|
+
let sawArgs = false;
|
1301
|
+
let sawKwArgs = false;
|
1302
|
+
while (true) {
|
1303
|
+
if (this._peekTokenType() === terminator) {
|
1304
|
+
break;
|
1305
|
+
}
|
1306
|
+
const param = this._parseParameter(allowAnnotations);
|
1307
|
+
if (!param) {
|
1308
|
+
this._consumeTokensUntilType([terminator]);
|
1309
|
+
break;
|
1310
|
+
}
|
1311
|
+
if (param.name) {
|
1312
|
+
const name = param.name.value;
|
1313
|
+
if (paramMap.has(name)) {
|
1314
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateParam().format({ name }), param.name);
|
1315
|
+
}
|
1316
|
+
else {
|
1317
|
+
paramMap.set(name, name);
|
1318
|
+
}
|
1319
|
+
}
|
1320
|
+
else if (param.category === 0 /* Simple */) {
|
1321
|
+
if (paramList.length === 0) {
|
1322
|
+
this._addError(localize_1.Localizer.Diagnostic.positionOnlyFirstParam(), param);
|
1323
|
+
}
|
1324
|
+
}
|
1325
|
+
if (param.category === 0 /* Simple */) {
|
1326
|
+
if (!param.name) {
|
1327
|
+
if (sawPositionOnlySeparator) {
|
1328
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicatePositionOnly(), param);
|
1329
|
+
}
|
1330
|
+
else if (sawKeywordOnlySeparator) {
|
1331
|
+
this._addError(localize_1.Localizer.Diagnostic.positionOnlyAfterKeywordOnly(), param);
|
1332
|
+
}
|
1333
|
+
else if (sawArgs) {
|
1334
|
+
this._addError(localize_1.Localizer.Diagnostic.positionOnlyAfterArgs(), param);
|
1335
|
+
}
|
1336
|
+
sawPositionOnlySeparator = true;
|
1337
|
+
}
|
1338
|
+
else {
|
1339
|
+
if (param.defaultValue) {
|
1340
|
+
sawDefaultParam = true;
|
1341
|
+
}
|
1342
|
+
else if (sawDefaultParam && !sawKeywordOnlySeparator && !sawArgs) {
|
1343
|
+
// Report this error only once.
|
1344
|
+
if (!reportedNonDefaultParamErr) {
|
1345
|
+
this._addError(localize_1.Localizer.Diagnostic.nonDefaultAfterDefault(), param);
|
1346
|
+
reportedNonDefaultParamErr = true;
|
1347
|
+
}
|
1348
|
+
}
|
1349
|
+
}
|
1350
|
+
}
|
1351
|
+
paramList.push(param);
|
1352
|
+
if (param.category === 1 /* VarArgList */) {
|
1353
|
+
if (!param.name) {
|
1354
|
+
if (sawKeywordOnlySeparator) {
|
1355
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateKeywordOnly(), param);
|
1356
|
+
}
|
1357
|
+
else if (sawArgs) {
|
1358
|
+
this._addError(localize_1.Localizer.Diagnostic.keywordOnlyAfterArgs(), param);
|
1359
|
+
}
|
1360
|
+
sawKeywordOnlySeparator = true;
|
1361
|
+
}
|
1362
|
+
else {
|
1363
|
+
if (sawKeywordOnlySeparator || sawArgs) {
|
1364
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateArgsParam(), param);
|
1365
|
+
}
|
1366
|
+
sawArgs = true;
|
1367
|
+
}
|
1368
|
+
}
|
1369
|
+
if (param.category === 2 /* VarArgDictionary */) {
|
1370
|
+
if (sawKwArgs) {
|
1371
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateKwargsParam(), param);
|
1372
|
+
}
|
1373
|
+
sawKwArgs = true;
|
1374
|
+
}
|
1375
|
+
else if (sawKwArgs) {
|
1376
|
+
this._addError(localize_1.Localizer.Diagnostic.paramAfterKwargsParam(), param);
|
1377
|
+
}
|
1378
|
+
const foundComma = this._consumeTokenIfType(12 /* Comma */);
|
1379
|
+
if (allowAnnotations && !param.typeAnnotation) {
|
1380
|
+
// Look for a type annotation comment at the end of the line.
|
1381
|
+
const typeAnnotationComment = this._parseVariableTypeAnnotationComment();
|
1382
|
+
if (typeAnnotationComment) {
|
1383
|
+
param.typeAnnotationComment = typeAnnotationComment;
|
1384
|
+
param.typeAnnotationComment.parent = param;
|
1385
|
+
(0, parseNodes_1.extendRange)(param, param.typeAnnotationComment);
|
1386
|
+
}
|
1387
|
+
}
|
1388
|
+
if (!foundComma) {
|
1389
|
+
break;
|
1390
|
+
}
|
1391
|
+
}
|
1392
|
+
if (paramList.length > 0) {
|
1393
|
+
const lastParam = paramList[paramList.length - 1];
|
1394
|
+
if (lastParam.category === 1 /* VarArgList */ && !lastParam.name) {
|
1395
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedNamedParameter(), lastParam);
|
1396
|
+
}
|
1397
|
+
}
|
1398
|
+
return paramList;
|
1399
|
+
}
|
1400
|
+
_parseParameter(allowAnnotations) {
|
1401
|
+
let starCount = 0;
|
1402
|
+
let slashCount = 0;
|
1403
|
+
const firstToken = this._peekToken();
|
1404
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1405
|
+
starCount = 1;
|
1406
|
+
}
|
1407
|
+
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
1408
|
+
starCount = 2;
|
1409
|
+
}
|
1410
|
+
else if (this._consumeTokenIfOperator(10 /* Divide */)) {
|
1411
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_8 && !this._parseOptions.isStubFile) {
|
1412
|
+
this._addError(localize_1.Localizer.Diagnostic.positionOnlyIncompatible(), firstToken);
|
1413
|
+
}
|
1414
|
+
slashCount = 1;
|
1415
|
+
}
|
1416
|
+
const paramName = this._getTokenIfIdentifier();
|
1417
|
+
if (!paramName) {
|
1418
|
+
if (starCount === 1) {
|
1419
|
+
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 1 /* VarArgList */);
|
1420
|
+
return paramNode;
|
1421
|
+
}
|
1422
|
+
else if (slashCount === 1) {
|
1423
|
+
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 0 /* Simple */);
|
1424
|
+
return paramNode;
|
1425
|
+
}
|
1426
|
+
// Check for the Python 2.x parameter sublist syntax and handle it gracefully.
|
1427
|
+
if (this._peekTokenType() === 13 /* OpenParenthesis */) {
|
1428
|
+
const sublistStart = this._getNextToken();
|
1429
|
+
if (this._consumeTokensUntilType([14 /* CloseParenthesis */])) {
|
1430
|
+
this._getNextToken();
|
1431
|
+
}
|
1432
|
+
this._addError(localize_1.Localizer.Diagnostic.sublistParamsIncompatible(), sublistStart);
|
1433
|
+
}
|
1434
|
+
else {
|
1435
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedParamName(), this._peekToken());
|
1436
|
+
}
|
1437
|
+
}
|
1438
|
+
let paramType = 0 /* Simple */;
|
1439
|
+
if (starCount === 1) {
|
1440
|
+
paramType = 1 /* VarArgList */;
|
1441
|
+
}
|
1442
|
+
else if (starCount === 2) {
|
1443
|
+
paramType = 2 /* VarArgDictionary */;
|
1444
|
+
}
|
1445
|
+
const paramNode = parseNodes_1.ParameterNode.create(firstToken, paramType);
|
1446
|
+
if (paramName) {
|
1447
|
+
paramNode.name = parseNodes_1.NameNode.create(paramName);
|
1448
|
+
paramNode.name.parent = paramNode;
|
1449
|
+
(0, parseNodes_1.extendRange)(paramNode, paramName);
|
1450
|
+
}
|
1451
|
+
if (allowAnnotations && this._consumeTokenIfType(10 /* Colon */)) {
|
1452
|
+
paramNode.typeAnnotation = this._parseTypeAnnotation(paramType === 1 /* VarArgList */);
|
1453
|
+
paramNode.typeAnnotation.parent = paramNode;
|
1454
|
+
(0, parseNodes_1.extendRange)(paramNode, paramNode.typeAnnotation);
|
1455
|
+
}
|
1456
|
+
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
1457
|
+
paramNode.defaultValue = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
1458
|
+
paramNode.defaultValue.parent = paramNode;
|
1459
|
+
(0, parseNodes_1.extendRange)(paramNode, paramNode.defaultValue);
|
1460
|
+
if (starCount > 0) {
|
1461
|
+
this._addError(localize_1.Localizer.Diagnostic.defaultValueNotAllowed(), paramNode.defaultValue);
|
1462
|
+
}
|
1463
|
+
}
|
1464
|
+
return paramNode;
|
1465
|
+
}
|
1466
|
+
// with_stmt: 'with' with_item (',' with_item)* ':' suite
|
1467
|
+
// Python 3.10 adds support for optional parentheses around
|
1468
|
+
// with_item list.
|
1469
|
+
_parseWithStatement(asyncToken) {
|
1470
|
+
const withToken = this._getKeywordToken(36 /* With */);
|
1471
|
+
let withItemList = [];
|
1472
|
+
const possibleParen = this._peekToken();
|
1473
|
+
// If the expression starts with a paren, parse it as though the
|
1474
|
+
// paren is enclosing the list of "with items". This is done as a
|
1475
|
+
// "dry run" to determine whether the entire list of "with items"
|
1476
|
+
// is enclosed in parentheses.
|
1477
|
+
let isParenthesizedWithItemList = false;
|
1478
|
+
if (possibleParen.type === 13 /* OpenParenthesis */) {
|
1479
|
+
const openParenTokenIndex = this._tokenIndex;
|
1480
|
+
this._suppressErrors(() => {
|
1481
|
+
this._getNextToken();
|
1482
|
+
while (true) {
|
1483
|
+
withItemList.push(this._parseWithItem());
|
1484
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1485
|
+
break;
|
1486
|
+
}
|
1487
|
+
if (this._peekToken().type === 14 /* CloseParenthesis */) {
|
1488
|
+
break;
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
if (this._peekToken().type === 14 /* CloseParenthesis */ &&
|
1492
|
+
this._peekToken(1).type === 10 /* Colon */) {
|
1493
|
+
isParenthesizedWithItemList = withItemList.length !== 1 || withItemList[0].target !== undefined;
|
1494
|
+
}
|
1495
|
+
this._tokenIndex = openParenTokenIndex;
|
1496
|
+
withItemList = [];
|
1497
|
+
});
|
1498
|
+
}
|
1499
|
+
if (isParenthesizedWithItemList) {
|
1500
|
+
this._consumeTokenIfType(13 /* OpenParenthesis */);
|
1501
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_9) {
|
1502
|
+
this._addError(localize_1.Localizer.Diagnostic.parenthesizedContextManagerIllegal(), possibleParen);
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
while (true) {
|
1506
|
+
withItemList.push(this._parseWithItem());
|
1507
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1508
|
+
break;
|
1509
|
+
}
|
1510
|
+
if (this._peekToken().type === 14 /* CloseParenthesis */) {
|
1511
|
+
break;
|
1512
|
+
}
|
1513
|
+
}
|
1514
|
+
if (isParenthesizedWithItemList) {
|
1515
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1516
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), possibleParen);
|
1517
|
+
}
|
1518
|
+
}
|
1519
|
+
const withSuite = this._parseSuite(this._isInFunction, /* skipBody */ false, () => {
|
1520
|
+
this._detectUnsupportedTypeAnnotationComment();
|
1521
|
+
});
|
1522
|
+
const withNode = parseNodes_1.WithNode.create(withToken, withSuite);
|
1523
|
+
if (asyncToken) {
|
1524
|
+
withNode.isAsync = true;
|
1525
|
+
withNode.asyncToken = asyncToken;
|
1526
|
+
(0, parseNodes_1.extendRange)(withNode, asyncToken);
|
1527
|
+
}
|
1528
|
+
withNode.withItems = withItemList;
|
1529
|
+
withItemList.forEach((withItem) => {
|
1530
|
+
withItem.parent = withNode;
|
1531
|
+
});
|
1532
|
+
return withNode;
|
1533
|
+
}
|
1534
|
+
// with_item: test ['as' expr]
|
1535
|
+
_parseWithItem() {
|
1536
|
+
const expr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1537
|
+
const itemNode = parseNodes_1.WithItemNode.create(expr);
|
1538
|
+
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1539
|
+
itemNode.target = this._parseExpression(/* allowUnpack */ false);
|
1540
|
+
itemNode.target.parent = itemNode;
|
1541
|
+
(0, parseNodes_1.extendRange)(itemNode, itemNode.target);
|
1542
|
+
}
|
1543
|
+
return itemNode;
|
1544
|
+
}
|
1545
|
+
// decorators: decorator+
|
1546
|
+
// decorated: decorators (classdef | funcdef | async_funcdef)
|
1547
|
+
_parseDecorated() {
|
1548
|
+
const decoratorList = [];
|
1549
|
+
while (true) {
|
1550
|
+
if (this._peekOperatorType() === 22 /* MatrixMultiply */) {
|
1551
|
+
decoratorList.push(this._parseDecorator());
|
1552
|
+
}
|
1553
|
+
else {
|
1554
|
+
break;
|
1555
|
+
}
|
1556
|
+
}
|
1557
|
+
const nextToken = this._peekToken();
|
1558
|
+
if (nextToken.type === 8 /* Keyword */) {
|
1559
|
+
if (nextToken.keywordType === 3 /* Async */) {
|
1560
|
+
this._getNextToken();
|
1561
|
+
if (this._peekKeywordType() !== 10 /* Def */) {
|
1562
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedFunctionAfterAsync(), this._peekToken());
|
1563
|
+
}
|
1564
|
+
else {
|
1565
|
+
return this._parseFunctionDef(nextToken, decoratorList);
|
1566
|
+
}
|
1567
|
+
}
|
1568
|
+
else if (nextToken.keywordType === 10 /* Def */) {
|
1569
|
+
return this._parseFunctionDef(undefined, decoratorList);
|
1570
|
+
}
|
1571
|
+
else if (nextToken.keywordType === 7 /* Class */) {
|
1572
|
+
return this._parseClassDef(decoratorList);
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedAfterDecorator(), this._peekToken());
|
1576
|
+
// Return a dummy class declaration so the completion provider has
|
1577
|
+
// some parse nodes to work with.
|
1578
|
+
return parseNodes_1.ClassNode.createDummyForDecorators(decoratorList);
|
1579
|
+
}
|
1580
|
+
// decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
|
1581
|
+
_parseDecorator() {
|
1582
|
+
const atOperator = this._getNextToken();
|
1583
|
+
(0, debug_1.assert)(atOperator.operatorType === 22 /* MatrixMultiply */);
|
1584
|
+
const expression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1585
|
+
// Versions of Python prior to 3.9 support a limited set of
|
1586
|
+
// expression forms.
|
1587
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_9) {
|
1588
|
+
let isSupportedExpressionForm = false;
|
1589
|
+
if (this._isNameOrMemberAccessExpression(expression)) {
|
1590
|
+
isSupportedExpressionForm = true;
|
1591
|
+
}
|
1592
|
+
else if (expression.nodeType === 9 /* Call */ &&
|
1593
|
+
this._isNameOrMemberAccessExpression(expression.leftExpression)) {
|
1594
|
+
isSupportedExpressionForm = true;
|
1595
|
+
}
|
1596
|
+
if (!isSupportedExpressionForm) {
|
1597
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedDecoratorExpr(), expression);
|
1598
|
+
}
|
1599
|
+
}
|
1600
|
+
const decoratorNode = parseNodes_1.DecoratorNode.create(atOperator, expression);
|
1601
|
+
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
1602
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedDecoratorNewline(), this._peekToken());
|
1603
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
1604
|
+
}
|
1605
|
+
return decoratorNode;
|
1606
|
+
}
|
1607
|
+
_isNameOrMemberAccessExpression(expression) {
|
1608
|
+
if (expression.nodeType === 38 /* Name */) {
|
1609
|
+
return true;
|
1610
|
+
}
|
1611
|
+
else if (expression.nodeType === 35 /* MemberAccess */) {
|
1612
|
+
return this._isNameOrMemberAccessExpression(expression.leftExpression);
|
1613
|
+
}
|
1614
|
+
return false;
|
1615
|
+
}
|
1616
|
+
// classdef: 'class' NAME ['(' [arglist] ')'] suite
|
1617
|
+
_parseClassDef(decorators) {
|
1618
|
+
const classToken = this._getKeywordToken(7 /* Class */);
|
1619
|
+
let nameToken = this._getTokenIfIdentifier();
|
1620
|
+
if (!nameToken) {
|
1621
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedClassName(), this._peekToken());
|
1622
|
+
nameToken = tokenizerTypes_1.IdentifierToken.create(0, 0, '', /* comments */ undefined);
|
1623
|
+
}
|
1624
|
+
let argList = [];
|
1625
|
+
const openParenToken = this._peekToken();
|
1626
|
+
if (this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
1627
|
+
argList = this._parseArgList().args;
|
1628
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1629
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1630
|
+
}
|
1631
|
+
}
|
1632
|
+
const suite = this._parseSuite(/* isFunction */ false, this._parseOptions.skipFunctionAndClassBody);
|
1633
|
+
const classNode = parseNodes_1.ClassNode.create(classToken, parseNodes_1.NameNode.create(nameToken), suite);
|
1634
|
+
classNode.arguments = argList;
|
1635
|
+
argList.forEach((arg) => {
|
1636
|
+
arg.parent = classNode;
|
1637
|
+
});
|
1638
|
+
if (decorators) {
|
1639
|
+
classNode.decorators = decorators;
|
1640
|
+
if (decorators.length > 0) {
|
1641
|
+
decorators.forEach((decorator) => {
|
1642
|
+
decorator.parent = classNode;
|
1643
|
+
});
|
1644
|
+
(0, parseNodes_1.extendRange)(classNode, decorators[0]);
|
1645
|
+
}
|
1646
|
+
}
|
1647
|
+
return classNode;
|
1648
|
+
}
|
1649
|
+
_parsePassStatement() {
|
1650
|
+
return parseNodes_1.PassNode.create(this._getKeywordToken(30 /* Pass */));
|
1651
|
+
}
|
1652
|
+
_parseBreakStatement() {
|
1653
|
+
const breakToken = this._getKeywordToken(5 /* Break */);
|
1654
|
+
if (!this._isInLoop) {
|
1655
|
+
this._addError(localize_1.Localizer.Diagnostic.breakOutsideLoop(), breakToken);
|
1656
|
+
}
|
1657
|
+
return parseNodes_1.BreakNode.create(breakToken);
|
1658
|
+
}
|
1659
|
+
_parseContinueStatement() {
|
1660
|
+
const continueToken = this._getKeywordToken(8 /* Continue */);
|
1661
|
+
if (!this._isInLoop) {
|
1662
|
+
this._addError(localize_1.Localizer.Diagnostic.continueOutsideLoop(), continueToken);
|
1663
|
+
}
|
1664
|
+
else if (this._isInFinally) {
|
1665
|
+
this._addError(localize_1.Localizer.Diagnostic.continueInFinally(), continueToken);
|
1666
|
+
}
|
1667
|
+
return parseNodes_1.ContinueNode.create(continueToken);
|
1668
|
+
}
|
1669
|
+
// return_stmt: 'return' [testlist]
|
1670
|
+
_parseReturnStatement() {
|
1671
|
+
const returnToken = this._getKeywordToken(32 /* Return */);
|
1672
|
+
const returnNode = parseNodes_1.ReturnNode.create(returnToken);
|
1673
|
+
if (!this._isInFunction) {
|
1674
|
+
this._addError(localize_1.Localizer.Diagnostic.returnOutsideFunction(), returnToken);
|
1675
|
+
}
|
1676
|
+
if (!this._isNextTokenNeverExpression()) {
|
1677
|
+
const returnExpr = this._parseTestOrStarListAsExpression(
|
1678
|
+
/* allowAssignmentExpression */ true,
|
1679
|
+
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
1680
|
+
this._reportConditionalErrorForStarTupleElement(returnExpr);
|
1681
|
+
returnNode.returnExpression = returnExpr;
|
1682
|
+
returnNode.returnExpression.parent = returnNode;
|
1683
|
+
(0, parseNodes_1.extendRange)(returnNode, returnExpr);
|
1684
|
+
}
|
1685
|
+
return returnNode;
|
1686
|
+
}
|
1687
|
+
// import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
|
1688
|
+
// 'import' ('*' | '(' import_as_names ')' | import_as_names))
|
1689
|
+
// import_as_names: import_as_name (',' import_as_name)* [',']
|
1690
|
+
// import_as_name: NAME ['as' NAME]
|
1691
|
+
_parseFromStatement() {
|
1692
|
+
const fromToken = this._getKeywordToken(18 /* From */);
|
1693
|
+
const modName = this._parseDottedModuleName(/* allowJustDots */ true);
|
1694
|
+
const importFromNode = parseNodes_1.ImportFromNode.create(fromToken, modName);
|
1695
|
+
// Handle imports from __future__ specially because they can
|
1696
|
+
// change the way we interpret the rest of the file.
|
1697
|
+
const isFutureImport = modName.leadingDots === 0 && modName.nameParts.length === 1 && modName.nameParts[0].value === '__future__';
|
1698
|
+
const possibleInputToken = this._peekToken();
|
1699
|
+
if (!this._consumeTokenIfKeyword(21 /* Import */)) {
|
1700
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedImport(), this._peekToken());
|
1701
|
+
if (!modName.hasTrailingDot) {
|
1702
|
+
importFromNode.missingImportKeyword = true;
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
else {
|
1706
|
+
(0, parseNodes_1.extendRange)(importFromNode, possibleInputToken);
|
1707
|
+
// Look for "*" token.
|
1708
|
+
const possibleStarToken = this._peekToken();
|
1709
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1710
|
+
(0, parseNodes_1.extendRange)(importFromNode, possibleStarToken);
|
1711
|
+
importFromNode.isWildcardImport = true;
|
1712
|
+
importFromNode.wildcardToken = possibleStarToken;
|
1713
|
+
this._containsWildcardImport = true;
|
1714
|
+
}
|
1715
|
+
else {
|
1716
|
+
const openParenToken = this._peekToken();
|
1717
|
+
const inParen = this._consumeTokenIfType(13 /* OpenParenthesis */);
|
1718
|
+
let trailingCommaToken;
|
1719
|
+
while (true) {
|
1720
|
+
const importName = this._getTokenIfIdentifier();
|
1721
|
+
if (!importName) {
|
1722
|
+
break;
|
1723
|
+
}
|
1724
|
+
trailingCommaToken = undefined;
|
1725
|
+
const importFromAsNode = parseNodes_1.ImportFromAsNode.create(parseNodes_1.NameNode.create(importName));
|
1726
|
+
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1727
|
+
const aliasName = this._getTokenIfIdentifier();
|
1728
|
+
if (!aliasName) {
|
1729
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedImportAlias(), this._peekToken());
|
1730
|
+
}
|
1731
|
+
else {
|
1732
|
+
importFromAsNode.alias = parseNodes_1.NameNode.create(aliasName);
|
1733
|
+
importFromAsNode.alias.parent = importFromAsNode;
|
1734
|
+
(0, parseNodes_1.extendRange)(importFromAsNode, aliasName);
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
importFromNode.imports.push(importFromAsNode);
|
1738
|
+
importFromAsNode.parent = importFromNode;
|
1739
|
+
(0, parseNodes_1.extendRange)(importFromNode, importFromAsNode);
|
1740
|
+
if (isFutureImport) {
|
1741
|
+
// Add the future import to the map.
|
1742
|
+
this._futureImportMap.set(importName.value, true);
|
1743
|
+
}
|
1744
|
+
const nextToken = this._peekToken();
|
1745
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1746
|
+
break;
|
1747
|
+
}
|
1748
|
+
trailingCommaToken = nextToken;
|
1749
|
+
}
|
1750
|
+
if (importFromNode.imports.length === 0) {
|
1751
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedImportSymbols(), this._peekToken());
|
1752
|
+
}
|
1753
|
+
if (inParen) {
|
1754
|
+
importFromNode.usesParens = true;
|
1755
|
+
const nextToken = this._peekToken();
|
1756
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1757
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1758
|
+
}
|
1759
|
+
else {
|
1760
|
+
(0, parseNodes_1.extendRange)(importFromNode, nextToken);
|
1761
|
+
}
|
1762
|
+
}
|
1763
|
+
else if (trailingCommaToken) {
|
1764
|
+
this._addError(localize_1.Localizer.Diagnostic.trailingCommaInFromImport(), trailingCommaToken);
|
1765
|
+
}
|
1766
|
+
}
|
1767
|
+
}
|
1768
|
+
this._importedModules.push({
|
1769
|
+
nameNode: importFromNode.module,
|
1770
|
+
leadingDots: importFromNode.module.leadingDots,
|
1771
|
+
nameParts: importFromNode.module.nameParts.map((p) => p.value),
|
1772
|
+
importedSymbols: importFromNode.imports.map((imp) => imp.name.value),
|
1773
|
+
});
|
1774
|
+
let isTypingImport = false;
|
1775
|
+
if (importFromNode.module.nameParts.length === 1) {
|
1776
|
+
const firstNamePartValue = importFromNode.module.nameParts[0].value;
|
1777
|
+
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1778
|
+
isTypingImport = true;
|
1779
|
+
}
|
1780
|
+
}
|
1781
|
+
if (isTypingImport) {
|
1782
|
+
const typingSymbolsOfInterest = ['Literal', 'TypeAlias', 'Annotated'];
|
1783
|
+
if (importFromNode.isWildcardImport) {
|
1784
|
+
typingSymbolsOfInterest.forEach((s) => {
|
1785
|
+
this._typingSymbolAliases.set(s, s);
|
1786
|
+
});
|
1787
|
+
}
|
1788
|
+
else {
|
1789
|
+
importFromNode.imports.forEach((imp) => {
|
1790
|
+
var _a;
|
1791
|
+
if (typingSymbolsOfInterest.some((s) => s === imp.name.value)) {
|
1792
|
+
this._typingSymbolAliases.set(((_a = imp.alias) === null || _a === void 0 ? void 0 : _a.value) || imp.name.value, imp.name.value);
|
1793
|
+
}
|
1794
|
+
});
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
return importFromNode;
|
1798
|
+
}
|
1799
|
+
// import_name: 'import' dotted_as_names
|
1800
|
+
// dotted_as_names: dotted_as_name (',' dotted_as_name)*
|
1801
|
+
// dotted_as_name: dotted_name ['as' NAME]
|
1802
|
+
_parseImportStatement() {
|
1803
|
+
var _a;
|
1804
|
+
const importToken = this._getKeywordToken(21 /* Import */);
|
1805
|
+
const importNode = parseNodes_1.ImportNode.create(importToken);
|
1806
|
+
while (true) {
|
1807
|
+
const modName = this._parseDottedModuleName();
|
1808
|
+
const importAsNode = parseNodes_1.ImportAsNode.create(modName);
|
1809
|
+
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1810
|
+
const aliasToken = this._getTokenIfIdentifier();
|
1811
|
+
if (aliasToken) {
|
1812
|
+
importAsNode.alias = parseNodes_1.NameNode.create(aliasToken);
|
1813
|
+
importAsNode.alias.parent = importAsNode;
|
1814
|
+
(0, parseNodes_1.extendRange)(importAsNode, importAsNode.alias);
|
1815
|
+
}
|
1816
|
+
else {
|
1817
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedImportAlias(), this._peekToken());
|
1818
|
+
}
|
1819
|
+
}
|
1820
|
+
if (importAsNode.module.leadingDots > 0) {
|
1821
|
+
this._addError(localize_1.Localizer.Diagnostic.relativeImportNotAllowed(), importAsNode.module);
|
1822
|
+
}
|
1823
|
+
importNode.list.push(importAsNode);
|
1824
|
+
importAsNode.parent = importNode;
|
1825
|
+
this._importedModules.push({
|
1826
|
+
nameNode: importAsNode.module,
|
1827
|
+
leadingDots: importAsNode.module.leadingDots,
|
1828
|
+
nameParts: importAsNode.module.nameParts.map((p) => p.value),
|
1829
|
+
importedSymbols: undefined,
|
1830
|
+
});
|
1831
|
+
if (modName.nameParts.length === 1) {
|
1832
|
+
const firstNamePartValue = modName.nameParts[0].value;
|
1833
|
+
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1834
|
+
this._typingImportAliases.push(((_a = importAsNode.alias) === null || _a === void 0 ? void 0 : _a.value) || firstNamePartValue);
|
1835
|
+
}
|
1836
|
+
}
|
1837
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1838
|
+
break;
|
1839
|
+
}
|
1840
|
+
}
|
1841
|
+
if (importNode.list.length > 0) {
|
1842
|
+
(0, parseNodes_1.extendRange)(importNode, importNode.list[importNode.list.length - 1]);
|
1843
|
+
}
|
1844
|
+
return importNode;
|
1845
|
+
}
|
1846
|
+
// ('.' | '...')* dotted_name | ('.' | '...')+
|
1847
|
+
// dotted_name: NAME ('.' NAME)*
|
1848
|
+
_parseDottedModuleName(allowJustDots = false) {
|
1849
|
+
var _a;
|
1850
|
+
const moduleNameNode = parseNodes_1.ModuleNameNode.create(this._peekToken());
|
1851
|
+
while (true) {
|
1852
|
+
const token = (_a = this._getTokenIfType(19 /* Ellipsis */)) !== null && _a !== void 0 ? _a : this._getTokenIfType(20 /* Dot */);
|
1853
|
+
if (token) {
|
1854
|
+
if (token.type === 19 /* Ellipsis */) {
|
1855
|
+
moduleNameNode.leadingDots += 3;
|
1856
|
+
}
|
1857
|
+
else {
|
1858
|
+
moduleNameNode.leadingDots++;
|
1859
|
+
}
|
1860
|
+
(0, parseNodes_1.extendRange)(moduleNameNode, token);
|
1861
|
+
}
|
1862
|
+
else {
|
1863
|
+
break;
|
1864
|
+
}
|
1865
|
+
}
|
1866
|
+
while (true) {
|
1867
|
+
const identifier = this._getTokenIfIdentifier();
|
1868
|
+
if (!identifier) {
|
1869
|
+
if (!allowJustDots || moduleNameNode.leadingDots === 0 || moduleNameNode.nameParts.length > 0) {
|
1870
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedModuleName(), this._peekToken());
|
1871
|
+
moduleNameNode.hasTrailingDot = true;
|
1872
|
+
}
|
1873
|
+
break;
|
1874
|
+
}
|
1875
|
+
const namePart = parseNodes_1.NameNode.create(identifier);
|
1876
|
+
moduleNameNode.nameParts.push(namePart);
|
1877
|
+
namePart.parent = moduleNameNode;
|
1878
|
+
(0, parseNodes_1.extendRange)(moduleNameNode, namePart);
|
1879
|
+
const nextToken = this._peekToken();
|
1880
|
+
if (!this._consumeTokenIfType(20 /* Dot */)) {
|
1881
|
+
break;
|
1882
|
+
}
|
1883
|
+
// Extend the module name to include the dot.
|
1884
|
+
(0, parseNodes_1.extendRange)(moduleNameNode, nextToken);
|
1885
|
+
}
|
1886
|
+
return moduleNameNode;
|
1887
|
+
}
|
1888
|
+
_parseGlobalStatement() {
|
1889
|
+
const globalToken = this._getKeywordToken(19 /* Global */);
|
1890
|
+
const globalNode = parseNodes_1.GlobalNode.create(globalToken);
|
1891
|
+
globalNode.nameList = this._parseNameList();
|
1892
|
+
if (globalNode.nameList.length > 0) {
|
1893
|
+
globalNode.nameList.forEach((name) => {
|
1894
|
+
name.parent = globalNode;
|
1895
|
+
});
|
1896
|
+
(0, parseNodes_1.extendRange)(globalNode, globalNode.nameList[globalNode.nameList.length - 1]);
|
1897
|
+
}
|
1898
|
+
return globalNode;
|
1899
|
+
}
|
1900
|
+
_parseNonlocalStatement() {
|
1901
|
+
const nonlocalToken = this._getKeywordToken(27 /* Nonlocal */);
|
1902
|
+
const nonlocalNode = parseNodes_1.NonlocalNode.create(nonlocalToken);
|
1903
|
+
nonlocalNode.nameList = this._parseNameList();
|
1904
|
+
if (nonlocalNode.nameList.length > 0) {
|
1905
|
+
nonlocalNode.nameList.forEach((name) => {
|
1906
|
+
name.parent = nonlocalNode;
|
1907
|
+
});
|
1908
|
+
(0, parseNodes_1.extendRange)(nonlocalNode, nonlocalNode.nameList[nonlocalNode.nameList.length - 1]);
|
1909
|
+
}
|
1910
|
+
return nonlocalNode;
|
1911
|
+
}
|
1912
|
+
_parseNameList() {
|
1913
|
+
const nameList = [];
|
1914
|
+
while (true) {
|
1915
|
+
const name = this._getTokenIfIdentifier();
|
1916
|
+
if (!name) {
|
1917
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
1918
|
+
break;
|
1919
|
+
}
|
1920
|
+
nameList.push(parseNodes_1.NameNode.create(name));
|
1921
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1922
|
+
break;
|
1923
|
+
}
|
1924
|
+
}
|
1925
|
+
return nameList;
|
1926
|
+
}
|
1927
|
+
// raise_stmt: 'raise' [test ['from' test]]
|
1928
|
+
// (old) raise_stmt: 'raise' [test [',' test [',' test]]]
|
1929
|
+
_parseRaiseStatement() {
|
1930
|
+
const raiseToken = this._getKeywordToken(31 /* Raise */);
|
1931
|
+
const raiseNode = parseNodes_1.RaiseNode.create(raiseToken);
|
1932
|
+
if (!this._isNextTokenNeverExpression()) {
|
1933
|
+
raiseNode.typeExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1934
|
+
raiseNode.typeExpression.parent = raiseNode;
|
1935
|
+
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.typeExpression);
|
1936
|
+
if (this._consumeTokenIfKeyword(18 /* From */)) {
|
1937
|
+
raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1938
|
+
raiseNode.valueExpression.parent = raiseNode;
|
1939
|
+
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.valueExpression);
|
1940
|
+
}
|
1941
|
+
else {
|
1942
|
+
if (this._consumeTokenIfType(12 /* Comma */)) {
|
1943
|
+
// Handle the Python 2.x variant
|
1944
|
+
raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1945
|
+
raiseNode.valueExpression.parent = raiseNode;
|
1946
|
+
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.valueExpression);
|
1947
|
+
if (this._consumeTokenIfType(12 /* Comma */)) {
|
1948
|
+
raiseNode.tracebackExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1949
|
+
raiseNode.tracebackExpression.parent = raiseNode;
|
1950
|
+
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.tracebackExpression);
|
1951
|
+
}
|
1952
|
+
}
|
1953
|
+
}
|
1954
|
+
}
|
1955
|
+
return raiseNode;
|
1956
|
+
}
|
1957
|
+
// assert_stmt: 'assert' test [',' test]
|
1958
|
+
_parseAssertStatement() {
|
1959
|
+
const assertToken = this._getKeywordToken(2 /* Assert */);
|
1960
|
+
const expr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1961
|
+
const assertNode = parseNodes_1.AssertNode.create(assertToken, expr);
|
1962
|
+
if (this._consumeTokenIfType(12 /* Comma */)) {
|
1963
|
+
const exceptionExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1964
|
+
assertNode.exceptionExpression = exceptionExpr;
|
1965
|
+
assertNode.exceptionExpression.parent = assertNode;
|
1966
|
+
(0, parseNodes_1.extendRange)(assertNode, exceptionExpr);
|
1967
|
+
}
|
1968
|
+
return assertNode;
|
1969
|
+
}
|
1970
|
+
// del_stmt: 'del' exprlist
|
1971
|
+
_parseDelStatement() {
|
1972
|
+
const delToken = this._getKeywordToken(11 /* Del */);
|
1973
|
+
const exprListResult = this._parseExpressionList(/* allowStar */ true);
|
1974
|
+
if (!exprListResult.parseError && exprListResult.list.length === 0) {
|
1975
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedDelExpr(), this._peekToken());
|
1976
|
+
}
|
1977
|
+
const delNode = parseNodes_1.DelNode.create(delToken);
|
1978
|
+
delNode.expressions = exprListResult.list;
|
1979
|
+
if (delNode.expressions.length > 0) {
|
1980
|
+
delNode.expressions.forEach((expr) => {
|
1981
|
+
expr.parent = delNode;
|
1982
|
+
});
|
1983
|
+
(0, parseNodes_1.extendRange)(delNode, delNode.expressions[delNode.expressions.length - 1]);
|
1984
|
+
}
|
1985
|
+
return delNode;
|
1986
|
+
}
|
1987
|
+
// yield_expr: 'yield' [yield_arg]
|
1988
|
+
// yield_arg: 'from' test | testlist
|
1989
|
+
_parseYieldExpression() {
|
1990
|
+
const yieldToken = this._getKeywordToken(37 /* Yield */);
|
1991
|
+
const nextToken = this._peekToken();
|
1992
|
+
if (this._consumeTokenIfKeyword(18 /* From */)) {
|
1993
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_3) {
|
1994
|
+
this._addError(localize_1.Localizer.Diagnostic.yieldFromIllegal(), nextToken);
|
1995
|
+
}
|
1996
|
+
return parseNodes_1.YieldFromNode.create(yieldToken, this._parseTestExpression(/* allowAssignmentExpression */ true));
|
1997
|
+
}
|
1998
|
+
let exprList;
|
1999
|
+
if (!this._isNextTokenNeverExpression()) {
|
2000
|
+
exprList = this._parseTestOrStarListAsExpression(
|
2001
|
+
/* allowAssignmentExpression */ true,
|
2002
|
+
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedYieldExpr());
|
2003
|
+
this._reportConditionalErrorForStarTupleElement(exprList);
|
2004
|
+
}
|
2005
|
+
return parseNodes_1.YieldNode.create(yieldToken, exprList);
|
2006
|
+
}
|
2007
|
+
_tryParseYieldExpression() {
|
2008
|
+
if (this._peekKeywordType() !== 37 /* Yield */) {
|
2009
|
+
return undefined;
|
2010
|
+
}
|
2011
|
+
return this._parseYieldExpression();
|
2012
|
+
}
|
2013
|
+
// simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
|
2014
|
+
_parseSimpleStatement() {
|
2015
|
+
const statement = parseNodes_1.StatementListNode.create(this._peekToken());
|
2016
|
+
while (true) {
|
2017
|
+
// Swallow invalid tokens to make sure we make forward progress.
|
2018
|
+
if (this._peekTokenType() === 0 /* Invalid */) {
|
2019
|
+
const invalidToken = this._getNextToken();
|
2020
|
+
const text = this._fileContents.substr(invalidToken.start, invalidToken.length);
|
2021
|
+
const firstCharCode = text.charCodeAt(0);
|
2022
|
+
// Remove any non-printable characters.
|
2023
|
+
this._addError(localize_1.Localizer.Diagnostic.invalidTokenChars().format({ text: `\\u${firstCharCode.toString(16)}` }), invalidToken);
|
2024
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
2025
|
+
break;
|
2026
|
+
}
|
2027
|
+
const smallStatement = this._parseSmallStatement();
|
2028
|
+
statement.statements.push(smallStatement);
|
2029
|
+
smallStatement.parent = statement;
|
2030
|
+
(0, parseNodes_1.extendRange)(statement, smallStatement);
|
2031
|
+
if (smallStatement.nodeType === 0 /* Error */) {
|
2032
|
+
// No need to log an error here. We assume that
|
2033
|
+
// it was already logged by _parseSmallStatement.
|
2034
|
+
break;
|
2035
|
+
}
|
2036
|
+
// Consume the semicolon if present.
|
2037
|
+
if (!this._consumeTokenIfType(11 /* Semicolon */)) {
|
2038
|
+
break;
|
2039
|
+
}
|
2040
|
+
const nextTokenType = this._peekTokenType();
|
2041
|
+
if (nextTokenType === 2 /* NewLine */ || nextTokenType === 1 /* EndOfStream */) {
|
2042
|
+
break;
|
2043
|
+
}
|
2044
|
+
}
|
2045
|
+
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
2046
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedNewlineOrSemicolon(), this._peekToken());
|
2047
|
+
}
|
2048
|
+
return statement;
|
2049
|
+
}
|
2050
|
+
// small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
|
2051
|
+
// import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
|
2052
|
+
// flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
|
2053
|
+
// import_stmt: import_name | import_from
|
2054
|
+
_parseSmallStatement() {
|
2055
|
+
switch (this._peekKeywordType()) {
|
2056
|
+
case 30 /* Pass */:
|
2057
|
+
return this._parsePassStatement();
|
2058
|
+
case 5 /* Break */:
|
2059
|
+
return this._parseBreakStatement();
|
2060
|
+
case 8 /* Continue */:
|
2061
|
+
return this._parseContinueStatement();
|
2062
|
+
case 32 /* Return */:
|
2063
|
+
return this._parseReturnStatement();
|
2064
|
+
case 18 /* From */:
|
2065
|
+
return this._parseFromStatement();
|
2066
|
+
case 21 /* Import */:
|
2067
|
+
return this._parseImportStatement();
|
2068
|
+
case 19 /* Global */:
|
2069
|
+
return this._parseGlobalStatement();
|
2070
|
+
case 27 /* Nonlocal */:
|
2071
|
+
return this._parseNonlocalStatement();
|
2072
|
+
case 31 /* Raise */:
|
2073
|
+
return this._parseRaiseStatement();
|
2074
|
+
case 2 /* Assert */:
|
2075
|
+
return this._parseAssertStatement();
|
2076
|
+
case 11 /* Del */:
|
2077
|
+
return this._parseDelStatement();
|
2078
|
+
case 37 /* Yield */:
|
2079
|
+
return this._parseYieldExpression();
|
2080
|
+
}
|
2081
|
+
return this._parseExpressionStatement();
|
2082
|
+
}
|
2083
|
+
_makeExpressionOrTuple(exprListResult, enclosedInParens) {
|
2084
|
+
// A single-element tuple with no trailing comma is simply an expression
|
2085
|
+
// that's surrounded by parens.
|
2086
|
+
if (exprListResult.list.length === 1 && !exprListResult.trailingComma) {
|
2087
|
+
if (exprListResult.list[0].nodeType === 56 /* Unpack */) {
|
2088
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackOperatorNotAllowed(), exprListResult.list[0]);
|
2089
|
+
}
|
2090
|
+
return exprListResult.list[0];
|
2091
|
+
}
|
2092
|
+
// To accommodate empty tuples ("()"), we will reach back to get
|
2093
|
+
// the opening parenthesis as the opening token.
|
2094
|
+
const tupleStartRange = exprListResult.list.length > 0 ? exprListResult.list[0] : this._peekToken(-1);
|
2095
|
+
const tupleNode = parseNodes_1.TupleNode.create(tupleStartRange, enclosedInParens);
|
2096
|
+
tupleNode.expressions = exprListResult.list;
|
2097
|
+
if (exprListResult.list.length > 0) {
|
2098
|
+
exprListResult.list.forEach((expr) => {
|
2099
|
+
expr.parent = tupleNode;
|
2100
|
+
});
|
2101
|
+
(0, parseNodes_1.extendRange)(tupleNode, exprListResult.list[exprListResult.list.length - 1]);
|
2102
|
+
}
|
2103
|
+
return tupleNode;
|
2104
|
+
}
|
2105
|
+
_parseExpressionListAsPossibleTuple(errorCategory, errorString, errorToken) {
|
2106
|
+
if (this._isNextTokenNeverExpression()) {
|
2107
|
+
this._addError(errorString, errorToken);
|
2108
|
+
return parseNodes_1.ErrorNode.create(errorToken, errorCategory);
|
2109
|
+
}
|
2110
|
+
const exprListResult = this._parseExpressionList(/* allowStar */ true);
|
2111
|
+
if (exprListResult.parseError) {
|
2112
|
+
return exprListResult.parseError;
|
2113
|
+
}
|
2114
|
+
return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
|
2115
|
+
}
|
2116
|
+
_parseTestListAsExpression(errorCategory, errorString) {
|
2117
|
+
if (this._isNextTokenNeverExpression()) {
|
2118
|
+
return this._handleExpressionParseError(errorCategory, errorString);
|
2119
|
+
}
|
2120
|
+
const exprListResult = this._parseTestExpressionList();
|
2121
|
+
if (exprListResult.parseError) {
|
2122
|
+
return exprListResult.parseError;
|
2123
|
+
}
|
2124
|
+
return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
|
2125
|
+
}
|
2126
|
+
_parseTestOrStarListAsExpression(allowAssignmentExpression, allowMultipleUnpack, errorCategory, errorString) {
|
2127
|
+
if (this._isNextTokenNeverExpression()) {
|
2128
|
+
return this._handleExpressionParseError(errorCategory, errorString);
|
2129
|
+
}
|
2130
|
+
const exprListResult = this._parseTestOrStarExpressionList(allowAssignmentExpression, allowMultipleUnpack);
|
2131
|
+
if (exprListResult.parseError) {
|
2132
|
+
return exprListResult.parseError;
|
2133
|
+
}
|
2134
|
+
return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
|
2135
|
+
}
|
2136
|
+
_parseExpressionList(allowStar) {
|
2137
|
+
return this._parseExpressionListGeneric(() => this._parseExpression(allowStar));
|
2138
|
+
}
|
2139
|
+
// testlist: test (',' test)* [',']
|
2140
|
+
_parseTestExpressionList() {
|
2141
|
+
return this._parseExpressionListGeneric(() => this._parseTestExpression(/* allowAssignmentExpression */ false));
|
2142
|
+
}
|
2143
|
+
_parseTestOrStarExpressionList(allowAssignmentExpression, allowMultipleUnpack) {
|
2144
|
+
const exprListResult = this._parseExpressionListGeneric(() => this._parseTestOrStarExpression(allowAssignmentExpression));
|
2145
|
+
if (!allowMultipleUnpack && !exprListResult.parseError) {
|
2146
|
+
let sawStar = false;
|
2147
|
+
for (const expr of exprListResult.list) {
|
2148
|
+
if (expr.nodeType === 56 /* Unpack */) {
|
2149
|
+
if (sawStar) {
|
2150
|
+
this._addError(localize_1.Localizer.Diagnostic.duplicateUnpack(), expr);
|
2151
|
+
break;
|
2152
|
+
}
|
2153
|
+
sawStar = true;
|
2154
|
+
}
|
2155
|
+
}
|
2156
|
+
}
|
2157
|
+
return exprListResult;
|
2158
|
+
}
|
2159
|
+
// exp_or_star: expr | star_expr
|
2160
|
+
// expr: xor_expr ('|' xor_expr)*
|
2161
|
+
// star_expr: '*' expr
|
2162
|
+
_parseExpression(allowUnpack) {
|
2163
|
+
const startToken = this._peekToken();
|
2164
|
+
if (allowUnpack && this._consumeTokenIfOperator(26 /* Multiply */)) {
|
2165
|
+
return parseNodes_1.UnpackNode.create(startToken, this._parseExpression(/* allowUnpack */ false));
|
2166
|
+
}
|
2167
|
+
return this._parseBitwiseOrExpression();
|
2168
|
+
}
|
2169
|
+
// test_or_star: test | star_expr
|
2170
|
+
_parseTestOrStarExpression(allowAssignmentExpression) {
|
2171
|
+
if (this._peekOperatorType() === 26 /* Multiply */) {
|
2172
|
+
return this._parseExpression(/* allowUnpack */ true);
|
2173
|
+
}
|
2174
|
+
return this._parseTestExpression(allowAssignmentExpression);
|
2175
|
+
}
|
2176
|
+
// test: or_test ['if' or_test 'else' test] | lambdef
|
2177
|
+
_parseTestExpression(allowAssignmentExpression) {
|
2178
|
+
if (this._peekKeywordType() === 24 /* Lambda */) {
|
2179
|
+
return this._parseLambdaExpression();
|
2180
|
+
}
|
2181
|
+
const ifExpr = allowAssignmentExpression ? this._parseAssignmentExpression() : this._parseOrTest();
|
2182
|
+
if (ifExpr.nodeType === 0 /* Error */) {
|
2183
|
+
return ifExpr;
|
2184
|
+
}
|
2185
|
+
if (!this._consumeTokenIfKeyword(20 /* If */)) {
|
2186
|
+
return ifExpr;
|
2187
|
+
}
|
2188
|
+
const testExpr = this._parseOrTest();
|
2189
|
+
if (testExpr.nodeType === 0 /* Error */) {
|
2190
|
+
return testExpr;
|
2191
|
+
}
|
2192
|
+
if (!this._consumeTokenIfKeyword(13 /* Else */)) {
|
2193
|
+
return this._handleExpressionParseError(1 /* MissingElse */, localize_1.Localizer.Diagnostic.expectedElse());
|
2194
|
+
}
|
2195
|
+
const elseExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2196
|
+
if (elseExpr.nodeType === 0 /* Error */) {
|
2197
|
+
return elseExpr;
|
2198
|
+
}
|
2199
|
+
return parseNodes_1.TernaryNode.create(ifExpr, testExpr, elseExpr);
|
2200
|
+
}
|
2201
|
+
// assign_expr: NAME := test
|
2202
|
+
_parseAssignmentExpression(disallowAssignmentExpression = false) {
|
2203
|
+
const leftExpr = this._parseOrTest();
|
2204
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2205
|
+
return leftExpr;
|
2206
|
+
}
|
2207
|
+
if (leftExpr.nodeType !== 38 /* Name */) {
|
2208
|
+
return leftExpr;
|
2209
|
+
}
|
2210
|
+
const walrusToken = this._peekToken();
|
2211
|
+
if (!this._consumeTokenIfOperator(35 /* Walrus */)) {
|
2212
|
+
return leftExpr;
|
2213
|
+
}
|
2214
|
+
if (!this._assignmentExpressionsAllowed || this._isParsingTypeAnnotation || disallowAssignmentExpression) {
|
2215
|
+
this._addError(localize_1.Localizer.Diagnostic.walrusNotAllowed(), walrusToken);
|
2216
|
+
}
|
2217
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_8) {
|
2218
|
+
this._addError(localize_1.Localizer.Diagnostic.walrusIllegal(), walrusToken);
|
2219
|
+
}
|
2220
|
+
const rightExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2221
|
+
return parseNodes_1.AssignmentExpressionNode.create(leftExpr, rightExpr);
|
2222
|
+
}
|
2223
|
+
// or_test: and_test ('or' and_test)*
|
2224
|
+
_parseOrTest() {
|
2225
|
+
let leftExpr = this._parseAndTest();
|
2226
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2227
|
+
return leftExpr;
|
2228
|
+
}
|
2229
|
+
while (true) {
|
2230
|
+
const peekToken = this._peekToken();
|
2231
|
+
if (!this._consumeTokenIfKeyword(29 /* Or */)) {
|
2232
|
+
break;
|
2233
|
+
}
|
2234
|
+
const rightExpr = this._parseAndTest();
|
2235
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 37 /* Or */);
|
2236
|
+
}
|
2237
|
+
return leftExpr;
|
2238
|
+
}
|
2239
|
+
// and_test: not_test ('and' not_test)*
|
2240
|
+
_parseAndTest() {
|
2241
|
+
let leftExpr = this._parseNotTest();
|
2242
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2243
|
+
return leftExpr;
|
2244
|
+
}
|
2245
|
+
while (true) {
|
2246
|
+
const peekToken = this._peekToken();
|
2247
|
+
if (!this._consumeTokenIfKeyword(0 /* And */)) {
|
2248
|
+
break;
|
2249
|
+
}
|
2250
|
+
const rightExpr = this._parseNotTest();
|
2251
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 36 /* And */);
|
2252
|
+
}
|
2253
|
+
return leftExpr;
|
2254
|
+
}
|
2255
|
+
// not_test: 'not' not_test | comparison
|
2256
|
+
_parseNotTest() {
|
2257
|
+
const notToken = this._peekToken();
|
2258
|
+
if (this._consumeTokenIfKeyword(28 /* Not */)) {
|
2259
|
+
const notExpr = this._parseNotTest();
|
2260
|
+
return this._createUnaryOperationNode(notToken, notExpr, 38 /* Not */);
|
2261
|
+
}
|
2262
|
+
return this._parseComparison();
|
2263
|
+
}
|
2264
|
+
// comparison: expr (comp_op expr)*
|
2265
|
+
// comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
|
2266
|
+
_parseComparison() {
|
2267
|
+
let leftExpr = this._parseBitwiseOrExpression();
|
2268
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2269
|
+
return leftExpr;
|
2270
|
+
}
|
2271
|
+
while (true) {
|
2272
|
+
let comparisonOperator;
|
2273
|
+
const peekToken = this._peekToken();
|
2274
|
+
if (tokenizer_1.Tokenizer.isOperatorComparison(this._peekOperatorType())) {
|
2275
|
+
comparisonOperator = this._peekOperatorType();
|
2276
|
+
if (comparisonOperator === 19 /* LessOrGreaterThan */) {
|
2277
|
+
this._addError(localize_1.Localizer.Diagnostic.operatorLessOrGreaterDeprecated(), peekToken);
|
2278
|
+
comparisonOperator = 28 /* NotEquals */;
|
2279
|
+
}
|
2280
|
+
this._getNextToken();
|
2281
|
+
}
|
2282
|
+
else if (this._consumeTokenIfKeyword(22 /* In */)) {
|
2283
|
+
comparisonOperator = 41 /* In */;
|
2284
|
+
}
|
2285
|
+
else if (this._consumeTokenIfKeyword(23 /* Is */)) {
|
2286
|
+
if (this._consumeTokenIfKeyword(28 /* Not */)) {
|
2287
|
+
comparisonOperator = 40 /* IsNot */;
|
2288
|
+
}
|
2289
|
+
else {
|
2290
|
+
comparisonOperator = 39 /* Is */;
|
2291
|
+
}
|
2292
|
+
}
|
2293
|
+
else if (this._peekKeywordType() === 28 /* Not */) {
|
2294
|
+
const tokenAfterNot = this._peekToken(1);
|
2295
|
+
if (tokenAfterNot.type === 8 /* Keyword */ &&
|
2296
|
+
tokenAfterNot.keywordType === 22 /* In */) {
|
2297
|
+
this._getNextToken();
|
2298
|
+
this._getNextToken();
|
2299
|
+
comparisonOperator = 42 /* NotIn */;
|
2300
|
+
}
|
2301
|
+
}
|
2302
|
+
if (comparisonOperator === undefined) {
|
2303
|
+
break;
|
2304
|
+
}
|
2305
|
+
const rightExpr = this._parseComparison();
|
2306
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, comparisonOperator);
|
2307
|
+
}
|
2308
|
+
return leftExpr;
|
2309
|
+
}
|
2310
|
+
// expr: xor_expr ('|' xor_expr)*
|
2311
|
+
_parseBitwiseOrExpression() {
|
2312
|
+
let leftExpr = this._parseBitwiseXorExpression();
|
2313
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2314
|
+
return leftExpr;
|
2315
|
+
}
|
2316
|
+
while (true) {
|
2317
|
+
const peekToken = this._peekToken();
|
2318
|
+
if (!this._consumeTokenIfOperator(6 /* BitwiseOr */)) {
|
2319
|
+
break;
|
2320
|
+
}
|
2321
|
+
const rightExpr = this._parseBitwiseXorExpression();
|
2322
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 6 /* BitwiseOr */);
|
2323
|
+
}
|
2324
|
+
return leftExpr;
|
2325
|
+
}
|
2326
|
+
// xor_expr: and_expr ('^' and_expr)*
|
2327
|
+
_parseBitwiseXorExpression() {
|
2328
|
+
let leftExpr = this._parseBitwiseAndExpression();
|
2329
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2330
|
+
return leftExpr;
|
2331
|
+
}
|
2332
|
+
while (true) {
|
2333
|
+
const peekToken = this._peekToken();
|
2334
|
+
if (!this._consumeTokenIfOperator(8 /* BitwiseXor */)) {
|
2335
|
+
break;
|
2336
|
+
}
|
2337
|
+
const rightExpr = this._parseBitwiseAndExpression();
|
2338
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 8 /* BitwiseXor */);
|
2339
|
+
}
|
2340
|
+
return leftExpr;
|
2341
|
+
}
|
2342
|
+
// and_expr: shift_expr ('&' shift_expr)*
|
2343
|
+
_parseBitwiseAndExpression() {
|
2344
|
+
let leftExpr = this._parseShiftExpression();
|
2345
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2346
|
+
return leftExpr;
|
2347
|
+
}
|
2348
|
+
while (true) {
|
2349
|
+
const peekToken = this._peekToken();
|
2350
|
+
if (!this._consumeTokenIfOperator(3 /* BitwiseAnd */)) {
|
2351
|
+
break;
|
2352
|
+
}
|
2353
|
+
const rightExpr = this._parseShiftExpression();
|
2354
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 3 /* BitwiseAnd */);
|
2355
|
+
}
|
2356
|
+
return leftExpr;
|
2357
|
+
}
|
2358
|
+
// shift_expr: arith_expr (('<<'|'>>') arith_expr)*
|
2359
|
+
_parseShiftExpression() {
|
2360
|
+
let leftExpr = this._parseArithmeticExpression();
|
2361
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2362
|
+
return leftExpr;
|
2363
|
+
}
|
2364
|
+
let peekToken = this._peekToken();
|
2365
|
+
let nextOperator = this._peekOperatorType();
|
2366
|
+
while (nextOperator === 17 /* LeftShift */ || nextOperator === 31 /* RightShift */) {
|
2367
|
+
this._getNextToken();
|
2368
|
+
const rightExpr = this._parseArithmeticExpression();
|
2369
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
2370
|
+
peekToken = this._peekToken();
|
2371
|
+
nextOperator = this._peekOperatorType();
|
2372
|
+
}
|
2373
|
+
return leftExpr;
|
2374
|
+
}
|
2375
|
+
// arith_expr: term (('+'|'-') term)*
|
2376
|
+
_parseArithmeticExpression() {
|
2377
|
+
let leftExpr = this._parseArithmeticTerm();
|
2378
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2379
|
+
return leftExpr;
|
2380
|
+
}
|
2381
|
+
let peekToken = this._peekToken();
|
2382
|
+
let nextOperator = this._peekOperatorType();
|
2383
|
+
while (nextOperator === 0 /* Add */ || nextOperator === 33 /* Subtract */) {
|
2384
|
+
this._getNextToken();
|
2385
|
+
const rightExpr = this._parseArithmeticTerm();
|
2386
|
+
if (rightExpr.nodeType === 0 /* Error */) {
|
2387
|
+
return rightExpr;
|
2388
|
+
}
|
2389
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
2390
|
+
peekToken = this._peekToken();
|
2391
|
+
nextOperator = this._peekOperatorType();
|
2392
|
+
}
|
2393
|
+
return leftExpr;
|
2394
|
+
}
|
2395
|
+
// term: factor (('*'|'@'|'/'|'%'|'//') factor)*
|
2396
|
+
_parseArithmeticTerm() {
|
2397
|
+
let leftExpr = this._parseArithmeticFactor();
|
2398
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2399
|
+
return leftExpr;
|
2400
|
+
}
|
2401
|
+
let peekToken = this._peekToken();
|
2402
|
+
let nextOperator = this._peekOperatorType();
|
2403
|
+
while (nextOperator === 26 /* Multiply */ ||
|
2404
|
+
nextOperator === 22 /* MatrixMultiply */ ||
|
2405
|
+
nextOperator === 10 /* Divide */ ||
|
2406
|
+
nextOperator === 24 /* Mod */ ||
|
2407
|
+
nextOperator === 13 /* FloorDivide */) {
|
2408
|
+
this._getNextToken();
|
2409
|
+
const rightExpr = this._parseArithmeticFactor();
|
2410
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
2411
|
+
peekToken = this._peekToken();
|
2412
|
+
nextOperator = this._peekOperatorType();
|
2413
|
+
}
|
2414
|
+
return leftExpr;
|
2415
|
+
}
|
2416
|
+
// factor: ('+'|'-'|'~') factor | power
|
2417
|
+
// power: atom_expr ['**' factor]
|
2418
|
+
_parseArithmeticFactor() {
|
2419
|
+
const nextToken = this._peekToken();
|
2420
|
+
const nextOperator = this._peekOperatorType();
|
2421
|
+
if (nextOperator === 0 /* Add */ ||
|
2422
|
+
nextOperator === 33 /* Subtract */ ||
|
2423
|
+
nextOperator === 5 /* BitwiseInvert */) {
|
2424
|
+
this._getNextToken();
|
2425
|
+
const expression = this._parseArithmeticFactor();
|
2426
|
+
return this._createUnaryOperationNode(nextToken, expression, nextOperator);
|
2427
|
+
}
|
2428
|
+
const leftExpr = this._parseAtomExpression();
|
2429
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
2430
|
+
return leftExpr;
|
2431
|
+
}
|
2432
|
+
const peekToken = this._peekToken();
|
2433
|
+
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
2434
|
+
const rightExpr = this._parseArithmeticFactor();
|
2435
|
+
return this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 29 /* Power */);
|
2436
|
+
}
|
2437
|
+
return leftExpr;
|
2438
|
+
}
|
2439
|
+
// Determines whether the expression refers to a type exported by the typing
|
2440
|
+
// or typing_extensions modules. We can directly evaluate the types at binding
|
2441
|
+
// time. We assume here that the code isn't making use of some custom type alias
|
2442
|
+
// to refer to the typing types.
|
2443
|
+
_isTypingAnnotation(typeAnnotation, name) {
|
2444
|
+
if (typeAnnotation.nodeType === 38 /* Name */) {
|
2445
|
+
const alias = this._typingSymbolAliases.get(typeAnnotation.value);
|
2446
|
+
if (alias === name) {
|
2447
|
+
return true;
|
2448
|
+
}
|
2449
|
+
}
|
2450
|
+
else if (typeAnnotation.nodeType === 35 /* MemberAccess */) {
|
2451
|
+
if (typeAnnotation.leftExpression.nodeType === 38 /* Name */ &&
|
2452
|
+
typeAnnotation.memberName.value === name) {
|
2453
|
+
const baseName = typeAnnotation.leftExpression.value;
|
2454
|
+
return this._typingImportAliases.some((alias) => alias === baseName);
|
2455
|
+
}
|
2456
|
+
}
|
2457
|
+
return false;
|
2458
|
+
}
|
2459
|
+
// atom_expr: ['await'] atom trailer*
|
2460
|
+
// trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
2461
|
+
_parseAtomExpression() {
|
2462
|
+
let awaitToken;
|
2463
|
+
if (this._peekKeywordType() === 4 /* Await */ && !this._isParsingTypeAnnotation) {
|
2464
|
+
awaitToken = this._getKeywordToken(4 /* Await */);
|
2465
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_5) {
|
2466
|
+
this._addError(localize_1.Localizer.Diagnostic.awaitIllegal(), awaitToken);
|
2467
|
+
}
|
2468
|
+
}
|
2469
|
+
let atomExpression = this._parseAtom();
|
2470
|
+
if (atomExpression.nodeType === 0 /* Error */) {
|
2471
|
+
return atomExpression;
|
2472
|
+
}
|
2473
|
+
// Consume trailers.
|
2474
|
+
while (true) {
|
2475
|
+
// Is it a function call?
|
2476
|
+
const startOfTrailerToken = this._peekToken();
|
2477
|
+
if (this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
2478
|
+
// Generally, function calls are not allowed within type annotations,
|
2479
|
+
// but they are permitted in "Annotated" annotations.
|
2480
|
+
const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
|
2481
|
+
this._isParsingTypeAnnotation = false;
|
2482
|
+
const argListResult = this._parseArgList();
|
2483
|
+
const callNode = parseNodes_1.CallNode.create(atomExpression, argListResult.args, argListResult.trailingComma);
|
2484
|
+
if (argListResult.args.length > 1 || argListResult.trailingComma) {
|
2485
|
+
argListResult.args.forEach((arg) => {
|
2486
|
+
if (arg.valueExpression.nodeType === 32 /* ListComprehension */) {
|
2487
|
+
if (!arg.valueExpression.isParenthesized) {
|
2488
|
+
this._addError(localize_1.Localizer.Diagnostic.generatorNotParenthesized(), arg.valueExpression);
|
2489
|
+
}
|
2490
|
+
}
|
2491
|
+
});
|
2492
|
+
}
|
2493
|
+
const nextToken = this._peekToken();
|
2494
|
+
let isArgListTerminated = false;
|
2495
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
2496
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), startOfTrailerToken);
|
2497
|
+
// Consume the remainder of tokens on the line for error
|
2498
|
+
// recovery.
|
2499
|
+
this._consumeTokensUntilType([2 /* NewLine */]);
|
2500
|
+
// Extend the node's range to include the rest of the line.
|
2501
|
+
// This helps the signatureHelpProvider.
|
2502
|
+
(0, parseNodes_1.extendRange)(callNode, this._peekToken());
|
2503
|
+
}
|
2504
|
+
else {
|
2505
|
+
(0, parseNodes_1.extendRange)(callNode, nextToken);
|
2506
|
+
isArgListTerminated = true;
|
2507
|
+
}
|
2508
|
+
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
2509
|
+
if (this._isParsingTypeAnnotation) {
|
2510
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
2511
|
+
if (atomExpression.nodeType === 38 /* Name */ && atomExpression.value === 'type') {
|
2512
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTypeInstead());
|
2513
|
+
this._addError(localize_1.Localizer.Diagnostic.typeCallNotAllowed() + diag.getString(), callNode);
|
2514
|
+
}
|
2515
|
+
}
|
2516
|
+
atomExpression = callNode;
|
2517
|
+
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2518
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2519
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2520
|
+
}
|
2521
|
+
// If the argument list wasn't terminated, break out of the loop
|
2522
|
+
if (!isArgListTerminated) {
|
2523
|
+
break;
|
2524
|
+
}
|
2525
|
+
}
|
2526
|
+
else if (this._consumeTokenIfType(15 /* OpenBracket */)) {
|
2527
|
+
// Is it an index operator?
|
2528
|
+
// This is an unfortunate hack that's necessary to accommodate 'Literal'
|
2529
|
+
// and 'Annotated' type annotations properly. We need to suspend treating
|
2530
|
+
// strings as type annotations within a Literal or Annotated subscript.
|
2531
|
+
const wasParsingIndexTrailer = this._isParsingIndexTrailer;
|
2532
|
+
const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
|
2533
|
+
if (this._isTypingAnnotation(atomExpression, 'Literal') ||
|
2534
|
+
this._isTypingAnnotation(atomExpression, 'Annotated')) {
|
2535
|
+
this._isParsingTypeAnnotation = false;
|
2536
|
+
}
|
2537
|
+
this._isParsingIndexTrailer = true;
|
2538
|
+
const subscriptList = this._parseSubscriptList();
|
2539
|
+
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
2540
|
+
this._isParsingIndexTrailer = wasParsingIndexTrailer;
|
2541
|
+
const closingToken = this._peekToken();
|
2542
|
+
const indexNode = parseNodes_1.IndexNode.create(atomExpression, subscriptList.list, subscriptList.trailingComma, closingToken);
|
2543
|
+
(0, parseNodes_1.extendRange)(indexNode, indexNode);
|
2544
|
+
if (!this._consumeTokenIfType(16 /* CloseBracket */)) {
|
2545
|
+
// Handle the error case, but don't use the error node in this
|
2546
|
+
// case because it creates problems for the completion provider.
|
2547
|
+
this._handleExpressionParseError(6 /* MissingIndexCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startOfTrailerToken, indexNode);
|
2548
|
+
}
|
2549
|
+
atomExpression = indexNode;
|
2550
|
+
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2551
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2552
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2553
|
+
}
|
2554
|
+
}
|
2555
|
+
else if (this._consumeTokenIfType(20 /* Dot */)) {
|
2556
|
+
// Is it a member access?
|
2557
|
+
const memberName = this._getTokenIfIdentifier();
|
2558
|
+
if (!memberName) {
|
2559
|
+
return this._handleExpressionParseError(7 /* MissingMemberAccessName */, localize_1.Localizer.Diagnostic.expectedMemberName(), startOfTrailerToken, atomExpression, [8 /* Keyword */]);
|
2560
|
+
}
|
2561
|
+
atomExpression = parseNodes_1.MemberAccessNode.create(atomExpression, parseNodes_1.NameNode.create(memberName));
|
2562
|
+
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2563
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2564
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2565
|
+
}
|
2566
|
+
}
|
2567
|
+
else {
|
2568
|
+
break;
|
2569
|
+
}
|
2570
|
+
}
|
2571
|
+
if (awaitToken) {
|
2572
|
+
return parseNodes_1.AwaitNode.create(awaitToken, atomExpression);
|
2573
|
+
}
|
2574
|
+
return atomExpression;
|
2575
|
+
}
|
2576
|
+
// subscriptlist: subscript (',' subscript)* [',']
|
2577
|
+
_parseSubscriptList() {
|
2578
|
+
const argList = [];
|
2579
|
+
let sawKeywordArg = false;
|
2580
|
+
let trailingComma = false;
|
2581
|
+
while (true) {
|
2582
|
+
const firstToken = this._peekToken();
|
2583
|
+
if (firstToken.type !== 10 /* Colon */ && this._isNextTokenNeverExpression()) {
|
2584
|
+
break;
|
2585
|
+
}
|
2586
|
+
let argType = 0 /* Simple */;
|
2587
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
2588
|
+
argType = 1 /* UnpackedList */;
|
2589
|
+
}
|
2590
|
+
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
2591
|
+
argType = 2 /* UnpackedDictionary */;
|
2592
|
+
}
|
2593
|
+
const startOfSubscriptIndex = this._tokenIndex;
|
2594
|
+
let valueExpr = this._parsePossibleSlice();
|
2595
|
+
let nameIdentifier;
|
2596
|
+
// Is this a keyword argument?
|
2597
|
+
if (argType === 0 /* Simple */) {
|
2598
|
+
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
2599
|
+
const nameExpr = valueExpr;
|
2600
|
+
valueExpr = this._parsePossibleSlice();
|
2601
|
+
if (nameExpr.nodeType === 38 /* Name */) {
|
2602
|
+
nameIdentifier = nameExpr.token;
|
2603
|
+
}
|
2604
|
+
else {
|
2605
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedParamName(), nameExpr);
|
2606
|
+
}
|
2607
|
+
}
|
2608
|
+
else if (valueExpr.nodeType === 38 /* Name */ &&
|
2609
|
+
this._peekOperatorType() === 35 /* Walrus */) {
|
2610
|
+
this._tokenIndex = startOfSubscriptIndex;
|
2611
|
+
valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2612
|
+
// Python 3.10 and newer allow assignment expressions to be used inside of a subscript.
|
2613
|
+
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_10) {
|
2614
|
+
this._addError(localize_1.Localizer.Diagnostic.assignmentExprInSubscript(), valueExpr);
|
2615
|
+
}
|
2616
|
+
}
|
2617
|
+
}
|
2618
|
+
const argNode = parseNodes_1.ArgumentNode.create(firstToken, valueExpr, argType);
|
2619
|
+
if (nameIdentifier) {
|
2620
|
+
argNode.name = parseNodes_1.NameNode.create(nameIdentifier);
|
2621
|
+
argNode.name.parent = argNode;
|
2622
|
+
}
|
2623
|
+
if (argNode.name) {
|
2624
|
+
sawKeywordArg = true;
|
2625
|
+
}
|
2626
|
+
else if (sawKeywordArg && argNode.argumentCategory === 0 /* Simple */) {
|
2627
|
+
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), argNode);
|
2628
|
+
}
|
2629
|
+
argList.push(argNode);
|
2630
|
+
if (argNode.name) {
|
2631
|
+
this._addError(localize_1.Localizer.Diagnostic.keywordSubscriptIllegal(), argNode.name);
|
2632
|
+
}
|
2633
|
+
if (argType !== 0 /* Simple */) {
|
2634
|
+
const unpackAllowed = this._parseOptions.isStubFile || this._getLanguageVersion() >= pythonVersion_1.PythonVersion.V3_11;
|
2635
|
+
if (argType === 2 /* UnpackedDictionary */ || !unpackAllowed) {
|
2636
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackedSubscriptIllegal(), argNode);
|
2637
|
+
}
|
2638
|
+
}
|
2639
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2640
|
+
trailingComma = false;
|
2641
|
+
break;
|
2642
|
+
}
|
2643
|
+
trailingComma = true;
|
2644
|
+
}
|
2645
|
+
// An empty subscript list is illegal.
|
2646
|
+
if (argList.length === 0) {
|
2647
|
+
const errorNode = this._handleExpressionParseError(3 /* MissingIndexOrSlice */, localize_1.Localizer.Diagnostic.expectedSliceIndex(),
|
2648
|
+
/* targetToken */ undefined,
|
2649
|
+
/* childNode */ undefined, [16 /* CloseBracket */]);
|
2650
|
+
argList.push(parseNodes_1.ArgumentNode.create(this._peekToken(), errorNode, 0 /* Simple */));
|
2651
|
+
}
|
2652
|
+
return {
|
2653
|
+
list: argList,
|
2654
|
+
trailingComma,
|
2655
|
+
};
|
2656
|
+
}
|
2657
|
+
// subscript: test | [test] ':' [test] [sliceop]
|
2658
|
+
// sliceop: ':' [test]
|
2659
|
+
_parsePossibleSlice() {
|
2660
|
+
const firstToken = this._peekToken();
|
2661
|
+
const sliceExpressions = [undefined, undefined, undefined];
|
2662
|
+
let sliceIndex = 0;
|
2663
|
+
let sawColon = false;
|
2664
|
+
while (true) {
|
2665
|
+
const nextTokenType = this._peekTokenType();
|
2666
|
+
if (nextTokenType === 16 /* CloseBracket */ || nextTokenType === 12 /* Comma */) {
|
2667
|
+
break;
|
2668
|
+
}
|
2669
|
+
if (nextTokenType !== 10 /* Colon */) {
|
2670
|
+
sliceExpressions[sliceIndex] = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2671
|
+
}
|
2672
|
+
sliceIndex++;
|
2673
|
+
if (sliceIndex >= 3 || !this._consumeTokenIfType(10 /* Colon */)) {
|
2674
|
+
break;
|
2675
|
+
}
|
2676
|
+
sawColon = true;
|
2677
|
+
}
|
2678
|
+
// If this was a simple expression with no colons return it.
|
2679
|
+
if (!sawColon) {
|
2680
|
+
if (sliceExpressions[0]) {
|
2681
|
+
return sliceExpressions[0];
|
2682
|
+
}
|
2683
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 3 /* MissingIndexOrSlice */);
|
2684
|
+
}
|
2685
|
+
const sliceNode = parseNodes_1.SliceNode.create(firstToken);
|
2686
|
+
sliceNode.startValue = sliceExpressions[0];
|
2687
|
+
if (sliceNode.startValue) {
|
2688
|
+
sliceNode.startValue.parent = sliceNode;
|
2689
|
+
}
|
2690
|
+
sliceNode.endValue = sliceExpressions[1];
|
2691
|
+
if (sliceNode.endValue) {
|
2692
|
+
sliceNode.endValue.parent = sliceNode;
|
2693
|
+
}
|
2694
|
+
sliceNode.stepValue = sliceExpressions[2];
|
2695
|
+
if (sliceNode.stepValue) {
|
2696
|
+
sliceNode.stepValue.parent = sliceNode;
|
2697
|
+
}
|
2698
|
+
const extension = sliceExpressions[2] || sliceExpressions[1] || sliceExpressions[0];
|
2699
|
+
if (extension) {
|
2700
|
+
(0, parseNodes_1.extendRange)(sliceNode, extension);
|
2701
|
+
}
|
2702
|
+
return sliceNode;
|
2703
|
+
}
|
2704
|
+
// arglist: argument (',' argument)* [',']
|
2705
|
+
_parseArgList() {
|
2706
|
+
const argList = [];
|
2707
|
+
let sawKeywordArg = false;
|
2708
|
+
let trailingComma = false;
|
2709
|
+
while (true) {
|
2710
|
+
const nextTokenType = this._peekTokenType();
|
2711
|
+
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
2712
|
+
nextTokenType === 2 /* NewLine */ ||
|
2713
|
+
nextTokenType === 1 /* EndOfStream */) {
|
2714
|
+
break;
|
2715
|
+
}
|
2716
|
+
trailingComma = false;
|
2717
|
+
const arg = this._parseArgument();
|
2718
|
+
if (arg.name) {
|
2719
|
+
sawKeywordArg = true;
|
2720
|
+
}
|
2721
|
+
else if (sawKeywordArg && arg.argumentCategory === 0 /* Simple */) {
|
2722
|
+
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
|
2723
|
+
}
|
2724
|
+
argList.push(arg);
|
2725
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2726
|
+
break;
|
2727
|
+
}
|
2728
|
+
trailingComma = true;
|
2729
|
+
}
|
2730
|
+
return { args: argList, trailingComma };
|
2731
|
+
}
|
2732
|
+
// argument: ( test [comp_for] |
|
2733
|
+
// test '=' test |
|
2734
|
+
// '**' test |
|
2735
|
+
// '*' test )
|
2736
|
+
_parseArgument() {
|
2737
|
+
const firstToken = this._peekToken();
|
2738
|
+
let argType = 0 /* Simple */;
|
2739
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
2740
|
+
argType = 1 /* UnpackedList */;
|
2741
|
+
}
|
2742
|
+
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
2743
|
+
argType = 2 /* UnpackedDictionary */;
|
2744
|
+
}
|
2745
|
+
let valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2746
|
+
let nameIdentifier;
|
2747
|
+
if (argType === 0 /* Simple */) {
|
2748
|
+
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
2749
|
+
const nameExpr = valueExpr;
|
2750
|
+
valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2751
|
+
if (nameExpr.nodeType === 38 /* Name */) {
|
2752
|
+
nameIdentifier = nameExpr.token;
|
2753
|
+
}
|
2754
|
+
else {
|
2755
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedParamName(), nameExpr);
|
2756
|
+
}
|
2757
|
+
}
|
2758
|
+
else {
|
2759
|
+
const listComp = this._tryParseListComprehension(valueExpr);
|
2760
|
+
if (listComp) {
|
2761
|
+
valueExpr = listComp;
|
2762
|
+
}
|
2763
|
+
}
|
2764
|
+
}
|
2765
|
+
const argNode = parseNodes_1.ArgumentNode.create(firstToken, valueExpr, argType);
|
2766
|
+
if (nameIdentifier) {
|
2767
|
+
argNode.name = parseNodes_1.NameNode.create(nameIdentifier);
|
2768
|
+
argNode.name.parent = argNode;
|
2769
|
+
}
|
2770
|
+
return argNode;
|
2771
|
+
}
|
2772
|
+
// atom: ('(' [yield_expr | testlist_comp] ')' |
|
2773
|
+
// '[' [testlist_comp] ']' |
|
2774
|
+
// '{' [dictorsetmaker] '}' |
|
2775
|
+
// NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False' | '__debug__')
|
2776
|
+
_parseAtom() {
|
2777
|
+
const nextToken = this._peekToken();
|
2778
|
+
if (nextToken.type === 19 /* Ellipsis */) {
|
2779
|
+
return parseNodes_1.EllipsisNode.create(this._getNextToken());
|
2780
|
+
}
|
2781
|
+
if (nextToken.type === 6 /* Number */) {
|
2782
|
+
return parseNodes_1.NumberNode.create(this._getNextToken());
|
2783
|
+
}
|
2784
|
+
if (nextToken.type === 7 /* Identifier */) {
|
2785
|
+
return parseNodes_1.NameNode.create(this._getNextToken());
|
2786
|
+
}
|
2787
|
+
if (nextToken.type === 5 /* String */) {
|
2788
|
+
return this._parseStringList();
|
2789
|
+
}
|
2790
|
+
if (nextToken.type === 22 /* Backtick */) {
|
2791
|
+
this._getNextToken();
|
2792
|
+
// Atoms with backticks are no longer allowed in Python 3.x, but they
|
2793
|
+
// were a thing in Python 2.x. We'll parse them to improve parse recovery
|
2794
|
+
// and emit an error.
|
2795
|
+
this._addError(localize_1.Localizer.Diagnostic.backticksIllegal(), nextToken);
|
2796
|
+
const expressionNode = this._parseTestListAsExpression(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr());
|
2797
|
+
this._consumeTokenIfType(22 /* Backtick */);
|
2798
|
+
return expressionNode;
|
2799
|
+
}
|
2800
|
+
if (nextToken.type === 13 /* OpenParenthesis */) {
|
2801
|
+
const possibleTupleNode = this._parseTupleAtom();
|
2802
|
+
if (possibleTupleNode.nodeType === 52 /* Tuple */ &&
|
2803
|
+
this._isParsingTypeAnnotation &&
|
2804
|
+
!this._isParsingIndexTrailer) {
|
2805
|
+
// This is allowed inside of an index trailer, specifically
|
2806
|
+
// to support Tuple[()], which is the documented way to annotate
|
2807
|
+
// a zero-length tuple.
|
2808
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
2809
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTupleInstead());
|
2810
|
+
this._addError(localize_1.Localizer.Diagnostic.tupleInAnnotation() + diag.getString(), possibleTupleNode);
|
2811
|
+
}
|
2812
|
+
if (possibleTupleNode.nodeType === 7 /* BinaryOperation */) {
|
2813
|
+
// Mark the binary expression as parenthesized so we don't attempt
|
2814
|
+
// to use comparison chaining, which isn't appropriate when the
|
2815
|
+
// expression is parenthesized.
|
2816
|
+
possibleTupleNode.parenthesized = true;
|
2817
|
+
}
|
2818
|
+
if (possibleTupleNode.nodeType === 48 /* StringList */) {
|
2819
|
+
possibleTupleNode.isParenthesized = true;
|
2820
|
+
}
|
2821
|
+
if (possibleTupleNode.nodeType === 32 /* ListComprehension */) {
|
2822
|
+
possibleTupleNode.isParenthesized = true;
|
2823
|
+
}
|
2824
|
+
return possibleTupleNode;
|
2825
|
+
}
|
2826
|
+
else if (nextToken.type === 15 /* OpenBracket */) {
|
2827
|
+
const listNode = this._parseListAtom();
|
2828
|
+
if (this._isParsingTypeAnnotation && !this._isParsingIndexTrailer) {
|
2829
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
2830
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useListInstead());
|
2831
|
+
this._addError(localize_1.Localizer.Diagnostic.listInAnnotation() + diag.getString(), listNode);
|
2832
|
+
}
|
2833
|
+
return listNode;
|
2834
|
+
}
|
2835
|
+
else if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
2836
|
+
const dictNode = this._parseDictionaryOrSetAtom();
|
2837
|
+
if (this._isParsingTypeAnnotation) {
|
2838
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
2839
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useDictInstead());
|
2840
|
+
this._addError(localize_1.Localizer.Diagnostic.dictInAnnotation() + diag.getString(), dictNode);
|
2841
|
+
}
|
2842
|
+
return dictNode;
|
2843
|
+
}
|
2844
|
+
if (nextToken.type === 8 /* Keyword */) {
|
2845
|
+
const keywordToken = nextToken;
|
2846
|
+
if (keywordToken.keywordType === 15 /* False */ ||
|
2847
|
+
keywordToken.keywordType === 33 /* True */ ||
|
2848
|
+
keywordToken.keywordType === 9 /* Debug */ ||
|
2849
|
+
keywordToken.keywordType === 26 /* None */) {
|
2850
|
+
return parseNodes_1.ConstantNode.create(this._getNextToken());
|
2851
|
+
}
|
2852
|
+
// Make an identifier out of the keyword.
|
2853
|
+
const keywordAsIdentifier = this._getTokenIfIdentifier();
|
2854
|
+
if (keywordAsIdentifier) {
|
2855
|
+
return parseNodes_1.NameNode.create(keywordAsIdentifier);
|
2856
|
+
}
|
2857
|
+
}
|
2858
|
+
return this._handleExpressionParseError(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr());
|
2859
|
+
}
|
2860
|
+
// Allocates a dummy "error expression" and consumes the remainder
|
2861
|
+
// of the tokens on the line for error recovery. A partially-completed
|
2862
|
+
// child node can be passed to help the completion provider determine
|
2863
|
+
// what to do.
|
2864
|
+
_handleExpressionParseError(category, errorMsg, targetToken, childNode, additionalStopTokens) {
|
2865
|
+
this._addError(errorMsg, targetToken !== null && targetToken !== void 0 ? targetToken : this._peekToken());
|
2866
|
+
const expr = parseNodes_1.ErrorNode.create(this._peekToken(), category, childNode);
|
2867
|
+
const stopTokens = [2 /* NewLine */];
|
2868
|
+
if (additionalStopTokens) {
|
2869
|
+
(0, collectionUtils_1.appendArray)(stopTokens, additionalStopTokens);
|
2870
|
+
}
|
2871
|
+
this._consumeTokensUntilType(stopTokens);
|
2872
|
+
return expr;
|
2873
|
+
}
|
2874
|
+
// lambdef: 'lambda' [varargslist] ':' test
|
2875
|
+
_parseLambdaExpression(allowConditional = true) {
|
2876
|
+
const lambdaToken = this._getKeywordToken(24 /* Lambda */);
|
2877
|
+
const argList = this._parseVarArgsList(10 /* Colon */, /* allowAnnotations */ false);
|
2878
|
+
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
2879
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), this._peekToken());
|
2880
|
+
}
|
2881
|
+
let testExpr;
|
2882
|
+
if (allowConditional) {
|
2883
|
+
testExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2884
|
+
}
|
2885
|
+
else {
|
2886
|
+
testExpr = this._tryParseLambdaExpression(/* allowConditional */ false) || this._parseOrTest();
|
2887
|
+
}
|
2888
|
+
const lambdaNode = parseNodes_1.LambdaNode.create(lambdaToken, testExpr);
|
2889
|
+
lambdaNode.parameters = argList;
|
2890
|
+
argList.forEach((arg) => {
|
2891
|
+
arg.parent = lambdaNode;
|
2892
|
+
});
|
2893
|
+
return lambdaNode;
|
2894
|
+
}
|
2895
|
+
_tryParseLambdaExpression(allowConditional = true) {
|
2896
|
+
if (this._peekKeywordType() !== 24 /* Lambda */) {
|
2897
|
+
return undefined;
|
2898
|
+
}
|
2899
|
+
return this._parseLambdaExpression(allowConditional);
|
2900
|
+
}
|
2901
|
+
// ('(' [yield_expr | testlist_comp] ')'
|
2902
|
+
// testlist_comp: (test | star_expr) (comp_for | (',' (test | star_expr))* [','])
|
2903
|
+
_parseTupleAtom() {
|
2904
|
+
var _a;
|
2905
|
+
const startParen = this._getNextToken();
|
2906
|
+
(0, debug_1.assert)(startParen.type === 13 /* OpenParenthesis */);
|
2907
|
+
const yieldExpr = this._tryParseYieldExpression();
|
2908
|
+
if (yieldExpr) {
|
2909
|
+
if (this._peekTokenType() !== 14 /* CloseParenthesis */) {
|
2910
|
+
return this._handleExpressionParseError(8 /* MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, yieldExpr);
|
2911
|
+
}
|
2912
|
+
else {
|
2913
|
+
(0, parseNodes_1.extendRange)(yieldExpr, this._getNextToken());
|
2914
|
+
}
|
2915
|
+
return yieldExpr;
|
2916
|
+
}
|
2917
|
+
const exprListResult = this._parseTestListWithComprehension();
|
2918
|
+
const tupleOrExpression = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ true);
|
2919
|
+
const isExpression = exprListResult.list.length === 1 && !exprListResult.trailingComma;
|
2920
|
+
if (!isExpression) {
|
2921
|
+
(0, parseNodes_1.extendRange)(tupleOrExpression, startParen);
|
2922
|
+
}
|
2923
|
+
if (this._peekTokenType() !== 14 /* CloseParenthesis */) {
|
2924
|
+
return this._handleExpressionParseError(8 /* MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : tupleOrExpression);
|
2925
|
+
}
|
2926
|
+
else {
|
2927
|
+
const nextToken = this._getNextToken();
|
2928
|
+
if (!isExpression) {
|
2929
|
+
(0, parseNodes_1.extendRange)(tupleOrExpression, nextToken);
|
2930
|
+
}
|
2931
|
+
}
|
2932
|
+
return tupleOrExpression;
|
2933
|
+
}
|
2934
|
+
// '[' [testlist_comp] ']'
|
2935
|
+
// testlist_comp: (test | star_expr) (comp_for | (',' (test | star_expr))* [','])
|
2936
|
+
_parseListAtom() {
|
2937
|
+
var _a;
|
2938
|
+
const startBracket = this._getNextToken();
|
2939
|
+
(0, debug_1.assert)(startBracket.type === 15 /* OpenBracket */);
|
2940
|
+
const exprListResult = this._parseTestListWithComprehension();
|
2941
|
+
const closeBracket = this._peekToken();
|
2942
|
+
if (!this._consumeTokenIfType(16 /* CloseBracket */)) {
|
2943
|
+
return this._handleExpressionParseError(9 /* MissingListCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startBracket, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : _createList());
|
2944
|
+
}
|
2945
|
+
return _createList();
|
2946
|
+
function _createList() {
|
2947
|
+
const listAtom = parseNodes_1.ListNode.create(startBracket);
|
2948
|
+
if (closeBracket) {
|
2949
|
+
(0, parseNodes_1.extendRange)(listAtom, closeBracket);
|
2950
|
+
}
|
2951
|
+
if (exprListResult.list.length > 0) {
|
2952
|
+
exprListResult.list.forEach((expr) => {
|
2953
|
+
expr.parent = listAtom;
|
2954
|
+
});
|
2955
|
+
(0, parseNodes_1.extendRange)(listAtom, exprListResult.list[exprListResult.list.length - 1]);
|
2956
|
+
}
|
2957
|
+
listAtom.entries = exprListResult.list;
|
2958
|
+
return listAtom;
|
2959
|
+
}
|
2960
|
+
}
|
2961
|
+
_parseTestListWithComprehension() {
|
2962
|
+
let sawComprehension = false;
|
2963
|
+
return this._parseExpressionListGeneric(() => {
|
2964
|
+
let expr = this._parseTestOrStarExpression(/* allowAssignmentExpression */ true);
|
2965
|
+
const listComp = this._tryParseListComprehension(expr);
|
2966
|
+
if (listComp) {
|
2967
|
+
expr = listComp;
|
2968
|
+
sawComprehension = true;
|
2969
|
+
}
|
2970
|
+
return expr;
|
2971
|
+
}, () => this._isNextTokenNeverExpression(), () => sawComprehension);
|
2972
|
+
}
|
2973
|
+
// '{' [dictorsetmaker] '}'
|
2974
|
+
// dictorsetmaker: (
|
2975
|
+
// (dictentry (comp_for | (',' dictentry)* [',']))
|
2976
|
+
// | (setentry (comp_for | (',' setentry)* [',']))
|
2977
|
+
// )
|
2978
|
+
// dictentry: (test ':' test | '**' expr)
|
2979
|
+
// setentry: test | star_expr
|
2980
|
+
_parseDictionaryOrSetAtom() {
|
2981
|
+
const startBrace = this._getNextToken();
|
2982
|
+
(0, debug_1.assert)(startBrace.type === 17 /* OpenCurlyBrace */);
|
2983
|
+
const dictionaryEntries = [];
|
2984
|
+
const setEntries = [];
|
2985
|
+
let isDictionary = false;
|
2986
|
+
let isSet = false;
|
2987
|
+
let sawListComprehension = false;
|
2988
|
+
let isFirstEntry = true;
|
2989
|
+
let trailingCommaToken;
|
2990
|
+
while (true) {
|
2991
|
+
if (this._peekTokenType() === 18 /* CloseCurlyBrace */) {
|
2992
|
+
break;
|
2993
|
+
}
|
2994
|
+
trailingCommaToken = undefined;
|
2995
|
+
let doubleStarExpression;
|
2996
|
+
let keyExpression;
|
2997
|
+
let valueExpression;
|
2998
|
+
const doubleStar = this._peekToken();
|
2999
|
+
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
3000
|
+
doubleStarExpression = this._parseExpression(/* allowUnpack */ false);
|
3001
|
+
}
|
3002
|
+
else {
|
3003
|
+
keyExpression = this._parseTestOrStarExpression(/* allowAssignmentExpression */ true);
|
3004
|
+
if (this._consumeTokenIfType(10 /* Colon */)) {
|
3005
|
+
valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
3006
|
+
}
|
3007
|
+
}
|
3008
|
+
if (keyExpression && valueExpression) {
|
3009
|
+
if (keyExpression.nodeType === 56 /* Unpack */) {
|
3010
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackInDict(), keyExpression);
|
3011
|
+
}
|
3012
|
+
if (isSet) {
|
3013
|
+
this._addError(localize_1.Localizer.Diagnostic.keyValueInSet(), valueExpression);
|
3014
|
+
}
|
3015
|
+
else {
|
3016
|
+
const keyEntryNode = parseNodes_1.DictionaryKeyEntryNode.create(keyExpression, valueExpression);
|
3017
|
+
let dictEntry = keyEntryNode;
|
3018
|
+
const listComp = this._tryParseListComprehension(keyEntryNode);
|
3019
|
+
if (listComp) {
|
3020
|
+
dictEntry = listComp;
|
3021
|
+
sawListComprehension = true;
|
3022
|
+
if (!isFirstEntry) {
|
3023
|
+
this._addError(localize_1.Localizer.Diagnostic.comprehensionInDict(), dictEntry);
|
3024
|
+
}
|
3025
|
+
}
|
3026
|
+
dictionaryEntries.push(dictEntry);
|
3027
|
+
isDictionary = true;
|
3028
|
+
}
|
3029
|
+
}
|
3030
|
+
else if (doubleStarExpression) {
|
3031
|
+
if (isSet) {
|
3032
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackInSet(), doubleStarExpression);
|
3033
|
+
}
|
3034
|
+
else {
|
3035
|
+
const listEntryNode = parseNodes_1.DictionaryExpandEntryNode.create(doubleStarExpression);
|
3036
|
+
(0, parseNodes_1.extendRange)(listEntryNode, doubleStar);
|
3037
|
+
let expandEntryNode = listEntryNode;
|
3038
|
+
const listComp = this._tryParseListComprehension(listEntryNode);
|
3039
|
+
if (listComp) {
|
3040
|
+
expandEntryNode = listComp;
|
3041
|
+
sawListComprehension = true;
|
3042
|
+
if (!isFirstEntry) {
|
3043
|
+
this._addError(localize_1.Localizer.Diagnostic.comprehensionInDict(), doubleStarExpression);
|
3044
|
+
}
|
3045
|
+
}
|
3046
|
+
dictionaryEntries.push(expandEntryNode);
|
3047
|
+
isDictionary = true;
|
3048
|
+
}
|
3049
|
+
}
|
3050
|
+
else {
|
3051
|
+
(0, debug_1.assert)(keyExpression !== undefined);
|
3052
|
+
if (keyExpression) {
|
3053
|
+
if (isDictionary) {
|
3054
|
+
const missingValueErrorNode = parseNodes_1.ErrorNode.create(this._peekToken(), 13 /* MissingDictValue */);
|
3055
|
+
const keyEntryNode = parseNodes_1.DictionaryKeyEntryNode.create(keyExpression, missingValueErrorNode);
|
3056
|
+
dictionaryEntries.push(keyEntryNode);
|
3057
|
+
this._addError(localize_1.Localizer.Diagnostic.dictKeyValuePairs(), keyExpression);
|
3058
|
+
}
|
3059
|
+
else {
|
3060
|
+
const listComp = this._tryParseListComprehension(keyExpression);
|
3061
|
+
if (listComp) {
|
3062
|
+
keyExpression = listComp;
|
3063
|
+
sawListComprehension = true;
|
3064
|
+
if (!isFirstEntry) {
|
3065
|
+
this._addError(localize_1.Localizer.Diagnostic.comprehensionInSet(), keyExpression);
|
3066
|
+
}
|
3067
|
+
}
|
3068
|
+
setEntries.push(keyExpression);
|
3069
|
+
isSet = true;
|
3070
|
+
}
|
3071
|
+
}
|
3072
|
+
}
|
3073
|
+
// List comprehension statements always end the list.
|
3074
|
+
if (sawListComprehension) {
|
3075
|
+
break;
|
3076
|
+
}
|
3077
|
+
if (this._peekTokenType() !== 12 /* Comma */) {
|
3078
|
+
break;
|
3079
|
+
}
|
3080
|
+
trailingCommaToken = this._getNextToken();
|
3081
|
+
isFirstEntry = false;
|
3082
|
+
}
|
3083
|
+
let closeCurlyBrace = this._peekToken();
|
3084
|
+
if (!this._consumeTokenIfType(18 /* CloseCurlyBrace */)) {
|
3085
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBrace(), startBrace);
|
3086
|
+
closeCurlyBrace = undefined;
|
3087
|
+
}
|
3088
|
+
if (isSet) {
|
3089
|
+
const setAtom = parseNodes_1.SetNode.create(startBrace);
|
3090
|
+
if (closeCurlyBrace) {
|
3091
|
+
(0, parseNodes_1.extendRange)(setAtom, closeCurlyBrace);
|
3092
|
+
}
|
3093
|
+
if (setEntries.length > 0) {
|
3094
|
+
(0, parseNodes_1.extendRange)(setAtom, setEntries[setEntries.length - 1]);
|
3095
|
+
}
|
3096
|
+
setEntries.forEach((entry) => {
|
3097
|
+
entry.parent = setAtom;
|
3098
|
+
});
|
3099
|
+
setAtom.entries = setEntries;
|
3100
|
+
return setAtom;
|
3101
|
+
}
|
3102
|
+
const dictionaryAtom = parseNodes_1.DictionaryNode.create(startBrace);
|
3103
|
+
if (trailingCommaToken) {
|
3104
|
+
dictionaryAtom.trailingCommaToken = trailingCommaToken;
|
3105
|
+
(0, parseNodes_1.extendRange)(dictionaryAtom, trailingCommaToken);
|
3106
|
+
}
|
3107
|
+
if (closeCurlyBrace) {
|
3108
|
+
(0, parseNodes_1.extendRange)(dictionaryAtom, closeCurlyBrace);
|
3109
|
+
}
|
3110
|
+
if (dictionaryEntries.length > 0) {
|
3111
|
+
dictionaryEntries.forEach((entry) => {
|
3112
|
+
entry.parent = dictionaryAtom;
|
3113
|
+
});
|
3114
|
+
(0, parseNodes_1.extendRange)(dictionaryAtom, dictionaryEntries[dictionaryEntries.length - 1]);
|
3115
|
+
}
|
3116
|
+
dictionaryAtom.entries = dictionaryEntries;
|
3117
|
+
return dictionaryAtom;
|
3118
|
+
}
|
3119
|
+
_parseExpressionListGeneric(parser, terminalCheck = () => this._isNextTokenNeverExpression(), finalEntryCheck = () => false) {
|
3120
|
+
let trailingComma = false;
|
3121
|
+
const list = [];
|
3122
|
+
let parseError;
|
3123
|
+
while (true) {
|
3124
|
+
if (terminalCheck()) {
|
3125
|
+
break;
|
3126
|
+
}
|
3127
|
+
const expr = parser();
|
3128
|
+
if (expr.nodeType === 0 /* Error */) {
|
3129
|
+
parseError = expr;
|
3130
|
+
break;
|
3131
|
+
}
|
3132
|
+
list.push(expr);
|
3133
|
+
// Should we stop without checking for a trailing comma?
|
3134
|
+
if (finalEntryCheck()) {
|
3135
|
+
break;
|
3136
|
+
}
|
3137
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
3138
|
+
trailingComma = false;
|
3139
|
+
break;
|
3140
|
+
}
|
3141
|
+
trailingComma = true;
|
3142
|
+
}
|
3143
|
+
return { trailingComma, list, parseError };
|
3144
|
+
}
|
3145
|
+
// expr_stmt: testlist_star_expr (annassign | augassign (yield_expr | testlist) |
|
3146
|
+
// ('=' (yield_expr | testlist_star_expr))*)
|
3147
|
+
// testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
|
3148
|
+
// annassign: ':' test ['=' (yield_expr | testlist_star_expr)]
|
3149
|
+
// augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
|
3150
|
+
// '<<=' | '>>=' | '**=' | '//=')
|
3151
|
+
_parseExpressionStatement() {
|
3152
|
+
let leftExpr = this._parseTestOrStarListAsExpression(
|
3153
|
+
/* allowAssignmentExpression */ false,
|
3154
|
+
/* allowMultipleUnpack */ false, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr());
|
3155
|
+
let annotationExpr;
|
3156
|
+
if (leftExpr.nodeType === 0 /* Error */) {
|
3157
|
+
return leftExpr;
|
3158
|
+
}
|
3159
|
+
// Is this a type annotation assignment?
|
3160
|
+
if (this._consumeTokenIfType(10 /* Colon */)) {
|
3161
|
+
annotationExpr = this._parseTypeAnnotation();
|
3162
|
+
leftExpr = parseNodes_1.TypeAnnotationNode.create(leftExpr, annotationExpr);
|
3163
|
+
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_6) {
|
3164
|
+
this._addError(localize_1.Localizer.Diagnostic.varAnnotationIllegal(), annotationExpr);
|
3165
|
+
}
|
3166
|
+
if (!this._consumeTokenIfOperator(2 /* Assign */)) {
|
3167
|
+
return leftExpr;
|
3168
|
+
}
|
3169
|
+
// This is an unfortunate hack that's necessary to accommodate 'TypeAlias'
|
3170
|
+
// declarations properly. We need to treat this assignment differently than
|
3171
|
+
// most because the expression on the right side is treated like a type
|
3172
|
+
// annotation and therefore allows string-literal forward declarations.
|
3173
|
+
const isTypeAliasDeclaration = this._isTypingAnnotation(annotationExpr, 'TypeAlias');
|
3174
|
+
const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
|
3175
|
+
if (isTypeAliasDeclaration) {
|
3176
|
+
this._isParsingTypeAnnotation = true;
|
3177
|
+
}
|
3178
|
+
const rightExpr = this._tryParseYieldExpression() ||
|
3179
|
+
this._parseTestOrStarListAsExpression(
|
3180
|
+
/* allowAssignmentExpression */ false,
|
3181
|
+
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3182
|
+
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
3183
|
+
return parseNodes_1.AssignmentNode.create(leftExpr, rightExpr);
|
3184
|
+
}
|
3185
|
+
// Is this a simple assignment?
|
3186
|
+
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
3187
|
+
return this._parseChainAssignments(leftExpr);
|
3188
|
+
}
|
3189
|
+
if (tokenizer_1.Tokenizer.isOperatorAssignment(this._peekOperatorType())) {
|
3190
|
+
const operatorToken = this._getNextToken();
|
3191
|
+
const rightExpr = this._tryParseYieldExpression() ||
|
3192
|
+
this._parseTestListAsExpression(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedBinaryRightHandExpr());
|
3193
|
+
// Make a shallow copy of the dest expression but give it a new ID.
|
3194
|
+
const destExpr = Object.assign({}, leftExpr);
|
3195
|
+
destExpr.id = (0, parseNodes_1.getNextNodeId)();
|
3196
|
+
return parseNodes_1.AugmentedAssignmentNode.create(leftExpr, rightExpr, operatorToken.operatorType, destExpr);
|
3197
|
+
}
|
3198
|
+
return leftExpr;
|
3199
|
+
}
|
3200
|
+
_parseChainAssignments(leftExpr) {
|
3201
|
+
let rightExpr = this._tryParseYieldExpression() ||
|
3202
|
+
this._parseTestOrStarListAsExpression(
|
3203
|
+
/* allowAssignmentExpression */ false,
|
3204
|
+
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3205
|
+
if (rightExpr.nodeType === 0 /* Error */) {
|
3206
|
+
return parseNodes_1.AssignmentNode.create(leftExpr, rightExpr);
|
3207
|
+
}
|
3208
|
+
// Recur until we've consumed the entire chain.
|
3209
|
+
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
3210
|
+
rightExpr = this._parseChainAssignments(rightExpr);
|
3211
|
+
if (rightExpr.nodeType === 0 /* Error */) {
|
3212
|
+
return rightExpr;
|
3213
|
+
}
|
3214
|
+
}
|
3215
|
+
const assignmentNode = parseNodes_1.AssignmentNode.create(leftExpr, rightExpr);
|
3216
|
+
// Look for a type annotation comment at the end of the line.
|
3217
|
+
const typeAnnotationComment = this._parseVariableTypeAnnotationComment();
|
3218
|
+
if (typeAnnotationComment) {
|
3219
|
+
assignmentNode.typeAnnotationComment = typeAnnotationComment;
|
3220
|
+
assignmentNode.typeAnnotationComment.parent = assignmentNode;
|
3221
|
+
(0, parseNodes_1.extendRange)(assignmentNode, assignmentNode.typeAnnotationComment);
|
3222
|
+
}
|
3223
|
+
return assignmentNode;
|
3224
|
+
}
|
3225
|
+
_parseFunctionTypeAnnotation() {
|
3226
|
+
const openParenToken = this._peekToken();
|
3227
|
+
if (!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
3228
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
|
3229
|
+
return undefined;
|
3230
|
+
}
|
3231
|
+
let paramAnnotations = [];
|
3232
|
+
while (true) {
|
3233
|
+
const nextTokenType = this._peekTokenType();
|
3234
|
+
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
3235
|
+
nextTokenType === 2 /* NewLine */ ||
|
3236
|
+
nextTokenType === 1 /* EndOfStream */) {
|
3237
|
+
break;
|
3238
|
+
}
|
3239
|
+
// Consume "*" or "**" indicators but don't do anything with them.
|
3240
|
+
// (We don't enforce that these are present, absent, or match
|
3241
|
+
// the corresponding parameter types.)
|
3242
|
+
this._consumeTokenIfOperator(26 /* Multiply */) || this._consumeTokenIfOperator(29 /* Power */);
|
3243
|
+
const paramAnnotation = this._parseTypeAnnotation();
|
3244
|
+
paramAnnotations.push(paramAnnotation);
|
3245
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
3246
|
+
break;
|
3247
|
+
}
|
3248
|
+
}
|
3249
|
+
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
3250
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
3251
|
+
this._consumeTokensUntilType([10 /* Colon */]);
|
3252
|
+
}
|
3253
|
+
if (!this._consumeTokenIfType(21 /* Arrow */)) {
|
3254
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedArrow(), this._peekToken());
|
3255
|
+
return undefined;
|
3256
|
+
}
|
3257
|
+
const returnType = this._parseTypeAnnotation();
|
3258
|
+
let isParamListEllipsis = false;
|
3259
|
+
if (paramAnnotations.length === 1 && paramAnnotations[0].nodeType === 18 /* Ellipsis */) {
|
3260
|
+
paramAnnotations = [];
|
3261
|
+
isParamListEllipsis = true;
|
3262
|
+
}
|
3263
|
+
return parseNodes_1.FunctionAnnotationNode.create(openParenToken, isParamListEllipsis, paramAnnotations, returnType);
|
3264
|
+
}
|
3265
|
+
_parseTypeAnnotation(allowUnpack = false) {
|
3266
|
+
// Temporary set a flag that indicates we're parsing a type annotation.
|
3267
|
+
const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
|
3268
|
+
this._isParsingTypeAnnotation = true;
|
3269
|
+
// Allow unpack operators.
|
3270
|
+
const startToken = this._peekToken();
|
3271
|
+
const isUnpack = this._consumeTokenIfOperator(26 /* Multiply */);
|
3272
|
+
if (isUnpack) {
|
3273
|
+
if (!allowUnpack) {
|
3274
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackInAnnotation(), startToken);
|
3275
|
+
}
|
3276
|
+
else if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_11) {
|
3277
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackedSubscriptIllegal(), startToken);
|
3278
|
+
}
|
3279
|
+
}
|
3280
|
+
let result = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
3281
|
+
if (isUnpack && allowUnpack) {
|
3282
|
+
result = parseNodes_1.UnpackNode.create(startToken, result);
|
3283
|
+
}
|
3284
|
+
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
3285
|
+
return result;
|
3286
|
+
}
|
3287
|
+
_reportStringTokenErrors(stringToken, unescapedResult) {
|
3288
|
+
if (stringToken.flags & 65536 /* Unterminated */) {
|
3289
|
+
this._addError(localize_1.Localizer.Diagnostic.stringUnterminated(), stringToken);
|
3290
|
+
}
|
3291
|
+
if (unescapedResult.nonAsciiInBytes) {
|
3292
|
+
this._addError(localize_1.Localizer.Diagnostic.stringNonAsciiBytes(), stringToken);
|
3293
|
+
}
|
3294
|
+
if (stringToken.flags & 64 /* Format */) {
|
3295
|
+
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_6) {
|
3296
|
+
this._addError(localize_1.Localizer.Diagnostic.formatStringIllegal(), stringToken);
|
3297
|
+
}
|
3298
|
+
if (stringToken.flags & 32 /* Bytes */) {
|
3299
|
+
this._addError(localize_1.Localizer.Diagnostic.formatStringBytes(), stringToken);
|
3300
|
+
}
|
3301
|
+
if (stringToken.flags & 16 /* Unicode */) {
|
3302
|
+
this._addError(localize_1.Localizer.Diagnostic.formatStringUnicode(), stringToken);
|
3303
|
+
}
|
3304
|
+
}
|
3305
|
+
}
|
3306
|
+
_makeStringNode(stringToken) {
|
3307
|
+
const unescapedResult = StringTokenUtils.getUnescapedString(stringToken);
|
3308
|
+
this._reportStringTokenErrors(stringToken, unescapedResult);
|
3309
|
+
return parseNodes_1.StringNode.create(stringToken, unescapedResult.value, unescapedResult.unescapeErrors.length > 0);
|
3310
|
+
}
|
3311
|
+
_getTypeAnnotationCommentText() {
|
3312
|
+
if (this._tokenIndex === 0) {
|
3313
|
+
return undefined;
|
3314
|
+
}
|
3315
|
+
const curToken = this._tokenizerOutput.tokens.getItemAt(this._tokenIndex - 1);
|
3316
|
+
const nextToken = this._tokenizerOutput.tokens.getItemAt(this._tokenIndex);
|
3317
|
+
if (curToken.start + curToken.length === nextToken.start) {
|
3318
|
+
return undefined;
|
3319
|
+
}
|
3320
|
+
const interTokenContents = this._fileContents.substring(curToken.start + curToken.length, nextToken.start);
|
3321
|
+
const commentRegEx = /^(\s*#\s*type:\s*)([^\r\n]*)/;
|
3322
|
+
const match = interTokenContents.match(commentRegEx);
|
3323
|
+
if (!match) {
|
3324
|
+
return undefined;
|
3325
|
+
}
|
3326
|
+
// Synthesize a string token and StringNode.
|
3327
|
+
const typeString = match[2];
|
3328
|
+
// Ignore all "ignore" comments. Include "[" in the regular
|
3329
|
+
// expression because mypy supports ignore comments of the
|
3330
|
+
// form ignore[errorCode, ...]. We'll treat these as regular
|
3331
|
+
// ignore statements (as though no errorCodes were included).
|
3332
|
+
if (typeString.trim().match(/^ignore(\s|\[|$)/)) {
|
3333
|
+
return undefined;
|
3334
|
+
}
|
3335
|
+
const tokenOffset = curToken.start + curToken.length + match[1].length;
|
3336
|
+
return tokenizerTypes_1.StringToken.create(tokenOffset, typeString.length, 0 /* None */, typeString, 0,
|
3337
|
+
/* comments */ undefined);
|
3338
|
+
}
|
3339
|
+
_detectUnsupportedTypeAnnotationComment() {
|
3340
|
+
const stringToken = this._getTypeAnnotationCommentText();
|
3341
|
+
if (!stringToken) {
|
3342
|
+
return undefined;
|
3343
|
+
}
|
3344
|
+
this._addError(localize_1.Localizer.Diagnostic.annotationNotSupported(), stringToken);
|
3345
|
+
}
|
3346
|
+
_parseVariableTypeAnnotationComment() {
|
3347
|
+
const stringToken = this._getTypeAnnotationCommentText();
|
3348
|
+
if (!stringToken) {
|
3349
|
+
return undefined;
|
3350
|
+
}
|
3351
|
+
const stringNode = this._makeStringNode(stringToken);
|
3352
|
+
const stringListNode = parseNodes_1.StringListNode.create([stringNode]);
|
3353
|
+
const parser = new Parser();
|
3354
|
+
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 1 /* VariableAnnotation */,
|
3355
|
+
/* initialParenDepth */ undefined, this._typingSymbolAliases);
|
3356
|
+
parseResults.diagnostics.forEach((diag) => {
|
3357
|
+
this._addError(diag.message, stringListNode);
|
3358
|
+
});
|
3359
|
+
if (!parseResults.parseTree) {
|
3360
|
+
return undefined;
|
3361
|
+
}
|
3362
|
+
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3363
|
+
return parseResults.parseTree;
|
3364
|
+
}
|
3365
|
+
_parseFunctionTypeAnnotationComment(stringToken, functionNode) {
|
3366
|
+
const stringNode = this._makeStringNode(stringToken);
|
3367
|
+
const stringListNode = parseNodes_1.StringListNode.create([stringNode]);
|
3368
|
+
const parser = new Parser();
|
3369
|
+
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 2 /* FunctionAnnotation */,
|
3370
|
+
/* initialParenDepth */ undefined, this._typingSymbolAliases);
|
3371
|
+
parseResults.diagnostics.forEach((diag) => {
|
3372
|
+
this._addError(diag.message, stringListNode);
|
3373
|
+
});
|
3374
|
+
if (!parseResults.parseTree || parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */) {
|
3375
|
+
return;
|
3376
|
+
}
|
3377
|
+
const functionAnnotation = parseResults.parseTree;
|
3378
|
+
functionNode.functionAnnotationComment = functionAnnotation;
|
3379
|
+
functionAnnotation.parent = functionNode;
|
3380
|
+
(0, parseNodes_1.extendRange)(functionNode, functionAnnotation);
|
3381
|
+
}
|
3382
|
+
_parseFormatStringSegment(stringToken, segment, segmentOffset, segmentLength) {
|
3383
|
+
(0, debug_1.assert)(segment.isExpression);
|
3384
|
+
const parser = new Parser();
|
3385
|
+
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start + stringToken.prefixLength + stringToken.quoteMarkLength + segment.offset + segmentOffset, segmentLength, this._parseOptions, 0 /* Expression */,
|
3386
|
+
/* initialParenDepth */ 1, this._typingSymbolAliases);
|
3387
|
+
parseResults.diagnostics.forEach((diag) => {
|
3388
|
+
const textRangeStart = (diag.range ? (0, positionUtils_1.convertPositionToOffset)(diag.range.start, parseResults.lines) : stringToken.start) ||
|
3389
|
+
stringToken.start;
|
3390
|
+
const textRangeEnd = (diag.range
|
3391
|
+
? ((0, positionUtils_1.convertPositionToOffset)(diag.range.end, parseResults.lines) || 0) + 1
|
3392
|
+
: stringToken.start + stringToken.length) || stringToken.start + stringToken.length;
|
3393
|
+
const textRange = { start: textRangeStart, length: textRangeEnd - textRangeStart };
|
3394
|
+
this._addError(diag.message, textRange);
|
3395
|
+
});
|
3396
|
+
return parseResults.parseTree;
|
3397
|
+
}
|
3398
|
+
_parseFormatString(stringToken) {
|
3399
|
+
const unescapedResult = StringTokenUtils.getUnescapedString(stringToken);
|
3400
|
+
this._reportStringTokenErrors(stringToken, unescapedResult);
|
3401
|
+
const formatExpressions = [];
|
3402
|
+
for (const segment of unescapedResult.formatStringSegments) {
|
3403
|
+
if (segment.isExpression) {
|
3404
|
+
// Determine if we need to truncate the expression because it
|
3405
|
+
// contains formatting directives that start with a ! or :.
|
3406
|
+
const segmentExprLength = this._getFormatStringExpressionLength(segment.value.trimEnd());
|
3407
|
+
const parseTree = this._parseFormatStringSegment(stringToken, segment, 0, segmentExprLength);
|
3408
|
+
if (parseTree) {
|
3409
|
+
(0, debug_1.assert)(parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3410
|
+
formatExpressions.push(parseTree);
|
3411
|
+
}
|
3412
|
+
// Look for additional expressions within the format directive.
|
3413
|
+
const formatDirective = segment.value.substr(segmentExprLength);
|
3414
|
+
let braceDepth = 0;
|
3415
|
+
let startOfExprOffset = 0;
|
3416
|
+
for (let i = 0; i < formatDirective.length; i++) {
|
3417
|
+
if (formatDirective.charCodeAt(i) === 123 /* OpenBrace */) {
|
3418
|
+
if (braceDepth === 0) {
|
3419
|
+
startOfExprOffset = i + 1;
|
3420
|
+
}
|
3421
|
+
braceDepth++;
|
3422
|
+
}
|
3423
|
+
else if (formatDirective.charCodeAt(i) === 125 /* CloseBrace */) {
|
3424
|
+
if (braceDepth > 0) {
|
3425
|
+
braceDepth--;
|
3426
|
+
if (braceDepth === 0) {
|
3427
|
+
const formatSegmentLength = this._getFormatStringExpressionLength(segment.value.substr(segmentExprLength + startOfExprOffset, i - startOfExprOffset));
|
3428
|
+
const parseTree = this._parseFormatStringSegment(stringToken, segment, segmentExprLength + startOfExprOffset, formatSegmentLength);
|
3429
|
+
if (parseTree) {
|
3430
|
+
(0, debug_1.assert)(parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3431
|
+
formatExpressions.push(parseTree);
|
3432
|
+
}
|
3433
|
+
}
|
3434
|
+
}
|
3435
|
+
}
|
3436
|
+
}
|
3437
|
+
}
|
3438
|
+
}
|
3439
|
+
return parseNodes_1.FormatStringNode.create(stringToken, unescapedResult.value, unescapedResult.unescapeErrors.length > 0, formatExpressions);
|
3440
|
+
}
|
3441
|
+
_getFormatStringExpressionLength(segmentValue) {
|
3442
|
+
let segmentExprLength = 0;
|
3443
|
+
// PEP 498 says: Expressions cannot contain ':' or '!' outside of
|
3444
|
+
// strings or parentheses, brackets, or braces. The exception is
|
3445
|
+
// that the '!=' operator is allowed as a special case.
|
3446
|
+
const quoteStack = [];
|
3447
|
+
let braceCount = 0;
|
3448
|
+
let parenCount = 0;
|
3449
|
+
let bracketCount = 0;
|
3450
|
+
let indexOfDebugEqual;
|
3451
|
+
while (segmentExprLength < segmentValue.length) {
|
3452
|
+
const curChar = segmentValue[segmentExprLength];
|
3453
|
+
const ignoreSeparator = quoteStack.length > 0 || braceCount > 0 || parenCount > 0 || bracketCount > 0;
|
3454
|
+
const inString = quoteStack.length > 0;
|
3455
|
+
if (curChar === '=') {
|
3456
|
+
indexOfDebugEqual = segmentExprLength;
|
3457
|
+
}
|
3458
|
+
else {
|
3459
|
+
if (curChar === ':') {
|
3460
|
+
if (!ignoreSeparator) {
|
3461
|
+
break;
|
3462
|
+
}
|
3463
|
+
}
|
3464
|
+
else if (curChar === '!') {
|
3465
|
+
if (!ignoreSeparator) {
|
3466
|
+
// Allow !=, as per PEP 498
|
3467
|
+
if (segmentExprLength === segmentValue.length - 1 ||
|
3468
|
+
segmentValue[segmentExprLength + 1] !== '=') {
|
3469
|
+
break;
|
3470
|
+
}
|
3471
|
+
}
|
3472
|
+
}
|
3473
|
+
else if (curChar === "'" || curChar === '"') {
|
3474
|
+
let quoteSequence = curChar;
|
3475
|
+
if (segmentExprLength + 2 < segmentValue.length &&
|
3476
|
+
segmentValue[segmentExprLength + 1] === curChar &&
|
3477
|
+
segmentValue[segmentExprLength + 2] === curChar) {
|
3478
|
+
quoteSequence = curChar + curChar + curChar;
|
3479
|
+
segmentExprLength += 2;
|
3480
|
+
}
|
3481
|
+
if (quoteStack.length > 0 && quoteStack[quoteStack.length - 1] === quoteSequence) {
|
3482
|
+
quoteStack.pop();
|
3483
|
+
}
|
3484
|
+
else if (quoteStack.length === 0) {
|
3485
|
+
quoteStack.push(quoteSequence);
|
3486
|
+
}
|
3487
|
+
}
|
3488
|
+
else if (curChar === '(') {
|
3489
|
+
if (!inString) {
|
3490
|
+
parenCount++;
|
3491
|
+
}
|
3492
|
+
}
|
3493
|
+
else if (curChar === ')') {
|
3494
|
+
if (!inString && parenCount > 0) {
|
3495
|
+
parenCount--;
|
3496
|
+
}
|
3497
|
+
}
|
3498
|
+
else if (curChar === '{') {
|
3499
|
+
if (!inString) {
|
3500
|
+
braceCount++;
|
3501
|
+
}
|
3502
|
+
}
|
3503
|
+
else if (curChar === '}') {
|
3504
|
+
if (!inString && braceCount > 0) {
|
3505
|
+
braceCount--;
|
3506
|
+
}
|
3507
|
+
}
|
3508
|
+
else if (curChar === '[') {
|
3509
|
+
if (!inString) {
|
3510
|
+
bracketCount++;
|
3511
|
+
}
|
3512
|
+
}
|
3513
|
+
else if (curChar === ']') {
|
3514
|
+
if (!inString && bracketCount > 0) {
|
3515
|
+
bracketCount--;
|
3516
|
+
}
|
3517
|
+
}
|
3518
|
+
if (curChar !== ' ') {
|
3519
|
+
indexOfDebugEqual = undefined;
|
3520
|
+
}
|
3521
|
+
}
|
3522
|
+
segmentExprLength++;
|
3523
|
+
}
|
3524
|
+
// Handle Python 3.8 f-string formatting expressions that
|
3525
|
+
// end in an "=".
|
3526
|
+
if (this._parseOptions.pythonVersion >= pythonVersion_1.PythonVersion.V3_8 && indexOfDebugEqual !== undefined) {
|
3527
|
+
segmentExprLength = indexOfDebugEqual;
|
3528
|
+
}
|
3529
|
+
return segmentExprLength;
|
3530
|
+
}
|
3531
|
+
_createBinaryOperationNode(leftExpression, rightExpression, operatorToken, operator) {
|
3532
|
+
// Determine if we're exceeding the max parse depth. If so, replace
|
3533
|
+
// the subnode with an error node. Otherwise we risk crashing in the binder
|
3534
|
+
// or type evaluator.
|
3535
|
+
if (leftExpression.maxChildDepth !== undefined && leftExpression.maxChildDepth >= maxChildNodeDepth) {
|
3536
|
+
leftExpression = parseNodes_1.ErrorNode.create(leftExpression, 14 /* MaxDepthExceeded */);
|
3537
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), leftExpression);
|
3538
|
+
}
|
3539
|
+
if (rightExpression.maxChildDepth !== undefined && rightExpression.maxChildDepth >= maxChildNodeDepth) {
|
3540
|
+
rightExpression = parseNodes_1.ErrorNode.create(rightExpression, 14 /* MaxDepthExceeded */);
|
3541
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), rightExpression);
|
3542
|
+
}
|
3543
|
+
return parseNodes_1.BinaryOperationNode.create(leftExpression, rightExpression, operatorToken, operator);
|
3544
|
+
}
|
3545
|
+
_createUnaryOperationNode(operatorToken, expression, operator) {
|
3546
|
+
// Determine if we're exceeding the max parse depth. If so, replace
|
3547
|
+
// the subnode with an error node. Otherwise we risk crashing in the binder
|
3548
|
+
// or type evaluator.
|
3549
|
+
if (expression.maxChildDepth !== undefined && expression.maxChildDepth >= maxChildNodeDepth) {
|
3550
|
+
expression = parseNodes_1.ErrorNode.create(expression, 14 /* MaxDepthExceeded */);
|
3551
|
+
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), expression);
|
3552
|
+
}
|
3553
|
+
return parseNodes_1.UnaryOperationNode.create(operatorToken, expression, operator);
|
3554
|
+
}
|
3555
|
+
_parseStringList() {
|
3556
|
+
const stringList = [];
|
3557
|
+
while (this._peekTokenType() === 5 /* String */) {
|
3558
|
+
const stringToken = this._getNextToken();
|
3559
|
+
if (stringToken.flags & 64 /* Format */) {
|
3560
|
+
stringList.push(this._parseFormatString(stringToken));
|
3561
|
+
}
|
3562
|
+
else {
|
3563
|
+
stringList.push(this._makeStringNode(stringToken));
|
3564
|
+
}
|
3565
|
+
}
|
3566
|
+
const stringNode = parseNodes_1.StringListNode.create(stringList);
|
3567
|
+
// If we're parsing a type annotation, parse the contents of the string.
|
3568
|
+
if (this._isParsingTypeAnnotation) {
|
3569
|
+
// Don't allow multiple strings because we have no way of reporting
|
3570
|
+
// parse errors that span strings.
|
3571
|
+
if (stringNode.strings.length > 1) {
|
3572
|
+
this._addError(localize_1.Localizer.Diagnostic.annotationSpansStrings(), stringNode);
|
3573
|
+
}
|
3574
|
+
else if (stringNode.strings[0].token.flags & 64 /* Format */) {
|
3575
|
+
this._addError(localize_1.Localizer.Diagnostic.annotationFormatString(), stringNode);
|
3576
|
+
}
|
3577
|
+
else {
|
3578
|
+
const stringToken = stringNode.strings[0].token;
|
3579
|
+
const stringValue = StringTokenUtils.getUnescapedString(stringNode.strings[0].token);
|
3580
|
+
const unescapedString = stringValue.value;
|
3581
|
+
const tokenOffset = stringToken.start;
|
3582
|
+
const prefixLength = stringToken.prefixLength + stringToken.quoteMarkLength;
|
3583
|
+
// Don't allow escape characters because we have no way of mapping
|
3584
|
+
// error ranges back to the escaped text.
|
3585
|
+
if (unescapedString.length !== stringToken.length - prefixLength - stringToken.quoteMarkLength) {
|
3586
|
+
this._addError(localize_1.Localizer.Diagnostic.annotationStringEscape(), stringNode);
|
3587
|
+
}
|
3588
|
+
else {
|
3589
|
+
const parser = new Parser();
|
3590
|
+
const parseResults = parser.parseTextExpression(this._fileContents, tokenOffset + prefixLength, unescapedString.length, this._parseOptions, 1 /* VariableAnnotation */, (stringNode.strings[0].token.flags & 4 /* Triplicate */) !== 0 ? 1 : 0, this._typingSymbolAliases);
|
3591
|
+
if (parseResults.diagnostics.length === 0 ||
|
3592
|
+
this._parseOptions.reportErrorsForParsedStringContents) {
|
3593
|
+
parseResults.diagnostics.forEach((diag) => {
|
3594
|
+
this._addError(diag.message, stringNode);
|
3595
|
+
});
|
3596
|
+
if (parseResults.parseTree) {
|
3597
|
+
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3598
|
+
stringNode.typeAnnotation = parseResults.parseTree;
|
3599
|
+
stringNode.typeAnnotation.parent = stringNode;
|
3600
|
+
}
|
3601
|
+
}
|
3602
|
+
}
|
3603
|
+
}
|
3604
|
+
}
|
3605
|
+
return stringNode;
|
3606
|
+
}
|
3607
|
+
// Python 3.8 added support for star (unpack) expressions in tuples
|
3608
|
+
// following a return or yield statement in cases where the tuple
|
3609
|
+
// wasn't surrounded in parentheses.
|
3610
|
+
_reportConditionalErrorForStarTupleElement(possibleTupleExpr) {
|
3611
|
+
if (possibleTupleExpr.nodeType !== 52 /* Tuple */) {
|
3612
|
+
return;
|
3613
|
+
}
|
3614
|
+
if (possibleTupleExpr.enclosedInParens) {
|
3615
|
+
return;
|
3616
|
+
}
|
3617
|
+
if (this._parseOptions.pythonVersion >= pythonVersion_1.PythonVersion.V3_8) {
|
3618
|
+
return;
|
3619
|
+
}
|
3620
|
+
for (const expr of possibleTupleExpr.expressions) {
|
3621
|
+
if (expr.nodeType === 56 /* Unpack */) {
|
3622
|
+
this._addError(localize_1.Localizer.Diagnostic.unpackTuplesIllegal(), expr);
|
3623
|
+
return;
|
3624
|
+
}
|
3625
|
+
}
|
3626
|
+
}
|
3627
|
+
// Peeks at the next token and returns true if it can never
|
3628
|
+
// represent the start of an expression.
|
3629
|
+
_isNextTokenNeverExpression() {
|
3630
|
+
const nextToken = this._peekToken();
|
3631
|
+
switch (nextToken.type) {
|
3632
|
+
case 8 /* Keyword */: {
|
3633
|
+
switch (this._peekKeywordType()) {
|
3634
|
+
case 17 /* For */:
|
3635
|
+
case 22 /* In */:
|
3636
|
+
case 20 /* If */:
|
3637
|
+
return true;
|
3638
|
+
}
|
3639
|
+
break;
|
3640
|
+
}
|
3641
|
+
case 9 /* Operator */: {
|
3642
|
+
switch (this._peekOperatorType()) {
|
3643
|
+
case 1 /* AddEqual */:
|
3644
|
+
case 34 /* SubtractEqual */:
|
3645
|
+
case 27 /* MultiplyEqual */:
|
3646
|
+
case 11 /* DivideEqual */:
|
3647
|
+
case 25 /* ModEqual */:
|
3648
|
+
case 4 /* BitwiseAndEqual */:
|
3649
|
+
case 7 /* BitwiseOrEqual */:
|
3650
|
+
case 9 /* BitwiseXorEqual */:
|
3651
|
+
case 18 /* LeftShiftEqual */:
|
3652
|
+
case 32 /* RightShiftEqual */:
|
3653
|
+
case 30 /* PowerEqual */:
|
3654
|
+
case 14 /* FloorDivideEqual */:
|
3655
|
+
case 2 /* Assign */:
|
3656
|
+
return true;
|
3657
|
+
}
|
3658
|
+
break;
|
3659
|
+
}
|
3660
|
+
case 3 /* Indent */:
|
3661
|
+
case 4 /* Dedent */:
|
3662
|
+
case 2 /* NewLine */:
|
3663
|
+
case 1 /* EndOfStream */:
|
3664
|
+
case 11 /* Semicolon */:
|
3665
|
+
case 14 /* CloseParenthesis */:
|
3666
|
+
case 16 /* CloseBracket */:
|
3667
|
+
case 18 /* CloseCurlyBrace */:
|
3668
|
+
case 12 /* Comma */:
|
3669
|
+
case 10 /* Colon */:
|
3670
|
+
return true;
|
3671
|
+
}
|
3672
|
+
return false;
|
3673
|
+
}
|
3674
|
+
_disallowAssignmentExpression(callback) {
|
3675
|
+
const wasAllowed = this._assignmentExpressionsAllowed;
|
3676
|
+
this._assignmentExpressionsAllowed = false;
|
3677
|
+
callback();
|
3678
|
+
this._assignmentExpressionsAllowed = wasAllowed;
|
3679
|
+
}
|
3680
|
+
_getNextToken() {
|
3681
|
+
const token = this._tokenizerOutput.tokens.getItemAt(this._tokenIndex);
|
3682
|
+
if (!this._atEof()) {
|
3683
|
+
this._tokenIndex++;
|
3684
|
+
}
|
3685
|
+
return token;
|
3686
|
+
}
|
3687
|
+
_atEof() {
|
3688
|
+
// Are we pointing at the last token in the stream (which is
|
3689
|
+
// assumed to be an end-of-stream token)?
|
3690
|
+
return this._tokenIndex >= this._tokenizerOutput.tokens.count - 1;
|
3691
|
+
}
|
3692
|
+
_peekToken(count = 0) {
|
3693
|
+
if (this._tokenIndex + count < 0) {
|
3694
|
+
return this._tokenizerOutput.tokens.getItemAt(0);
|
3695
|
+
}
|
3696
|
+
if (this._tokenIndex + count >= this._tokenizerOutput.tokens.count) {
|
3697
|
+
return this._tokenizerOutput.tokens.getItemAt(this._tokenizerOutput.tokens.count - 1);
|
3698
|
+
}
|
3699
|
+
return this._tokenizerOutput.tokens.getItemAt(this._tokenIndex + count);
|
3700
|
+
}
|
3701
|
+
_peekTokenType() {
|
3702
|
+
return this._peekToken().type;
|
3703
|
+
}
|
3704
|
+
_peekKeywordType() {
|
3705
|
+
const nextToken = this._peekToken();
|
3706
|
+
if (nextToken.type !== 8 /* Keyword */) {
|
3707
|
+
return undefined;
|
3708
|
+
}
|
3709
|
+
return nextToken.keywordType;
|
3710
|
+
}
|
3711
|
+
_peekOperatorType() {
|
3712
|
+
const nextToken = this._peekToken();
|
3713
|
+
if (nextToken.type !== 9 /* Operator */) {
|
3714
|
+
return undefined;
|
3715
|
+
}
|
3716
|
+
return nextToken.operatorType;
|
3717
|
+
}
|
3718
|
+
_getTokenIfIdentifier() {
|
3719
|
+
const nextToken = this._peekToken();
|
3720
|
+
if (nextToken.type === 7 /* Identifier */) {
|
3721
|
+
return this._getNextToken();
|
3722
|
+
}
|
3723
|
+
// If the next token is invalid, treat it as an identifier.
|
3724
|
+
if (nextToken.type === 0 /* Invalid */) {
|
3725
|
+
this._getNextToken();
|
3726
|
+
this._addError(localize_1.Localizer.Diagnostic.invalidIdentifierChar(), nextToken);
|
3727
|
+
return tokenizerTypes_1.IdentifierToken.create(nextToken.start, nextToken.length, '', nextToken.comments);
|
3728
|
+
}
|
3729
|
+
// If this is a "soft keyword", it can be converted into an identifier.
|
3730
|
+
if (nextToken.type === 8 /* Keyword */) {
|
3731
|
+
const keywordType = this._peekKeywordType();
|
3732
|
+
const softKeywords = [9 /* Debug */, 25 /* Match */, 6 /* Case */];
|
3733
|
+
if (softKeywords.find((type) => type === keywordType)) {
|
3734
|
+
const keywordText = this._fileContents.substr(nextToken.start, nextToken.length);
|
3735
|
+
this._getNextToken();
|
3736
|
+
return tokenizerTypes_1.IdentifierToken.create(nextToken.start, nextToken.length, keywordText, nextToken.comments);
|
3737
|
+
}
|
3738
|
+
}
|
3739
|
+
return undefined;
|
3740
|
+
}
|
3741
|
+
// Consumes tokens until the next one in the stream is
|
3742
|
+
// either a specified terminator or the end-of-stream
|
3743
|
+
// token.
|
3744
|
+
_consumeTokensUntilType(terminators) {
|
3745
|
+
while (true) {
|
3746
|
+
const token = this._peekToken();
|
3747
|
+
if (terminators.some((term) => term === token.type)) {
|
3748
|
+
return true;
|
3749
|
+
}
|
3750
|
+
if (token.type === 1 /* EndOfStream */) {
|
3751
|
+
return false;
|
3752
|
+
}
|
3753
|
+
this._getNextToken();
|
3754
|
+
}
|
3755
|
+
}
|
3756
|
+
_getTokenIfType(tokenType) {
|
3757
|
+
if (this._peekTokenType() === tokenType) {
|
3758
|
+
return this._getNextToken();
|
3759
|
+
}
|
3760
|
+
return undefined;
|
3761
|
+
}
|
3762
|
+
_consumeTokenIfType(tokenType) {
|
3763
|
+
return !!this._getTokenIfType(tokenType);
|
3764
|
+
}
|
3765
|
+
_consumeTokenIfKeyword(keywordType) {
|
3766
|
+
if (this._peekKeywordType() === keywordType) {
|
3767
|
+
this._getNextToken();
|
3768
|
+
return true;
|
3769
|
+
}
|
3770
|
+
return false;
|
3771
|
+
}
|
3772
|
+
_consumeTokenIfOperator(operatorType) {
|
3773
|
+
if (this._peekOperatorType() === operatorType) {
|
3774
|
+
this._getNextToken();
|
3775
|
+
return true;
|
3776
|
+
}
|
3777
|
+
return false;
|
3778
|
+
}
|
3779
|
+
_getKeywordToken(keywordType) {
|
3780
|
+
const keywordToken = this._getNextToken();
|
3781
|
+
(0, debug_1.assert)(keywordToken.type === 8 /* Keyword */);
|
3782
|
+
(0, debug_1.assert)(keywordToken.keywordType === keywordType);
|
3783
|
+
return keywordToken;
|
3784
|
+
}
|
3785
|
+
_getLanguageVersion() {
|
3786
|
+
return this._parseOptions.pythonVersion;
|
3787
|
+
}
|
3788
|
+
_suppressErrors(callback) {
|
3789
|
+
const errorsWereSuppressed = this._areErrorsSuppressed;
|
3790
|
+
try {
|
3791
|
+
this._areErrorsSuppressed = true;
|
3792
|
+
callback();
|
3793
|
+
}
|
3794
|
+
finally {
|
3795
|
+
this._areErrorsSuppressed = errorsWereSuppressed;
|
3796
|
+
}
|
3797
|
+
}
|
3798
|
+
_addError(message, range) {
|
3799
|
+
(0, debug_1.assert)(range !== undefined);
|
3800
|
+
if (!this._areErrorsSuppressed) {
|
3801
|
+
this._diagSink.addError(message, (0, positionUtils_1.convertOffsetsToRange)(range.start, range.start + range.length, this._tokenizerOutput.lines));
|
3802
|
+
}
|
3803
|
+
}
|
3804
|
+
}
|
3805
|
+
exports.Parser = Parser;
|
3806
|
+
//# sourceMappingURL=parser.js.map
|