@zzzen/pyright-internal 1.2.0-dev.20231119 → 1.2.0-dev.20231203
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/analysis.d.ts +1 -1
- package/dist/analyzer/analysis.js +5 -1
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
- package/dist/analyzer/analyzerNodeInfo.d.ts +1 -1
- package/dist/analyzer/analyzerNodeInfo.js +1 -1
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +201 -194
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.js +1 -1
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -1
- package/dist/analyzer/checker.js +403 -248
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +1 -1
- package/dist/analyzer/codeFlowEngine.js +33 -26
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -1
- package/dist/analyzer/codeFlowTypes.js +23 -23
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +39 -37
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/commentUtils.js +7 -0
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +51 -47
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +8 -8
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +25 -26
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +124 -109
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +2 -2
- package/dist/analyzer/declaration.js +10 -10
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +41 -41
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +51 -51
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +27 -27
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +4 -4
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +21 -17
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.js +1 -1
- package/dist/analyzer/importResult.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +31 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +36 -32
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +94 -92
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeReport.d.ts +1 -1
- package/dist/analyzer/packageTypeReport.js +2 -2
- package/dist/analyzer/packageTypeReport.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +90 -90
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +14 -14
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.d.ts +2 -2
- package/dist/analyzer/parseTreeCleaner.js +5 -1
- package/dist/analyzer/parseTreeCleaner.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.js +383 -379
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +161 -157
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +52 -50
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +18 -14
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +53 -44
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +41 -27
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +5 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/regions.js +3 -3
- package/dist/analyzer/regions.js.map +1 -1
- package/dist/analyzer/scope.js +8 -8
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/scopeUtils.js +1 -1
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/service.js +5 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +25 -21
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +2 -2
- package/dist/analyzer/sourceMapper.js +12 -8
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +40 -40
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +1 -1
- package/dist/analyzer/symbol.js +26 -26
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/symbolUtils.js +1 -1
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/testWalker.js +5 -5
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +1 -1
- package/dist/analyzer/tracePrinter.js +35 -31
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.js +5 -1
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +13 -9
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +1347 -1270
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +79 -65
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +80 -76
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +26 -22
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +139 -135
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +2 -0
- package/dist/analyzer/typeVarContext.js +36 -9
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +10 -10
- package/dist/analyzer/typedDicts.js +76 -102
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +18 -18
- package/dist/analyzer/types.js +186 -191
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -2
- package/dist/backgroundAnalysisBase.js +5 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +5 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/commandController.js +6 -7
- package/dist/commands/commandController.js.map +1 -1
- package/dist/commands/commandResult.js +1 -1
- package/dist/commands/commandResult.js.map +1 -1
- package/dist/commands/commands.d.ts +0 -1
- package/dist/commands/commands.js +1 -2
- package/dist/commands/commands.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +196 -196
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/charCodes.js +1 -1
- package/dist/common/charCodes.js.map +1 -1
- package/dist/common/chokidarFileWatcherProvider.js +5 -1
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
- package/dist/common/collectionUtils.d.ts +3 -3
- package/dist/common/collectionUtils.js +3 -3
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -1
- package/dist/common/commandLineOptions.js +5 -5
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +102 -10
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.js +7 -3
- package/dist/common/console.js.map +1 -1
- package/dist/common/core.d.ts +2 -2
- package/dist/common/core.js +6 -6
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +0 -4
- package/dist/common/diagnostic.js +6 -6
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticRules.js +1 -1
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/diagnosticSink.js +12 -12
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/editAction.d.ts +1 -1
- package/dist/common/editAction.js +2 -2
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/envVarUtils.js +5 -1
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.js +1 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +5 -1
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js +2 -2
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fileWatcher.d.ts +2 -2
- package/dist/common/fullAccessHost.js +10 -6
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +1 -1
- package/dist/common/host.js +2 -2
- package/dist/common/host.js.map +1 -1
- package/dist/common/lspUtils.js +7 -7
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/memUtils.d.ts +1 -1
- package/dist/common/pathUtils.js +12 -8
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/common/realFileSystem.js +5 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -1
- package/dist/common/serviceProvider.js +5 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.js +1 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/stringUtils.js +5 -5
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/textEditTracker.js +11 -7
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRange.js +3 -3
- package/dist/common/textRange.js.map +1 -1
- package/dist/languageServerBase.js +13 -13
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -3
- package/dist/languageService/autoImporter.js +12 -8
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +27 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +5 -19
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +166 -162
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +9 -9
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.js +14 -10
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +7 -3
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +1 -1
- package/dist/languageService/documentSymbolCollector.js +21 -17
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +30 -26
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +1 -1
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/quickActions.d.ts +1 -2
- package/dist/languageService/quickActions.js +1 -77
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +1 -1
- package/dist/languageService/referencesProvider.js +24 -20
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +8 -4
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +8 -4
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +20 -16
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +5 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +19 -18
- package/dist/localization/localize.js +11 -8
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -7
- package/dist/localization/package.nls.de.json +0 -7
- package/dist/localization/package.nls.en-us.json +11 -8
- package/dist/localization/package.nls.es.json +2 -9
- package/dist/localization/package.nls.fr.json +0 -7
- package/dist/localization/package.nls.it.json +0 -7
- package/dist/localization/package.nls.ja.json +0 -7
- package/dist/localization/package.nls.ko.json +0 -7
- package/dist/localization/package.nls.pl.json +0 -7
- package/dist/localization/package.nls.pt-br.json +0 -7
- package/dist/localization/package.nls.qps-ploc.json +0 -7
- package/dist/localization/package.nls.ru.json +0 -7
- package/dist/localization/package.nls.tr.json +0 -7
- package/dist/localization/package.nls.zh-cn.json +0 -7
- package/dist/localization/package.nls.zh-tw.json +0 -7
- package/dist/parser/characterStream.js +3 -3
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/characters.js +13 -9
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +12 -12
- package/dist/parser/parseNodes.js +193 -193
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +563 -559
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +47 -47
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +288 -288
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.js +35 -35
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/parser/unicode.d.ts +3 -3
- package/dist/pyright.js +21 -17
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +2 -2
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +2 -1
- package/dist/readonlyAugmentedFileSystem.js +15 -5
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +5 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +13 -1
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/collectionUtils.test.js +5 -1
- package/dist/tests/collectionUtils.test.js.map +1 -1
- package/dist/tests/common.test.js +5 -1
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/debug.test.js +8 -4
- package/dist/tests/debug.test.js.map +1 -1
- package/dist/tests/deferred.test.js +5 -1
- package/dist/tests/deferred.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +5 -1
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/docStringUtils.test.js +5 -1
- package/dist/tests/docStringUtils.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +5 -1
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +5 -1
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/fourSlashRunner.test.js +5 -1
- package/dist/tests/fourSlashRunner.test.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -2
- package/dist/tests/harness/fourslash/fourSlashParser.js +13 -13
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.js +11 -7
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/runner.d.ts +1 -1
- package/dist/tests/harness/fourslash/runner.js +5 -1
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +5 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -2
- package/dist/tests/harness/fourslash/testState.Consts.js +6 -3
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +18 -14
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +9 -5
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +5 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/harness/testHost.js +5 -1
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/utils.d.ts +13 -12
- package/dist/tests/harness/utils.js.map +1 -1
- package/dist/tests/harness/vfs/factory.js +6 -2
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +4 -3
- package/dist/tests/harness/vfs/filesystem.js +11 -7
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +30 -26
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +25 -25
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +6 -6
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/localizer.test.js +5 -1
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/logger.test.js +5 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +10 -10
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +13 -9
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +5 -1
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +48 -1
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +5 -1
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +5 -1
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/stringUtils.test.js +10 -6
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/symbolNameUtils.test.js +5 -1
- package/dist/tests/symbolNameUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +5 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +11 -7
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textRange.test.js +5 -1
- package/dist/tests/textRange.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +463 -459
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +22 -7
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +14 -6
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +23 -12
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +16 -4
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +13 -5
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +44 -40
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +5 -1
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +5 -1
- package/dist/tests/zipfs.test.js.map +1 -1
- package/dist/workspaceFactory.js +2 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +2 -2
package/dist/parser/parser.js
CHANGED
@@ -13,7 +13,11 @@
|
|
13
13
|
*/
|
14
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
15
15
|
if (k2 === undefined) k2 = k;
|
16
|
-
Object.
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
19
|
+
}
|
20
|
+
Object.defineProperty(o, k2, desc);
|
17
21
|
}) : (function(o, m, k, k2) {
|
18
22
|
if (k2 === undefined) k2 = k;
|
19
23
|
o[k2] = m[k];
|
@@ -91,10 +95,10 @@ class Parser {
|
|
91
95
|
const moduleNode = parseNodes_1.ModuleNode.create({ start: 0, length: fileContents.length });
|
92
96
|
timing_1.timingStats.parseFileTime.timeOperation(() => {
|
93
97
|
while (!this._atEof()) {
|
94
|
-
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
98
|
+
if (!this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
95
99
|
// Handle a common error case and try to recover.
|
96
100
|
const nextToken = this._peekToken();
|
97
|
-
if (nextToken.type === 3 /* Indent */) {
|
101
|
+
if (nextToken.type === 3 /* TokenType.Indent */) {
|
98
102
|
this._getNextToken();
|
99
103
|
const indentToken = nextToken;
|
100
104
|
if (indentToken.isIndentAmbiguous) {
|
@@ -107,7 +111,7 @@ class Parser {
|
|
107
111
|
const statement = this._parseStatement();
|
108
112
|
if (!statement) {
|
109
113
|
// Perform basic error recovery to get to the next line.
|
110
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
114
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
111
115
|
}
|
112
116
|
else {
|
113
117
|
statement.parent = moduleNode;
|
@@ -127,18 +131,18 @@ class Parser {
|
|
127
131
|
typingSymbolAliases: this._typingSymbolAliases,
|
128
132
|
};
|
129
133
|
}
|
130
|
-
parseTextExpression(fileContents, textOffset, textLength, parseOptions, parseTextMode = 0 /* Expression */, initialParenDepth = 0, typingSymbolAliases) {
|
134
|
+
parseTextExpression(fileContents, textOffset, textLength, parseOptions, parseTextMode = 0 /* ParseTextMode.Expression */, initialParenDepth = 0, typingSymbolAliases) {
|
131
135
|
const diagSink = new diagnosticSink_1.DiagnosticSink();
|
132
136
|
this._startNewParse(fileContents, textOffset, textLength, parseOptions, diagSink, initialParenDepth);
|
133
137
|
if (typingSymbolAliases) {
|
134
138
|
this._typingSymbolAliases = new Map(typingSymbolAliases);
|
135
139
|
}
|
136
140
|
let parseTree;
|
137
|
-
if (parseTextMode === 1 /* VariableAnnotation */) {
|
141
|
+
if (parseTextMode === 1 /* ParseTextMode.VariableAnnotation */) {
|
138
142
|
this._isParsingQuotedText = true;
|
139
143
|
parseTree = this._parseTypeAnnotation();
|
140
144
|
}
|
141
|
-
else if (parseTextMode === 2 /* FunctionAnnotation */) {
|
145
|
+
else if (parseTextMode === 2 /* ParseTextMode.FunctionAnnotation */) {
|
142
146
|
this._isParsingQuotedText = true;
|
143
147
|
parseTree = this._parseFunctionTypeAnnotation();
|
144
148
|
}
|
@@ -156,7 +160,7 @@ class Parser {
|
|
156
160
|
parseTree = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
|
157
161
|
}
|
158
162
|
}
|
159
|
-
if (this._peekTokenType() === 2 /* NewLine */) {
|
163
|
+
if (this._peekTokenType() === 2 /* TokenType.NewLine */) {
|
160
164
|
this._getNextToken();
|
161
165
|
}
|
162
166
|
if (!this._atEof()) {
|
@@ -183,46 +187,46 @@ class Parser {
|
|
183
187
|
_parseStatement() {
|
184
188
|
// Handle the errant condition of a dedent token here to provide
|
185
189
|
// better recovery.
|
186
|
-
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
190
|
+
if (this._consumeTokenIfType(4 /* TokenType.Dedent */)) {
|
187
191
|
this._addError(localize_1.Localizer.Diagnostic.unexpectedUnindent(), this._peekToken());
|
188
192
|
}
|
189
193
|
switch (this._peekKeywordType()) {
|
190
|
-
case 20 /* If */:
|
194
|
+
case 20 /* KeywordType.If */:
|
191
195
|
return this._parseIfStatement();
|
192
|
-
case 36 /* While */:
|
196
|
+
case 36 /* KeywordType.While */:
|
193
197
|
return this._parseWhileStatement();
|
194
|
-
case 17 /* For */:
|
198
|
+
case 17 /* KeywordType.For */:
|
195
199
|
return this._parseForStatement();
|
196
|
-
case 34 /* Try */:
|
200
|
+
case 34 /* KeywordType.Try */:
|
197
201
|
return this._parseTryStatement();
|
198
|
-
case 37 /* With */:
|
202
|
+
case 37 /* KeywordType.With */:
|
199
203
|
return this._parseWithStatement();
|
200
|
-
case 10 /* Def */:
|
204
|
+
case 10 /* KeywordType.Def */:
|
201
205
|
return this._parseFunctionDef();
|
202
|
-
case 7 /* Class */:
|
206
|
+
case 7 /* KeywordType.Class */:
|
203
207
|
return this._parseClassDef();
|
204
|
-
case 3 /* Async */:
|
208
|
+
case 3 /* KeywordType.Async */:
|
205
209
|
return this._parseAsyncStatement();
|
206
|
-
case 25 /* Match */: {
|
210
|
+
case 25 /* KeywordType.Match */: {
|
207
211
|
// Match is considered a "soft" keyword, so we will treat
|
208
212
|
// it as an identifier if it is followed by an unexpected
|
209
213
|
// token.
|
210
214
|
const peekToken = this._peekToken(1);
|
211
215
|
let isInvalidMatchToken = false;
|
212
|
-
if (peekToken.type === 10 /* Colon */ ||
|
213
|
-
peekToken.type === 11 /* Semicolon */ ||
|
214
|
-
peekToken.type === 12 /* Comma */ ||
|
215
|
-
peekToken.type === 20 /* Dot */ ||
|
216
|
-
peekToken.type === 2 /* NewLine */ ||
|
217
|
-
peekToken.type === 1 /* EndOfStream */) {
|
216
|
+
if (peekToken.type === 10 /* TokenType.Colon */ ||
|
217
|
+
peekToken.type === 11 /* TokenType.Semicolon */ ||
|
218
|
+
peekToken.type === 12 /* TokenType.Comma */ ||
|
219
|
+
peekToken.type === 20 /* TokenType.Dot */ ||
|
220
|
+
peekToken.type === 2 /* TokenType.NewLine */ ||
|
221
|
+
peekToken.type === 1 /* TokenType.EndOfStream */) {
|
218
222
|
isInvalidMatchToken = true;
|
219
223
|
}
|
220
|
-
else if (peekToken.type === 9 /* Operator */) {
|
224
|
+
else if (peekToken.type === 9 /* TokenType.Operator */) {
|
221
225
|
const operatorToken = peekToken;
|
222
|
-
if (operatorToken.operatorType !== 26 /* Multiply */ &&
|
223
|
-
operatorToken.operatorType !== 0 /* Add */ &&
|
224
|
-
operatorToken.operatorType !== 5 /* BitwiseInvert */ &&
|
225
|
-
operatorToken.operatorType !== 33 /* Subtract */) {
|
226
|
+
if (operatorToken.operatorType !== 26 /* OperatorType.Multiply */ &&
|
227
|
+
operatorToken.operatorType !== 0 /* OperatorType.Add */ &&
|
228
|
+
operatorToken.operatorType !== 5 /* OperatorType.BitwiseInvert */ &&
|
229
|
+
operatorToken.operatorType !== 33 /* OperatorType.Subtract */) {
|
226
230
|
isInvalidMatchToken = true;
|
227
231
|
}
|
228
232
|
}
|
@@ -237,20 +241,20 @@ class Parser {
|
|
237
241
|
break;
|
238
242
|
}
|
239
243
|
}
|
240
|
-
if (this._peekOperatorType() === 22 /* MatrixMultiply */) {
|
244
|
+
if (this._peekOperatorType() === 22 /* OperatorType.MatrixMultiply */) {
|
241
245
|
return this._parseDecorated();
|
242
246
|
}
|
243
247
|
return this._parseSimpleStatement();
|
244
248
|
}
|
245
249
|
// async_stmt: 'async' (funcdef | with_stmt | for_stmt)
|
246
250
|
_parseAsyncStatement() {
|
247
|
-
const asyncToken = this._getKeywordToken(3 /* Async */);
|
251
|
+
const asyncToken = this._getKeywordToken(3 /* KeywordType.Async */);
|
248
252
|
switch (this._peekKeywordType()) {
|
249
|
-
case 10 /* Def */:
|
253
|
+
case 10 /* KeywordType.Def */:
|
250
254
|
return this._parseFunctionDef(asyncToken);
|
251
|
-
case 37 /* With */:
|
255
|
+
case 37 /* KeywordType.With */:
|
252
256
|
return this._parseWithStatement(asyncToken);
|
253
|
-
case 17 /* For */:
|
257
|
+
case 17 /* KeywordType.For */:
|
254
258
|
return this._parseForStatement(asyncToken);
|
255
259
|
}
|
256
260
|
this._addError(localize_1.Localizer.Diagnostic.unexpectedAsyncToken(), asyncToken);
|
@@ -258,7 +262,7 @@ class Parser {
|
|
258
262
|
}
|
259
263
|
// type_alias_stmt: "type" name [type_param_seq] = expr
|
260
264
|
_parseTypeAliasStatement() {
|
261
|
-
const typeToken = this._getKeywordToken(35 /* Type */);
|
265
|
+
const typeToken = this._getKeywordToken(35 /* KeywordType.Type */);
|
262
266
|
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
263
267
|
this._addError(localize_1.Localizer.Diagnostic.typeAliasStatementIllegal(), typeToken);
|
264
268
|
}
|
@@ -266,12 +270,12 @@ class Parser {
|
|
266
270
|
(0, debug_1.assert)(nameToken !== undefined);
|
267
271
|
const name = parseNodes_1.NameNode.create(nameToken);
|
268
272
|
let typeParameters;
|
269
|
-
if (this._peekToken().type === 15 /* OpenBracket */) {
|
273
|
+
if (this._peekToken().type === 15 /* TokenType.OpenBracket */) {
|
270
274
|
typeParameters = this._parseTypeParameterList();
|
271
275
|
}
|
272
276
|
const assignToken = this._peekToken();
|
273
|
-
if (assignToken.type !== 9 /* Operator */ ||
|
274
|
-
assignToken.operatorType !== 2 /* Assign */) {
|
277
|
+
if (assignToken.type !== 9 /* TokenType.Operator */ ||
|
278
|
+
assignToken.operatorType !== 2 /* OperatorType.Assign */) {
|
275
279
|
this._addError(localize_1.Localizer.Diagnostic.expectedEquals(), assignToken);
|
276
280
|
}
|
277
281
|
else {
|
@@ -284,10 +288,10 @@ class Parser {
|
|
284
288
|
_parseTypeParameterList() {
|
285
289
|
const typeVariableNodes = [];
|
286
290
|
const openBracketToken = this._getNextToken();
|
287
|
-
(0, debug_1.assert)(openBracketToken.type === 15 /* OpenBracket */);
|
291
|
+
(0, debug_1.assert)(openBracketToken.type === 15 /* TokenType.OpenBracket */);
|
288
292
|
while (true) {
|
289
293
|
const firstToken = this._peekToken();
|
290
|
-
if (firstToken.type === 16 /* CloseBracket */) {
|
294
|
+
if (firstToken.type === 16 /* TokenType.CloseBracket */) {
|
291
295
|
if (typeVariableNodes.length === 0) {
|
292
296
|
this._addError(localize_1.Localizer.Diagnostic.typeParametersMissing(), this._peekToken());
|
293
297
|
}
|
@@ -298,14 +302,14 @@ class Parser {
|
|
298
302
|
break;
|
299
303
|
}
|
300
304
|
typeVariableNodes.push(typeVarNode);
|
301
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
305
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
302
306
|
break;
|
303
307
|
}
|
304
308
|
}
|
305
309
|
const closingToken = this._peekToken();
|
306
|
-
if (closingToken.type !== 16 /* CloseBracket */) {
|
310
|
+
if (closingToken.type !== 16 /* TokenType.CloseBracket */) {
|
307
311
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBracket(), this._peekToken());
|
308
|
-
this._consumeTokensUntilType([2 /* NewLine */, 16 /* CloseBracket */, 10 /* Colon */]);
|
312
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */, 16 /* TokenType.CloseBracket */, 10 /* TokenType.Colon */]);
|
309
313
|
}
|
310
314
|
else {
|
311
315
|
this._getNextToken();
|
@@ -315,10 +319,10 @@ class Parser {
|
|
315
319
|
// type_param: ['*' | '**'] NAME [':' bound_expr] ['=' default_expr]
|
316
320
|
_parseTypeParameter() {
|
317
321
|
let typeParamCategory = parseNodes_1.TypeParameterCategory.TypeVar;
|
318
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
322
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
319
323
|
typeParamCategory = parseNodes_1.TypeParameterCategory.TypeVarTuple;
|
320
324
|
}
|
321
|
-
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
325
|
+
else if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
322
326
|
typeParamCategory = parseNodes_1.TypeParameterCategory.ParamSpec;
|
323
327
|
}
|
324
328
|
const nameToken = this._getTokenIfIdentifier();
|
@@ -328,14 +332,14 @@ class Parser {
|
|
328
332
|
}
|
329
333
|
const name = parseNodes_1.NameNode.create(nameToken);
|
330
334
|
let boundExpression;
|
331
|
-
if (this._consumeTokenIfType(10 /* Colon */)) {
|
335
|
+
if (this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
332
336
|
boundExpression = this._parseExpression(/* allowUnpack */ false);
|
333
337
|
if (typeParamCategory !== parseNodes_1.TypeParameterCategory.TypeVar) {
|
334
338
|
this._addError(localize_1.Localizer.Diagnostic.typeParameterBoundNotAllowed(), boundExpression);
|
335
339
|
}
|
336
340
|
}
|
337
341
|
let defaultExpression;
|
338
|
-
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
342
|
+
if (this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
339
343
|
defaultExpression = this._parseExpression(
|
340
344
|
/* allowUnpack */ typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple);
|
341
345
|
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_13) {
|
@@ -357,40 +361,40 @@ class Parser {
|
|
357
361
|
let smellsLikeMatchStatement = false;
|
358
362
|
this._suppressErrors(() => {
|
359
363
|
const curTokenIndex = this._tokenIndex;
|
360
|
-
this._getKeywordToken(25 /* Match */);
|
364
|
+
this._getKeywordToken(25 /* KeywordType.Match */);
|
361
365
|
const expression = this._parseTestOrStarListAsExpression(
|
362
366
|
/* allowAssignmentExpression */ true,
|
363
|
-
/* allowMultipleUnpack */ true, 12 /* MissingPatternSubject */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
367
|
+
/* allowMultipleUnpack */ true, 12 /* ErrorExpressionCategory.MissingPatternSubject */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
364
368
|
smellsLikeMatchStatement =
|
365
|
-
expression.nodeType !== 0 /* Error */ && this._peekToken().type === 10 /* Colon */;
|
369
|
+
expression.nodeType !== 0 /* ParseNodeType.Error */ && this._peekToken().type === 10 /* TokenType.Colon */;
|
366
370
|
// Set the token index back to the start.
|
367
371
|
this._tokenIndex = curTokenIndex;
|
368
372
|
});
|
369
373
|
if (!smellsLikeMatchStatement) {
|
370
374
|
return undefined;
|
371
375
|
}
|
372
|
-
const matchToken = this._getKeywordToken(25 /* Match */);
|
376
|
+
const matchToken = this._getKeywordToken(25 /* KeywordType.Match */);
|
373
377
|
const subjectExpression = this._parseTestOrStarListAsExpression(
|
374
378
|
/* allowAssignmentExpression */ true,
|
375
|
-
/* allowMultipleUnpack */ true, 12 /* MissingPatternSubject */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
379
|
+
/* allowMultipleUnpack */ true, 12 /* ErrorExpressionCategory.MissingPatternSubject */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
376
380
|
const matchNode = parseNodes_1.MatchNode.create(matchToken, subjectExpression);
|
377
381
|
const nextToken = this._peekToken();
|
378
|
-
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
382
|
+
if (!this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
379
383
|
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), nextToken);
|
380
384
|
// Try to perform parse recovery by consuming tokens until
|
381
385
|
// we find the end of the line.
|
382
|
-
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
386
|
+
if (this._consumeTokensUntilType([2 /* TokenType.NewLine */, 10 /* TokenType.Colon */])) {
|
383
387
|
this._getNextToken();
|
384
388
|
}
|
385
389
|
}
|
386
390
|
else {
|
387
391
|
(0, parseNodes_1.extendRange)(matchNode, nextToken);
|
388
|
-
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
392
|
+
if (!this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
389
393
|
this._addError(localize_1.Localizer.Diagnostic.expectedNewline(), nextToken);
|
390
394
|
}
|
391
395
|
else {
|
392
396
|
const possibleIndent = this._peekToken();
|
393
|
-
if (!this._consumeTokenIfType(3 /* Indent */)) {
|
397
|
+
if (!this._consumeTokenIfType(3 /* TokenType.Indent */)) {
|
394
398
|
this._addError(localize_1.Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
|
395
399
|
}
|
396
400
|
else {
|
@@ -402,7 +406,7 @@ class Parser {
|
|
402
406
|
while (true) {
|
403
407
|
// Handle a common error here and see if we can recover.
|
404
408
|
const possibleUnexpectedIndent = this._peekToken();
|
405
|
-
if (possibleUnexpectedIndent.type === 3 /* Indent */) {
|
409
|
+
if (possibleUnexpectedIndent.type === 3 /* TokenType.Indent */) {
|
406
410
|
this._getNextToken();
|
407
411
|
const indentToken = possibleUnexpectedIndent;
|
408
412
|
if (indentToken.isIndentAmbiguous) {
|
@@ -415,7 +419,7 @@ class Parser {
|
|
415
419
|
const caseStatement = this._parseCaseStatement();
|
416
420
|
if (!caseStatement) {
|
417
421
|
// Perform basic error recovery to get to the next line.
|
418
|
-
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
422
|
+
if (this._consumeTokensUntilType([2 /* TokenType.NewLine */, 10 /* TokenType.Colon */])) {
|
419
423
|
this._getNextToken();
|
420
424
|
}
|
421
425
|
}
|
@@ -424,7 +428,7 @@ class Parser {
|
|
424
428
|
matchNode.cases.push(caseStatement);
|
425
429
|
}
|
426
430
|
const dedentToken = this._peekToken();
|
427
|
-
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
431
|
+
if (this._consumeTokenIfType(4 /* TokenType.Dedent */)) {
|
428
432
|
if (!dedentToken.matchesIndent) {
|
429
433
|
this._addError(localize_1.Localizer.Diagnostic.inconsistentIndent(), dedentToken);
|
430
434
|
}
|
@@ -433,7 +437,7 @@ class Parser {
|
|
433
437
|
}
|
434
438
|
break;
|
435
439
|
}
|
436
|
-
if (this._peekTokenType() === 1 /* EndOfStream */) {
|
440
|
+
if (this._peekTokenType() === 1 /* TokenType.EndOfStream */) {
|
437
441
|
break;
|
438
442
|
}
|
439
443
|
}
|
@@ -463,7 +467,7 @@ class Parser {
|
|
463
467
|
// guard: 'if' named_expression
|
464
468
|
_parseCaseStatement() {
|
465
469
|
const caseToken = this._peekToken();
|
466
|
-
if (!this._consumeTokenIfKeyword(6 /* Case */)) {
|
470
|
+
if (!this._consumeTokenIfKeyword(6 /* KeywordType.Case */)) {
|
467
471
|
this._addError(localize_1.Localizer.Diagnostic.expectedCase(), caseToken);
|
468
472
|
return undefined;
|
469
473
|
}
|
@@ -474,11 +478,11 @@ class Parser {
|
|
474
478
|
}
|
475
479
|
else if (patternList.list.length === 0) {
|
476
480
|
this._addError(localize_1.Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
|
477
|
-
casePattern = parseNodes_1.ErrorNode.create(caseToken, 11 /* MissingPattern */);
|
481
|
+
casePattern = parseNodes_1.ErrorNode.create(caseToken, 11 /* ErrorExpressionCategory.MissingPattern */);
|
478
482
|
}
|
479
483
|
else if (patternList.list.length === 1 && !patternList.trailingComma) {
|
480
484
|
const pattern = patternList.list[0].orPatterns[0];
|
481
|
-
if (pattern.nodeType === 69 /* PatternCapture */ && pattern.isStar) {
|
485
|
+
if (pattern.nodeType === 69 /* ParseNodeType.PatternCapture */ && pattern.isStar) {
|
482
486
|
casePattern = parseNodes_1.PatternSequenceNode.create(patternList.list[0], patternList.list);
|
483
487
|
}
|
484
488
|
else {
|
@@ -488,13 +492,13 @@ class Parser {
|
|
488
492
|
else {
|
489
493
|
casePattern = parseNodes_1.PatternSequenceNode.create(patternList.list[0], patternList.list);
|
490
494
|
}
|
491
|
-
if (casePattern.nodeType !== 0 /* Error */) {
|
495
|
+
if (casePattern.nodeType !== 0 /* ParseNodeType.Error */) {
|
492
496
|
const globalNameMap = new Map();
|
493
497
|
const localNameMap = new Map();
|
494
498
|
this._reportDuplicatePatternCaptureTargets(casePattern, globalNameMap, localNameMap);
|
495
499
|
}
|
496
500
|
let guardExpression;
|
497
|
-
if (this._consumeTokenIfKeyword(20 /* If */)) {
|
501
|
+
if (this._consumeTokenIfKeyword(20 /* KeywordType.If */)) {
|
498
502
|
guardExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
499
503
|
}
|
500
504
|
const suite = this._parseSuite(this._isInFunction);
|
@@ -503,10 +507,10 @@ class Parser {
|
|
503
507
|
// PEP 634 defines the concept of an "irrefutable" pattern - a pattern that
|
504
508
|
// will always be matched.
|
505
509
|
_isPatternIrrefutable(node) {
|
506
|
-
if (node.nodeType === 69 /* PatternCapture */) {
|
510
|
+
if (node.nodeType === 69 /* ParseNodeType.PatternCapture */) {
|
507
511
|
return true;
|
508
512
|
}
|
509
|
-
if (node.nodeType === 66 /* PatternAs */) {
|
513
|
+
if (node.nodeType === 66 /* ParseNodeType.PatternAs */) {
|
510
514
|
return node.orPatterns.some((pattern) => this._isPatternIrrefutable(pattern));
|
511
515
|
}
|
512
516
|
return false;
|
@@ -527,19 +531,19 @@ class Parser {
|
|
527
531
|
}
|
528
532
|
};
|
529
533
|
switch (node.nodeType) {
|
530
|
-
case 65 /* PatternSequence */: {
|
534
|
+
case 65 /* ParseNodeType.PatternSequence */: {
|
531
535
|
node.entries.forEach((subpattern) => {
|
532
536
|
this._reportDuplicatePatternCaptureTargets(subpattern, globalNameMap, localNameMap);
|
533
537
|
});
|
534
538
|
break;
|
535
539
|
}
|
536
|
-
case 68 /* PatternClass */: {
|
540
|
+
case 68 /* ParseNodeType.PatternClass */: {
|
537
541
|
node.arguments.forEach((arg) => {
|
538
542
|
this._reportDuplicatePatternCaptureTargets(arg.pattern, globalNameMap, localNameMap);
|
539
543
|
});
|
540
544
|
break;
|
541
545
|
}
|
542
|
-
case 66 /* PatternAs */: {
|
546
|
+
case 66 /* ParseNodeType.PatternAs */: {
|
543
547
|
if (node.target) {
|
544
548
|
reportTargetIfDuplicate(node.target);
|
545
549
|
}
|
@@ -559,15 +563,15 @@ class Parser {
|
|
559
563
|
});
|
560
564
|
break;
|
561
565
|
}
|
562
|
-
case 69 /* PatternCapture */: {
|
566
|
+
case 69 /* ParseNodeType.PatternCapture */: {
|
563
567
|
if (!node.isWildcard) {
|
564
568
|
reportTargetIfDuplicate(node.target);
|
565
569
|
}
|
566
570
|
break;
|
567
571
|
}
|
568
|
-
case 70 /* PatternMapping */: {
|
572
|
+
case 70 /* ParseNodeType.PatternMapping */: {
|
569
573
|
node.entries.forEach((mapEntry) => {
|
570
|
-
if (mapEntry.nodeType === 72 /* PatternMappingExpandEntry */) {
|
574
|
+
if (mapEntry.nodeType === 72 /* ParseNodeType.PatternMappingExpandEntry */) {
|
571
575
|
reportTargetIfDuplicate(mapEntry.target);
|
572
576
|
}
|
573
577
|
else {
|
@@ -577,28 +581,28 @@ class Parser {
|
|
577
581
|
});
|
578
582
|
break;
|
579
583
|
}
|
580
|
-
case 67 /* PatternLiteral */:
|
581
|
-
case 73 /* PatternValue */:
|
582
|
-
case 0 /* Error */: {
|
584
|
+
case 67 /* ParseNodeType.PatternLiteral */:
|
585
|
+
case 73 /* ParseNodeType.PatternValue */:
|
586
|
+
case 0 /* ParseNodeType.Error */: {
|
583
587
|
break;
|
584
588
|
}
|
585
589
|
}
|
586
590
|
}
|
587
591
|
_getPatternTargetNames(node, nameSet) {
|
588
592
|
switch (node.nodeType) {
|
589
|
-
case 65 /* PatternSequence */: {
|
593
|
+
case 65 /* ParseNodeType.PatternSequence */: {
|
590
594
|
node.entries.forEach((subpattern) => {
|
591
595
|
this._getPatternTargetNames(subpattern, nameSet);
|
592
596
|
});
|
593
597
|
break;
|
594
598
|
}
|
595
|
-
case 68 /* PatternClass */: {
|
599
|
+
case 68 /* ParseNodeType.PatternClass */: {
|
596
600
|
node.arguments.forEach((arg) => {
|
597
601
|
this._getPatternTargetNames(arg.pattern, nameSet);
|
598
602
|
});
|
599
603
|
break;
|
600
604
|
}
|
601
|
-
case 66 /* PatternAs */: {
|
605
|
+
case 66 /* ParseNodeType.PatternAs */: {
|
602
606
|
if (node.target) {
|
603
607
|
nameSet.add(node.target.value);
|
604
608
|
}
|
@@ -607,15 +611,15 @@ class Parser {
|
|
607
611
|
});
|
608
612
|
break;
|
609
613
|
}
|
610
|
-
case 69 /* PatternCapture */: {
|
614
|
+
case 69 /* ParseNodeType.PatternCapture */: {
|
611
615
|
if (!node.isWildcard) {
|
612
616
|
nameSet.add(node.target.value);
|
613
617
|
}
|
614
618
|
break;
|
615
619
|
}
|
616
|
-
case 70 /* PatternMapping */: {
|
620
|
+
case 70 /* ParseNodeType.PatternMapping */: {
|
617
621
|
node.entries.forEach((mapEntry) => {
|
618
|
-
if (mapEntry.nodeType === 72 /* PatternMappingExpandEntry */) {
|
622
|
+
if (mapEntry.nodeType === 72 /* ParseNodeType.PatternMappingExpandEntry */) {
|
619
623
|
nameSet.add(mapEntry.target.value);
|
620
624
|
}
|
621
625
|
else {
|
@@ -625,9 +629,9 @@ class Parser {
|
|
625
629
|
});
|
626
630
|
break;
|
627
631
|
}
|
628
|
-
case 67 /* PatternLiteral */:
|
629
|
-
case 73 /* PatternValue */:
|
630
|
-
case 0 /* Error */: {
|
632
|
+
case 67 /* ParseNodeType.PatternLiteral */:
|
633
|
+
case 73 /* ParseNodeType.PatternValue */:
|
634
|
+
case 0 /* ParseNodeType.Error */: {
|
631
635
|
break;
|
632
636
|
}
|
633
637
|
}
|
@@ -636,7 +640,7 @@ class Parser {
|
|
636
640
|
const patternList = this._parseExpressionListGeneric(() => this._parsePatternAs());
|
637
641
|
// Check for more than one star entry.
|
638
642
|
const starEntries = patternList.list.filter((entry) => entry.orPatterns.length === 1 &&
|
639
|
-
entry.orPatterns[0].nodeType === 69 /* PatternCapture */ &&
|
643
|
+
entry.orPatterns[0].nodeType === 69 /* ParseNodeType.PatternCapture */ &&
|
640
644
|
entry.orPatterns[0].isStar);
|
641
645
|
if (starEntries.length > 1) {
|
642
646
|
this._addError(localize_1.Localizer.Diagnostic.duplicateStarPattern(), starEntries[1].orPatterns[0]);
|
@@ -650,20 +654,20 @@ class Parser {
|
|
650
654
|
while (true) {
|
651
655
|
const patternAtom = this._parsePatternAtom();
|
652
656
|
orPatterns.push(patternAtom);
|
653
|
-
if (!this._consumeTokenIfOperator(6 /* BitwiseOr */)) {
|
657
|
+
if (!this._consumeTokenIfOperator(6 /* OperatorType.BitwiseOr */)) {
|
654
658
|
break;
|
655
659
|
}
|
656
660
|
}
|
657
661
|
if (orPatterns.length > 1) {
|
658
662
|
// Star patterns cannot be ORed with other patterns.
|
659
663
|
orPatterns.forEach((patternAtom) => {
|
660
|
-
if (patternAtom.nodeType === 69 /* PatternCapture */ && patternAtom.isStar) {
|
664
|
+
if (patternAtom.nodeType === 69 /* ParseNodeType.PatternCapture */ && patternAtom.isStar) {
|
661
665
|
this._addError(localize_1.Localizer.Diagnostic.starPatternInOrPattern(), patternAtom);
|
662
666
|
}
|
663
667
|
});
|
664
668
|
}
|
665
669
|
let target;
|
666
|
-
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
670
|
+
if (this._consumeTokenIfKeyword(1 /* KeywordType.As */)) {
|
667
671
|
const nameToken = this._getTokenIfIdentifier();
|
668
672
|
if (nameToken) {
|
669
673
|
target = parseNodes_1.NameNode.create(nameToken);
|
@@ -675,7 +679,7 @@ class Parser {
|
|
675
679
|
// Star patterns cannot be used with AS pattern.
|
676
680
|
if (target &&
|
677
681
|
orPatterns.length === 1 &&
|
678
|
-
orPatterns[0].nodeType === 69 /* PatternCapture */ &&
|
682
|
+
orPatterns[0].nodeType === 69 /* ParseNodeType.PatternCapture */ &&
|
679
683
|
orPatterns[0].isStar) {
|
680
684
|
this._addError(localize_1.Localizer.Diagnostic.starPatternInAsPattern(), orPatterns[0]);
|
681
685
|
}
|
@@ -725,20 +729,20 @@ class Parser {
|
|
725
729
|
const patternCaptureOrValue = this._parsePatternCaptureOrValue();
|
726
730
|
if (patternCaptureOrValue) {
|
727
731
|
const openParenToken = this._peekToken();
|
728
|
-
if (patternCaptureOrValue.nodeType === 0 /* Error */ ||
|
729
|
-
!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
732
|
+
if (patternCaptureOrValue.nodeType === 0 /* ParseNodeType.Error */ ||
|
733
|
+
!this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */)) {
|
730
734
|
return patternCaptureOrValue;
|
731
735
|
}
|
732
736
|
const args = this._parseClassPatternArgList();
|
733
|
-
const classNameExpr = patternCaptureOrValue.nodeType === 69 /* PatternCapture */
|
737
|
+
const classNameExpr = patternCaptureOrValue.nodeType === 69 /* ParseNodeType.PatternCapture */
|
734
738
|
? patternCaptureOrValue.target
|
735
739
|
: patternCaptureOrValue.expression;
|
736
740
|
const classPattern = parseNodes_1.PatternClassNode.create(classNameExpr, args);
|
737
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
741
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
738
742
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
739
743
|
// Consume the remainder of tokens on the line for error
|
740
744
|
// recovery.
|
741
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
745
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
742
746
|
// Extend the node's range to include the rest of the line.
|
743
747
|
// This helps the signatureHelpProvider.
|
744
748
|
(0, parseNodes_1.extendRange)(classPattern, this._peekToken());
|
@@ -747,18 +751,18 @@ class Parser {
|
|
747
751
|
}
|
748
752
|
const nextToken = this._peekToken();
|
749
753
|
const nextOperator = this._peekOperatorType();
|
750
|
-
if (nextOperator === 26 /* Multiply */) {
|
754
|
+
if (nextOperator === 26 /* OperatorType.Multiply */) {
|
751
755
|
const starToken = this._getNextToken();
|
752
756
|
const identifierToken = this._getTokenIfIdentifier();
|
753
757
|
if (!identifierToken) {
|
754
758
|
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
755
|
-
return parseNodes_1.ErrorNode.create(starToken, 2 /* MissingExpression */);
|
759
|
+
return parseNodes_1.ErrorNode.create(starToken, 2 /* ErrorExpressionCategory.MissingExpression */);
|
756
760
|
}
|
757
761
|
else {
|
758
762
|
return parseNodes_1.PatternCaptureNode.create(parseNodes_1.NameNode.create(identifierToken), starToken);
|
759
763
|
}
|
760
764
|
}
|
761
|
-
if (nextToken.type === 13 /* OpenParenthesis */ || nextToken.type === 15 /* OpenBracket */) {
|
765
|
+
if (nextToken.type === 13 /* TokenType.OpenParenthesis */ || nextToken.type === 15 /* TokenType.OpenBracket */) {
|
762
766
|
const startToken = this._getNextToken();
|
763
767
|
const patternList = this._parsePatternSequence();
|
764
768
|
let casePattern;
|
@@ -767,9 +771,9 @@ class Parser {
|
|
767
771
|
}
|
768
772
|
else if (patternList.list.length === 1 &&
|
769
773
|
!patternList.trailingComma &&
|
770
|
-
startToken.type === 13 /* OpenParenthesis */) {
|
774
|
+
startToken.type === 13 /* TokenType.OpenParenthesis */) {
|
771
775
|
const pattern = patternList.list[0].orPatterns[0];
|
772
|
-
if (pattern.nodeType === 69 /* PatternCapture */ && pattern.isStar) {
|
776
|
+
if (pattern.nodeType === 69 /* ParseNodeType.PatternCapture */ && pattern.isStar) {
|
773
777
|
casePattern = parseNodes_1.PatternSequenceNode.create(startToken, patternList.list);
|
774
778
|
}
|
775
779
|
else {
|
@@ -781,34 +785,34 @@ class Parser {
|
|
781
785
|
casePattern = parseNodes_1.PatternSequenceNode.create(startToken, patternList.list);
|
782
786
|
}
|
783
787
|
const endToken = this._peekToken();
|
784
|
-
if (this._consumeTokenIfType(nextToken.type === 13 /* OpenParenthesis */ ? 14 /* CloseParenthesis */ : 16 /* CloseBracket */)) {
|
788
|
+
if (this._consumeTokenIfType(nextToken.type === 13 /* TokenType.OpenParenthesis */ ? 14 /* TokenType.CloseParenthesis */ : 16 /* TokenType.CloseBracket */)) {
|
785
789
|
(0, parseNodes_1.extendRange)(casePattern, endToken);
|
786
790
|
}
|
787
791
|
else {
|
788
|
-
this._addError(nextToken.type === 13 /* OpenParenthesis */
|
792
|
+
this._addError(nextToken.type === 13 /* TokenType.OpenParenthesis */
|
789
793
|
? localize_1.Localizer.Diagnostic.expectedCloseParen()
|
790
794
|
: localize_1.Localizer.Diagnostic.expectedCloseBracket(), nextToken);
|
791
795
|
this._consumeTokensUntilType([
|
792
|
-
10 /* Colon */,
|
793
|
-
nextToken.type === 13 /* OpenParenthesis */ ? 14 /* CloseParenthesis */ : 16 /* CloseBracket */,
|
796
|
+
10 /* TokenType.Colon */,
|
797
|
+
nextToken.type === 13 /* TokenType.OpenParenthesis */ ? 14 /* TokenType.CloseParenthesis */ : 16 /* TokenType.CloseBracket */,
|
794
798
|
]);
|
795
799
|
}
|
796
800
|
return casePattern;
|
797
801
|
}
|
798
|
-
else if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
802
|
+
else if (nextToken.type === 17 /* TokenType.OpenCurlyBrace */) {
|
799
803
|
const firstToken = this._getNextToken();
|
800
804
|
const mappingPattern = this._parsePatternMapping(firstToken);
|
801
805
|
const lastToken = this._peekToken();
|
802
|
-
if (this._consumeTokenIfType(18 /* CloseCurlyBrace */)) {
|
806
|
+
if (this._consumeTokenIfType(18 /* TokenType.CloseCurlyBrace */)) {
|
803
807
|
(0, parseNodes_1.extendRange)(mappingPattern, lastToken);
|
804
808
|
}
|
805
809
|
else {
|
806
810
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBrace(), nextToken);
|
807
|
-
this._consumeTokensUntilType([10 /* Colon */, 18 /* CloseCurlyBrace */]);
|
811
|
+
this._consumeTokensUntilType([10 /* TokenType.Colon */, 18 /* TokenType.CloseCurlyBrace */]);
|
808
812
|
}
|
809
813
|
return mappingPattern;
|
810
814
|
}
|
811
|
-
return this._handleExpressionParseError(11 /* MissingPattern */, localize_1.Localizer.Diagnostic.expectedPatternExpr());
|
815
|
+
return this._handleExpressionParseError(11 /* ErrorExpressionCategory.MissingPattern */, localize_1.Localizer.Diagnostic.expectedPatternExpr());
|
812
816
|
}
|
813
817
|
// pattern_arguments:
|
814
818
|
// | positional_patterns [',' keyword_patterns]
|
@@ -820,9 +824,9 @@ class Parser {
|
|
820
824
|
let sawKeywordArg = false;
|
821
825
|
while (true) {
|
822
826
|
const nextTokenType = this._peekTokenType();
|
823
|
-
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
824
|
-
nextTokenType === 2 /* NewLine */ ||
|
825
|
-
nextTokenType === 1 /* EndOfStream */) {
|
827
|
+
if (nextTokenType === 14 /* TokenType.CloseParenthesis */ ||
|
828
|
+
nextTokenType === 2 /* TokenType.NewLine */ ||
|
829
|
+
nextTokenType === 1 /* TokenType.EndOfStream */) {
|
826
830
|
break;
|
827
831
|
}
|
828
832
|
const arg = this._parseClassPatternArgument();
|
@@ -833,7 +837,7 @@ class Parser {
|
|
833
837
|
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
|
834
838
|
}
|
835
839
|
argList.push(arg);
|
836
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
840
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
837
841
|
break;
|
838
842
|
}
|
839
843
|
}
|
@@ -844,9 +848,9 @@ class Parser {
|
|
844
848
|
const firstToken = this._peekToken();
|
845
849
|
const secondToken = this._peekToken(1);
|
846
850
|
let keywordName;
|
847
|
-
if ((firstToken.type === 7 /* Identifier */ || firstToken.type === 8 /* Keyword */) &&
|
848
|
-
secondToken.type === 9 /* Operator */ &&
|
849
|
-
secondToken.operatorType === 2 /* Assign */) {
|
851
|
+
if ((firstToken.type === 7 /* TokenType.Identifier */ || firstToken.type === 8 /* TokenType.Keyword */) &&
|
852
|
+
secondToken.type === 9 /* TokenType.Operator */ &&
|
853
|
+
secondToken.operatorType === 2 /* OperatorType.Assign */) {
|
850
854
|
const classNameToken = this._getTokenIfIdentifier();
|
851
855
|
if (classNameToken !== undefined) {
|
852
856
|
keywordName = parseNodes_1.NameNode.create(classNameToken);
|
@@ -867,25 +871,25 @@ class Parser {
|
|
867
871
|
_parsePatternLiteral() {
|
868
872
|
const nextToken = this._peekToken();
|
869
873
|
const nextOperator = this._peekOperatorType();
|
870
|
-
if (nextToken.type === 6 /* Number */ || nextOperator === 33 /* Subtract */) {
|
874
|
+
if (nextToken.type === 6 /* TokenType.Number */ || nextOperator === 33 /* OperatorType.Subtract */) {
|
871
875
|
return this._parsePatternLiteralNumber();
|
872
876
|
}
|
873
|
-
if (nextToken.type === 5 /* String */) {
|
877
|
+
if (nextToken.type === 5 /* TokenType.String */) {
|
874
878
|
const stringList = this._parseAtom();
|
875
|
-
(0, debug_1.assert)(stringList.nodeType === 48 /* StringList */);
|
879
|
+
(0, debug_1.assert)(stringList.nodeType === 48 /* ParseNodeType.StringList */);
|
876
880
|
// Check for f-strings, which are not allowed.
|
877
881
|
stringList.strings.forEach((stringAtom) => {
|
878
|
-
if (stringAtom.nodeType === 27 /* FormatString */) {
|
882
|
+
if (stringAtom.nodeType === 27 /* ParseNodeType.FormatString */) {
|
879
883
|
this._addError(localize_1.Localizer.Diagnostic.formatStringInPattern(), stringAtom);
|
880
884
|
}
|
881
885
|
});
|
882
886
|
return parseNodes_1.PatternLiteralNode.create(stringList);
|
883
887
|
}
|
884
|
-
if (nextToken.type === 8 /* Keyword */) {
|
888
|
+
if (nextToken.type === 8 /* TokenType.Keyword */) {
|
885
889
|
const keywordToken = nextToken;
|
886
|
-
if (keywordToken.keywordType === 15 /* False */ ||
|
887
|
-
keywordToken.keywordType === 33 /* True */ ||
|
888
|
-
keywordToken.keywordType === 26 /* None */) {
|
890
|
+
if (keywordToken.keywordType === 15 /* KeywordType.False */ ||
|
891
|
+
keywordToken.keywordType === 33 /* KeywordType.True */ ||
|
892
|
+
keywordToken.keywordType === 26 /* KeywordType.None */) {
|
889
893
|
return parseNodes_1.PatternLiteralNode.create(this._parseAtom());
|
890
894
|
}
|
891
895
|
}
|
@@ -896,8 +900,8 @@ class Parser {
|
|
896
900
|
const expression = this._parseArithmeticExpression();
|
897
901
|
let realValue;
|
898
902
|
let imagValue;
|
899
|
-
if (expression.nodeType === 7 /* BinaryOperation */) {
|
900
|
-
if (expression.operator === 33 /* Subtract */ || expression.operator === 0 /* Add */) {
|
903
|
+
if (expression.nodeType === 7 /* ParseNodeType.BinaryOperation */) {
|
904
|
+
if (expression.operator === 33 /* OperatorType.Subtract */ || expression.operator === 0 /* OperatorType.Add */) {
|
901
905
|
realValue = expression.leftExpression;
|
902
906
|
imagValue = expression.rightExpression;
|
903
907
|
}
|
@@ -906,19 +910,19 @@ class Parser {
|
|
906
910
|
realValue = expression;
|
907
911
|
}
|
908
912
|
if (realValue) {
|
909
|
-
if (realValue.nodeType === 55 /* UnaryOperation */ && realValue.operator === 33 /* Subtract */) {
|
913
|
+
if (realValue.nodeType === 55 /* ParseNodeType.UnaryOperation */ && realValue.operator === 33 /* OperatorType.Subtract */) {
|
910
914
|
realValue = realValue.expression;
|
911
915
|
}
|
912
|
-
if (realValue.nodeType !== 40 /* Number */ || (imagValue !== undefined && realValue.isImaginary)) {
|
916
|
+
if (realValue.nodeType !== 40 /* ParseNodeType.Number */ || (imagValue !== undefined && realValue.isImaginary)) {
|
913
917
|
this._addError(localize_1.Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
|
914
918
|
imagValue = undefined;
|
915
919
|
}
|
916
920
|
}
|
917
921
|
if (imagValue) {
|
918
|
-
if (imagValue.nodeType === 55 /* UnaryOperation */ && imagValue.operator === 33 /* Subtract */) {
|
922
|
+
if (imagValue.nodeType === 55 /* ParseNodeType.UnaryOperation */ && imagValue.operator === 33 /* OperatorType.Subtract */) {
|
919
923
|
imagValue = imagValue.expression;
|
920
924
|
}
|
921
|
-
if (imagValue.nodeType !== 40 /* Number */ || !imagValue.isImaginary) {
|
925
|
+
if (imagValue.nodeType !== 40 /* ParseNodeType.Number */ || !imagValue.isImaginary) {
|
922
926
|
this._addError(localize_1.Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
|
923
927
|
}
|
924
928
|
}
|
@@ -928,13 +932,13 @@ class Parser {
|
|
928
932
|
const itemList = this._parseExpressionListGeneric(() => this._parsePatternMappingItem());
|
929
933
|
if (itemList.list.length > 0) {
|
930
934
|
// Verify there's at most one ** entry.
|
931
|
-
const starStarEntries = itemList.list.filter((entry) => entry.nodeType === 72 /* PatternMappingExpandEntry */);
|
935
|
+
const starStarEntries = itemList.list.filter((entry) => entry.nodeType === 72 /* ParseNodeType.PatternMappingExpandEntry */);
|
932
936
|
if (starStarEntries.length > 1) {
|
933
937
|
this._addError(localize_1.Localizer.Diagnostic.duplicateStarStarPattern(), starStarEntries[1]);
|
934
938
|
}
|
935
939
|
return parseNodes_1.PatternMappingNode.create(firstToken, itemList.list);
|
936
940
|
}
|
937
|
-
return itemList.parseError || parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
941
|
+
return itemList.parseError || parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
938
942
|
}
|
939
943
|
// key_value_pattern:
|
940
944
|
// | (literal_pattern | attr) ':' as_pattern
|
@@ -942,11 +946,11 @@ class Parser {
|
|
942
946
|
_parsePatternMappingItem() {
|
943
947
|
let keyExpression;
|
944
948
|
const doubleStar = this._peekToken();
|
945
|
-
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
949
|
+
if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
946
950
|
const identifierToken = this._getTokenIfIdentifier();
|
947
951
|
if (!identifierToken) {
|
948
952
|
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
949
|
-
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
953
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
950
954
|
}
|
951
955
|
const nameNode = parseNodes_1.NameNode.create(identifierToken);
|
952
956
|
if (identifierToken.value === '_') {
|
@@ -961,23 +965,23 @@ class Parser {
|
|
961
965
|
else {
|
962
966
|
const patternCaptureOrValue = this._parsePatternCaptureOrValue();
|
963
967
|
if (patternCaptureOrValue) {
|
964
|
-
if (patternCaptureOrValue.nodeType === 73 /* PatternValue */) {
|
968
|
+
if (patternCaptureOrValue.nodeType === 73 /* ParseNodeType.PatternValue */) {
|
965
969
|
keyExpression = patternCaptureOrValue;
|
966
970
|
}
|
967
971
|
else {
|
968
972
|
this._addError(localize_1.Localizer.Diagnostic.expectedPatternValue(), patternCaptureOrValue);
|
969
|
-
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
973
|
+
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
970
974
|
}
|
971
975
|
}
|
972
976
|
}
|
973
977
|
if (!keyExpression) {
|
974
978
|
this._addError(localize_1.Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
|
975
|
-
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
979
|
+
keyExpression = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
976
980
|
}
|
977
981
|
let valuePattern;
|
978
|
-
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
982
|
+
if (!this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
979
983
|
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), this._peekToken());
|
980
|
-
valuePattern = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
984
|
+
valuePattern = parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
981
985
|
}
|
982
986
|
else {
|
983
987
|
valuePattern = this._parsePatternAs();
|
@@ -986,7 +990,7 @@ class Parser {
|
|
986
990
|
}
|
987
991
|
_parsePatternCaptureOrValue() {
|
988
992
|
const nextToken = this._peekToken();
|
989
|
-
if (nextToken.type === 7 /* Identifier */ || nextToken.type === 8 /* Keyword */) {
|
993
|
+
if (nextToken.type === 7 /* TokenType.Identifier */ || nextToken.type === 8 /* TokenType.Keyword */) {
|
990
994
|
let nameOrMember;
|
991
995
|
while (true) {
|
992
996
|
const identifierToken = this._getTokenIfIdentifier();
|
@@ -998,15 +1002,15 @@ class Parser {
|
|
998
1002
|
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
999
1003
|
break;
|
1000
1004
|
}
|
1001
|
-
if (!this._consumeTokenIfType(20 /* Dot */)) {
|
1005
|
+
if (!this._consumeTokenIfType(20 /* TokenType.Dot */)) {
|
1002
1006
|
break;
|
1003
1007
|
}
|
1004
1008
|
}
|
1005
1009
|
if (!nameOrMember) {
|
1006
1010
|
this._addError(localize_1.Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
|
1007
|
-
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* MissingPattern */);
|
1011
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 11 /* ErrorExpressionCategory.MissingPattern */);
|
1008
1012
|
}
|
1009
|
-
if (nameOrMember.nodeType === 35 /* MemberAccess */) {
|
1013
|
+
if (nameOrMember.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
1010
1014
|
return parseNodes_1.PatternValueNode.create(nameOrMember);
|
1011
1015
|
}
|
1012
1016
|
return parseNodes_1.PatternCaptureNode.create(nameOrMember);
|
@@ -1016,19 +1020,19 @@ class Parser {
|
|
1016
1020
|
// if_stmt: 'if' test_suite ('elif' test_suite)* ['else' suite]
|
1017
1021
|
// test_suite: test suite
|
1018
1022
|
// test: or_test ['if' or_test 'else' test] | lambdef
|
1019
|
-
_parseIfStatement(keywordType = 20 /* If */) {
|
1023
|
+
_parseIfStatement(keywordType = 20 /* KeywordType.If */) {
|
1020
1024
|
const ifOrElifToken = this._getKeywordToken(keywordType);
|
1021
1025
|
const test = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1022
1026
|
const suite = this._parseSuite(this._isInFunction);
|
1023
1027
|
const ifNode = parseNodes_1.IfNode.create(ifOrElifToken, test, suite);
|
1024
|
-
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1028
|
+
if (this._consumeTokenIfKeyword(13 /* KeywordType.Else */)) {
|
1025
1029
|
ifNode.elseSuite = this._parseSuite(this._isInFunction);
|
1026
1030
|
ifNode.elseSuite.parent = ifNode;
|
1027
1031
|
(0, parseNodes_1.extendRange)(ifNode, ifNode.elseSuite);
|
1028
1032
|
}
|
1029
|
-
else if (this._peekKeywordType() === 12 /* Elif */) {
|
1033
|
+
else if (this._peekKeywordType() === 12 /* KeywordType.Elif */) {
|
1030
1034
|
// Recursively handle an "elif" statement.
|
1031
|
-
ifNode.elseSuite = this._parseIfStatement(12 /* Elif */);
|
1035
|
+
ifNode.elseSuite = this._parseIfStatement(12 /* KeywordType.Elif */);
|
1032
1036
|
ifNode.elseSuite.parent = ifNode;
|
1033
1037
|
(0, parseNodes_1.extendRange)(ifNode, ifNode.elseSuite);
|
1034
1038
|
}
|
@@ -1057,14 +1061,14 @@ class Parser {
|
|
1057
1061
|
_parseSuite(isFunction = false, skipBody = false, postColonCallback) {
|
1058
1062
|
const nextToken = this._peekToken();
|
1059
1063
|
const suite = parseNodes_1.SuiteNode.create(nextToken);
|
1060
|
-
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
1064
|
+
if (!this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
1061
1065
|
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), nextToken);
|
1062
1066
|
// Try to perform parse recovery by consuming tokens.
|
1063
|
-
if (this._consumeTokensUntilType([2 /* NewLine */, 10 /* Colon */])) {
|
1064
|
-
if (this._peekTokenType() === 10 /* Colon */) {
|
1067
|
+
if (this._consumeTokensUntilType([2 /* TokenType.NewLine */, 10 /* TokenType.Colon */])) {
|
1068
|
+
if (this._peekTokenType() === 10 /* TokenType.Colon */) {
|
1065
1069
|
this._getNextToken();
|
1066
1070
|
}
|
1067
|
-
else if (this._peekToken(1).type !== 3 /* Indent */) {
|
1071
|
+
else if (this._peekToken(1).type !== 3 /* TokenType.Indent */) {
|
1068
1072
|
// Bail so we resume the at the next statement.
|
1069
1073
|
// We can't parse as a simple statement as we've skipped all but the newline.
|
1070
1074
|
this._getNextToken();
|
@@ -1073,14 +1077,14 @@ class Parser {
|
|
1073
1077
|
}
|
1074
1078
|
}
|
1075
1079
|
if (skipBody) {
|
1076
|
-
if (this._consumeTokenIfType(2 /* NewLine */)) {
|
1080
|
+
if (this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
1077
1081
|
let indent = 0;
|
1078
1082
|
while (true) {
|
1079
1083
|
const nextToken = this._getNextToken();
|
1080
|
-
if (nextToken.type === 3 /* Indent */) {
|
1084
|
+
if (nextToken.type === 3 /* TokenType.Indent */) {
|
1081
1085
|
indent++;
|
1082
1086
|
}
|
1083
|
-
if (nextToken.type === 4 /* Dedent */) {
|
1087
|
+
if (nextToken.type === 4 /* TokenType.Dedent */) {
|
1084
1088
|
if (nextToken.isDedentAmbiguous) {
|
1085
1089
|
this._addError(localize_1.Localizer.Diagnostic.inconsistentTabs(), nextToken);
|
1086
1090
|
}
|
@@ -1089,7 +1093,7 @@ class Parser {
|
|
1089
1093
|
break;
|
1090
1094
|
}
|
1091
1095
|
}
|
1092
|
-
if (nextToken.type === 1 /* EndOfStream */) {
|
1096
|
+
if (nextToken.type === 1 /* TokenType.EndOfStream */) {
|
1093
1097
|
break;
|
1094
1098
|
}
|
1095
1099
|
}
|
@@ -1108,12 +1112,12 @@ class Parser {
|
|
1108
1112
|
}
|
1109
1113
|
const wasFunction = this._isInFunction;
|
1110
1114
|
this._isInFunction = isFunction;
|
1111
|
-
if (this._consumeTokenIfType(2 /* NewLine */)) {
|
1115
|
+
if (this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
1112
1116
|
if (postColonCallback) {
|
1113
1117
|
postColonCallback();
|
1114
1118
|
}
|
1115
1119
|
const possibleIndent = this._peekToken();
|
1116
|
-
if (!this._consumeTokenIfType(3 /* Indent */)) {
|
1120
|
+
if (!this._consumeTokenIfType(3 /* TokenType.Indent */)) {
|
1117
1121
|
this._addError(localize_1.Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
|
1118
1122
|
return suite;
|
1119
1123
|
}
|
@@ -1124,7 +1128,7 @@ class Parser {
|
|
1124
1128
|
while (true) {
|
1125
1129
|
// Handle a common error here and see if we can recover.
|
1126
1130
|
const nextToken = this._peekToken();
|
1127
|
-
if (nextToken.type === 3 /* Indent */) {
|
1131
|
+
if (nextToken.type === 3 /* TokenType.Indent */) {
|
1128
1132
|
this._getNextToken();
|
1129
1133
|
const indentToken = nextToken;
|
1130
1134
|
if (indentToken.isIndentAmbiguous) {
|
@@ -1134,7 +1138,7 @@ class Parser {
|
|
1134
1138
|
this._addError(localize_1.Localizer.Diagnostic.unexpectedIndent(), nextToken);
|
1135
1139
|
}
|
1136
1140
|
}
|
1137
|
-
else if (nextToken.type === 4 /* Dedent */) {
|
1141
|
+
else if (nextToken.type === 4 /* TokenType.Dedent */) {
|
1138
1142
|
// When we see a dedent, stop before parsing the dedented statement.
|
1139
1143
|
const dedentToken = nextToken;
|
1140
1144
|
if (!dedentToken.matchesIndent) {
|
@@ -1148,7 +1152,7 @@ class Parser {
|
|
1148
1152
|
// multiple levels of nested suites. Also extend the suite's range in this
|
1149
1153
|
// case so it is multi-line as this works better with indentationUtils.
|
1150
1154
|
if (suite.statements.length > 0) {
|
1151
|
-
this._consumeTokenIfType(4 /* Dedent */);
|
1155
|
+
this._consumeTokenIfType(4 /* TokenType.Dedent */);
|
1152
1156
|
}
|
1153
1157
|
else {
|
1154
1158
|
(0, parseNodes_1.extendRange)(suite, dedentToken);
|
@@ -1163,7 +1167,7 @@ class Parser {
|
|
1163
1167
|
// level to a less than the initial indent of the suite body, swallow
|
1164
1168
|
// the extra dedent to help recover the parse.
|
1165
1169
|
const nextToken = this._peekToken();
|
1166
|
-
if (this._consumeTokenIfType(4 /* Dedent */)) {
|
1170
|
+
if (this._consumeTokenIfType(4 /* TokenType.Dedent */)) {
|
1167
1171
|
(0, parseNodes_1.extendRange)(suite, nextToken);
|
1168
1172
|
break;
|
1169
1173
|
}
|
@@ -1172,13 +1176,13 @@ class Parser {
|
|
1172
1176
|
const statement = this._parseStatement();
|
1173
1177
|
if (!statement) {
|
1174
1178
|
// Perform basic error recovery to get to the next line.
|
1175
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
1179
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
1176
1180
|
}
|
1177
1181
|
else {
|
1178
1182
|
statement.parent = suite;
|
1179
1183
|
suite.statements.push(statement);
|
1180
1184
|
}
|
1181
|
-
if (this._peekTokenType() === 1 /* EndOfStream */) {
|
1185
|
+
if (this._peekTokenType() === 1 /* TokenType.EndOfStream */) {
|
1182
1186
|
break;
|
1183
1187
|
}
|
1184
1188
|
}
|
@@ -1196,34 +1200,34 @@ class Parser {
|
|
1196
1200
|
}
|
1197
1201
|
// for_stmt: [async] 'for' exprlist 'in' testlist suite ['else' suite]
|
1198
1202
|
_parseForStatement(asyncToken) {
|
1199
|
-
const forToken = this._getKeywordToken(17 /* For */);
|
1200
|
-
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1203
|
+
const forToken = this._getKeywordToken(17 /* KeywordType.For */);
|
1204
|
+
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1201
1205
|
let seqExpr;
|
1202
1206
|
let forSuite;
|
1203
1207
|
let elseSuite;
|
1204
|
-
if (!this._consumeTokenIfKeyword(22 /* In */)) {
|
1205
|
-
seqExpr = this._handleExpressionParseError(0 /* MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1208
|
+
if (!this._consumeTokenIfKeyword(22 /* KeywordType.In */)) {
|
1209
|
+
seqExpr = this._handleExpressionParseError(0 /* ErrorExpressionCategory.MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1206
1210
|
forSuite = parseNodes_1.SuiteNode.create(this._peekToken());
|
1207
1211
|
}
|
1208
1212
|
else {
|
1209
1213
|
seqExpr = this._parseTestOrStarListAsExpression(
|
1210
1214
|
/* allowAssignmentExpression */ false,
|
1211
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedInExpr());
|
1215
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedInExpr());
|
1212
1216
|
forSuite = this._parseLoopSuite();
|
1213
1217
|
// Versions of Python earlier than 3.9 didn't allow unpack operators if the
|
1214
1218
|
// tuple wasn't enclosed in parentheses.
|
1215
1219
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_9 && !this._parseOptions.isStubFile) {
|
1216
|
-
if (seqExpr.nodeType === 52 /* Tuple */ && !seqExpr.enclosedInParens) {
|
1220
|
+
if (seqExpr.nodeType === 52 /* ParseNodeType.Tuple */ && !seqExpr.enclosedInParens) {
|
1217
1221
|
let sawStar = false;
|
1218
1222
|
seqExpr.expressions.forEach((expr) => {
|
1219
|
-
if (expr.nodeType === 56 /* Unpack */ && !sawStar) {
|
1223
|
+
if (expr.nodeType === 56 /* ParseNodeType.Unpack */ && !sawStar) {
|
1220
1224
|
this._addError(localize_1.Localizer.Diagnostic.unpackOperatorNotAllowed(), expr);
|
1221
1225
|
sawStar = true;
|
1222
1226
|
}
|
1223
1227
|
});
|
1224
1228
|
}
|
1225
1229
|
}
|
1226
|
-
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1230
|
+
if (this._consumeTokenIfKeyword(13 /* KeywordType.Else */)) {
|
1227
1231
|
elseSuite = this._parseSuite(this._isInFunction);
|
1228
1232
|
}
|
1229
1233
|
}
|
@@ -1249,10 +1253,10 @@ class Parser {
|
|
1249
1253
|
if (!compFor) {
|
1250
1254
|
return undefined;
|
1251
1255
|
}
|
1252
|
-
if (target.nodeType === 56 /* Unpack */) {
|
1256
|
+
if (target.nodeType === 56 /* ParseNodeType.Unpack */) {
|
1253
1257
|
this._addError(localize_1.Localizer.Diagnostic.unpackIllegalInComprehension(), target);
|
1254
1258
|
}
|
1255
|
-
else if (target.nodeType === 16 /* DictionaryExpandEntry */) {
|
1259
|
+
else if (target.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
|
1256
1260
|
this._addError(localize_1.Localizer.Diagnostic.dictExpandIllegalInComprehension(), target);
|
1257
1261
|
}
|
1258
1262
|
const listCompNode = parseNodes_1.ListComprehensionNode.create(target, isGenerator);
|
@@ -1277,24 +1281,24 @@ class Parser {
|
|
1277
1281
|
// comp_for: ['async'] 'for' exprlist 'in' or_test [comp_iter]
|
1278
1282
|
_tryParseCompForStatement() {
|
1279
1283
|
const startTokenKeywordType = this._peekKeywordType();
|
1280
|
-
if (startTokenKeywordType === 3 /* Async */) {
|
1284
|
+
if (startTokenKeywordType === 3 /* KeywordType.Async */) {
|
1281
1285
|
const nextToken = this._peekToken(1);
|
1282
|
-
if (nextToken.type !== 8 /* Keyword */ || nextToken.keywordType !== 17 /* For */) {
|
1286
|
+
if (nextToken.type !== 8 /* TokenType.Keyword */ || nextToken.keywordType !== 17 /* KeywordType.For */) {
|
1283
1287
|
return undefined;
|
1284
1288
|
}
|
1285
1289
|
}
|
1286
|
-
else if (startTokenKeywordType !== 17 /* For */) {
|
1290
|
+
else if (startTokenKeywordType !== 17 /* KeywordType.For */) {
|
1287
1291
|
return undefined;
|
1288
1292
|
}
|
1289
1293
|
let asyncToken;
|
1290
|
-
if (this._peekKeywordType() === 3 /* Async */) {
|
1291
|
-
asyncToken = this._getKeywordToken(3 /* Async */);
|
1294
|
+
if (this._peekKeywordType() === 3 /* KeywordType.Async */) {
|
1295
|
+
asyncToken = this._getKeywordToken(3 /* KeywordType.Async */);
|
1292
1296
|
}
|
1293
|
-
const forToken = this._getKeywordToken(17 /* For */);
|
1294
|
-
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1297
|
+
const forToken = this._getKeywordToken(17 /* KeywordType.For */);
|
1298
|
+
const targetExpr = this._parseExpressionListAsPossibleTuple(2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr(), forToken);
|
1295
1299
|
let seqExpr;
|
1296
|
-
if (!this._consumeTokenIfKeyword(22 /* In */)) {
|
1297
|
-
seqExpr = this._handleExpressionParseError(0 /* MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1300
|
+
if (!this._consumeTokenIfKeyword(22 /* KeywordType.In */)) {
|
1301
|
+
seqExpr = this._handleExpressionParseError(0 /* ErrorExpressionCategory.MissingIn */, localize_1.Localizer.Diagnostic.expectedIn());
|
1298
1302
|
}
|
1299
1303
|
else {
|
1300
1304
|
this._disallowAssignmentExpression(() => {
|
@@ -1311,10 +1315,10 @@ class Parser {
|
|
1311
1315
|
// comp_if: 'if' test_nocond [comp_iter]
|
1312
1316
|
// comp_iter: comp_for | comp_if
|
1313
1317
|
_tryParseCompIfStatement() {
|
1314
|
-
if (this._peekKeywordType() !== 20 /* If */) {
|
1318
|
+
if (this._peekKeywordType() !== 20 /* KeywordType.If */) {
|
1315
1319
|
return undefined;
|
1316
1320
|
}
|
1317
|
-
const ifToken = this._getKeywordToken(20 /* If */);
|
1321
|
+
const ifToken = this._getKeywordToken(20 /* KeywordType.If */);
|
1318
1322
|
const ifExpr = this._tryParseLambdaExpression() ||
|
1319
1323
|
this._parseAssignmentExpression(/* disallowAssignmentExpression */ true);
|
1320
1324
|
const compIfNode = parseNodes_1.ListComprehensionIfNode.create(ifToken, ifExpr);
|
@@ -1322,9 +1326,9 @@ class Parser {
|
|
1322
1326
|
}
|
1323
1327
|
// while_stmt: 'while' test suite ['else' suite]
|
1324
1328
|
_parseWhileStatement() {
|
1325
|
-
const whileToken = this._getKeywordToken(36 /* While */);
|
1329
|
+
const whileToken = this._getKeywordToken(36 /* KeywordType.While */);
|
1326
1330
|
const whileNode = parseNodes_1.WhileNode.create(whileToken, this._parseTestExpression(/* allowAssignmentExpression */ true), this._parseLoopSuite());
|
1327
|
-
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1331
|
+
if (this._consumeTokenIfKeyword(13 /* KeywordType.Else */)) {
|
1328
1332
|
whileNode.elseSuite = this._parseSuite(this._isInFunction);
|
1329
1333
|
whileNode.elseSuite.parent = whileNode;
|
1330
1334
|
(0, parseNodes_1.extendRange)(whileNode, whileNode.elseSuite);
|
@@ -1338,19 +1342,19 @@ class Parser {
|
|
1338
1342
|
// 'finally' suite))
|
1339
1343
|
// except_clause: 'except' [test ['as' NAME]]
|
1340
1344
|
_parseTryStatement() {
|
1341
|
-
const tryToken = this._getKeywordToken(34 /* Try */);
|
1345
|
+
const tryToken = this._getKeywordToken(34 /* KeywordType.Try */);
|
1342
1346
|
const trySuite = this._parseSuite(this._isInFunction);
|
1343
1347
|
const tryNode = parseNodes_1.TryNode.create(tryToken, trySuite);
|
1344
1348
|
let sawCatchAllExcept = false;
|
1345
1349
|
while (true) {
|
1346
1350
|
const exceptToken = this._peekToken();
|
1347
|
-
if (!this._consumeTokenIfKeyword(14 /* Except */)) {
|
1351
|
+
if (!this._consumeTokenIfKeyword(14 /* KeywordType.Except */)) {
|
1348
1352
|
break;
|
1349
1353
|
}
|
1350
1354
|
// See if this is a Python 3.11 exception group.
|
1351
1355
|
const possibleStarToken = this._peekToken();
|
1352
1356
|
let isExceptGroup = false;
|
1353
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1357
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
1354
1358
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_11 && !this._parseOptions.isStubFile) {
|
1355
1359
|
this._addError(localize_1.Localizer.Diagnostic.exceptionGroupIncompatible(), possibleStarToken);
|
1356
1360
|
}
|
@@ -1358,9 +1362,9 @@ class Parser {
|
|
1358
1362
|
}
|
1359
1363
|
let typeExpr;
|
1360
1364
|
let symbolName;
|
1361
|
-
if (this._peekTokenType() !== 10 /* Colon */) {
|
1365
|
+
if (this._peekTokenType() !== 10 /* TokenType.Colon */) {
|
1362
1366
|
typeExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1363
|
-
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1367
|
+
if (this._consumeTokenIfKeyword(1 /* KeywordType.As */)) {
|
1364
1368
|
symbolName = this._getTokenIfIdentifier();
|
1365
1369
|
if (!symbolName) {
|
1366
1370
|
this._addError(localize_1.Localizer.Diagnostic.expectedNameAfterAs(), this._peekToken());
|
@@ -1369,7 +1373,7 @@ class Parser {
|
|
1369
1373
|
else {
|
1370
1374
|
// Handle the python 2.x syntax in a graceful manner.
|
1371
1375
|
const peekToken = this._peekToken();
|
1372
|
-
if (this._consumeTokenIfType(12 /* Comma */)) {
|
1376
|
+
if (this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
1373
1377
|
this._addError(localize_1.Localizer.Diagnostic.expectedAsAfterException(), peekToken);
|
1374
1378
|
// Parse the expression expected in python 2.x, but discard it.
|
1375
1379
|
this._parseTestExpression(/* allowAssignmentExpression */ false);
|
@@ -1402,13 +1406,13 @@ class Parser {
|
|
1402
1406
|
}
|
1403
1407
|
if (tryNode.exceptClauses.length > 0) {
|
1404
1408
|
(0, parseNodes_1.extendRange)(tryNode, tryNode.exceptClauses[tryNode.exceptClauses.length - 1]);
|
1405
|
-
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1409
|
+
if (this._consumeTokenIfKeyword(13 /* KeywordType.Else */)) {
|
1406
1410
|
tryNode.elseSuite = this._parseSuite(this._isInFunction);
|
1407
1411
|
tryNode.elseSuite.parent = tryNode;
|
1408
1412
|
(0, parseNodes_1.extendRange)(tryNode, tryNode.elseSuite);
|
1409
1413
|
}
|
1410
1414
|
}
|
1411
|
-
if (this._consumeTokenIfKeyword(16 /* Finally */)) {
|
1415
|
+
if (this._consumeTokenIfKeyword(16 /* KeywordType.Finally */)) {
|
1412
1416
|
tryNode.finallySuite = this._parseSuite(this._isInFunction);
|
1413
1417
|
tryNode.finallySuite.parent = tryNode;
|
1414
1418
|
(0, parseNodes_1.extendRange)(tryNode, tryNode.finallySuite);
|
@@ -1421,32 +1425,32 @@ class Parser {
|
|
1421
1425
|
// funcdef: 'def' NAME parameters ['->' test] ':' suite
|
1422
1426
|
// parameters: '(' [typedargslist] ')'
|
1423
1427
|
_parseFunctionDef(asyncToken, decorators) {
|
1424
|
-
const defToken = this._getKeywordToken(10 /* Def */);
|
1428
|
+
const defToken = this._getKeywordToken(10 /* KeywordType.Def */);
|
1425
1429
|
const nameToken = this._getTokenIfIdentifier();
|
1426
1430
|
if (!nameToken) {
|
1427
1431
|
this._addError(localize_1.Localizer.Diagnostic.expectedFunctionName(), defToken);
|
1428
|
-
return parseNodes_1.ErrorNode.create(defToken, 10 /* MissingFunctionParameterList */, undefined, decorators);
|
1432
|
+
return parseNodes_1.ErrorNode.create(defToken, 10 /* ErrorExpressionCategory.MissingFunctionParameterList */, undefined, decorators);
|
1429
1433
|
}
|
1430
1434
|
let typeParameters;
|
1431
1435
|
const possibleOpenBracket = this._peekToken();
|
1432
|
-
if (possibleOpenBracket.type === 15 /* OpenBracket */) {
|
1436
|
+
if (possibleOpenBracket.type === 15 /* TokenType.OpenBracket */) {
|
1433
1437
|
typeParameters = this._parseTypeParameterList();
|
1434
1438
|
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
1435
1439
|
this._addError(localize_1.Localizer.Diagnostic.functionTypeParametersIllegal(), typeParameters);
|
1436
1440
|
}
|
1437
1441
|
}
|
1438
1442
|
const openParenToken = this._peekToken();
|
1439
|
-
if (!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
1443
|
+
if (!this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */)) {
|
1440
1444
|
this._addError(localize_1.Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
|
1441
|
-
return parseNodes_1.ErrorNode.create(nameToken, 10 /* MissingFunctionParameterList */, parseNodes_1.NameNode.create(nameToken), decorators);
|
1445
|
+
return parseNodes_1.ErrorNode.create(nameToken, 10 /* ErrorExpressionCategory.MissingFunctionParameterList */, parseNodes_1.NameNode.create(nameToken), decorators);
|
1442
1446
|
}
|
1443
|
-
const paramList = this._parseVarArgsList(14 /* CloseParenthesis */, /* allowAnnotations */ true);
|
1444
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1447
|
+
const paramList = this._parseVarArgsList(14 /* TokenType.CloseParenthesis */, /* allowAnnotations */ true);
|
1448
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
1445
1449
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1446
|
-
this._consumeTokensUntilType([10 /* Colon */]);
|
1450
|
+
this._consumeTokensUntilType([10 /* TokenType.Colon */]);
|
1447
1451
|
}
|
1448
1452
|
let returnType;
|
1449
|
-
if (this._consumeTokenIfType(21 /* Arrow */)) {
|
1453
|
+
if (this._consumeTokenIfType(21 /* TokenType.Arrow */)) {
|
1450
1454
|
returnType = this._parseTypeAnnotation();
|
1451
1455
|
}
|
1452
1456
|
let functionTypeAnnotationToken;
|
@@ -1525,12 +1529,12 @@ class Parser {
|
|
1525
1529
|
paramMap.set(name, name);
|
1526
1530
|
}
|
1527
1531
|
}
|
1528
|
-
else if (param.category === 0 /* Simple */) {
|
1532
|
+
else if (param.category === 0 /* ParameterCategory.Simple */) {
|
1529
1533
|
if (paramList.length === 0) {
|
1530
1534
|
this._addError(localize_1.Localizer.Diagnostic.positionOnlyFirstParam(), param);
|
1531
1535
|
}
|
1532
1536
|
}
|
1533
|
-
if (param.category === 0 /* Simple */) {
|
1537
|
+
if (param.category === 0 /* ParameterCategory.Simple */) {
|
1534
1538
|
if (!param.name) {
|
1535
1539
|
if (sawPositionOnlySeparator) {
|
1536
1540
|
this._addError(localize_1.Localizer.Diagnostic.duplicatePositionOnly(), param);
|
@@ -1560,7 +1564,7 @@ class Parser {
|
|
1560
1564
|
}
|
1561
1565
|
}
|
1562
1566
|
paramList.push(param);
|
1563
|
-
if (param.category === 1 /* ArgsList */) {
|
1567
|
+
if (param.category === 1 /* ParameterCategory.ArgsList */) {
|
1564
1568
|
if (!param.name) {
|
1565
1569
|
if (sawKeywordOnlySeparator) {
|
1566
1570
|
this._addError(localize_1.Localizer.Diagnostic.duplicateKeywordOnly(), param);
|
@@ -1577,7 +1581,7 @@ class Parser {
|
|
1577
1581
|
sawArgs = true;
|
1578
1582
|
}
|
1579
1583
|
}
|
1580
|
-
if (param.category === 2 /* KwargsDict */) {
|
1584
|
+
if (param.category === 2 /* ParameterCategory.KwargsDict */) {
|
1581
1585
|
if (sawKwArgs) {
|
1582
1586
|
this._addError(localize_1.Localizer.Diagnostic.duplicateKwargsParam(), param);
|
1583
1587
|
}
|
@@ -1590,7 +1594,7 @@ class Parser {
|
|
1590
1594
|
else if (sawKwArgs) {
|
1591
1595
|
this._addError(localize_1.Localizer.Diagnostic.paramAfterKwargsParam(), param);
|
1592
1596
|
}
|
1593
|
-
const foundComma = this._consumeTokenIfType(12 /* Comma */);
|
1597
|
+
const foundComma = this._consumeTokenIfType(12 /* TokenType.Comma */);
|
1594
1598
|
if (allowAnnotations && !param.typeAnnotation) {
|
1595
1599
|
// Look for a type annotation comment at the end of the line.
|
1596
1600
|
const typeAnnotationComment = this._parseVariableTypeAnnotationComment();
|
@@ -1606,7 +1610,7 @@ class Parser {
|
|
1606
1610
|
}
|
1607
1611
|
if (paramList.length > 0) {
|
1608
1612
|
const lastParam = paramList[paramList.length - 1];
|
1609
|
-
if (lastParam.category === 1 /* ArgsList */ && !lastParam.name) {
|
1613
|
+
if (lastParam.category === 1 /* ParameterCategory.ArgsList */ && !lastParam.name) {
|
1610
1614
|
this._addError(localize_1.Localizer.Diagnostic.expectedNamedParameter(), lastParam);
|
1611
1615
|
}
|
1612
1616
|
}
|
@@ -1616,13 +1620,13 @@ class Parser {
|
|
1616
1620
|
let starCount = 0;
|
1617
1621
|
let slashCount = 0;
|
1618
1622
|
const firstToken = this._peekToken();
|
1619
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1623
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
1620
1624
|
starCount = 1;
|
1621
1625
|
}
|
1622
|
-
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
1626
|
+
else if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
1623
1627
|
starCount = 2;
|
1624
1628
|
}
|
1625
|
-
else if (this._consumeTokenIfOperator(10 /* Divide */)) {
|
1629
|
+
else if (this._consumeTokenIfOperator(10 /* OperatorType.Divide */)) {
|
1626
1630
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_8 && !this._parseOptions.isStubFile) {
|
1627
1631
|
this._addError(localize_1.Localizer.Diagnostic.positionOnlyIncompatible(), firstToken);
|
1628
1632
|
}
|
@@ -1631,17 +1635,17 @@ class Parser {
|
|
1631
1635
|
const paramName = this._getTokenIfIdentifier();
|
1632
1636
|
if (!paramName) {
|
1633
1637
|
if (starCount === 1) {
|
1634
|
-
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 1 /* ArgsList */);
|
1638
|
+
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 1 /* ParameterCategory.ArgsList */);
|
1635
1639
|
return paramNode;
|
1636
1640
|
}
|
1637
1641
|
else if (slashCount === 1) {
|
1638
|
-
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 0 /* Simple */);
|
1642
|
+
const paramNode = parseNodes_1.ParameterNode.create(firstToken, 0 /* ParameterCategory.Simple */);
|
1639
1643
|
return paramNode;
|
1640
1644
|
}
|
1641
1645
|
// Check for the Python 2.x parameter sublist syntax and handle it gracefully.
|
1642
|
-
if (this._peekTokenType() === 13 /* OpenParenthesis */) {
|
1646
|
+
if (this._peekTokenType() === 13 /* TokenType.OpenParenthesis */) {
|
1643
1647
|
const sublistStart = this._getNextToken();
|
1644
|
-
if (this._consumeTokensUntilType([14 /* CloseParenthesis */])) {
|
1648
|
+
if (this._consumeTokensUntilType([14 /* TokenType.CloseParenthesis */])) {
|
1645
1649
|
this._getNextToken();
|
1646
1650
|
}
|
1647
1651
|
this._addError(localize_1.Localizer.Diagnostic.sublistParamsIncompatible(), sublistStart);
|
@@ -1650,12 +1654,12 @@ class Parser {
|
|
1650
1654
|
this._addError(localize_1.Localizer.Diagnostic.expectedParamName(), this._peekToken());
|
1651
1655
|
}
|
1652
1656
|
}
|
1653
|
-
let paramType = 0 /* Simple */;
|
1657
|
+
let paramType = 0 /* ParameterCategory.Simple */;
|
1654
1658
|
if (starCount === 1) {
|
1655
|
-
paramType = 1 /* ArgsList */;
|
1659
|
+
paramType = 1 /* ParameterCategory.ArgsList */;
|
1656
1660
|
}
|
1657
1661
|
else if (starCount === 2) {
|
1658
|
-
paramType = 2 /* KwargsDict */;
|
1662
|
+
paramType = 2 /* ParameterCategory.KwargsDict */;
|
1659
1663
|
}
|
1660
1664
|
const paramNode = parseNodes_1.ParameterNode.create(firstToken, paramType);
|
1661
1665
|
if (paramName) {
|
@@ -1663,12 +1667,12 @@ class Parser {
|
|
1663
1667
|
paramNode.name.parent = paramNode;
|
1664
1668
|
(0, parseNodes_1.extendRange)(paramNode, paramName);
|
1665
1669
|
}
|
1666
|
-
if (allowAnnotations && this._consumeTokenIfType(10 /* Colon */)) {
|
1667
|
-
paramNode.typeAnnotation = this._parseTypeAnnotation(paramType === 1 /* ArgsList */);
|
1670
|
+
if (allowAnnotations && this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
1671
|
+
paramNode.typeAnnotation = this._parseTypeAnnotation(paramType === 1 /* ParameterCategory.ArgsList */);
|
1668
1672
|
paramNode.typeAnnotation.parent = paramNode;
|
1669
1673
|
(0, parseNodes_1.extendRange)(paramNode, paramNode.typeAnnotation);
|
1670
1674
|
}
|
1671
|
-
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
1675
|
+
if (this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
1672
1676
|
paramNode.defaultValue = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
1673
1677
|
paramNode.defaultValue.parent = paramNode;
|
1674
1678
|
(0, parseNodes_1.extendRange)(paramNode, paramNode.defaultValue);
|
@@ -1682,7 +1686,7 @@ class Parser {
|
|
1682
1686
|
// Python 3.10 adds support for optional parentheses around
|
1683
1687
|
// with_item list.
|
1684
1688
|
_parseWithStatement(asyncToken) {
|
1685
|
-
const withToken = this._getKeywordToken(37 /* With */);
|
1689
|
+
const withToken = this._getKeywordToken(37 /* KeywordType.With */);
|
1686
1690
|
let withItemList = [];
|
1687
1691
|
const possibleParen = this._peekToken();
|
1688
1692
|
// If the expression starts with a paren, parse it as though the
|
@@ -1690,21 +1694,21 @@ class Parser {
|
|
1690
1694
|
// "dry run" to determine whether the entire list of "with items"
|
1691
1695
|
// is enclosed in parentheses.
|
1692
1696
|
let isParenthesizedWithItemList = false;
|
1693
|
-
if (possibleParen.type === 13 /* OpenParenthesis */) {
|
1697
|
+
if (possibleParen.type === 13 /* TokenType.OpenParenthesis */) {
|
1694
1698
|
const openParenTokenIndex = this._tokenIndex;
|
1695
1699
|
this._suppressErrors(() => {
|
1696
1700
|
this._getNextToken();
|
1697
1701
|
while (true) {
|
1698
1702
|
withItemList.push(this._parseWithItem());
|
1699
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1703
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
1700
1704
|
break;
|
1701
1705
|
}
|
1702
|
-
if (this._peekToken().type === 14 /* CloseParenthesis */) {
|
1706
|
+
if (this._peekToken().type === 14 /* TokenType.CloseParenthesis */) {
|
1703
1707
|
break;
|
1704
1708
|
}
|
1705
1709
|
}
|
1706
|
-
if (this._peekToken().type === 14 /* CloseParenthesis */ &&
|
1707
|
-
this._peekToken(1).type === 10 /* Colon */) {
|
1710
|
+
if (this._peekToken().type === 14 /* TokenType.CloseParenthesis */ &&
|
1711
|
+
this._peekToken(1).type === 10 /* TokenType.Colon */) {
|
1708
1712
|
isParenthesizedWithItemList = withItemList.length !== 1 || withItemList[0].target !== undefined;
|
1709
1713
|
}
|
1710
1714
|
this._tokenIndex = openParenTokenIndex;
|
@@ -1712,22 +1716,22 @@ class Parser {
|
|
1712
1716
|
});
|
1713
1717
|
}
|
1714
1718
|
if (isParenthesizedWithItemList) {
|
1715
|
-
this._consumeTokenIfType(13 /* OpenParenthesis */);
|
1719
|
+
this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */);
|
1716
1720
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_9) {
|
1717
1721
|
this._addError(localize_1.Localizer.Diagnostic.parenthesizedContextManagerIllegal(), possibleParen);
|
1718
1722
|
}
|
1719
1723
|
}
|
1720
1724
|
while (true) {
|
1721
1725
|
withItemList.push(this._parseWithItem());
|
1722
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1726
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
1723
1727
|
break;
|
1724
1728
|
}
|
1725
|
-
if (this._peekToken().type === 14 /* CloseParenthesis */) {
|
1729
|
+
if (this._peekToken().type === 14 /* TokenType.CloseParenthesis */) {
|
1726
1730
|
break;
|
1727
1731
|
}
|
1728
1732
|
}
|
1729
1733
|
if (isParenthesizedWithItemList) {
|
1730
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1734
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
1731
1735
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), possibleParen);
|
1732
1736
|
}
|
1733
1737
|
}
|
@@ -1757,7 +1761,7 @@ class Parser {
|
|
1757
1761
|
_parseWithItem() {
|
1758
1762
|
const expr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1759
1763
|
const itemNode = parseNodes_1.WithItemNode.create(expr);
|
1760
|
-
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1764
|
+
if (this._consumeTokenIfKeyword(1 /* KeywordType.As */)) {
|
1761
1765
|
itemNode.target = this._parseExpression(/* allowUnpack */ false);
|
1762
1766
|
itemNode.target.parent = itemNode;
|
1763
1767
|
(0, parseNodes_1.extendRange)(itemNode, itemNode.target);
|
@@ -1769,7 +1773,7 @@ class Parser {
|
|
1769
1773
|
_parseDecorated() {
|
1770
1774
|
const decoratorList = [];
|
1771
1775
|
while (true) {
|
1772
|
-
if (this._peekOperatorType() === 22 /* MatrixMultiply */) {
|
1776
|
+
if (this._peekOperatorType() === 22 /* OperatorType.MatrixMultiply */) {
|
1773
1777
|
decoratorList.push(this._parseDecorator());
|
1774
1778
|
}
|
1775
1779
|
else {
|
@@ -1777,20 +1781,20 @@ class Parser {
|
|
1777
1781
|
}
|
1778
1782
|
}
|
1779
1783
|
const nextToken = this._peekToken();
|
1780
|
-
if (nextToken.type === 8 /* Keyword */) {
|
1781
|
-
if (nextToken.keywordType === 3 /* Async */) {
|
1784
|
+
if (nextToken.type === 8 /* TokenType.Keyword */) {
|
1785
|
+
if (nextToken.keywordType === 3 /* KeywordType.Async */) {
|
1782
1786
|
this._getNextToken();
|
1783
|
-
if (this._peekKeywordType() !== 10 /* Def */) {
|
1787
|
+
if (this._peekKeywordType() !== 10 /* KeywordType.Def */) {
|
1784
1788
|
this._addError(localize_1.Localizer.Diagnostic.expectedFunctionAfterAsync(), this._peekToken());
|
1785
1789
|
}
|
1786
1790
|
else {
|
1787
1791
|
return this._parseFunctionDef(nextToken, decoratorList);
|
1788
1792
|
}
|
1789
1793
|
}
|
1790
|
-
else if (nextToken.keywordType === 10 /* Def */) {
|
1794
|
+
else if (nextToken.keywordType === 10 /* KeywordType.Def */) {
|
1791
1795
|
return this._parseFunctionDef(undefined, decoratorList);
|
1792
1796
|
}
|
1793
|
-
else if (nextToken.keywordType === 7 /* Class */) {
|
1797
|
+
else if (nextToken.keywordType === 7 /* KeywordType.Class */) {
|
1794
1798
|
return this._parseClassDef(decoratorList);
|
1795
1799
|
}
|
1796
1800
|
}
|
@@ -1802,7 +1806,7 @@ class Parser {
|
|
1802
1806
|
// decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
|
1803
1807
|
_parseDecorator() {
|
1804
1808
|
const atOperator = this._getNextToken();
|
1805
|
-
(0, debug_1.assert)(atOperator.operatorType === 22 /* MatrixMultiply */);
|
1809
|
+
(0, debug_1.assert)(atOperator.operatorType === 22 /* OperatorType.MatrixMultiply */);
|
1806
1810
|
const expression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
1807
1811
|
// Versions of Python prior to 3.9 support a limited set of
|
1808
1812
|
// expression forms.
|
@@ -1811,7 +1815,7 @@ class Parser {
|
|
1811
1815
|
if (this._isNameOrMemberAccessExpression(expression)) {
|
1812
1816
|
isSupportedExpressionForm = true;
|
1813
1817
|
}
|
1814
|
-
else if (expression.nodeType === 9 /* Call */ &&
|
1818
|
+
else if (expression.nodeType === 9 /* ParseNodeType.Call */ &&
|
1815
1819
|
this._isNameOrMemberAccessExpression(expression.leftExpression)) {
|
1816
1820
|
isSupportedExpressionForm = true;
|
1817
1821
|
}
|
@@ -1820,24 +1824,24 @@ class Parser {
|
|
1820
1824
|
}
|
1821
1825
|
}
|
1822
1826
|
const decoratorNode = parseNodes_1.DecoratorNode.create(atOperator, expression);
|
1823
|
-
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
1827
|
+
if (!this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
1824
1828
|
this._addError(localize_1.Localizer.Diagnostic.expectedDecoratorNewline(), this._peekToken());
|
1825
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
1829
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
1826
1830
|
}
|
1827
1831
|
return decoratorNode;
|
1828
1832
|
}
|
1829
1833
|
_isNameOrMemberAccessExpression(expression) {
|
1830
|
-
if (expression.nodeType === 38 /* Name */) {
|
1834
|
+
if (expression.nodeType === 38 /* ParseNodeType.Name */) {
|
1831
1835
|
return true;
|
1832
1836
|
}
|
1833
|
-
else if (expression.nodeType === 35 /* MemberAccess */) {
|
1837
|
+
else if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
1834
1838
|
return this._isNameOrMemberAccessExpression(expression.leftExpression);
|
1835
1839
|
}
|
1836
1840
|
return false;
|
1837
1841
|
}
|
1838
1842
|
// classdef: 'class' NAME ['(' [arglist] ')'] suite
|
1839
1843
|
_parseClassDef(decorators) {
|
1840
|
-
const classToken = this._getKeywordToken(7 /* Class */);
|
1844
|
+
const classToken = this._getKeywordToken(7 /* KeywordType.Class */);
|
1841
1845
|
let nameToken = this._getTokenIfIdentifier();
|
1842
1846
|
if (!nameToken) {
|
1843
1847
|
this._addError(localize_1.Localizer.Diagnostic.expectedClassName(), this._peekToken());
|
@@ -1845,7 +1849,7 @@ class Parser {
|
|
1845
1849
|
}
|
1846
1850
|
let typeParameters;
|
1847
1851
|
const possibleOpenBracket = this._peekToken();
|
1848
|
-
if (possibleOpenBracket.type === 15 /* OpenBracket */) {
|
1852
|
+
if (possibleOpenBracket.type === 15 /* TokenType.OpenBracket */) {
|
1849
1853
|
typeParameters = this._parseTypeParameterList();
|
1850
1854
|
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
1851
1855
|
this._addError(localize_1.Localizer.Diagnostic.classTypeParametersIllegal(), typeParameters);
|
@@ -1853,9 +1857,9 @@ class Parser {
|
|
1853
1857
|
}
|
1854
1858
|
let argList = [];
|
1855
1859
|
const openParenToken = this._peekToken();
|
1856
|
-
if (this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
1860
|
+
if (this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */)) {
|
1857
1861
|
argList = this._parseArgList().args;
|
1858
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1862
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
1859
1863
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1860
1864
|
}
|
1861
1865
|
}
|
@@ -1877,17 +1881,17 @@ class Parser {
|
|
1877
1881
|
return classNode;
|
1878
1882
|
}
|
1879
1883
|
_parsePassStatement() {
|
1880
|
-
return parseNodes_1.PassNode.create(this._getKeywordToken(30 /* Pass */));
|
1884
|
+
return parseNodes_1.PassNode.create(this._getKeywordToken(30 /* KeywordType.Pass */));
|
1881
1885
|
}
|
1882
1886
|
_parseBreakStatement() {
|
1883
|
-
const breakToken = this._getKeywordToken(5 /* Break */);
|
1887
|
+
const breakToken = this._getKeywordToken(5 /* KeywordType.Break */);
|
1884
1888
|
if (!this._isInLoop) {
|
1885
1889
|
this._addError(localize_1.Localizer.Diagnostic.breakOutsideLoop(), breakToken);
|
1886
1890
|
}
|
1887
1891
|
return parseNodes_1.BreakNode.create(breakToken);
|
1888
1892
|
}
|
1889
1893
|
_parseContinueStatement() {
|
1890
|
-
const continueToken = this._getKeywordToken(8 /* Continue */);
|
1894
|
+
const continueToken = this._getKeywordToken(8 /* KeywordType.Continue */);
|
1891
1895
|
if (!this._isInLoop) {
|
1892
1896
|
this._addError(localize_1.Localizer.Diagnostic.continueOutsideLoop(), continueToken);
|
1893
1897
|
}
|
@@ -1898,7 +1902,7 @@ class Parser {
|
|
1898
1902
|
}
|
1899
1903
|
// return_stmt: 'return' [testlist]
|
1900
1904
|
_parseReturnStatement() {
|
1901
|
-
const returnToken = this._getKeywordToken(32 /* Return */);
|
1905
|
+
const returnToken = this._getKeywordToken(32 /* KeywordType.Return */);
|
1902
1906
|
const returnNode = parseNodes_1.ReturnNode.create(returnToken);
|
1903
1907
|
if (!this._isInFunction) {
|
1904
1908
|
this._addError(localize_1.Localizer.Diagnostic.returnOutsideFunction(), returnToken);
|
@@ -1906,7 +1910,7 @@ class Parser {
|
|
1906
1910
|
if (!this._isNextTokenNeverExpression()) {
|
1907
1911
|
const returnExpr = this._parseTestOrStarListAsExpression(
|
1908
1912
|
/* allowAssignmentExpression */ true,
|
1909
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
1913
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedReturnExpr());
|
1910
1914
|
this._reportConditionalErrorForStarTupleElement(returnExpr);
|
1911
1915
|
returnNode.returnExpression = returnExpr;
|
1912
1916
|
returnNode.returnExpression.parent = returnNode;
|
@@ -1919,14 +1923,14 @@ class Parser {
|
|
1919
1923
|
// import_as_names: import_as_name (',' import_as_name)* [',']
|
1920
1924
|
// import_as_name: NAME ['as' NAME]
|
1921
1925
|
_parseFromStatement() {
|
1922
|
-
const fromToken = this._getKeywordToken(18 /* From */);
|
1926
|
+
const fromToken = this._getKeywordToken(18 /* KeywordType.From */);
|
1923
1927
|
const modName = this._parseDottedModuleName(/* allowJustDots */ true);
|
1924
1928
|
const importFromNode = parseNodes_1.ImportFromNode.create(fromToken, modName);
|
1925
1929
|
// Handle imports from __future__ specially because they can
|
1926
1930
|
// change the way we interpret the rest of the file.
|
1927
1931
|
const isFutureImport = modName.leadingDots === 0 && modName.nameParts.length === 1 && modName.nameParts[0].value === '__future__';
|
1928
1932
|
const possibleInputToken = this._peekToken();
|
1929
|
-
if (!this._consumeTokenIfKeyword(21 /* Import */)) {
|
1933
|
+
if (!this._consumeTokenIfKeyword(21 /* KeywordType.Import */)) {
|
1930
1934
|
this._addError(localize_1.Localizer.Diagnostic.expectedImport(), this._peekToken());
|
1931
1935
|
if (!modName.hasTrailingDot) {
|
1932
1936
|
importFromNode.missingImportKeyword = true;
|
@@ -1936,7 +1940,7 @@ class Parser {
|
|
1936
1940
|
(0, parseNodes_1.extendRange)(importFromNode, possibleInputToken);
|
1937
1941
|
// Look for "*" token.
|
1938
1942
|
const possibleStarToken = this._peekToken();
|
1939
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
1943
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
1940
1944
|
(0, parseNodes_1.extendRange)(importFromNode, possibleStarToken);
|
1941
1945
|
importFromNode.isWildcardImport = true;
|
1942
1946
|
importFromNode.wildcardToken = possibleStarToken;
|
@@ -1944,7 +1948,7 @@ class Parser {
|
|
1944
1948
|
}
|
1945
1949
|
else {
|
1946
1950
|
const openParenToken = this._peekToken();
|
1947
|
-
const inParen = this._consumeTokenIfType(13 /* OpenParenthesis */);
|
1951
|
+
const inParen = this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */);
|
1948
1952
|
let trailingCommaToken;
|
1949
1953
|
while (true) {
|
1950
1954
|
const importName = this._getTokenIfIdentifier();
|
@@ -1953,7 +1957,7 @@ class Parser {
|
|
1953
1957
|
}
|
1954
1958
|
trailingCommaToken = undefined;
|
1955
1959
|
const importFromAsNode = parseNodes_1.ImportFromAsNode.create(parseNodes_1.NameNode.create(importName));
|
1956
|
-
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
1960
|
+
if (this._consumeTokenIfKeyword(1 /* KeywordType.As */)) {
|
1957
1961
|
const aliasName = this._getTokenIfIdentifier();
|
1958
1962
|
if (!aliasName) {
|
1959
1963
|
this._addError(localize_1.Localizer.Diagnostic.expectedImportAlias(), this._peekToken());
|
@@ -1972,7 +1976,7 @@ class Parser {
|
|
1972
1976
|
this._futureImports.add(importName.value);
|
1973
1977
|
}
|
1974
1978
|
const nextToken = this._peekToken();
|
1975
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
1979
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
1976
1980
|
break;
|
1977
1981
|
}
|
1978
1982
|
trailingCommaToken = nextToken;
|
@@ -1983,7 +1987,7 @@ class Parser {
|
|
1983
1987
|
if (inParen) {
|
1984
1988
|
importFromNode.usesParens = true;
|
1985
1989
|
const nextToken = this._peekToken();
|
1986
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
1990
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
1987
1991
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
1988
1992
|
}
|
1989
1993
|
else {
|
@@ -2031,12 +2035,12 @@ class Parser {
|
|
2031
2035
|
// dotted_as_name: dotted_name ['as' NAME]
|
2032
2036
|
_parseImportStatement() {
|
2033
2037
|
var _a;
|
2034
|
-
const importToken = this._getKeywordToken(21 /* Import */);
|
2038
|
+
const importToken = this._getKeywordToken(21 /* KeywordType.Import */);
|
2035
2039
|
const importNode = parseNodes_1.ImportNode.create(importToken);
|
2036
2040
|
while (true) {
|
2037
2041
|
const modName = this._parseDottedModuleName();
|
2038
2042
|
const importAsNode = parseNodes_1.ImportAsNode.create(modName);
|
2039
|
-
if (this._consumeTokenIfKeyword(1 /* As */)) {
|
2043
|
+
if (this._consumeTokenIfKeyword(1 /* KeywordType.As */)) {
|
2040
2044
|
const aliasToken = this._getTokenIfIdentifier();
|
2041
2045
|
if (aliasToken) {
|
2042
2046
|
importAsNode.alias = parseNodes_1.NameNode.create(aliasToken);
|
@@ -2081,7 +2085,7 @@ class Parser {
|
|
2081
2085
|
this._typingImportAliases.push(((_a = importAsNode.alias) === null || _a === void 0 ? void 0 : _a.value) || firstNamePartValue);
|
2082
2086
|
}
|
2083
2087
|
}
|
2084
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2088
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2085
2089
|
break;
|
2086
2090
|
}
|
2087
2091
|
}
|
@@ -2096,9 +2100,9 @@ class Parser {
|
|
2096
2100
|
var _a;
|
2097
2101
|
const moduleNameNode = parseNodes_1.ModuleNameNode.create(this._peekToken());
|
2098
2102
|
while (true) {
|
2099
|
-
const token = (_a = this._getTokenIfType(19 /* Ellipsis */)) !== null && _a !== void 0 ? _a : this._getTokenIfType(20 /* Dot */);
|
2103
|
+
const token = (_a = this._getTokenIfType(19 /* TokenType.Ellipsis */)) !== null && _a !== void 0 ? _a : this._getTokenIfType(20 /* TokenType.Dot */);
|
2100
2104
|
if (token) {
|
2101
|
-
if (token.type === 19 /* Ellipsis */) {
|
2105
|
+
if (token.type === 19 /* TokenType.Ellipsis */) {
|
2102
2106
|
moduleNameNode.leadingDots += 3;
|
2103
2107
|
}
|
2104
2108
|
else {
|
@@ -2124,7 +2128,7 @@ class Parser {
|
|
2124
2128
|
namePart.parent = moduleNameNode;
|
2125
2129
|
(0, parseNodes_1.extendRange)(moduleNameNode, namePart);
|
2126
2130
|
const nextToken = this._peekToken();
|
2127
|
-
if (!this._consumeTokenIfType(20 /* Dot */)) {
|
2131
|
+
if (!this._consumeTokenIfType(20 /* TokenType.Dot */)) {
|
2128
2132
|
break;
|
2129
2133
|
}
|
2130
2134
|
// Extend the module name to include the dot.
|
@@ -2133,7 +2137,7 @@ class Parser {
|
|
2133
2137
|
return moduleNameNode;
|
2134
2138
|
}
|
2135
2139
|
_parseGlobalStatement() {
|
2136
|
-
const globalToken = this._getKeywordToken(19 /* Global */);
|
2140
|
+
const globalToken = this._getKeywordToken(19 /* KeywordType.Global */);
|
2137
2141
|
const globalNode = parseNodes_1.GlobalNode.create(globalToken);
|
2138
2142
|
globalNode.nameList = this._parseNameList();
|
2139
2143
|
if (globalNode.nameList.length > 0) {
|
@@ -2145,7 +2149,7 @@ class Parser {
|
|
2145
2149
|
return globalNode;
|
2146
2150
|
}
|
2147
2151
|
_parseNonlocalStatement() {
|
2148
|
-
const nonlocalToken = this._getKeywordToken(27 /* Nonlocal */);
|
2152
|
+
const nonlocalToken = this._getKeywordToken(27 /* KeywordType.Nonlocal */);
|
2149
2153
|
const nonlocalNode = parseNodes_1.NonlocalNode.create(nonlocalToken);
|
2150
2154
|
nonlocalNode.nameList = this._parseNameList();
|
2151
2155
|
if (nonlocalNode.nameList.length > 0) {
|
@@ -2165,7 +2169,7 @@ class Parser {
|
|
2165
2169
|
break;
|
2166
2170
|
}
|
2167
2171
|
nameList.push(parseNodes_1.NameNode.create(name));
|
2168
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2172
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2169
2173
|
break;
|
2170
2174
|
}
|
2171
2175
|
}
|
@@ -2174,24 +2178,24 @@ class Parser {
|
|
2174
2178
|
// raise_stmt: 'raise' [test ['from' test]]
|
2175
2179
|
// (old) raise_stmt: 'raise' [test [',' test [',' test]]]
|
2176
2180
|
_parseRaiseStatement() {
|
2177
|
-
const raiseToken = this._getKeywordToken(31 /* Raise */);
|
2181
|
+
const raiseToken = this._getKeywordToken(31 /* KeywordType.Raise */);
|
2178
2182
|
const raiseNode = parseNodes_1.RaiseNode.create(raiseToken);
|
2179
2183
|
if (!this._isNextTokenNeverExpression()) {
|
2180
2184
|
raiseNode.typeExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2181
2185
|
raiseNode.typeExpression.parent = raiseNode;
|
2182
2186
|
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.typeExpression);
|
2183
|
-
if (this._consumeTokenIfKeyword(18 /* From */)) {
|
2187
|
+
if (this._consumeTokenIfKeyword(18 /* KeywordType.From */)) {
|
2184
2188
|
raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2185
2189
|
raiseNode.valueExpression.parent = raiseNode;
|
2186
2190
|
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.valueExpression);
|
2187
2191
|
}
|
2188
2192
|
else {
|
2189
|
-
if (this._consumeTokenIfType(12 /* Comma */)) {
|
2193
|
+
if (this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2190
2194
|
// Handle the Python 2.x variant
|
2191
2195
|
raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2192
2196
|
raiseNode.valueExpression.parent = raiseNode;
|
2193
2197
|
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.valueExpression);
|
2194
|
-
if (this._consumeTokenIfType(12 /* Comma */)) {
|
2198
|
+
if (this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2195
2199
|
raiseNode.tracebackExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2196
2200
|
raiseNode.tracebackExpression.parent = raiseNode;
|
2197
2201
|
(0, parseNodes_1.extendRange)(raiseNode, raiseNode.tracebackExpression);
|
@@ -2203,10 +2207,10 @@ class Parser {
|
|
2203
2207
|
}
|
2204
2208
|
// assert_stmt: 'assert' test [',' test]
|
2205
2209
|
_parseAssertStatement() {
|
2206
|
-
const assertToken = this._getKeywordToken(2 /* Assert */);
|
2210
|
+
const assertToken = this._getKeywordToken(2 /* KeywordType.Assert */);
|
2207
2211
|
const expr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2208
2212
|
const assertNode = parseNodes_1.AssertNode.create(assertToken, expr);
|
2209
|
-
if (this._consumeTokenIfType(12 /* Comma */)) {
|
2213
|
+
if (this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2210
2214
|
const exceptionExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
2211
2215
|
assertNode.exceptionExpression = exceptionExpr;
|
2212
2216
|
assertNode.exceptionExpression.parent = assertNode;
|
@@ -2216,7 +2220,7 @@ class Parser {
|
|
2216
2220
|
}
|
2217
2221
|
// del_stmt: 'del' exprlist
|
2218
2222
|
_parseDelStatement() {
|
2219
|
-
const delToken = this._getKeywordToken(11 /* Del */);
|
2223
|
+
const delToken = this._getKeywordToken(11 /* KeywordType.Del */);
|
2220
2224
|
const exprListResult = this._parseExpressionList(/* allowStar */ true);
|
2221
2225
|
if (!exprListResult.parseError && exprListResult.list.length === 0) {
|
2222
2226
|
this._addError(localize_1.Localizer.Diagnostic.expectedDelExpr(), this._peekToken());
|
@@ -2234,9 +2238,9 @@ class Parser {
|
|
2234
2238
|
// yield_expr: 'yield' [yield_arg]
|
2235
2239
|
// yield_arg: 'from' test | testlist
|
2236
2240
|
_parseYieldExpression() {
|
2237
|
-
const yieldToken = this._getKeywordToken(38 /* Yield */);
|
2241
|
+
const yieldToken = this._getKeywordToken(38 /* KeywordType.Yield */);
|
2238
2242
|
const nextToken = this._peekToken();
|
2239
|
-
if (this._consumeTokenIfKeyword(18 /* From */)) {
|
2243
|
+
if (this._consumeTokenIfKeyword(18 /* KeywordType.From */)) {
|
2240
2244
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_3) {
|
2241
2245
|
this._addError(localize_1.Localizer.Diagnostic.yieldFromIllegal(), nextToken);
|
2242
2246
|
}
|
@@ -2246,13 +2250,13 @@ class Parser {
|
|
2246
2250
|
if (!this._isNextTokenNeverExpression()) {
|
2247
2251
|
exprList = this._parseTestOrStarListAsExpression(
|
2248
2252
|
/* allowAssignmentExpression */ false,
|
2249
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedYieldExpr());
|
2253
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedYieldExpr());
|
2250
2254
|
this._reportConditionalErrorForStarTupleElement(exprList);
|
2251
2255
|
}
|
2252
2256
|
return parseNodes_1.YieldNode.create(yieldToken, exprList);
|
2253
2257
|
}
|
2254
2258
|
_tryParseYieldExpression() {
|
2255
|
-
if (this._peekKeywordType() !== 38 /* Yield */) {
|
2259
|
+
if (this._peekKeywordType() !== 38 /* KeywordType.Yield */) {
|
2256
2260
|
return undefined;
|
2257
2261
|
}
|
2258
2262
|
return this._parseYieldExpression();
|
@@ -2262,34 +2266,34 @@ class Parser {
|
|
2262
2266
|
const statement = parseNodes_1.StatementListNode.create(this._peekToken());
|
2263
2267
|
while (true) {
|
2264
2268
|
// Swallow invalid tokens to make sure we make forward progress.
|
2265
|
-
if (this._peekTokenType() === 0 /* Invalid */) {
|
2269
|
+
if (this._peekTokenType() === 0 /* TokenType.Invalid */) {
|
2266
2270
|
const invalidToken = this._getNextToken();
|
2267
2271
|
const text = this._fileContents.substr(invalidToken.start, invalidToken.length);
|
2268
2272
|
const firstCharCode = text.charCodeAt(0);
|
2269
2273
|
// Remove any non-printable characters.
|
2270
2274
|
this._addError(localize_1.Localizer.Diagnostic.invalidTokenChars().format({ text: `\\u${firstCharCode.toString(16)}` }), invalidToken);
|
2271
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
2275
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
2272
2276
|
break;
|
2273
2277
|
}
|
2274
2278
|
const smallStatement = this._parseSmallStatement();
|
2275
2279
|
statement.statements.push(smallStatement);
|
2276
2280
|
smallStatement.parent = statement;
|
2277
2281
|
(0, parseNodes_1.extendRange)(statement, smallStatement);
|
2278
|
-
if (smallStatement.nodeType === 0 /* Error */) {
|
2282
|
+
if (smallStatement.nodeType === 0 /* ParseNodeType.Error */) {
|
2279
2283
|
// No need to log an error here. We assume that
|
2280
2284
|
// it was already logged by _parseSmallStatement.
|
2281
2285
|
break;
|
2282
2286
|
}
|
2283
2287
|
// Consume the semicolon if present.
|
2284
|
-
if (!this._consumeTokenIfType(11 /* Semicolon */)) {
|
2288
|
+
if (!this._consumeTokenIfType(11 /* TokenType.Semicolon */)) {
|
2285
2289
|
break;
|
2286
2290
|
}
|
2287
2291
|
const nextTokenType = this._peekTokenType();
|
2288
|
-
if (nextTokenType === 2 /* NewLine */ || nextTokenType === 1 /* EndOfStream */) {
|
2292
|
+
if (nextTokenType === 2 /* TokenType.NewLine */ || nextTokenType === 1 /* TokenType.EndOfStream */) {
|
2289
2293
|
break;
|
2290
2294
|
}
|
2291
2295
|
}
|
2292
|
-
if (!this._consumeTokenIfType(2 /* NewLine */)) {
|
2296
|
+
if (!this._consumeTokenIfType(2 /* TokenType.NewLine */)) {
|
2293
2297
|
this._addError(localize_1.Localizer.Diagnostic.expectedNewlineOrSemicolon(), this._peekToken());
|
2294
2298
|
}
|
2295
2299
|
return statement;
|
@@ -2300,42 +2304,42 @@ class Parser {
|
|
2300
2304
|
// import_stmt: import_name | import_from
|
2301
2305
|
_parseSmallStatement() {
|
2302
2306
|
switch (this._peekKeywordType()) {
|
2303
|
-
case 30 /* Pass */:
|
2307
|
+
case 30 /* KeywordType.Pass */:
|
2304
2308
|
return this._parsePassStatement();
|
2305
|
-
case 5 /* Break */:
|
2309
|
+
case 5 /* KeywordType.Break */:
|
2306
2310
|
return this._parseBreakStatement();
|
2307
|
-
case 8 /* Continue */:
|
2311
|
+
case 8 /* KeywordType.Continue */:
|
2308
2312
|
return this._parseContinueStatement();
|
2309
|
-
case 32 /* Return */:
|
2313
|
+
case 32 /* KeywordType.Return */:
|
2310
2314
|
return this._parseReturnStatement();
|
2311
|
-
case 18 /* From */:
|
2315
|
+
case 18 /* KeywordType.From */:
|
2312
2316
|
return this._parseFromStatement();
|
2313
|
-
case 21 /* Import */:
|
2317
|
+
case 21 /* KeywordType.Import */:
|
2314
2318
|
return this._parseImportStatement();
|
2315
|
-
case 19 /* Global */:
|
2319
|
+
case 19 /* KeywordType.Global */:
|
2316
2320
|
return this._parseGlobalStatement();
|
2317
|
-
case 27 /* Nonlocal */:
|
2321
|
+
case 27 /* KeywordType.Nonlocal */:
|
2318
2322
|
return this._parseNonlocalStatement();
|
2319
|
-
case 31 /* Raise */:
|
2323
|
+
case 31 /* KeywordType.Raise */:
|
2320
2324
|
return this._parseRaiseStatement();
|
2321
|
-
case 2 /* Assert */:
|
2325
|
+
case 2 /* KeywordType.Assert */:
|
2322
2326
|
return this._parseAssertStatement();
|
2323
|
-
case 11 /* Del */:
|
2327
|
+
case 11 /* KeywordType.Del */:
|
2324
2328
|
return this._parseDelStatement();
|
2325
|
-
case 38 /* Yield */:
|
2329
|
+
case 38 /* KeywordType.Yield */:
|
2326
2330
|
return this._parseYieldExpression();
|
2327
|
-
case 35 /* Type */: {
|
2331
|
+
case 35 /* KeywordType.Type */: {
|
2328
2332
|
// Type is considered a "soft" keyword, so we will treat it
|
2329
2333
|
// as an identifier if it is followed by an unexpected token.
|
2330
2334
|
const peekToken1 = this._peekToken(1);
|
2331
2335
|
const peekToken2 = this._peekToken(2);
|
2332
2336
|
let isInvalidTypeToken = true;
|
2333
|
-
if (peekToken1.type === 7 /* Identifier */ || peekToken1.type === 8 /* Keyword */) {
|
2334
|
-
if (peekToken2.type === 15 /* OpenBracket */) {
|
2337
|
+
if (peekToken1.type === 7 /* TokenType.Identifier */ || peekToken1.type === 8 /* TokenType.Keyword */) {
|
2338
|
+
if (peekToken2.type === 15 /* TokenType.OpenBracket */) {
|
2335
2339
|
isInvalidTypeToken = false;
|
2336
2340
|
}
|
2337
|
-
else if (peekToken2.type === 9 /* Operator */ &&
|
2338
|
-
peekToken2.operatorType === 2 /* Assign */) {
|
2341
|
+
else if (peekToken2.type === 9 /* TokenType.Operator */ &&
|
2342
|
+
peekToken2.operatorType === 2 /* OperatorType.Assign */) {
|
2339
2343
|
isInvalidTypeToken = false;
|
2340
2344
|
}
|
2341
2345
|
}
|
@@ -2351,7 +2355,7 @@ class Parser {
|
|
2351
2355
|
// A single-element tuple with no trailing comma is simply an expression
|
2352
2356
|
// that's surrounded by parens.
|
2353
2357
|
if (exprListResult.list.length === 1 && !exprListResult.trailingComma) {
|
2354
|
-
if (exprListResult.list[0].nodeType === 56 /* Unpack */) {
|
2358
|
+
if (exprListResult.list[0].nodeType === 56 /* ParseNodeType.Unpack */) {
|
2355
2359
|
this._addError(localize_1.Localizer.Diagnostic.unpackOperatorNotAllowed(), exprListResult.list[0]);
|
2356
2360
|
}
|
2357
2361
|
return exprListResult.list[0];
|
@@ -2412,7 +2416,7 @@ class Parser {
|
|
2412
2416
|
if (!allowMultipleUnpack && !exprListResult.parseError) {
|
2413
2417
|
let sawStar = false;
|
2414
2418
|
for (const expr of exprListResult.list) {
|
2415
|
-
if (expr.nodeType === 56 /* Unpack */) {
|
2419
|
+
if (expr.nodeType === 56 /* ParseNodeType.Unpack */) {
|
2416
2420
|
if (sawStar) {
|
2417
2421
|
this._addError(localize_1.Localizer.Diagnostic.duplicateUnpack(), expr);
|
2418
2422
|
break;
|
@@ -2428,36 +2432,36 @@ class Parser {
|
|
2428
2432
|
// star_expr: '*' expr
|
2429
2433
|
_parseExpression(allowUnpack) {
|
2430
2434
|
const startToken = this._peekToken();
|
2431
|
-
if (allowUnpack && this._consumeTokenIfOperator(26 /* Multiply */)) {
|
2435
|
+
if (allowUnpack && this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
2432
2436
|
return parseNodes_1.UnpackNode.create(startToken, this._parseExpression(/* allowUnpack */ false));
|
2433
2437
|
}
|
2434
2438
|
return this._parseBitwiseOrExpression();
|
2435
2439
|
}
|
2436
2440
|
// test_or_star: test | star_expr
|
2437
2441
|
_parseTestOrStarExpression(allowAssignmentExpression) {
|
2438
|
-
if (this._peekOperatorType() === 26 /* Multiply */) {
|
2442
|
+
if (this._peekOperatorType() === 26 /* OperatorType.Multiply */) {
|
2439
2443
|
return this._parseExpression(/* allowUnpack */ true);
|
2440
2444
|
}
|
2441
2445
|
return this._parseTestExpression(allowAssignmentExpression);
|
2442
2446
|
}
|
2443
2447
|
// test: or_test ['if' or_test 'else' test] | lambdef
|
2444
2448
|
_parseTestExpression(allowAssignmentExpression) {
|
2445
|
-
if (this._peekKeywordType() === 24 /* Lambda */) {
|
2449
|
+
if (this._peekKeywordType() === 24 /* KeywordType.Lambda */) {
|
2446
2450
|
return this._parseLambdaExpression();
|
2447
2451
|
}
|
2448
2452
|
const ifExpr = this._parseAssignmentExpression(!allowAssignmentExpression);
|
2449
|
-
if (ifExpr.nodeType === 0 /* Error */) {
|
2453
|
+
if (ifExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2450
2454
|
return ifExpr;
|
2451
2455
|
}
|
2452
|
-
if (!this._consumeTokenIfKeyword(20 /* If */)) {
|
2456
|
+
if (!this._consumeTokenIfKeyword(20 /* KeywordType.If */)) {
|
2453
2457
|
return ifExpr;
|
2454
2458
|
}
|
2455
2459
|
const testExpr = this._parseOrTest();
|
2456
|
-
if (testExpr.nodeType === 0 /* Error */) {
|
2460
|
+
if (testExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2457
2461
|
return testExpr;
|
2458
2462
|
}
|
2459
|
-
if (!this._consumeTokenIfKeyword(13 /* Else */)) {
|
2460
|
-
return parseNodes_1.TernaryNode.create(ifExpr, testExpr, this._handleExpressionParseError(1 /* MissingElse */, localize_1.Localizer.Diagnostic.expectedElse()));
|
2463
|
+
if (!this._consumeTokenIfKeyword(13 /* KeywordType.Else */)) {
|
2464
|
+
return parseNodes_1.TernaryNode.create(ifExpr, testExpr, this._handleExpressionParseError(1 /* ErrorExpressionCategory.MissingElse */, localize_1.Localizer.Diagnostic.expectedElse()));
|
2461
2465
|
}
|
2462
2466
|
const elseExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2463
2467
|
return parseNodes_1.TernaryNode.create(ifExpr, testExpr, elseExpr);
|
@@ -2465,14 +2469,14 @@ class Parser {
|
|
2465
2469
|
// assign_expr: NAME := test
|
2466
2470
|
_parseAssignmentExpression(disallowAssignmentExpression = false) {
|
2467
2471
|
const leftExpr = this._parseOrTest();
|
2468
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2472
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2469
2473
|
return leftExpr;
|
2470
2474
|
}
|
2471
|
-
if (leftExpr.nodeType !== 38 /* Name */) {
|
2475
|
+
if (leftExpr.nodeType !== 38 /* ParseNodeType.Name */) {
|
2472
2476
|
return leftExpr;
|
2473
2477
|
}
|
2474
2478
|
const walrusToken = this._peekToken();
|
2475
|
-
if (!this._consumeTokenIfOperator(35 /* Walrus */)) {
|
2479
|
+
if (!this._consumeTokenIfOperator(35 /* OperatorType.Walrus */)) {
|
2476
2480
|
return leftExpr;
|
2477
2481
|
}
|
2478
2482
|
if (!this._assignmentExpressionsAllowed || this._isParsingTypeAnnotation || disallowAssignmentExpression) {
|
@@ -2487,41 +2491,41 @@ class Parser {
|
|
2487
2491
|
// or_test: and_test ('or' and_test)*
|
2488
2492
|
_parseOrTest() {
|
2489
2493
|
let leftExpr = this._parseAndTest();
|
2490
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2494
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2491
2495
|
return leftExpr;
|
2492
2496
|
}
|
2493
2497
|
while (true) {
|
2494
2498
|
const peekToken = this._peekToken();
|
2495
|
-
if (!this._consumeTokenIfKeyword(29 /* Or */)) {
|
2499
|
+
if (!this._consumeTokenIfKeyword(29 /* KeywordType.Or */)) {
|
2496
2500
|
break;
|
2497
2501
|
}
|
2498
2502
|
const rightExpr = this._parseAndTest();
|
2499
|
-
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 37 /* Or */);
|
2503
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 37 /* OperatorType.Or */);
|
2500
2504
|
}
|
2501
2505
|
return leftExpr;
|
2502
2506
|
}
|
2503
2507
|
// and_test: not_test ('and' not_test)*
|
2504
2508
|
_parseAndTest() {
|
2505
2509
|
let leftExpr = this._parseNotTest();
|
2506
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2510
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2507
2511
|
return leftExpr;
|
2508
2512
|
}
|
2509
2513
|
while (true) {
|
2510
2514
|
const peekToken = this._peekToken();
|
2511
|
-
if (!this._consumeTokenIfKeyword(0 /* And */)) {
|
2515
|
+
if (!this._consumeTokenIfKeyword(0 /* KeywordType.And */)) {
|
2512
2516
|
break;
|
2513
2517
|
}
|
2514
2518
|
const rightExpr = this._parseNotTest();
|
2515
|
-
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 36 /* And */);
|
2519
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 36 /* OperatorType.And */);
|
2516
2520
|
}
|
2517
2521
|
return leftExpr;
|
2518
2522
|
}
|
2519
2523
|
// not_test: 'not' not_test | comparison
|
2520
2524
|
_parseNotTest() {
|
2521
2525
|
const notToken = this._peekToken();
|
2522
|
-
if (this._consumeTokenIfKeyword(28 /* Not */)) {
|
2526
|
+
if (this._consumeTokenIfKeyword(28 /* KeywordType.Not */)) {
|
2523
2527
|
const notExpr = this._parseNotTest();
|
2524
|
-
return this._createUnaryOperationNode(notToken, notExpr, 38 /* Not */);
|
2528
|
+
return this._createUnaryOperationNode(notToken, notExpr, 38 /* OperatorType.Not */);
|
2525
2529
|
}
|
2526
2530
|
return this._parseComparison();
|
2527
2531
|
}
|
@@ -2529,7 +2533,7 @@ class Parser {
|
|
2529
2533
|
// comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
|
2530
2534
|
_parseComparison() {
|
2531
2535
|
let leftExpr = this._parseBitwiseOrExpression();
|
2532
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2536
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2533
2537
|
return leftExpr;
|
2534
2538
|
}
|
2535
2539
|
while (true) {
|
@@ -2537,30 +2541,30 @@ class Parser {
|
|
2537
2541
|
const peekToken = this._peekToken();
|
2538
2542
|
if (tokenizer_1.Tokenizer.isOperatorComparison(this._peekOperatorType())) {
|
2539
2543
|
comparisonOperator = this._peekOperatorType();
|
2540
|
-
if (comparisonOperator === 19 /* LessOrGreaterThan */) {
|
2544
|
+
if (comparisonOperator === 19 /* OperatorType.LessOrGreaterThan */) {
|
2541
2545
|
this._addError(localize_1.Localizer.Diagnostic.operatorLessOrGreaterDeprecated(), peekToken);
|
2542
|
-
comparisonOperator = 28 /* NotEquals */;
|
2546
|
+
comparisonOperator = 28 /* OperatorType.NotEquals */;
|
2543
2547
|
}
|
2544
2548
|
this._getNextToken();
|
2545
2549
|
}
|
2546
|
-
else if (this._consumeTokenIfKeyword(22 /* In */)) {
|
2547
|
-
comparisonOperator = 41 /* In */;
|
2550
|
+
else if (this._consumeTokenIfKeyword(22 /* KeywordType.In */)) {
|
2551
|
+
comparisonOperator = 41 /* OperatorType.In */;
|
2548
2552
|
}
|
2549
|
-
else if (this._consumeTokenIfKeyword(23 /* Is */)) {
|
2550
|
-
if (this._consumeTokenIfKeyword(28 /* Not */)) {
|
2551
|
-
comparisonOperator = 40 /* IsNot */;
|
2553
|
+
else if (this._consumeTokenIfKeyword(23 /* KeywordType.Is */)) {
|
2554
|
+
if (this._consumeTokenIfKeyword(28 /* KeywordType.Not */)) {
|
2555
|
+
comparisonOperator = 40 /* OperatorType.IsNot */;
|
2552
2556
|
}
|
2553
2557
|
else {
|
2554
|
-
comparisonOperator = 39 /* Is */;
|
2558
|
+
comparisonOperator = 39 /* OperatorType.Is */;
|
2555
2559
|
}
|
2556
2560
|
}
|
2557
|
-
else if (this._peekKeywordType() === 28 /* Not */) {
|
2561
|
+
else if (this._peekKeywordType() === 28 /* KeywordType.Not */) {
|
2558
2562
|
const tokenAfterNot = this._peekToken(1);
|
2559
|
-
if (tokenAfterNot.type === 8 /* Keyword */ &&
|
2560
|
-
tokenAfterNot.keywordType === 22 /* In */) {
|
2563
|
+
if (tokenAfterNot.type === 8 /* TokenType.Keyword */ &&
|
2564
|
+
tokenAfterNot.keywordType === 22 /* KeywordType.In */) {
|
2561
2565
|
this._getNextToken();
|
2562
2566
|
this._getNextToken();
|
2563
|
-
comparisonOperator = 42 /* NotIn */;
|
2567
|
+
comparisonOperator = 42 /* OperatorType.NotIn */;
|
2564
2568
|
}
|
2565
2569
|
}
|
2566
2570
|
if (comparisonOperator === undefined) {
|
@@ -2574,60 +2578,60 @@ class Parser {
|
|
2574
2578
|
// expr: xor_expr ('|' xor_expr)*
|
2575
2579
|
_parseBitwiseOrExpression() {
|
2576
2580
|
let leftExpr = this._parseBitwiseXorExpression();
|
2577
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2581
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2578
2582
|
return leftExpr;
|
2579
2583
|
}
|
2580
2584
|
while (true) {
|
2581
2585
|
const peekToken = this._peekToken();
|
2582
|
-
if (!this._consumeTokenIfOperator(6 /* BitwiseOr */)) {
|
2586
|
+
if (!this._consumeTokenIfOperator(6 /* OperatorType.BitwiseOr */)) {
|
2583
2587
|
break;
|
2584
2588
|
}
|
2585
2589
|
const rightExpr = this._parseBitwiseXorExpression();
|
2586
|
-
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 6 /* BitwiseOr */);
|
2590
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 6 /* OperatorType.BitwiseOr */);
|
2587
2591
|
}
|
2588
2592
|
return leftExpr;
|
2589
2593
|
}
|
2590
2594
|
// xor_expr: and_expr ('^' and_expr)*
|
2591
2595
|
_parseBitwiseXorExpression() {
|
2592
2596
|
let leftExpr = this._parseBitwiseAndExpression();
|
2593
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2597
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2594
2598
|
return leftExpr;
|
2595
2599
|
}
|
2596
2600
|
while (true) {
|
2597
2601
|
const peekToken = this._peekToken();
|
2598
|
-
if (!this._consumeTokenIfOperator(8 /* BitwiseXor */)) {
|
2602
|
+
if (!this._consumeTokenIfOperator(8 /* OperatorType.BitwiseXor */)) {
|
2599
2603
|
break;
|
2600
2604
|
}
|
2601
2605
|
const rightExpr = this._parseBitwiseAndExpression();
|
2602
|
-
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 8 /* BitwiseXor */);
|
2606
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 8 /* OperatorType.BitwiseXor */);
|
2603
2607
|
}
|
2604
2608
|
return leftExpr;
|
2605
2609
|
}
|
2606
2610
|
// and_expr: shift_expr ('&' shift_expr)*
|
2607
2611
|
_parseBitwiseAndExpression() {
|
2608
2612
|
let leftExpr = this._parseShiftExpression();
|
2609
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2613
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2610
2614
|
return leftExpr;
|
2611
2615
|
}
|
2612
2616
|
while (true) {
|
2613
2617
|
const peekToken = this._peekToken();
|
2614
|
-
if (!this._consumeTokenIfOperator(3 /* BitwiseAnd */)) {
|
2618
|
+
if (!this._consumeTokenIfOperator(3 /* OperatorType.BitwiseAnd */)) {
|
2615
2619
|
break;
|
2616
2620
|
}
|
2617
2621
|
const rightExpr = this._parseShiftExpression();
|
2618
|
-
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 3 /* BitwiseAnd */);
|
2622
|
+
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 3 /* OperatorType.BitwiseAnd */);
|
2619
2623
|
}
|
2620
2624
|
return leftExpr;
|
2621
2625
|
}
|
2622
2626
|
// shift_expr: arith_expr (('<<'|'>>') arith_expr)*
|
2623
2627
|
_parseShiftExpression() {
|
2624
2628
|
let leftExpr = this._parseArithmeticExpression();
|
2625
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2629
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2626
2630
|
return leftExpr;
|
2627
2631
|
}
|
2628
2632
|
let peekToken = this._peekToken();
|
2629
2633
|
let nextOperator = this._peekOperatorType();
|
2630
|
-
while (nextOperator === 17 /* LeftShift */ || nextOperator === 31 /* RightShift */) {
|
2634
|
+
while (nextOperator === 17 /* OperatorType.LeftShift */ || nextOperator === 31 /* OperatorType.RightShift */) {
|
2631
2635
|
this._getNextToken();
|
2632
2636
|
const rightExpr = this._parseArithmeticExpression();
|
2633
2637
|
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
@@ -2639,15 +2643,15 @@ class Parser {
|
|
2639
2643
|
// arith_expr: term (('+'|'-') term)*
|
2640
2644
|
_parseArithmeticExpression() {
|
2641
2645
|
let leftExpr = this._parseArithmeticTerm();
|
2642
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2646
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2643
2647
|
return leftExpr;
|
2644
2648
|
}
|
2645
2649
|
let peekToken = this._peekToken();
|
2646
2650
|
let nextOperator = this._peekOperatorType();
|
2647
|
-
while (nextOperator === 0 /* Add */ || nextOperator === 33 /* Subtract */) {
|
2651
|
+
while (nextOperator === 0 /* OperatorType.Add */ || nextOperator === 33 /* OperatorType.Subtract */) {
|
2648
2652
|
this._getNextToken();
|
2649
2653
|
const rightExpr = this._parseArithmeticTerm();
|
2650
|
-
if (rightExpr.nodeType === 0 /* Error */) {
|
2654
|
+
if (rightExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2651
2655
|
return rightExpr;
|
2652
2656
|
}
|
2653
2657
|
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
@@ -2659,16 +2663,16 @@ class Parser {
|
|
2659
2663
|
// term: factor (('*'|'@'|'/'|'%'|'//') factor)*
|
2660
2664
|
_parseArithmeticTerm() {
|
2661
2665
|
let leftExpr = this._parseArithmeticFactor();
|
2662
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2666
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2663
2667
|
return leftExpr;
|
2664
2668
|
}
|
2665
2669
|
let peekToken = this._peekToken();
|
2666
2670
|
let nextOperator = this._peekOperatorType();
|
2667
|
-
while (nextOperator === 26 /* Multiply */ ||
|
2668
|
-
nextOperator === 22 /* MatrixMultiply */ ||
|
2669
|
-
nextOperator === 10 /* Divide */ ||
|
2670
|
-
nextOperator === 24 /* Mod */ ||
|
2671
|
-
nextOperator === 13 /* FloorDivide */) {
|
2671
|
+
while (nextOperator === 26 /* OperatorType.Multiply */ ||
|
2672
|
+
nextOperator === 22 /* OperatorType.MatrixMultiply */ ||
|
2673
|
+
nextOperator === 10 /* OperatorType.Divide */ ||
|
2674
|
+
nextOperator === 24 /* OperatorType.Mod */ ||
|
2675
|
+
nextOperator === 13 /* OperatorType.FloorDivide */) {
|
2672
2676
|
this._getNextToken();
|
2673
2677
|
const rightExpr = this._parseArithmeticFactor();
|
2674
2678
|
leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
|
@@ -2682,21 +2686,21 @@ class Parser {
|
|
2682
2686
|
_parseArithmeticFactor() {
|
2683
2687
|
const nextToken = this._peekToken();
|
2684
2688
|
const nextOperator = this._peekOperatorType();
|
2685
|
-
if (nextOperator === 0 /* Add */ ||
|
2686
|
-
nextOperator === 33 /* Subtract */ ||
|
2687
|
-
nextOperator === 5 /* BitwiseInvert */) {
|
2689
|
+
if (nextOperator === 0 /* OperatorType.Add */ ||
|
2690
|
+
nextOperator === 33 /* OperatorType.Subtract */ ||
|
2691
|
+
nextOperator === 5 /* OperatorType.BitwiseInvert */) {
|
2688
2692
|
this._getNextToken();
|
2689
2693
|
const expression = this._parseArithmeticFactor();
|
2690
2694
|
return this._createUnaryOperationNode(nextToken, expression, nextOperator);
|
2691
2695
|
}
|
2692
2696
|
const leftExpr = this._parseAtomExpression();
|
2693
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
2697
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
2694
2698
|
return leftExpr;
|
2695
2699
|
}
|
2696
2700
|
const peekToken = this._peekToken();
|
2697
|
-
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
2701
|
+
if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
2698
2702
|
const rightExpr = this._parseArithmeticFactor();
|
2699
|
-
return this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 29 /* Power */);
|
2703
|
+
return this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, 29 /* OperatorType.Power */);
|
2700
2704
|
}
|
2701
2705
|
return leftExpr;
|
2702
2706
|
}
|
@@ -2705,14 +2709,14 @@ class Parser {
|
|
2705
2709
|
// time. We assume here that the code isn't making use of some custom type alias
|
2706
2710
|
// to refer to the typing types.
|
2707
2711
|
_isTypingAnnotation(typeAnnotation, name) {
|
2708
|
-
if (typeAnnotation.nodeType === 38 /* Name */) {
|
2712
|
+
if (typeAnnotation.nodeType === 38 /* ParseNodeType.Name */) {
|
2709
2713
|
const alias = this._typingSymbolAliases.get(typeAnnotation.value);
|
2710
2714
|
if (alias === name) {
|
2711
2715
|
return true;
|
2712
2716
|
}
|
2713
2717
|
}
|
2714
|
-
else if (typeAnnotation.nodeType === 35 /* MemberAccess */) {
|
2715
|
-
if (typeAnnotation.leftExpression.nodeType === 38 /* Name */ &&
|
2718
|
+
else if (typeAnnotation.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2719
|
+
if (typeAnnotation.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
2716
2720
|
typeAnnotation.memberName.value === name) {
|
2717
2721
|
const baseName = typeAnnotation.leftExpression.value;
|
2718
2722
|
return this._typingImportAliases.some((alias) => alias === baseName);
|
@@ -2724,21 +2728,21 @@ class Parser {
|
|
2724
2728
|
// trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
2725
2729
|
_parseAtomExpression() {
|
2726
2730
|
let awaitToken;
|
2727
|
-
if (this._peekKeywordType() === 4 /* Await */ && !this._isParsingTypeAnnotation) {
|
2728
|
-
awaitToken = this._getKeywordToken(4 /* Await */);
|
2731
|
+
if (this._peekKeywordType() === 4 /* KeywordType.Await */ && !this._isParsingTypeAnnotation) {
|
2732
|
+
awaitToken = this._getKeywordToken(4 /* KeywordType.Await */);
|
2729
2733
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_5) {
|
2730
2734
|
this._addError(localize_1.Localizer.Diagnostic.awaitIllegal(), awaitToken);
|
2731
2735
|
}
|
2732
2736
|
}
|
2733
2737
|
let atomExpression = this._parseAtom();
|
2734
|
-
if (atomExpression.nodeType === 0 /* Error */) {
|
2738
|
+
if (atomExpression.nodeType === 0 /* ParseNodeType.Error */) {
|
2735
2739
|
return atomExpression;
|
2736
2740
|
}
|
2737
2741
|
// Consume trailers.
|
2738
2742
|
while (true) {
|
2739
2743
|
// Is it a function call?
|
2740
2744
|
const startOfTrailerToken = this._peekToken();
|
2741
|
-
if (this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
2745
|
+
if (this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */)) {
|
2742
2746
|
// Generally, function calls are not allowed within type annotations,
|
2743
2747
|
// but they are permitted in "Annotated" annotations.
|
2744
2748
|
const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
|
@@ -2747,7 +2751,7 @@ class Parser {
|
|
2747
2751
|
const callNode = parseNodes_1.CallNode.create(atomExpression, argListResult.args, argListResult.trailingComma);
|
2748
2752
|
if (argListResult.args.length > 1 || argListResult.trailingComma) {
|
2749
2753
|
argListResult.args.forEach((arg) => {
|
2750
|
-
if (arg.valueExpression.nodeType === 32 /* ListComprehension */) {
|
2754
|
+
if (arg.valueExpression.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
2751
2755
|
if (!arg.valueExpression.isParenthesized) {
|
2752
2756
|
this._addError(localize_1.Localizer.Diagnostic.generatorNotParenthesized(), arg.valueExpression);
|
2753
2757
|
}
|
@@ -2756,11 +2760,11 @@ class Parser {
|
|
2756
2760
|
}
|
2757
2761
|
const nextToken = this._peekToken();
|
2758
2762
|
let isArgListTerminated = false;
|
2759
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
2763
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
2760
2764
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), startOfTrailerToken);
|
2761
2765
|
// Consume the remainder of tokens on the line for error
|
2762
2766
|
// recovery.
|
2763
|
-
this._consumeTokensUntilType([2 /* NewLine */]);
|
2767
|
+
this._consumeTokensUntilType([2 /* TokenType.NewLine */]);
|
2764
2768
|
// Extend the node's range to include the rest of the line.
|
2765
2769
|
// This helps the signatureHelpProvider.
|
2766
2770
|
(0, parseNodes_1.extendRange)(callNode, this._peekToken());
|
@@ -2772,7 +2776,7 @@ class Parser {
|
|
2772
2776
|
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
2773
2777
|
atomExpression = callNode;
|
2774
2778
|
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2775
|
-
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2779
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
2776
2780
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2777
2781
|
}
|
2778
2782
|
// If the argument list wasn't terminated, break out of the loop
|
@@ -2780,7 +2784,7 @@ class Parser {
|
|
2780
2784
|
break;
|
2781
2785
|
}
|
2782
2786
|
}
|
2783
|
-
else if (this._consumeTokenIfType(15 /* OpenBracket */)) {
|
2787
|
+
else if (this._consumeTokenIfType(15 /* TokenType.OpenBracket */)) {
|
2784
2788
|
// Is it an index operator?
|
2785
2789
|
// This is an unfortunate hack that's necessary to accommodate 'Literal'
|
2786
2790
|
// and 'Annotated' type annotations properly. We need to suspend treating
|
@@ -2798,26 +2802,26 @@ class Parser {
|
|
2798
2802
|
const closingToken = this._peekToken();
|
2799
2803
|
const indexNode = parseNodes_1.IndexNode.create(atomExpression, subscriptList.list, subscriptList.trailingComma, closingToken);
|
2800
2804
|
(0, parseNodes_1.extendRange)(indexNode, indexNode);
|
2801
|
-
if (!this._consumeTokenIfType(16 /* CloseBracket */)) {
|
2805
|
+
if (!this._consumeTokenIfType(16 /* TokenType.CloseBracket */)) {
|
2802
2806
|
// Handle the error case, but don't use the error node in this
|
2803
2807
|
// case because it creates problems for the completion provider.
|
2804
|
-
this._handleExpressionParseError(6 /* MissingIndexCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startOfTrailerToken, indexNode);
|
2808
|
+
this._handleExpressionParseError(6 /* ErrorExpressionCategory.MissingIndexCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startOfTrailerToken, indexNode);
|
2805
2809
|
}
|
2806
2810
|
atomExpression = indexNode;
|
2807
2811
|
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2808
|
-
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2812
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
2809
2813
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2810
2814
|
}
|
2811
2815
|
}
|
2812
|
-
else if (this._consumeTokenIfType(20 /* Dot */)) {
|
2816
|
+
else if (this._consumeTokenIfType(20 /* TokenType.Dot */)) {
|
2813
2817
|
// Is it a member access?
|
2814
2818
|
const memberName = this._getTokenIfIdentifier();
|
2815
2819
|
if (!memberName) {
|
2816
|
-
return this._handleExpressionParseError(7 /* MissingMemberAccessName */, localize_1.Localizer.Diagnostic.expectedMemberName(), startOfTrailerToken, atomExpression, [8 /* Keyword */]);
|
2820
|
+
return this._handleExpressionParseError(7 /* ErrorExpressionCategory.MissingMemberAccessName */, localize_1.Localizer.Diagnostic.expectedMemberName(), startOfTrailerToken, atomExpression, [8 /* TokenType.Keyword */]);
|
2817
2821
|
}
|
2818
2822
|
atomExpression = parseNodes_1.MemberAccessNode.create(atomExpression, parseNodes_1.NameNode.create(memberName));
|
2819
2823
|
if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
|
2820
|
-
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* MaxDepthExceeded */);
|
2824
|
+
atomExpression = parseNodes_1.ErrorNode.create(atomExpression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
2821
2825
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
|
2822
2826
|
}
|
2823
2827
|
}
|
@@ -2837,33 +2841,33 @@ class Parser {
|
|
2837
2841
|
let trailingComma = false;
|
2838
2842
|
while (true) {
|
2839
2843
|
const firstToken = this._peekToken();
|
2840
|
-
if (firstToken.type !== 10 /* Colon */ && this._isNextTokenNeverExpression()) {
|
2844
|
+
if (firstToken.type !== 10 /* TokenType.Colon */ && this._isNextTokenNeverExpression()) {
|
2841
2845
|
break;
|
2842
2846
|
}
|
2843
|
-
let argType = 0 /* Simple */;
|
2844
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
2845
|
-
argType = 1 /* UnpackedList */;
|
2847
|
+
let argType = 0 /* ArgumentCategory.Simple */;
|
2848
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
2849
|
+
argType = 1 /* ArgumentCategory.UnpackedList */;
|
2846
2850
|
}
|
2847
|
-
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
2848
|
-
argType = 2 /* UnpackedDictionary */;
|
2851
|
+
else if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
2852
|
+
argType = 2 /* ArgumentCategory.UnpackedDictionary */;
|
2849
2853
|
}
|
2850
2854
|
const startOfSubscriptIndex = this._tokenIndex;
|
2851
2855
|
let valueExpr = this._parsePossibleSlice();
|
2852
2856
|
let nameIdentifier;
|
2853
2857
|
// Is this a keyword argument?
|
2854
|
-
if (argType === 0 /* Simple */) {
|
2855
|
-
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
2858
|
+
if (argType === 0 /* ArgumentCategory.Simple */) {
|
2859
|
+
if (this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
2856
2860
|
const nameExpr = valueExpr;
|
2857
2861
|
valueExpr = this._parsePossibleSlice();
|
2858
|
-
if (nameExpr.nodeType === 38 /* Name */) {
|
2862
|
+
if (nameExpr.nodeType === 38 /* ParseNodeType.Name */) {
|
2859
2863
|
nameIdentifier = nameExpr.token;
|
2860
2864
|
}
|
2861
2865
|
else {
|
2862
2866
|
this._addError(localize_1.Localizer.Diagnostic.expectedParamName(), nameExpr);
|
2863
2867
|
}
|
2864
2868
|
}
|
2865
|
-
else if (valueExpr.nodeType === 38 /* Name */ &&
|
2866
|
-
this._peekOperatorType() === 35 /* Walrus */) {
|
2869
|
+
else if (valueExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2870
|
+
this._peekOperatorType() === 35 /* OperatorType.Walrus */) {
|
2867
2871
|
this._tokenIndex = startOfSubscriptIndex;
|
2868
2872
|
valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
2869
2873
|
// Python 3.10 and newer allow assignment expressions to be used inside of a subscript.
|
@@ -2880,25 +2884,25 @@ class Parser {
|
|
2880
2884
|
if (argNode.name) {
|
2881
2885
|
sawKeywordArg = true;
|
2882
2886
|
}
|
2883
|
-
else if (sawKeywordArg && argNode.argumentCategory === 0 /* Simple */) {
|
2887
|
+
else if (sawKeywordArg && argNode.argumentCategory === 0 /* ArgumentCategory.Simple */) {
|
2884
2888
|
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), argNode);
|
2885
2889
|
}
|
2886
2890
|
argList.push(argNode);
|
2887
2891
|
if (argNode.name) {
|
2888
2892
|
this._addError(localize_1.Localizer.Diagnostic.keywordSubscriptIllegal(), argNode.name);
|
2889
2893
|
}
|
2890
|
-
if (argType !== 0 /* Simple */) {
|
2894
|
+
if (argType !== 0 /* ArgumentCategory.Simple */) {
|
2891
2895
|
const unpackListAllowed = this._parseOptions.isStubFile ||
|
2892
2896
|
this._isParsingQuotedText ||
|
2893
2897
|
this._getLanguageVersion() >= pythonVersion_1.PythonVersion.V3_11;
|
2894
|
-
if (argType === 1 /* UnpackedList */ && !unpackListAllowed) {
|
2898
|
+
if (argType === 1 /* ArgumentCategory.UnpackedList */ && !unpackListAllowed) {
|
2895
2899
|
this._addError(localize_1.Localizer.Diagnostic.unpackedSubscriptIllegal(), argNode);
|
2896
2900
|
}
|
2897
|
-
if (argType === 2 /* UnpackedDictionary */) {
|
2901
|
+
if (argType === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
2898
2902
|
this._addError(localize_1.Localizer.Diagnostic.unpackedDictSubscriptIllegal(), argNode);
|
2899
2903
|
}
|
2900
2904
|
}
|
2901
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2905
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2902
2906
|
trailingComma = false;
|
2903
2907
|
break;
|
2904
2908
|
}
|
@@ -2906,10 +2910,10 @@ class Parser {
|
|
2906
2910
|
}
|
2907
2911
|
// An empty subscript list is illegal.
|
2908
2912
|
if (argList.length === 0) {
|
2909
|
-
const errorNode = this._handleExpressionParseError(3 /* MissingIndexOrSlice */, localize_1.Localizer.Diagnostic.expectedSliceIndex(),
|
2913
|
+
const errorNode = this._handleExpressionParseError(3 /* ErrorExpressionCategory.MissingIndexOrSlice */, localize_1.Localizer.Diagnostic.expectedSliceIndex(),
|
2910
2914
|
/* targetToken */ undefined,
|
2911
|
-
/* childNode */ undefined, [16 /* CloseBracket */]);
|
2912
|
-
argList.push(parseNodes_1.ArgumentNode.create(this._peekToken(), errorNode, 0 /* Simple */));
|
2915
|
+
/* childNode */ undefined, [16 /* TokenType.CloseBracket */]);
|
2916
|
+
argList.push(parseNodes_1.ArgumentNode.create(this._peekToken(), errorNode, 0 /* ArgumentCategory.Simple */));
|
2913
2917
|
}
|
2914
2918
|
return {
|
2915
2919
|
list: argList,
|
@@ -2925,16 +2929,16 @@ class Parser {
|
|
2925
2929
|
let sawColon = false;
|
2926
2930
|
while (true) {
|
2927
2931
|
const nextTokenType = this._peekTokenType();
|
2928
|
-
if (nextTokenType === 16 /* CloseBracket */ || nextTokenType === 12 /* Comma */) {
|
2932
|
+
if (nextTokenType === 16 /* TokenType.CloseBracket */ || nextTokenType === 12 /* TokenType.Comma */) {
|
2929
2933
|
break;
|
2930
2934
|
}
|
2931
|
-
if (nextTokenType !== 10 /* Colon */) {
|
2935
|
+
if (nextTokenType !== 10 /* TokenType.Colon */) {
|
2932
2936
|
// Python 3.10 and newer allow assignment expressions to be used inside of a subscript.
|
2933
2937
|
const allowAssignmentExpression = this._parseOptions.isStubFile || this._getLanguageVersion() >= pythonVersion_1.PythonVersion.V3_10;
|
2934
2938
|
sliceExpressions[sliceIndex] = this._parseTestExpression(allowAssignmentExpression);
|
2935
2939
|
}
|
2936
2940
|
sliceIndex++;
|
2937
|
-
if (sliceIndex >= 3 || !this._consumeTokenIfType(10 /* Colon */)) {
|
2941
|
+
if (sliceIndex >= 3 || !this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
2938
2942
|
break;
|
2939
2943
|
}
|
2940
2944
|
sawColon = true;
|
@@ -2944,7 +2948,7 @@ class Parser {
|
|
2944
2948
|
if (sliceExpressions[0]) {
|
2945
2949
|
return sliceExpressions[0];
|
2946
2950
|
}
|
2947
|
-
return parseNodes_1.ErrorNode.create(this._peekToken(), 3 /* MissingIndexOrSlice */);
|
2951
|
+
return parseNodes_1.ErrorNode.create(this._peekToken(), 3 /* ErrorExpressionCategory.MissingIndexOrSlice */);
|
2948
2952
|
}
|
2949
2953
|
const sliceNode = parseNodes_1.SliceNode.create(firstToken);
|
2950
2954
|
sliceNode.startValue = sliceExpressions[0];
|
@@ -2972,9 +2976,9 @@ class Parser {
|
|
2972
2976
|
let trailingComma = false;
|
2973
2977
|
while (true) {
|
2974
2978
|
const nextTokenType = this._peekTokenType();
|
2975
|
-
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
2976
|
-
nextTokenType === 2 /* NewLine */ ||
|
2977
|
-
nextTokenType === 1 /* EndOfStream */) {
|
2979
|
+
if (nextTokenType === 14 /* TokenType.CloseParenthesis */ ||
|
2980
|
+
nextTokenType === 2 /* TokenType.NewLine */ ||
|
2981
|
+
nextTokenType === 1 /* TokenType.EndOfStream */) {
|
2978
2982
|
break;
|
2979
2983
|
}
|
2980
2984
|
trailingComma = false;
|
@@ -2982,11 +2986,11 @@ class Parser {
|
|
2982
2986
|
if (arg.name) {
|
2983
2987
|
sawKeywordArg = true;
|
2984
2988
|
}
|
2985
|
-
else if (sawKeywordArg && arg.argumentCategory === 0 /* Simple */) {
|
2989
|
+
else if (sawKeywordArg && arg.argumentCategory === 0 /* ArgumentCategory.Simple */) {
|
2986
2990
|
this._addError(localize_1.Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
|
2987
2991
|
}
|
2988
2992
|
argList.push(arg);
|
2989
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
2993
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
2990
2994
|
break;
|
2991
2995
|
}
|
2992
2996
|
trailingComma = true;
|
@@ -2999,20 +3003,20 @@ class Parser {
|
|
2999
3003
|
// '*' test )
|
3000
3004
|
_parseArgument() {
|
3001
3005
|
const firstToken = this._peekToken();
|
3002
|
-
let argType = 0 /* Simple */;
|
3003
|
-
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
3004
|
-
argType = 1 /* UnpackedList */;
|
3006
|
+
let argType = 0 /* ArgumentCategory.Simple */;
|
3007
|
+
if (this._consumeTokenIfOperator(26 /* OperatorType.Multiply */)) {
|
3008
|
+
argType = 1 /* ArgumentCategory.UnpackedList */;
|
3005
3009
|
}
|
3006
|
-
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
3007
|
-
argType = 2 /* UnpackedDictionary */;
|
3010
|
+
else if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
3011
|
+
argType = 2 /* ArgumentCategory.UnpackedDictionary */;
|
3008
3012
|
}
|
3009
3013
|
let valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
3010
3014
|
let nameIdentifier;
|
3011
|
-
if (argType === 0 /* Simple */) {
|
3012
|
-
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
3015
|
+
if (argType === 0 /* ArgumentCategory.Simple */) {
|
3016
|
+
if (this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
3013
3017
|
const nameExpr = valueExpr;
|
3014
3018
|
valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
3015
|
-
if (nameExpr.nodeType === 38 /* Name */) {
|
3019
|
+
if (nameExpr.nodeType === 38 /* ParseNodeType.Name */) {
|
3016
3020
|
nameIdentifier = nameExpr.token;
|
3017
3021
|
}
|
3018
3022
|
else {
|
@@ -3039,59 +3043,59 @@ class Parser {
|
|
3039
3043
|
// NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False' | '__debug__')
|
3040
3044
|
_parseAtom() {
|
3041
3045
|
const nextToken = this._peekToken();
|
3042
|
-
if (nextToken.type === 19 /* Ellipsis */) {
|
3046
|
+
if (nextToken.type === 19 /* TokenType.Ellipsis */) {
|
3043
3047
|
return parseNodes_1.EllipsisNode.create(this._getNextToken());
|
3044
3048
|
}
|
3045
|
-
if (nextToken.type === 6 /* Number */) {
|
3049
|
+
if (nextToken.type === 6 /* TokenType.Number */) {
|
3046
3050
|
return parseNodes_1.NumberNode.create(this._getNextToken());
|
3047
3051
|
}
|
3048
|
-
if (nextToken.type === 7 /* Identifier */) {
|
3052
|
+
if (nextToken.type === 7 /* TokenType.Identifier */) {
|
3049
3053
|
return parseNodes_1.NameNode.create(this._getNextToken());
|
3050
3054
|
}
|
3051
|
-
if (nextToken.type === 5 /* String */ || nextToken.type === 24 /* FStringStart */) {
|
3055
|
+
if (nextToken.type === 5 /* TokenType.String */ || nextToken.type === 24 /* TokenType.FStringStart */) {
|
3052
3056
|
return this._parseStringList();
|
3053
3057
|
}
|
3054
|
-
if (nextToken.type === 22 /* Backtick */) {
|
3058
|
+
if (nextToken.type === 22 /* TokenType.Backtick */) {
|
3055
3059
|
this._getNextToken();
|
3056
3060
|
// Atoms with backticks are no longer allowed in Python 3.x, but they
|
3057
3061
|
// were a thing in Python 2.x. We'll parse them to improve parse recovery
|
3058
3062
|
// and emit an error.
|
3059
3063
|
this._addError(localize_1.Localizer.Diagnostic.backticksIllegal(), nextToken);
|
3060
|
-
const expressionNode = this._parseTestListAsExpression(2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3061
|
-
this._consumeTokenIfType(22 /* Backtick */);
|
3064
|
+
const expressionNode = this._parseTestListAsExpression(2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3065
|
+
this._consumeTokenIfType(22 /* TokenType.Backtick */);
|
3062
3066
|
return expressionNode;
|
3063
3067
|
}
|
3064
|
-
if (nextToken.type === 13 /* OpenParenthesis */) {
|
3068
|
+
if (nextToken.type === 13 /* TokenType.OpenParenthesis */) {
|
3065
3069
|
const possibleTupleNode = this._parseTupleAtom();
|
3066
|
-
if (possibleTupleNode.nodeType === 55 /* UnaryOperation */ ||
|
3067
|
-
possibleTupleNode.nodeType === 6 /* Await */ ||
|
3068
|
-
possibleTupleNode.nodeType === 7 /* BinaryOperation */) {
|
3070
|
+
if (possibleTupleNode.nodeType === 55 /* ParseNodeType.UnaryOperation */ ||
|
3071
|
+
possibleTupleNode.nodeType === 6 /* ParseNodeType.Await */ ||
|
3072
|
+
possibleTupleNode.nodeType === 7 /* ParseNodeType.BinaryOperation */) {
|
3069
3073
|
// Mark binary expressions as parenthesized so we don't attempt
|
3070
3074
|
// to use comparison chaining, which isn't appropriate when the
|
3071
3075
|
// expression is parenthesized. Unary and await expressions
|
3072
3076
|
// are also marked to be able to display them unambiguously.
|
3073
3077
|
possibleTupleNode.parenthesized = true;
|
3074
3078
|
}
|
3075
|
-
if (possibleTupleNode.nodeType === 48 /* StringList */) {
|
3079
|
+
if (possibleTupleNode.nodeType === 48 /* ParseNodeType.StringList */) {
|
3076
3080
|
possibleTupleNode.isParenthesized = true;
|
3077
3081
|
}
|
3078
|
-
if (possibleTupleNode.nodeType === 32 /* ListComprehension */) {
|
3082
|
+
if (possibleTupleNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
3079
3083
|
possibleTupleNode.isParenthesized = true;
|
3080
3084
|
}
|
3081
3085
|
return possibleTupleNode;
|
3082
3086
|
}
|
3083
|
-
else if (nextToken.type === 15 /* OpenBracket */) {
|
3087
|
+
else if (nextToken.type === 15 /* TokenType.OpenBracket */) {
|
3084
3088
|
return this._parseListAtom();
|
3085
3089
|
}
|
3086
|
-
else if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
3090
|
+
else if (nextToken.type === 17 /* TokenType.OpenCurlyBrace */) {
|
3087
3091
|
return this._parseDictionaryOrSetAtom();
|
3088
3092
|
}
|
3089
|
-
if (nextToken.type === 8 /* Keyword */) {
|
3093
|
+
if (nextToken.type === 8 /* TokenType.Keyword */) {
|
3090
3094
|
const keywordToken = nextToken;
|
3091
|
-
if (keywordToken.keywordType === 15 /* False */ ||
|
3092
|
-
keywordToken.keywordType === 33 /* True */ ||
|
3093
|
-
keywordToken.keywordType === 9 /* Debug */ ||
|
3094
|
-
keywordToken.keywordType === 26 /* None */) {
|
3095
|
+
if (keywordToken.keywordType === 15 /* KeywordType.False */ ||
|
3096
|
+
keywordToken.keywordType === 33 /* KeywordType.True */ ||
|
3097
|
+
keywordToken.keywordType === 9 /* KeywordType.Debug */ ||
|
3098
|
+
keywordToken.keywordType === 26 /* KeywordType.None */) {
|
3095
3099
|
return parseNodes_1.ConstantNode.create(this._getNextToken());
|
3096
3100
|
}
|
3097
3101
|
// Make an identifier out of the keyword.
|
@@ -3100,7 +3104,7 @@ class Parser {
|
|
3100
3104
|
return parseNodes_1.NameNode.create(keywordAsIdentifier);
|
3101
3105
|
}
|
3102
3106
|
}
|
3103
|
-
return this._handleExpressionParseError(2 /* MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr());
|
3107
|
+
return this._handleExpressionParseError(2 /* ErrorExpressionCategory.MissingExpression */, localize_1.Localizer.Diagnostic.expectedExpr());
|
3104
3108
|
}
|
3105
3109
|
// Allocates a dummy "error expression" and consumes the remainder
|
3106
3110
|
// of the tokens on the line for error recovery. A partially-completed
|
@@ -3109,7 +3113,7 @@ class Parser {
|
|
3109
3113
|
_handleExpressionParseError(category, errorMsg, targetToken, childNode, additionalStopTokens) {
|
3110
3114
|
var _a;
|
3111
3115
|
this._addError(errorMsg, targetToken !== null && targetToken !== void 0 ? targetToken : this._peekToken());
|
3112
|
-
const stopTokens = [2 /* NewLine */];
|
3116
|
+
const stopTokens = [2 /* TokenType.NewLine */];
|
3113
3117
|
if (additionalStopTokens) {
|
3114
3118
|
(0, collectionUtils_1.appendArray)(stopTokens, additionalStopTokens);
|
3115
3119
|
}
|
@@ -3125,9 +3129,9 @@ class Parser {
|
|
3125
3129
|
}
|
3126
3130
|
// lambdef: 'lambda' [varargslist] ':' test
|
3127
3131
|
_parseLambdaExpression(allowConditional = true) {
|
3128
|
-
const lambdaToken = this._getKeywordToken(24 /* Lambda */);
|
3129
|
-
const argList = this._parseVarArgsList(10 /* Colon */, /* allowAnnotations */ false);
|
3130
|
-
if (!this._consumeTokenIfType(10 /* Colon */)) {
|
3132
|
+
const lambdaToken = this._getKeywordToken(24 /* KeywordType.Lambda */);
|
3133
|
+
const argList = this._parseVarArgsList(10 /* TokenType.Colon */, /* allowAnnotations */ false);
|
3134
|
+
if (!this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
3131
3135
|
this._addError(localize_1.Localizer.Diagnostic.expectedColon(), this._peekToken());
|
3132
3136
|
}
|
3133
3137
|
let testExpr;
|
@@ -3145,7 +3149,7 @@ class Parser {
|
|
3145
3149
|
return lambdaNode;
|
3146
3150
|
}
|
3147
3151
|
_tryParseLambdaExpression(allowConditional = true) {
|
3148
|
-
if (this._peekKeywordType() !== 24 /* Lambda */) {
|
3152
|
+
if (this._peekKeywordType() !== 24 /* KeywordType.Lambda */) {
|
3149
3153
|
return undefined;
|
3150
3154
|
}
|
3151
3155
|
return this._parseLambdaExpression(allowConditional);
|
@@ -3155,11 +3159,11 @@ class Parser {
|
|
3155
3159
|
_parseTupleAtom() {
|
3156
3160
|
var _a;
|
3157
3161
|
const startParen = this._getNextToken();
|
3158
|
-
(0, debug_1.assert)(startParen.type === 13 /* OpenParenthesis */);
|
3162
|
+
(0, debug_1.assert)(startParen.type === 13 /* TokenType.OpenParenthesis */);
|
3159
3163
|
const yieldExpr = this._tryParseYieldExpression();
|
3160
3164
|
if (yieldExpr) {
|
3161
|
-
if (this._peekTokenType() !== 14 /* CloseParenthesis */) {
|
3162
|
-
return this._handleExpressionParseError(8 /* MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, yieldExpr);
|
3165
|
+
if (this._peekTokenType() !== 14 /* TokenType.CloseParenthesis */) {
|
3166
|
+
return this._handleExpressionParseError(8 /* ErrorExpressionCategory.MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, yieldExpr);
|
3163
3167
|
}
|
3164
3168
|
else {
|
3165
3169
|
(0, parseNodes_1.extendRange)(yieldExpr, this._getNextToken());
|
@@ -3169,8 +3173,8 @@ class Parser {
|
|
3169
3173
|
const exprListResult = this._parseTestListWithComprehension(/* isGenerator */ true);
|
3170
3174
|
const tupleOrExpression = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ true);
|
3171
3175
|
(0, parseNodes_1.extendRange)(tupleOrExpression, startParen);
|
3172
|
-
if (this._peekTokenType() !== 14 /* CloseParenthesis */) {
|
3173
|
-
return this._handleExpressionParseError(8 /* MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : tupleOrExpression);
|
3176
|
+
if (this._peekTokenType() !== 14 /* TokenType.CloseParenthesis */) {
|
3177
|
+
return this._handleExpressionParseError(8 /* ErrorExpressionCategory.MissingTupleCloseParen */, localize_1.Localizer.Diagnostic.expectedCloseParen(), startParen, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : tupleOrExpression);
|
3174
3178
|
}
|
3175
3179
|
else {
|
3176
3180
|
(0, parseNodes_1.extendRange)(tupleOrExpression, this._getNextToken());
|
@@ -3182,11 +3186,11 @@ class Parser {
|
|
3182
3186
|
_parseListAtom() {
|
3183
3187
|
var _a;
|
3184
3188
|
const startBracket = this._getNextToken();
|
3185
|
-
(0, debug_1.assert)(startBracket.type === 15 /* OpenBracket */);
|
3189
|
+
(0, debug_1.assert)(startBracket.type === 15 /* TokenType.OpenBracket */);
|
3186
3190
|
const exprListResult = this._parseTestListWithComprehension(/* isGenerator */ false);
|
3187
3191
|
const closeBracket = this._peekToken();
|
3188
|
-
if (!this._consumeTokenIfType(16 /* CloseBracket */)) {
|
3189
|
-
return this._handleExpressionParseError(9 /* MissingListCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startBracket, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : _createList());
|
3192
|
+
if (!this._consumeTokenIfType(16 /* TokenType.CloseBracket */)) {
|
3193
|
+
return this._handleExpressionParseError(9 /* ErrorExpressionCategory.MissingListCloseBracket */, localize_1.Localizer.Diagnostic.expectedCloseBracket(), startBracket, (_a = exprListResult.parseError) !== null && _a !== void 0 ? _a : _createList());
|
3190
3194
|
}
|
3191
3195
|
return _createList();
|
3192
3196
|
function _createList() {
|
@@ -3225,7 +3229,7 @@ class Parser {
|
|
3225
3229
|
// setentry: test | star_expr
|
3226
3230
|
_parseDictionaryOrSetAtom() {
|
3227
3231
|
const startBrace = this._getNextToken();
|
3228
|
-
(0, debug_1.assert)(startBrace.type === 17 /* OpenCurlyBrace */);
|
3232
|
+
(0, debug_1.assert)(startBrace.type === 17 /* TokenType.OpenCurlyBrace */);
|
3229
3233
|
const dictionaryEntries = [];
|
3230
3234
|
const setEntries = [];
|
3231
3235
|
let isDictionary = false;
|
@@ -3234,7 +3238,7 @@ class Parser {
|
|
3234
3238
|
let isFirstEntry = true;
|
3235
3239
|
let trailingCommaToken;
|
3236
3240
|
while (true) {
|
3237
|
-
if (this._peekTokenType() === 18 /* CloseCurlyBrace */) {
|
3241
|
+
if (this._peekTokenType() === 18 /* TokenType.CloseCurlyBrace */) {
|
3238
3242
|
break;
|
3239
3243
|
}
|
3240
3244
|
trailingCommaToken = undefined;
|
@@ -3242,17 +3246,17 @@ class Parser {
|
|
3242
3246
|
let keyExpression;
|
3243
3247
|
let valueExpression;
|
3244
3248
|
const doubleStar = this._peekToken();
|
3245
|
-
if (this._consumeTokenIfOperator(29 /* Power */)) {
|
3249
|
+
if (this._consumeTokenIfOperator(29 /* OperatorType.Power */)) {
|
3246
3250
|
doubleStarExpression = this._parseExpression(/* allowUnpack */ false);
|
3247
3251
|
}
|
3248
3252
|
else {
|
3249
3253
|
keyExpression = this._parseTestOrStarExpression(/* allowAssignmentExpression */ true);
|
3250
|
-
if (this._consumeTokenIfType(10 /* Colon */)) {
|
3254
|
+
if (this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
3251
3255
|
valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
3252
3256
|
}
|
3253
3257
|
}
|
3254
3258
|
if (keyExpression && valueExpression) {
|
3255
|
-
if (keyExpression.nodeType === 56 /* Unpack */) {
|
3259
|
+
if (keyExpression.nodeType === 56 /* ParseNodeType.Unpack */) {
|
3256
3260
|
this._addError(localize_1.Localizer.Diagnostic.unpackInDict(), keyExpression);
|
3257
3261
|
}
|
3258
3262
|
if (isSet) {
|
@@ -3297,7 +3301,7 @@ class Parser {
|
|
3297
3301
|
(0, debug_1.assert)(keyExpression !== undefined);
|
3298
3302
|
if (keyExpression) {
|
3299
3303
|
if (isDictionary) {
|
3300
|
-
const missingValueErrorNode = parseNodes_1.ErrorNode.create(this._peekToken(), 13 /* MissingDictValue */);
|
3304
|
+
const missingValueErrorNode = parseNodes_1.ErrorNode.create(this._peekToken(), 13 /* ErrorExpressionCategory.MissingDictValue */);
|
3301
3305
|
const keyEntryNode = parseNodes_1.DictionaryKeyEntryNode.create(keyExpression, missingValueErrorNode);
|
3302
3306
|
dictionaryEntries.push(keyEntryNode);
|
3303
3307
|
this._addError(localize_1.Localizer.Diagnostic.dictKeyValuePairs(), keyExpression);
|
@@ -3320,14 +3324,14 @@ class Parser {
|
|
3320
3324
|
if (sawListComprehension) {
|
3321
3325
|
break;
|
3322
3326
|
}
|
3323
|
-
if (this._peekTokenType() !== 12 /* Comma */) {
|
3327
|
+
if (this._peekTokenType() !== 12 /* TokenType.Comma */) {
|
3324
3328
|
break;
|
3325
3329
|
}
|
3326
3330
|
trailingCommaToken = this._getNextToken();
|
3327
3331
|
isFirstEntry = false;
|
3328
3332
|
}
|
3329
3333
|
let closeCurlyBrace = this._peekToken();
|
3330
|
-
if (!this._consumeTokenIfType(18 /* CloseCurlyBrace */)) {
|
3334
|
+
if (!this._consumeTokenIfType(18 /* TokenType.CloseCurlyBrace */)) {
|
3331
3335
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBrace(), startBrace);
|
3332
3336
|
closeCurlyBrace = undefined;
|
3333
3337
|
}
|
@@ -3371,7 +3375,7 @@ class Parser {
|
|
3371
3375
|
break;
|
3372
3376
|
}
|
3373
3377
|
const expr = parser();
|
3374
|
-
if (expr.nodeType === 0 /* Error */) {
|
3378
|
+
if (expr.nodeType === 0 /* ParseNodeType.Error */) {
|
3375
3379
|
parseError = expr;
|
3376
3380
|
break;
|
3377
3381
|
}
|
@@ -3380,7 +3384,7 @@ class Parser {
|
|
3380
3384
|
if (finalEntryCheck()) {
|
3381
3385
|
break;
|
3382
3386
|
}
|
3383
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
3387
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
3384
3388
|
trailingComma = false;
|
3385
3389
|
break;
|
3386
3390
|
}
|
@@ -3398,19 +3402,19 @@ class Parser {
|
|
3398
3402
|
var _a, _b;
|
3399
3403
|
let leftExpr = this._parseTestOrStarListAsExpression(
|
3400
3404
|
/* allowAssignmentExpression */ false,
|
3401
|
-
/* allowMultipleUnpack */ false, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3405
|
+
/* allowMultipleUnpack */ false, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3402
3406
|
let annotationExpr;
|
3403
|
-
if (leftExpr.nodeType === 0 /* Error */) {
|
3407
|
+
if (leftExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
3404
3408
|
return leftExpr;
|
3405
3409
|
}
|
3406
3410
|
// Is this a type annotation assignment?
|
3407
|
-
if (this._consumeTokenIfType(10 /* Colon */)) {
|
3411
|
+
if (this._consumeTokenIfType(10 /* TokenType.Colon */)) {
|
3408
3412
|
annotationExpr = this._parseTypeAnnotation();
|
3409
3413
|
leftExpr = parseNodes_1.TypeAnnotationNode.create(leftExpr, annotationExpr);
|
3410
3414
|
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_6) {
|
3411
3415
|
this._addError(localize_1.Localizer.Diagnostic.varAnnotationIllegal(), annotationExpr);
|
3412
3416
|
}
|
3413
|
-
if (!this._consumeTokenIfOperator(2 /* Assign */)) {
|
3417
|
+
if (!this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
3414
3418
|
return leftExpr;
|
3415
3419
|
}
|
3416
3420
|
// This is an unfortunate hack that's necessary to accommodate 'TypeAlias'
|
@@ -3424,17 +3428,17 @@ class Parser {
|
|
3424
3428
|
}
|
3425
3429
|
const rightExpr = (_a = this._tryParseYieldExpression()) !== null && _a !== void 0 ? _a : this._parseTestOrStarListAsExpression(
|
3426
3430
|
/* allowAssignmentExpression */ false,
|
3427
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3431
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3428
3432
|
this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
|
3429
3433
|
return parseNodes_1.AssignmentNode.create(leftExpr, rightExpr);
|
3430
3434
|
}
|
3431
3435
|
// Is this a simple assignment?
|
3432
|
-
if (this._consumeTokenIfOperator(2 /* Assign */)) {
|
3436
|
+
if (this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
3433
3437
|
return this._parseChainAssignments(leftExpr);
|
3434
3438
|
}
|
3435
3439
|
if (tokenizer_1.Tokenizer.isOperatorAssignment(this._peekOperatorType())) {
|
3436
3440
|
const operatorToken = this._getNextToken();
|
3437
|
-
const rightExpr = (_b = this._tryParseYieldExpression()) !== null && _b !== void 0 ? _b : this._parseTestListAsExpression(2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedBinaryRightHandExpr());
|
3441
|
+
const rightExpr = (_b = this._tryParseYieldExpression()) !== null && _b !== void 0 ? _b : this._parseTestListAsExpression(2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedBinaryRightHandExpr());
|
3438
3442
|
// Make a shallow copy of the dest expression but give it a new ID.
|
3439
3443
|
const destExpr = Object.assign({}, leftExpr);
|
3440
3444
|
destExpr.id = (0, parseNodes_1.getNextNodeId)();
|
@@ -3451,12 +3455,12 @@ class Parser {
|
|
3451
3455
|
rightExpr =
|
3452
3456
|
(_a = this._tryParseYieldExpression()) !== null && _a !== void 0 ? _a : this._parseTestOrStarListAsExpression(
|
3453
3457
|
/* allowAssignmentExpression */ false,
|
3454
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3455
|
-
if (rightExpr.nodeType === 0 /* Error */) {
|
3458
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedAssignRightHandExpr());
|
3459
|
+
if (rightExpr.nodeType === 0 /* ParseNodeType.Error */) {
|
3456
3460
|
break;
|
3457
3461
|
}
|
3458
3462
|
// Continue until we've consumed the entire chain.
|
3459
|
-
if (!this._consumeTokenIfOperator(2 /* Assign */)) {
|
3463
|
+
if (!this._consumeTokenIfOperator(2 /* OperatorType.Assign */)) {
|
3460
3464
|
break;
|
3461
3465
|
}
|
3462
3466
|
assignmentTargets.push(rightExpr);
|
@@ -3489,39 +3493,39 @@ class Parser {
|
|
3489
3493
|
}
|
3490
3494
|
_parseFunctionTypeAnnotation() {
|
3491
3495
|
const openParenToken = this._peekToken();
|
3492
|
-
if (!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
3496
|
+
if (!this._consumeTokenIfType(13 /* TokenType.OpenParenthesis */)) {
|
3493
3497
|
this._addError(localize_1.Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
|
3494
3498
|
return undefined;
|
3495
3499
|
}
|
3496
3500
|
let paramAnnotations = [];
|
3497
3501
|
while (true) {
|
3498
3502
|
const nextTokenType = this._peekTokenType();
|
3499
|
-
if (nextTokenType === 14 /* CloseParenthesis */ ||
|
3500
|
-
nextTokenType === 2 /* NewLine */ ||
|
3501
|
-
nextTokenType === 1 /* EndOfStream */) {
|
3503
|
+
if (nextTokenType === 14 /* TokenType.CloseParenthesis */ ||
|
3504
|
+
nextTokenType === 2 /* TokenType.NewLine */ ||
|
3505
|
+
nextTokenType === 1 /* TokenType.EndOfStream */) {
|
3502
3506
|
break;
|
3503
3507
|
}
|
3504
3508
|
// Consume "*" or "**" indicators but don't do anything with them.
|
3505
3509
|
// (We don't enforce that these are present, absent, or match
|
3506
3510
|
// the corresponding parameter types.)
|
3507
|
-
this._consumeTokenIfOperator(26 /* Multiply */) || this._consumeTokenIfOperator(29 /* Power */);
|
3511
|
+
this._consumeTokenIfOperator(26 /* OperatorType.Multiply */) || this._consumeTokenIfOperator(29 /* OperatorType.Power */);
|
3508
3512
|
const paramAnnotation = this._parseTypeAnnotation();
|
3509
3513
|
paramAnnotations.push(paramAnnotation);
|
3510
|
-
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
3514
|
+
if (!this._consumeTokenIfType(12 /* TokenType.Comma */)) {
|
3511
3515
|
break;
|
3512
3516
|
}
|
3513
3517
|
}
|
3514
|
-
if (!this._consumeTokenIfType(14 /* CloseParenthesis */)) {
|
3518
|
+
if (!this._consumeTokenIfType(14 /* TokenType.CloseParenthesis */)) {
|
3515
3519
|
this._addError(localize_1.Localizer.Diagnostic.expectedCloseParen(), openParenToken);
|
3516
|
-
this._consumeTokensUntilType([10 /* Colon */]);
|
3520
|
+
this._consumeTokensUntilType([10 /* TokenType.Colon */]);
|
3517
3521
|
}
|
3518
|
-
if (!this._consumeTokenIfType(21 /* Arrow */)) {
|
3522
|
+
if (!this._consumeTokenIfType(21 /* TokenType.Arrow */)) {
|
3519
3523
|
this._addError(localize_1.Localizer.Diagnostic.expectedArrow(), this._peekToken());
|
3520
3524
|
return undefined;
|
3521
3525
|
}
|
3522
3526
|
const returnType = this._parseTypeAnnotation();
|
3523
3527
|
let isParamListEllipsis = false;
|
3524
|
-
if (paramAnnotations.length === 1 && paramAnnotations[0].nodeType === 18 /* Ellipsis */) {
|
3528
|
+
if (paramAnnotations.length === 1 && paramAnnotations[0].nodeType === 18 /* ParseNodeType.Ellipsis */) {
|
3525
3529
|
paramAnnotations = [];
|
3526
3530
|
isParamListEllipsis = true;
|
3527
3531
|
}
|
@@ -3533,7 +3537,7 @@ class Parser {
|
|
3533
3537
|
this._isParsingTypeAnnotation = true;
|
3534
3538
|
// Allow unpack operators.
|
3535
3539
|
const startToken = this._peekToken();
|
3536
|
-
const isUnpack = this._consumeTokenIfOperator(26 /* Multiply */);
|
3540
|
+
const isUnpack = this._consumeTokenIfOperator(26 /* OperatorType.Multiply */);
|
3537
3541
|
if (isUnpack) {
|
3538
3542
|
if (!allowUnpack) {
|
3539
3543
|
this._addError(localize_1.Localizer.Diagnostic.unpackInAnnotation(), startToken);
|
@@ -3552,20 +3556,20 @@ class Parser {
|
|
3552
3556
|
return result;
|
3553
3557
|
}
|
3554
3558
|
_reportStringTokenErrors(stringToken, unescapedResult) {
|
3555
|
-
if (stringToken.flags & 65536 /* Unterminated */) {
|
3559
|
+
if (stringToken.flags & 65536 /* StringTokenFlags.Unterminated */) {
|
3556
3560
|
this._addError(localize_1.Localizer.Diagnostic.stringUnterminated(), stringToken);
|
3557
3561
|
}
|
3558
3562
|
if (unescapedResult === null || unescapedResult === void 0 ? void 0 : unescapedResult.nonAsciiInBytes) {
|
3559
3563
|
this._addError(localize_1.Localizer.Diagnostic.stringNonAsciiBytes(), stringToken);
|
3560
3564
|
}
|
3561
|
-
if (stringToken.flags & 64 /* Format */) {
|
3565
|
+
if (stringToken.flags & 64 /* StringTokenFlags.Format */) {
|
3562
3566
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_6) {
|
3563
3567
|
this._addError(localize_1.Localizer.Diagnostic.formatStringIllegal(), stringToken);
|
3564
3568
|
}
|
3565
|
-
if (stringToken.flags & 32 /* Bytes */) {
|
3569
|
+
if (stringToken.flags & 32 /* StringTokenFlags.Bytes */) {
|
3566
3570
|
this._addError(localize_1.Localizer.Diagnostic.formatStringBytes(), stringToken);
|
3567
3571
|
}
|
3568
|
-
if (stringToken.flags & 16 /* Unicode */) {
|
3572
|
+
if (stringToken.flags & 16 /* StringTokenFlags.Unicode */) {
|
3569
3573
|
this._addError(localize_1.Localizer.Diagnostic.formatStringUnicode(), stringToken);
|
3570
3574
|
}
|
3571
3575
|
}
|
@@ -3600,7 +3604,7 @@ class Parser {
|
|
3600
3604
|
return undefined;
|
3601
3605
|
}
|
3602
3606
|
const tokenOffset = curToken.start + curToken.length + match[1].length;
|
3603
|
-
return tokenizerTypes_1.StringToken.create(tokenOffset, typeString.length, 0 /* None */, typeString, 0,
|
3607
|
+
return tokenizerTypes_1.StringToken.create(tokenOffset, typeString.length, 0 /* StringTokenFlags.None */, typeString, 0,
|
3604
3608
|
/* comments */ undefined);
|
3605
3609
|
}
|
3606
3610
|
_parseVariableTypeAnnotationComment() {
|
@@ -3611,7 +3615,7 @@ class Parser {
|
|
3611
3615
|
const stringNode = this._makeStringNode(stringToken);
|
3612
3616
|
const stringListNode = parseNodes_1.StringListNode.create([stringNode]);
|
3613
3617
|
const parser = new Parser();
|
3614
|
-
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 1 /* VariableAnnotation */,
|
3618
|
+
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 1 /* ParseTextMode.VariableAnnotation */,
|
3615
3619
|
/* initialParenDepth */ undefined, this._typingSymbolAliases);
|
3616
3620
|
parseResults.diagnostics.forEach((diag) => {
|
3617
3621
|
this._addError(diag.message, stringListNode);
|
@@ -3619,19 +3623,19 @@ class Parser {
|
|
3619
3623
|
if (!parseResults.parseTree) {
|
3620
3624
|
return undefined;
|
3621
3625
|
}
|
3622
|
-
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3626
|
+
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* ParseNodeType.FunctionAnnotation */);
|
3623
3627
|
return parseResults.parseTree;
|
3624
3628
|
}
|
3625
3629
|
_parseFunctionTypeAnnotationComment(stringToken, functionNode) {
|
3626
3630
|
const stringNode = this._makeStringNode(stringToken);
|
3627
3631
|
const stringListNode = parseNodes_1.StringListNode.create([stringNode]);
|
3628
3632
|
const parser = new Parser();
|
3629
|
-
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 2 /* FunctionAnnotation */,
|
3633
|
+
const parseResults = parser.parseTextExpression(this._fileContents, stringToken.start, stringToken.length, this._parseOptions, 2 /* ParseTextMode.FunctionAnnotation */,
|
3630
3634
|
/* initialParenDepth */ undefined, this._typingSymbolAliases);
|
3631
3635
|
parseResults.diagnostics.forEach((diag) => {
|
3632
3636
|
this._addError(diag.message, stringListNode);
|
3633
3637
|
});
|
3634
|
-
if (!parseResults.parseTree || parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */) {
|
3638
|
+
if (!parseResults.parseTree || parseResults.parseTree.nodeType !== 62 /* ParseNodeType.FunctionAnnotation */) {
|
3635
3639
|
return;
|
3636
3640
|
}
|
3637
3641
|
const functionAnnotation = parseResults.parseTree;
|
@@ -3643,19 +3647,19 @@ class Parser {
|
|
3643
3647
|
var _a;
|
3644
3648
|
let nextToken = this._getNextToken();
|
3645
3649
|
// The caller should have already confirmed that the next token is an open brace.
|
3646
|
-
(0, debug_1.assert)(nextToken.type === 17 /* OpenCurlyBrace */);
|
3650
|
+
(0, debug_1.assert)(nextToken.type === 17 /* TokenType.OpenCurlyBrace */);
|
3647
3651
|
// Consume the expression.
|
3648
3652
|
const expr = (_a = this._tryParseYieldExpression()) !== null && _a !== void 0 ? _a : this._parseTestOrStarListAsExpression(
|
3649
3653
|
/* allowAssignmentExpression */ true,
|
3650
|
-
/* allowMultipleUnpack */ true, 2 /* MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3654
|
+
/* allowMultipleUnpack */ true, 2 /* ErrorExpressionCategory.MissingExpression */, () => localize_1.Localizer.Diagnostic.expectedExpr());
|
3651
3655
|
fieldExpressions.push(expr);
|
3652
|
-
if (expr.nodeType === 0 /* Error */) {
|
3656
|
+
if (expr.nodeType === 0 /* ParseNodeType.Error */) {
|
3653
3657
|
return false;
|
3654
3658
|
}
|
3655
3659
|
// Consume an optional "=" token after the expression.
|
3656
3660
|
nextToken = this._peekToken();
|
3657
|
-
if (nextToken.type === 9 /* Operator */ &&
|
3658
|
-
nextToken.operatorType === 2 /* Assign */) {
|
3661
|
+
if (nextToken.type === 9 /* TokenType.Operator */ &&
|
3662
|
+
nextToken.operatorType === 2 /* OperatorType.Assign */) {
|
3659
3663
|
// This feature requires Python 3.8 or newer.
|
3660
3664
|
if (this._parseOptions.pythonVersion < pythonVersion_1.PythonVersion.V3_8) {
|
3661
3665
|
this._addError(localize_1.Localizer.Diagnostic.formatStringDebuggingIllegal(), nextToken);
|
@@ -3664,10 +3668,10 @@ class Parser {
|
|
3664
3668
|
nextToken = this._peekToken();
|
3665
3669
|
}
|
3666
3670
|
// Consume an optional !r, !s, or !a token.
|
3667
|
-
if (nextToken.type === 23 /* ExclamationMark */) {
|
3671
|
+
if (nextToken.type === 23 /* TokenType.ExclamationMark */) {
|
3668
3672
|
this._getNextToken();
|
3669
3673
|
nextToken = this._peekToken();
|
3670
|
-
if (nextToken.type !== 7 /* Identifier */) {
|
3674
|
+
if (nextToken.type !== 7 /* TokenType.Identifier */) {
|
3671
3675
|
this._addError(localize_1.Localizer.Diagnostic.formatStringExpectedConversion(), nextToken);
|
3672
3676
|
}
|
3673
3677
|
else {
|
@@ -3675,12 +3679,12 @@ class Parser {
|
|
3675
3679
|
nextToken = this._peekToken();
|
3676
3680
|
}
|
3677
3681
|
}
|
3678
|
-
if (nextToken.type === 10 /* Colon */) {
|
3682
|
+
if (nextToken.type === 10 /* TokenType.Colon */) {
|
3679
3683
|
this._getNextToken();
|
3680
3684
|
this._parseFStringFormatString(fieldExpressions, middleTokens, formatExpressions, nestingDepth);
|
3681
3685
|
nextToken = this._peekToken();
|
3682
3686
|
}
|
3683
|
-
if (nextToken.type !== 18 /* CloseCurlyBrace */) {
|
3687
|
+
if (nextToken.type !== 18 /* TokenType.CloseCurlyBrace */) {
|
3684
3688
|
this._addError(localize_1.Localizer.Diagnostic.formatStringUnterminated(), nextToken);
|
3685
3689
|
return false;
|
3686
3690
|
}
|
@@ -3693,14 +3697,14 @@ class Parser {
|
|
3693
3697
|
_parseFStringFormatString(fieldExpressions, middleTokens, formatExpressions, nestingDepth) {
|
3694
3698
|
while (true) {
|
3695
3699
|
const nextToken = this._peekToken();
|
3696
|
-
if (nextToken.type === 18 /* CloseCurlyBrace */ || nextToken.type === 26 /* FStringEnd */) {
|
3700
|
+
if (nextToken.type === 18 /* TokenType.CloseCurlyBrace */ || nextToken.type === 26 /* TokenType.FStringEnd */) {
|
3697
3701
|
break;
|
3698
3702
|
}
|
3699
|
-
if (nextToken.type === 25 /* FStringMiddle */) {
|
3703
|
+
if (nextToken.type === 25 /* TokenType.FStringMiddle */) {
|
3700
3704
|
this._getNextToken();
|
3701
3705
|
continue;
|
3702
3706
|
}
|
3703
|
-
if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
3707
|
+
if (nextToken.type === 17 /* TokenType.OpenCurlyBrace */) {
|
3704
3708
|
// The Python interpreter reports an error at the point where the
|
3705
3709
|
// nesting level exceeds 1. Don't report the error again for deeper nestings.
|
3706
3710
|
if (nestingDepth === 2) {
|
@@ -3720,24 +3724,24 @@ class Parser {
|
|
3720
3724
|
// Consume middle tokens and expressions until we hit a "{" or "}" token.
|
3721
3725
|
while (true) {
|
3722
3726
|
const nextToken = this._peekToken();
|
3723
|
-
if (nextToken.type === 26 /* FStringEnd */) {
|
3727
|
+
if (nextToken.type === 26 /* TokenType.FStringEnd */) {
|
3724
3728
|
endToken = nextToken;
|
3725
|
-
if ((endToken.flags & 65536 /* Unterminated */) !== 0) {
|
3729
|
+
if ((endToken.flags & 65536 /* StringTokenFlags.Unterminated */) !== 0) {
|
3726
3730
|
this._addError(localize_1.Localizer.Diagnostic.stringUnterminated(), startToken);
|
3727
3731
|
}
|
3728
3732
|
this._getNextToken();
|
3729
3733
|
break;
|
3730
3734
|
}
|
3731
|
-
if (nextToken.type === 25 /* FStringMiddle */) {
|
3735
|
+
if (nextToken.type === 25 /* TokenType.FStringMiddle */) {
|
3732
3736
|
middleTokens.push(nextToken);
|
3733
3737
|
this._getNextToken();
|
3734
3738
|
continue;
|
3735
3739
|
}
|
3736
|
-
if (nextToken.type === 17 /* OpenCurlyBrace */) {
|
3740
|
+
if (nextToken.type === 17 /* TokenType.OpenCurlyBrace */) {
|
3737
3741
|
if (!this._parseFStringReplacementField(fieldExpressions, middleTokens, formatExpressions)) {
|
3738
3742
|
// An error was reported. Try to recover the parse.
|
3739
|
-
if (this._consumeTokensUntilType([26 /* FStringEnd */, 2 /* NewLine */])) {
|
3740
|
-
if (this._peekToken().type === 26 /* FStringEnd */) {
|
3743
|
+
if (this._consumeTokensUntilType([26 /* TokenType.FStringEnd */, 2 /* TokenType.NewLine */])) {
|
3744
|
+
if (this._peekToken().type === 26 /* TokenType.FStringEnd */) {
|
3741
3745
|
this._getNextToken();
|
3742
3746
|
}
|
3743
3747
|
}
|
@@ -3746,10 +3750,10 @@ class Parser {
|
|
3746
3750
|
continue;
|
3747
3751
|
}
|
3748
3752
|
// We've hit an error. Consume tokens until we find the end.
|
3749
|
-
if (this._consumeTokensUntilType([26 /* FStringEnd */])) {
|
3753
|
+
if (this._consumeTokensUntilType([26 /* TokenType.FStringEnd */])) {
|
3750
3754
|
this._getNextToken();
|
3751
3755
|
}
|
3752
|
-
this._addError(nextToken.type === 18 /* CloseCurlyBrace */
|
3756
|
+
this._addError(nextToken.type === 18 /* TokenType.CloseCurlyBrace */
|
3753
3757
|
? localize_1.Localizer.Diagnostic.formatStringBrace()
|
3754
3758
|
: localize_1.Localizer.Diagnostic.stringUnterminated(), nextToken);
|
3755
3759
|
break;
|
@@ -3762,11 +3766,11 @@ class Parser {
|
|
3762
3766
|
// the subnode with an error node. Otherwise we risk crashing in the binder
|
3763
3767
|
// or type evaluator.
|
3764
3768
|
if (leftExpression.maxChildDepth !== undefined && leftExpression.maxChildDepth >= maxChildNodeDepth) {
|
3765
|
-
leftExpression = parseNodes_1.ErrorNode.create(leftExpression, 14 /* MaxDepthExceeded */);
|
3769
|
+
leftExpression = parseNodes_1.ErrorNode.create(leftExpression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
3766
3770
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), leftExpression);
|
3767
3771
|
}
|
3768
3772
|
if (rightExpression.maxChildDepth !== undefined && rightExpression.maxChildDepth >= maxChildNodeDepth) {
|
3769
|
-
rightExpression = parseNodes_1.ErrorNode.create(rightExpression, 14 /* MaxDepthExceeded */);
|
3773
|
+
rightExpression = parseNodes_1.ErrorNode.create(rightExpression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
3770
3774
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), rightExpression);
|
3771
3775
|
}
|
3772
3776
|
return parseNodes_1.BinaryOperationNode.create(leftExpression, rightExpression, operatorToken, operator);
|
@@ -3776,7 +3780,7 @@ class Parser {
|
|
3776
3780
|
// the subnode with an error node. Otherwise we risk crashing in the binder
|
3777
3781
|
// or type evaluator.
|
3778
3782
|
if (expression.maxChildDepth !== undefined && expression.maxChildDepth >= maxChildNodeDepth) {
|
3779
|
-
expression = parseNodes_1.ErrorNode.create(expression, 14 /* MaxDepthExceeded */);
|
3783
|
+
expression = parseNodes_1.ErrorNode.create(expression, 14 /* ErrorExpressionCategory.MaxDepthExceeded */);
|
3780
3784
|
this._addError(localize_1.Localizer.Diagnostic.maxParseDepthExceeded(), expression);
|
3781
3785
|
}
|
3782
3786
|
return parseNodes_1.UnaryOperationNode.create(operatorToken, expression, operator);
|
@@ -3785,10 +3789,10 @@ class Parser {
|
|
3785
3789
|
const stringList = [];
|
3786
3790
|
while (true) {
|
3787
3791
|
const nextToken = this._peekToken();
|
3788
|
-
if (nextToken.type === 5 /* String */) {
|
3792
|
+
if (nextToken.type === 5 /* TokenType.String */) {
|
3789
3793
|
stringList.push(this._makeStringNode(this._getNextToken()));
|
3790
3794
|
}
|
3791
|
-
else if (nextToken.type === 24 /* FStringStart */) {
|
3795
|
+
else if (nextToken.type === 24 /* TokenType.FStringStart */) {
|
3792
3796
|
stringList.push(this._parseFormatString(this._getNextToken()));
|
3793
3797
|
}
|
3794
3798
|
else {
|
@@ -3803,7 +3807,7 @@ class Parser {
|
|
3803
3807
|
if (stringNode.strings.length > 1) {
|
3804
3808
|
this._addError(localize_1.Localizer.Diagnostic.annotationSpansStrings(), stringNode);
|
3805
3809
|
}
|
3806
|
-
else if (stringNode.strings[0].nodeType === 27 /* FormatString */) {
|
3810
|
+
else if (stringNode.strings[0].nodeType === 27 /* ParseNodeType.FormatString */) {
|
3807
3811
|
this._addError(localize_1.Localizer.Diagnostic.annotationFormatString(), stringNode);
|
3808
3812
|
}
|
3809
3813
|
else {
|
@@ -3819,14 +3823,14 @@ class Parser {
|
|
3819
3823
|
}
|
3820
3824
|
else {
|
3821
3825
|
const parser = new Parser();
|
3822
|
-
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);
|
3826
|
+
const parseResults = parser.parseTextExpression(this._fileContents, tokenOffset + prefixLength, unescapedString.length, this._parseOptions, 1 /* ParseTextMode.VariableAnnotation */, (stringNode.strings[0].token.flags & 4 /* StringTokenFlags.Triplicate */) !== 0 ? 1 : 0, this._typingSymbolAliases);
|
3823
3827
|
if (parseResults.diagnostics.length === 0 ||
|
3824
3828
|
this._parseOptions.reportErrorsForParsedStringContents) {
|
3825
3829
|
parseResults.diagnostics.forEach((diag) => {
|
3826
3830
|
this._addError(diag.message, stringNode);
|
3827
3831
|
});
|
3828
3832
|
if (parseResults.parseTree) {
|
3829
|
-
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* FunctionAnnotation */);
|
3833
|
+
(0, debug_1.assert)(parseResults.parseTree.nodeType !== 62 /* ParseNodeType.FunctionAnnotation */);
|
3830
3834
|
stringNode.typeAnnotation = parseResults.parseTree;
|
3831
3835
|
stringNode.typeAnnotation.parent = stringNode;
|
3832
3836
|
}
|
@@ -3840,7 +3844,7 @@ class Parser {
|
|
3840
3844
|
// following a return or yield statement in cases where the tuple
|
3841
3845
|
// wasn't surrounded in parentheses.
|
3842
3846
|
_reportConditionalErrorForStarTupleElement(possibleTupleExpr) {
|
3843
|
-
if (possibleTupleExpr.nodeType !== 52 /* Tuple */) {
|
3847
|
+
if (possibleTupleExpr.nodeType !== 52 /* ParseNodeType.Tuple */) {
|
3844
3848
|
return;
|
3845
3849
|
}
|
3846
3850
|
if (possibleTupleExpr.enclosedInParens) {
|
@@ -3850,7 +3854,7 @@ class Parser {
|
|
3850
3854
|
return;
|
3851
3855
|
}
|
3852
3856
|
for (const expr of possibleTupleExpr.expressions) {
|
3853
|
-
if (expr.nodeType === 56 /* Unpack */) {
|
3857
|
+
if (expr.nodeType === 56 /* ParseNodeType.Unpack */) {
|
3854
3858
|
this._addError(localize_1.Localizer.Diagnostic.unpackTuplesIllegal(), expr);
|
3855
3859
|
return;
|
3856
3860
|
}
|
@@ -3861,47 +3865,47 @@ class Parser {
|
|
3861
3865
|
_isNextTokenNeverExpression() {
|
3862
3866
|
const nextToken = this._peekToken();
|
3863
3867
|
switch (nextToken.type) {
|
3864
|
-
case 8 /* Keyword */: {
|
3868
|
+
case 8 /* TokenType.Keyword */: {
|
3865
3869
|
switch (this._peekKeywordType()) {
|
3866
|
-
case 17 /* For */:
|
3867
|
-
case 22 /* In */:
|
3868
|
-
case 20 /* If */:
|
3870
|
+
case 17 /* KeywordType.For */:
|
3871
|
+
case 22 /* KeywordType.In */:
|
3872
|
+
case 20 /* KeywordType.If */:
|
3869
3873
|
return true;
|
3870
3874
|
}
|
3871
3875
|
break;
|
3872
3876
|
}
|
3873
|
-
case 9 /* Operator */: {
|
3877
|
+
case 9 /* TokenType.Operator */: {
|
3874
3878
|
switch (this._peekOperatorType()) {
|
3875
|
-
case 1 /* AddEqual */:
|
3876
|
-
case 34 /* SubtractEqual */:
|
3877
|
-
case 27 /* MultiplyEqual */:
|
3878
|
-
case 11 /* DivideEqual */:
|
3879
|
-
case 25 /* ModEqual */:
|
3880
|
-
case 4 /* BitwiseAndEqual */:
|
3881
|
-
case 7 /* BitwiseOrEqual */:
|
3882
|
-
case 9 /* BitwiseXorEqual */:
|
3883
|
-
case 18 /* LeftShiftEqual */:
|
3884
|
-
case 32 /* RightShiftEqual */:
|
3885
|
-
case 30 /* PowerEqual */:
|
3886
|
-
case 14 /* FloorDivideEqual */:
|
3887
|
-
case 2 /* Assign */:
|
3879
|
+
case 1 /* OperatorType.AddEqual */:
|
3880
|
+
case 34 /* OperatorType.SubtractEqual */:
|
3881
|
+
case 27 /* OperatorType.MultiplyEqual */:
|
3882
|
+
case 11 /* OperatorType.DivideEqual */:
|
3883
|
+
case 25 /* OperatorType.ModEqual */:
|
3884
|
+
case 4 /* OperatorType.BitwiseAndEqual */:
|
3885
|
+
case 7 /* OperatorType.BitwiseOrEqual */:
|
3886
|
+
case 9 /* OperatorType.BitwiseXorEqual */:
|
3887
|
+
case 18 /* OperatorType.LeftShiftEqual */:
|
3888
|
+
case 32 /* OperatorType.RightShiftEqual */:
|
3889
|
+
case 30 /* OperatorType.PowerEqual */:
|
3890
|
+
case 14 /* OperatorType.FloorDivideEqual */:
|
3891
|
+
case 2 /* OperatorType.Assign */:
|
3888
3892
|
return true;
|
3889
3893
|
}
|
3890
3894
|
break;
|
3891
3895
|
}
|
3892
|
-
case 3 /* Indent */:
|
3893
|
-
case 4 /* Dedent */:
|
3894
|
-
case 2 /* NewLine */:
|
3895
|
-
case 1 /* EndOfStream */:
|
3896
|
-
case 11 /* Semicolon */:
|
3897
|
-
case 14 /* CloseParenthesis */:
|
3898
|
-
case 16 /* CloseBracket */:
|
3899
|
-
case 18 /* CloseCurlyBrace */:
|
3900
|
-
case 12 /* Comma */:
|
3901
|
-
case 10 /* Colon */:
|
3902
|
-
case 23 /* ExclamationMark */:
|
3903
|
-
case 25 /* FStringMiddle */:
|
3904
|
-
case 26 /* FStringEnd */:
|
3896
|
+
case 3 /* TokenType.Indent */:
|
3897
|
+
case 4 /* TokenType.Dedent */:
|
3898
|
+
case 2 /* TokenType.NewLine */:
|
3899
|
+
case 1 /* TokenType.EndOfStream */:
|
3900
|
+
case 11 /* TokenType.Semicolon */:
|
3901
|
+
case 14 /* TokenType.CloseParenthesis */:
|
3902
|
+
case 16 /* TokenType.CloseBracket */:
|
3903
|
+
case 18 /* TokenType.CloseCurlyBrace */:
|
3904
|
+
case 12 /* TokenType.Comma */:
|
3905
|
+
case 10 /* TokenType.Colon */:
|
3906
|
+
case 23 /* TokenType.ExclamationMark */:
|
3907
|
+
case 25 /* TokenType.FStringMiddle */:
|
3908
|
+
case 26 /* TokenType.FStringEnd */:
|
3905
3909
|
return true;
|
3906
3910
|
}
|
3907
3911
|
return false;
|
@@ -3938,31 +3942,31 @@ class Parser {
|
|
3938
3942
|
}
|
3939
3943
|
_peekKeywordType() {
|
3940
3944
|
const nextToken = this._peekToken();
|
3941
|
-
if (nextToken.type !== 8 /* Keyword */) {
|
3945
|
+
if (nextToken.type !== 8 /* TokenType.Keyword */) {
|
3942
3946
|
return undefined;
|
3943
3947
|
}
|
3944
3948
|
return nextToken.keywordType;
|
3945
3949
|
}
|
3946
3950
|
_peekOperatorType() {
|
3947
3951
|
const nextToken = this._peekToken();
|
3948
|
-
if (nextToken.type !== 9 /* Operator */) {
|
3952
|
+
if (nextToken.type !== 9 /* TokenType.Operator */) {
|
3949
3953
|
return undefined;
|
3950
3954
|
}
|
3951
3955
|
return nextToken.operatorType;
|
3952
3956
|
}
|
3953
3957
|
_getTokenIfIdentifier() {
|
3954
3958
|
const nextToken = this._peekToken();
|
3955
|
-
if (nextToken.type === 7 /* Identifier */) {
|
3959
|
+
if (nextToken.type === 7 /* TokenType.Identifier */) {
|
3956
3960
|
return this._getNextToken();
|
3957
3961
|
}
|
3958
3962
|
// If the next token is invalid, treat it as an identifier.
|
3959
|
-
if (nextToken.type === 0 /* Invalid */) {
|
3963
|
+
if (nextToken.type === 0 /* TokenType.Invalid */) {
|
3960
3964
|
this._getNextToken();
|
3961
3965
|
this._addError(localize_1.Localizer.Diagnostic.invalidIdentifierChar(), nextToken);
|
3962
3966
|
return tokenizerTypes_1.IdentifierToken.create(nextToken.start, nextToken.length, '', nextToken.comments);
|
3963
3967
|
}
|
3964
3968
|
// If this is a "soft keyword", it can be converted into an identifier.
|
3965
|
-
if (nextToken.type === 8 /* Keyword */) {
|
3969
|
+
if (nextToken.type === 8 /* TokenType.Keyword */) {
|
3966
3970
|
const keywordType = this._peekKeywordType();
|
3967
3971
|
if (tokenizerTypes_1.softKeywords.find((type) => type === keywordType)) {
|
3968
3972
|
const keywordText = this._fileContents.substr(nextToken.start, nextToken.length);
|
@@ -3981,7 +3985,7 @@ class Parser {
|
|
3981
3985
|
if (terminators.some((term) => term === token.type)) {
|
3982
3986
|
return true;
|
3983
3987
|
}
|
3984
|
-
if (token.type === 1 /* EndOfStream */) {
|
3988
|
+
if (token.type === 1 /* TokenType.EndOfStream */) {
|
3985
3989
|
return false;
|
3986
3990
|
}
|
3987
3991
|
this._getNextToken();
|
@@ -4012,7 +4016,7 @@ class Parser {
|
|
4012
4016
|
}
|
4013
4017
|
_getKeywordToken(keywordType) {
|
4014
4018
|
const keywordToken = this._getNextToken();
|
4015
|
-
(0, debug_1.assert)(keywordToken.type === 8 /* Keyword */);
|
4019
|
+
(0, debug_1.assert)(keywordToken.type === 8 /* TokenType.Keyword */);
|
4016
4020
|
(0, debug_1.assert)(keywordToken.keywordType === keywordType);
|
4017
4021
|
return keywordToken;
|
4018
4022
|
}
|