brighterscript 1.0.0-alpha.5 → 1.0.0-alpha.50
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/README.md +76 -138
- package/bsconfig.schema.json +121 -5
- package/dist/ActionPipeline.d.ts +10 -0
- package/dist/ActionPipeline.js +40 -0
- package/dist/ActionPipeline.js.map +1 -0
- package/dist/AstValidationSegmenter.d.ts +45 -0
- package/dist/AstValidationSegmenter.js +322 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +72 -39
- package/dist/BusyStatusTracker.d.ts +61 -0
- package/dist/BusyStatusTracker.js +148 -0
- package/dist/BusyStatusTracker.js.map +1 -0
- package/dist/Cache.d.ts +3 -8
- package/dist/Cache.js +9 -14
- package/dist/Cache.js.map +1 -1
- package/dist/CacheVerifier.d.ts +7 -0
- package/dist/CacheVerifier.js +20 -0
- package/dist/CacheVerifier.js.map +1 -0
- package/dist/CodeActionUtil.d.ts +12 -4
- package/dist/CodeActionUtil.js +22 -5
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +7 -6
- package/dist/CommentFlagProcessor.js +11 -8
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.d.ts +68 -0
- package/dist/CrossScopeValidator.js +642 -0
- package/dist/CrossScopeValidator.js.map +1 -0
- package/dist/DependencyGraph.d.ts +8 -3
- package/dist/DependencyGraph.js +49 -16
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.d.ts +21 -5
- package/dist/DiagnosticCollection.js +77 -24
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +27 -6
- package/dist/DiagnosticFilterer.js +273 -60
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticManager.d.ts +82 -0
- package/dist/DiagnosticManager.js +406 -0
- package/dist/DiagnosticManager.js.map +1 -0
- package/dist/DiagnosticMessages.d.ts +558 -196
- package/dist/DiagnosticMessages.js +870 -340
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
- package/dist/DiagnosticSeverityAdjuster.js +45 -0
- package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
- package/dist/FunctionScope.d.ts +28 -0
- package/dist/FunctionScope.js +52 -0
- package/dist/FunctionScope.js.map +1 -0
- package/dist/KeyedThrottler.d.ts +3 -3
- package/dist/KeyedThrottler.js +3 -3
- package/dist/KeyedThrottler.js.map +1 -1
- package/dist/LanguageServer.d.ts +100 -105
- package/dist/LanguageServer.js +444 -745
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +17 -13
- package/dist/Logger.js +64 -34
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +32 -10
- package/dist/PluginInterface.js +117 -7
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +241 -98
- package/dist/Program.js +1432 -717
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +47 -23
- package/dist/ProgramBuilder.js +224 -178
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +149 -109
- package/dist/Scope.js +557 -550
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.js +5 -1
- package/dist/SemanticTokenUtils.js.map +1 -1
- package/dist/Stopwatch.d.ts +4 -0
- package/dist/Stopwatch.js +8 -1
- package/dist/Stopwatch.js.map +1 -1
- package/dist/SymbolTable.d.ts +136 -24
- package/dist/SymbolTable.js +565 -64
- package/dist/SymbolTable.js.map +1 -1
- package/dist/SymbolTypeFlag.d.ts +9 -0
- package/dist/SymbolTypeFlag.js +14 -0
- package/dist/SymbolTypeFlag.js.map +1 -0
- package/dist/Throttler.d.ts +12 -0
- package/dist/Throttler.js +39 -0
- package/dist/Throttler.js.map +1 -1
- package/dist/Watcher.d.ts +0 -3
- package/dist/Watcher.js +0 -3
- package/dist/Watcher.js.map +1 -1
- package/dist/XmlScope.d.ts +5 -15
- package/dist/XmlScope.js +34 -90
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +50 -0
- package/dist/astUtils/CachedLookups.js +334 -0
- package/dist/astUtils/CachedLookups.js.map +1 -0
- package/dist/astUtils/CachedLookups.spec.js +39 -0
- package/dist/astUtils/CachedLookups.spec.js.map +1 -0
- package/dist/astUtils/Editor.d.ts +69 -0
- package/dist/astUtils/Editor.js +245 -0
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/Editor.spec.js +258 -0
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +54 -19
- package/dist/astUtils/creators.js +242 -42
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +5 -5
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +196 -85
- package/dist/astUtils/reflection.js +497 -144
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +267 -167
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +14 -14
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +116 -53
- package/dist/astUtils/visitors.js +95 -15
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +629 -51
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +9 -8
- package/dist/astUtils/xml.js +12 -7
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +24 -4
- package/dist/bscPlugin/BscPlugin.js +88 -4
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
- package/dist/bscPlugin/CallExpressionInfo.js +143 -0
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
- package/dist/bscPlugin/FileWriter.d.ts +6 -0
- package/dist/bscPlugin/FileWriter.js +24 -0
- package/dist/bscPlugin/FileWriter.js.map +1 -0
- package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
- package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +6 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +173 -27
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +138 -21
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +65 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +633 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2512 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +212 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +87 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
- package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +230 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +991 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
- package/dist/bscPlugin/references/ReferencesProvider.js +57 -0
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +164 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +564 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +33 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +12 -0
- package/dist/bscPlugin/serialize/BslibManager.js +46 -0
- package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
- package/dist/bscPlugin/serialize/FileSerializer.js +75 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
- package/dist/bscPlugin/symbols/symbolUtils.js +141 -0
- package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +27 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +418 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +75 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.d.ts +7 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js +18 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +37 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +638 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1517 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
- package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
- package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +141 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +1323 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +6135 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +36 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/cli.js +126 -27
- package/dist/cli.js.map +1 -1
- package/dist/common/Sequencer.d.ts +53 -0
- package/dist/common/Sequencer.js +233 -0
- package/dist/common/Sequencer.js.map +1 -0
- package/dist/common/Sequencer.spec.d.ts +1 -0
- package/dist/common/Sequencer.spec.js +75 -0
- package/dist/common/Sequencer.spec.js.map +1 -0
- package/dist/deferred.d.ts +5 -3
- package/dist/deferred.js +10 -0
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +10 -3
- package/dist/diagnosticUtils.js +64 -25
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.d.ts +2 -2
- package/dist/examples/plugins/removePrint.js +8 -12
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +24 -0
- package/dist/files/AssetFile.js +25 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +1213 -259
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +145 -87
- package/dist/files/BrsFile.js +836 -934
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +4226 -902
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/BscFile.d.ts +102 -0
- package/dist/files/BscFile.js +15 -0
- package/dist/files/BscFile.js.map +1 -0
- package/dist/files/Factory.d.ts +25 -0
- package/dist/files/Factory.js +22 -0
- package/dist/files/Factory.js.map +1 -0
- package/dist/files/LazyFileData.d.ts +21 -0
- package/dist/files/LazyFileData.js +54 -0
- package/dist/files/LazyFileData.js.map +1 -0
- package/dist/files/LazyFileData.spec.d.ts +1 -0
- package/dist/files/LazyFileData.spec.js +27 -0
- package/dist/files/LazyFileData.spec.js.map +1 -0
- package/dist/files/XmlFile.d.ts +80 -41
- package/dist/files/XmlFile.js +161 -137
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +444 -336
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +62 -52
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
- package/dist/files/tests/optionalChaning.spec.js +152 -0
- package/dist/files/tests/optionalChaning.spec.js.map +1 -0
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +424 -184
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +54 -7
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +942 -125
- package/dist/interfaces.js +21 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Character.spec.js +5 -5
- package/dist/lexer/Character.spec.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +51 -12
- package/dist/lexer/Lexer.js +215 -65
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +812 -568
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +27 -11
- package/dist/lexer/Token.js +10 -2
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +40 -2
- package/dist/lexer/TokenKind.js +147 -10
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/logging.d.ts +14 -0
- package/dist/logging.js +29 -0
- package/dist/logging.js.map +1 -0
- package/dist/lsp/ActionQueue.d.ts +35 -0
- package/dist/lsp/ActionQueue.js +115 -0
- package/dist/lsp/ActionQueue.js.map +1 -0
- package/dist/lsp/ActionQueue.spec.d.ts +1 -0
- package/dist/lsp/ActionQueue.spec.js +80 -0
- package/dist/lsp/ActionQueue.spec.js.map +1 -0
- package/dist/lsp/DocumentManager.d.ts +63 -0
- package/dist/lsp/DocumentManager.js +122 -0
- package/dist/lsp/DocumentManager.js.map +1 -0
- package/dist/lsp/DocumentManager.spec.d.ts +1 -0
- package/dist/lsp/DocumentManager.spec.js +103 -0
- package/dist/lsp/DocumentManager.spec.js.map +1 -0
- package/dist/lsp/LspProject.d.ts +239 -0
- package/dist/lsp/LspProject.js +3 -0
- package/dist/lsp/LspProject.js.map +1 -0
- package/dist/lsp/PathFilterer.d.ts +75 -0
- package/dist/lsp/PathFilterer.js +196 -0
- package/dist/lsp/PathFilterer.js.map +1 -0
- package/dist/lsp/PathFilterer.spec.d.ts +1 -0
- package/dist/lsp/PathFilterer.spec.js +182 -0
- package/dist/lsp/PathFilterer.spec.js.map +1 -0
- package/dist/lsp/Project.d.ts +168 -0
- package/dist/lsp/Project.js +437 -0
- package/dist/lsp/Project.js.map +1 -0
- package/dist/lsp/Project.spec.d.ts +1 -0
- package/dist/lsp/Project.spec.js +267 -0
- package/dist/lsp/Project.spec.js.map +1 -0
- package/dist/lsp/ProjectManager.d.ts +242 -0
- package/dist/lsp/ProjectManager.js +824 -0
- package/dist/lsp/ProjectManager.js.map +1 -0
- package/dist/lsp/ProjectManager.spec.d.ts +1 -0
- package/dist/lsp/ProjectManager.spec.js +913 -0
- package/dist/lsp/ProjectManager.spec.js.map +1 -0
- package/dist/lsp/ReaderWriterManager.d.ts +21 -0
- package/dist/lsp/ReaderWriterManager.js +60 -0
- package/dist/lsp/ReaderWriterManager.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.d.ts +99 -0
- package/dist/lsp/worker/MessageHandler.js +138 -0
- package/dist/lsp/worker/MessageHandler.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.spec.d.ts +1 -0
- package/dist/lsp/worker/MessageHandler.spec.js +64 -0
- package/dist/lsp/worker/MessageHandler.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.d.ts +38 -0
- package/dist/lsp/worker/WorkerPool.js +78 -0
- package/dist/lsp/worker/WorkerPool.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.spec.d.ts +1 -0
- package/dist/lsp/worker/WorkerPool.spec.js +59 -0
- package/dist/lsp/worker/WorkerPool.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.d.ts +143 -0
- package/dist/lsp/worker/WorkerThreadProject.js +189 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +2 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js +71 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.d.ts +15 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js +58 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js.map +1 -0
- package/dist/lsp/worker/run.d.ts +1 -0
- package/dist/lsp/worker/run.js +14 -0
- package/dist/lsp/worker/run.js.map +1 -0
- package/dist/parser/AstNode.d.ts +203 -0
- package/dist/parser/AstNode.js +303 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +1455 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/BrightScriptDocParser.d.ts +56 -0
- package/dist/parser/BrightScriptDocParser.js +294 -0
- package/dist/parser/BrightScriptDocParser.js.map +1 -0
- package/dist/parser/BrightScriptDocParser.spec.d.ts +1 -0
- package/dist/parser/BrightScriptDocParser.spec.js +310 -0
- package/dist/parser/BrightScriptDocParser.spec.js.map +1 -0
- package/dist/parser/BrsTranspileState.d.ts +22 -3
- package/dist/parser/BrsTranspileState.js +19 -0
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +553 -221
- package/dist/parser/Expression.js +1414 -505
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Expression.spec.d.ts +1 -0
- package/dist/parser/Expression.spec.js +40 -0
- package/dist/parser/Expression.spec.js.map +1 -0
- package/dist/parser/Parser.Class.spec.js +255 -125
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +117 -124
- package/dist/parser/Parser.js +1669 -982
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +3 -1
- package/dist/parser/Parser.spec.js +2111 -525
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +29 -13
- package/dist/parser/SGParser.js +85 -56
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +30 -45
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +134 -46
- package/dist/parser/SGTypes.js +206 -115
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +849 -267
- package/dist/parser/Statement.js +2412 -625
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +133 -36
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +26 -12
- package/dist/parser/TranspileState.js +115 -24
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +3 -9
- package/dist/parser/tests/Parser.spec.js +7 -13
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +83 -75
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +85 -51
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +382 -239
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +52 -45
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +51 -43
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +192 -142
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +236 -160
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +41 -34
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +173 -55
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +20 -20
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +291 -282
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +193 -110
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +42 -42
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +260 -115
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +58 -52
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +76 -60
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/Relational.spec.js +50 -50
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +281 -94
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +747 -192
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +44 -44
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +500 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +119 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Declaration.spec.js +61 -55
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +29 -22
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +744 -0
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
- package/dist/parser/tests/statement/For.spec.d.ts +1 -0
- package/dist/parser/tests/statement/For.spec.js +45 -0
- package/dist/parser/tests/statement/For.spec.js.map +1 -0
- package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ForEach.spec.js +36 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/parser/tests/statement/Function.spec.js +226 -215
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +16 -15
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +64 -61
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +110 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +22 -22
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +127 -168
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +133 -114
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +57 -54
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +131 -117
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +14 -13
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +11 -8
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +6 -6
- package/dist/preprocessor/Manifest.js +17 -38
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/preprocessor/Manifest.spec.d.ts +1 -0
- package/dist/preprocessor/Manifest.spec.js +78 -103
- package/dist/preprocessor/Manifest.spec.js.map +1 -1
- package/dist/roku-types/data.json +20347 -0
- package/dist/roku-types/index.d.ts +5726 -0
- package/dist/roku-types/index.js +11 -0
- package/dist/roku-types/index.js.map +1 -0
- package/dist/types/ArrayType.d.ts +12 -5
- package/dist/types/ArrayType.js +89 -24
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +39 -11
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +15 -0
- package/dist/types/AssociativeArrayType.js +64 -0
- package/dist/types/AssociativeArrayType.js.map +1 -0
- package/dist/types/BaseFunctionType.d.ts +10 -0
- package/dist/types/BaseFunctionType.js +26 -0
- package/dist/types/BaseFunctionType.js.map +1 -0
- package/dist/types/BooleanType.d.ts +9 -5
- package/dist/types/BooleanType.js +19 -8
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +10 -4
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +41 -3
- package/dist/types/BscType.js +152 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +28 -0
- package/dist/types/BscTypeKind.js +33 -0
- package/dist/types/BscTypeKind.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.d.ts +28 -0
- package/dist/types/BuiltInInterfaceAdder.js +212 -0
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
- package/dist/types/CallFuncableType.d.ts +24 -0
- package/dist/types/CallFuncableType.js +91 -0
- package/dist/types/CallFuncableType.js.map +1 -0
- package/dist/types/ClassType.d.ts +17 -0
- package/dist/types/ClassType.js +60 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ClassType.spec.d.ts +1 -0
- package/dist/types/ClassType.spec.js +76 -0
- package/dist/types/ClassType.spec.js.map +1 -0
- package/dist/types/ComponentType.d.ts +22 -0
- package/dist/types/ComponentType.js +107 -0
- package/dist/types/ComponentType.js.map +1 -0
- package/dist/types/DoubleType.d.ts +10 -5
- package/dist/types/DoubleType.js +21 -17
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +12 -4
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +13 -5
- package/dist/types/DynamicType.js +26 -5
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +16 -5
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/EnumType.d.ts +42 -0
- package/dist/types/EnumType.js +98 -0
- package/dist/types/EnumType.js.map +1 -0
- package/dist/types/EnumType.spec.d.ts +1 -0
- package/dist/types/EnumType.spec.js +33 -0
- package/dist/types/EnumType.spec.js.map +1 -0
- package/dist/types/FloatType.d.ts +10 -5
- package/dist/types/FloatType.js +21 -17
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +4 -4
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +8 -22
- package/dist/types/FunctionType.js +25 -63
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +29 -0
- package/dist/types/InheritableType.js +173 -0
- package/dist/types/InheritableType.js.map +1 -0
- package/dist/types/InlineInterfaceType.d.ts +5 -0
- package/dist/types/InlineInterfaceType.js +17 -0
- package/dist/types/InlineInterfaceType.js.map +1 -0
- package/dist/types/IntegerType.d.ts +10 -5
- package/dist/types/IntegerType.js +21 -17
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +8 -4
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +14 -6
- package/dist/types/InterfaceType.js +30 -15
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +227 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/IntersectionType.d.ts +29 -0
- package/dist/types/IntersectionType.js +253 -0
- package/dist/types/IntersectionType.js.map +1 -0
- package/dist/types/IntersectionType.spec.d.ts +1 -0
- package/dist/types/IntersectionType.spec.js +150 -0
- package/dist/types/IntersectionType.spec.js.map +1 -0
- package/dist/types/InvalidType.d.ts +10 -5
- package/dist/types/InvalidType.js +21 -9
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +8 -4
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +10 -5
- package/dist/types/LongIntegerType.js +21 -17
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +10 -4
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +12 -0
- package/dist/types/NamespaceType.js +28 -0
- package/dist/types/NamespaceType.js.map +1 -0
- package/dist/types/ObjectType.d.ts +12 -5
- package/dist/types/ObjectType.js +25 -8
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +3 -3
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +123 -0
- package/dist/types/ReferenceType.js +720 -0
- package/dist/types/ReferenceType.js.map +1 -0
- package/dist/types/ReferenceType.spec.d.ts +1 -0
- package/dist/types/ReferenceType.spec.js +151 -0
- package/dist/types/ReferenceType.spec.js.map +1 -0
- package/dist/types/StringType.d.ts +12 -5
- package/dist/types/StringType.js +23 -8
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +3 -3
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypeStatementType.d.ts +18 -0
- package/dist/types/TypeStatementType.js +45 -0
- package/dist/types/TypeStatementType.js.map +1 -0
- package/dist/types/TypedFunctionType.d.ts +34 -0
- package/dist/types/TypedFunctionType.js +147 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +122 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.d.ts +11 -6
- package/dist/types/UninitializedType.js +20 -11
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +27 -0
- package/dist/types/UnionType.js +193 -0
- package/dist/types/UnionType.js.map +1 -0
- package/dist/types/UnionType.spec.d.ts +1 -0
- package/dist/types/UnionType.spec.js +205 -0
- package/dist/types/UnionType.spec.js.map +1 -0
- package/dist/types/VoidType.d.ts +11 -5
- package/dist/types/VoidType.js +22 -8
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +3 -3
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helper.spec.d.ts +1 -0
- package/dist/types/helper.spec.js +174 -0
- package/dist/types/helper.spec.js.map +1 -0
- package/dist/types/helpers.d.ts +51 -0
- package/dist/types/helpers.js +323 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +39 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/roFunctionType.d.ts +11 -0
- package/dist/types/roFunctionType.js +37 -0
- package/dist/types/roFunctionType.js.map +1 -0
- package/dist/types/roFunctionType.spec.d.ts +1 -0
- package/dist/types/roFunctionType.spec.js +20 -0
- package/dist/types/roFunctionType.spec.js.map +1 -0
- package/dist/util.d.ts +288 -187
- package/dist/util.js +2018 -575
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +9 -15
- package/dist/validators/ClassValidator.js +93 -138
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +185 -138
- package/CHANGELOG.md +0 -1188
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +0 -63
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +0 -45
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/SGTypes.spec.js +0 -351
- package/dist/parser/SGTypes.spec.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/Chunk.d.ts +0 -82
- package/dist/preprocessor/Chunk.js +0 -77
- package/dist/preprocessor/Chunk.js.map +0 -1
- package/dist/preprocessor/Preprocessor.d.ts +0 -60
- package/dist/preprocessor/Preprocessor.js +0 -156
- package/dist/preprocessor/Preprocessor.js.map +0 -1
- package/dist/preprocessor/Preprocessor.spec.js +0 -152
- package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
- package/dist/preprocessor/PreprocessorParser.js +0 -194
- package/dist/preprocessor/PreprocessorParser.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
- package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
- package/dist/types/CustomType.d.ts +0 -10
- package/dist/types/CustomType.js +0 -35
- package/dist/types/CustomType.js.map +0 -1
- package/dist/types/FunctionType.spec.js +0 -29
- package/dist/types/FunctionType.spec.js.map +0 -1
- package/dist/types/LazyType.d.ts +0 -15
- package/dist/types/LazyType.js +0 -32
- package/dist/types/LazyType.js.map +0 -1
- /package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/CachedLookups.spec.d.ts} +0 -0
- /package/dist/{parser/SGTypes.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
- /package/dist/{preprocessor/Preprocessor.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
- /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
- /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/hover/HoverProcessor.spec.d.ts} +0 -0
package/dist/lexer/Lexer.spec.js
CHANGED
|
@@ -1,74 +1,132 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/* eslint no-template-curly-in-string: 0 */
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const chai_config_spec_1 = require("../chai-config.spec");
|
|
5
|
+
const TokenKind_1 = require("./TokenKind");
|
|
6
6
|
const Lexer_1 = require("./Lexer");
|
|
7
7
|
const Token_1 = require("./Token");
|
|
8
8
|
const Parser_spec_1 = require("../parser/Parser.spec");
|
|
9
9
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
10
|
-
const
|
|
10
|
+
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
11
11
|
describe('lexer', () => {
|
|
12
|
+
it('recognizes the `const` keyword', () => {
|
|
13
|
+
let { tokens } = Lexer_1.Lexer.scan('const');
|
|
14
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
15
|
+
TokenKind_1.TokenKind.Const,
|
|
16
|
+
TokenKind_1.TokenKind.Eof
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
12
19
|
it('recognizes namespace keywords', () => {
|
|
13
20
|
let { tokens } = Lexer_1.Lexer.scan('namespace end namespace endnamespace end namespace');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
22
|
+
TokenKind_1.TokenKind.Namespace,
|
|
23
|
+
TokenKind_1.TokenKind.EndNamespace,
|
|
24
|
+
TokenKind_1.TokenKind.EndNamespace,
|
|
25
|
+
TokenKind_1.TokenKind.EndNamespace,
|
|
26
|
+
TokenKind_1.TokenKind.Eof
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
it('recognizes the question mark operator in various contexts', () => {
|
|
30
|
+
expectKinds('? ?? ?. ?[ ?.[ ?( ?@', [
|
|
31
|
+
TokenKind_1.TokenKind.Question,
|
|
32
|
+
TokenKind_1.TokenKind.QuestionQuestion,
|
|
33
|
+
TokenKind_1.TokenKind.QuestionDot,
|
|
34
|
+
TokenKind_1.TokenKind.QuestionLeftSquare,
|
|
35
|
+
TokenKind_1.TokenKind.QuestionDot,
|
|
36
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
37
|
+
TokenKind_1.TokenKind.QuestionLeftParen,
|
|
38
|
+
TokenKind_1.TokenKind.QuestionAt
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
it('separates optional chain characters and LeftSquare when found at beginning of statement locations', () => {
|
|
42
|
+
//a statement starting with a question mark is actually a print statement, so we need to keep the ? separate from [
|
|
43
|
+
expectKinds(`?[ ?[ : ?[ ?[`, [
|
|
44
|
+
TokenKind_1.TokenKind.Question,
|
|
45
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
46
|
+
TokenKind_1.TokenKind.QuestionLeftSquare,
|
|
47
|
+
TokenKind_1.TokenKind.Colon,
|
|
48
|
+
TokenKind_1.TokenKind.Question,
|
|
49
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
50
|
+
TokenKind_1.TokenKind.QuestionLeftSquare
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
it('separates optional chain characters and LeftParen when found at beginning of statement locations', () => {
|
|
54
|
+
//a statement starting with a question mark is actually a print statement, so we need to keep the ? separate from [
|
|
55
|
+
expectKinds(`?( ?( : ?( ?(`, [
|
|
56
|
+
TokenKind_1.TokenKind.Question,
|
|
57
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
58
|
+
TokenKind_1.TokenKind.QuestionLeftParen,
|
|
59
|
+
TokenKind_1.TokenKind.Colon,
|
|
60
|
+
TokenKind_1.TokenKind.Question,
|
|
61
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
62
|
+
TokenKind_1.TokenKind.QuestionLeftParen
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
it('handles QuestionDot and Square properly', () => {
|
|
66
|
+
expectKinds('?.[ ?. [', [
|
|
67
|
+
TokenKind_1.TokenKind.QuestionDot,
|
|
68
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
69
|
+
TokenKind_1.TokenKind.QuestionDot,
|
|
70
|
+
TokenKind_1.TokenKind.LeftSquareBracket
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
it('does not make conditional chaining tokens with space between', () => {
|
|
74
|
+
expectKinds('? . ? [ ? ( ? @', [
|
|
75
|
+
TokenKind_1.TokenKind.Question,
|
|
76
|
+
TokenKind_1.TokenKind.Dot,
|
|
77
|
+
TokenKind_1.TokenKind.Question,
|
|
78
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
79
|
+
TokenKind_1.TokenKind.Question,
|
|
80
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
81
|
+
TokenKind_1.TokenKind.Question,
|
|
82
|
+
TokenKind_1.TokenKind.At
|
|
20
83
|
]);
|
|
21
84
|
});
|
|
22
85
|
it('recognizes the callfunc operator', () => {
|
|
23
86
|
let { tokens } = Lexer_1.Lexer.scan('@.');
|
|
24
|
-
|
|
87
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Callfunc);
|
|
25
88
|
});
|
|
26
89
|
it('recognizes the import token', () => {
|
|
27
90
|
let { tokens } = Lexer_1.Lexer.scan('import');
|
|
28
|
-
|
|
91
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Import);
|
|
29
92
|
});
|
|
30
93
|
it('recognizes library token', () => {
|
|
31
94
|
let { tokens } = Lexer_1.Lexer.scan('library');
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
it('recognizes the question mark operator', () => {
|
|
35
|
-
let { tokens } = Lexer_1.Lexer.scan('?');
|
|
36
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.Question);
|
|
95
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Library);
|
|
37
96
|
});
|
|
38
97
|
it('produces an at symbol token', () => {
|
|
39
98
|
let { tokens } = Lexer_1.Lexer.scan('@');
|
|
40
|
-
|
|
99
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.At);
|
|
41
100
|
});
|
|
42
101
|
it('produces a semicolon token', () => {
|
|
43
102
|
let { tokens } = Lexer_1.Lexer.scan(';');
|
|
44
|
-
|
|
103
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Semicolon);
|
|
45
104
|
});
|
|
46
105
|
it('emits error on unknown character type', () => {
|
|
47
106
|
let { diagnostics } = Lexer_1.Lexer.scan('\0');
|
|
48
|
-
|
|
107
|
+
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1);
|
|
49
108
|
});
|
|
50
109
|
it('includes an end-of-file marker', () => {
|
|
51
110
|
let { tokens } = Lexer_1.Lexer.scan('');
|
|
52
|
-
|
|
111
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
|
|
53
112
|
});
|
|
54
113
|
it('ignores tabs and spaces', () => {
|
|
55
114
|
let { tokens } = Lexer_1.Lexer.scan('\t\t \t \t');
|
|
56
|
-
|
|
115
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
|
|
57
116
|
});
|
|
58
117
|
it('retains every single newline', () => {
|
|
59
118
|
let { tokens } = Lexer_1.Lexer.scan('\n\n\'foo\n\n\nprint 2\n\n');
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_1.TokenKind.Eof
|
|
119
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
120
|
+
TokenKind_1.TokenKind.Newline,
|
|
121
|
+
TokenKind_1.TokenKind.Newline,
|
|
122
|
+
TokenKind_1.TokenKind.Newline,
|
|
123
|
+
TokenKind_1.TokenKind.Newline,
|
|
124
|
+
TokenKind_1.TokenKind.Newline,
|
|
125
|
+
TokenKind_1.TokenKind.Print,
|
|
126
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
127
|
+
TokenKind_1.TokenKind.Newline,
|
|
128
|
+
TokenKind_1.TokenKind.Newline,
|
|
129
|
+
TokenKind_1.TokenKind.Eof
|
|
72
130
|
]);
|
|
73
131
|
});
|
|
74
132
|
it('does not insert double newlines with the windows \\r\\n newline', () => {
|
|
@@ -79,24 +137,24 @@ describe('lexer', () => {
|
|
|
79
137
|
' print 0\r\n' +
|
|
80
138
|
' end if\r\n' +
|
|
81
139
|
'end function\r\n').tokens.map(x => x.kind);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
140
|
+
(0, chai_config_spec_1.expect)(kinds).to.eql([
|
|
141
|
+
TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.LeftParen, TokenKind_1.TokenKind.RightParen, TokenKind_1.TokenKind.As, TokenKind_1.TokenKind.String, TokenKind_1.TokenKind.Newline,
|
|
142
|
+
TokenKind_1.TokenKind.If, TokenKind_1.TokenKind.True, TokenKind_1.TokenKind.Then, TokenKind_1.TokenKind.Newline,
|
|
143
|
+
TokenKind_1.TokenKind.Print, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Newline,
|
|
144
|
+
TokenKind_1.TokenKind.Else, TokenKind_1.TokenKind.Newline,
|
|
145
|
+
TokenKind_1.TokenKind.Print, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Newline,
|
|
146
|
+
TokenKind_1.TokenKind.EndIf, TokenKind_1.TokenKind.Newline,
|
|
147
|
+
TokenKind_1.TokenKind.EndFunction, TokenKind_1.TokenKind.Newline,
|
|
148
|
+
TokenKind_1.TokenKind.Eof
|
|
91
149
|
]);
|
|
92
150
|
});
|
|
93
151
|
it('computes range properly both with and without whitespace', () => {
|
|
94
152
|
let withoutWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
95
|
-
.map(x => Parser_spec_1.rangeToArray(x.range));
|
|
153
|
+
.map(x => { var _a; return (0, Parser_spec_1.rangeToArray)((_a = x.location) === null || _a === void 0 ? void 0 : _a.range); });
|
|
96
154
|
let withWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
97
155
|
//filter out the whitespace...we only care that it was computed during the scan
|
|
98
|
-
.filter(x => x.kind !==
|
|
99
|
-
.map(x => Parser_spec_1.rangeToArray(x.range));
|
|
156
|
+
.filter(x => x.kind !== TokenKind_1.TokenKind.Whitespace)
|
|
157
|
+
.map(x => { var _a; return (0, Parser_spec_1.rangeToArray)((_a = x.location) === null || _a === void 0 ? void 0 : _a.range); });
|
|
100
158
|
/*eslint-disable */
|
|
101
159
|
let expectedLocations = [
|
|
102
160
|
[0, 0, 0, 3],
|
|
@@ -112,57 +170,72 @@ describe('lexer', () => {
|
|
|
112
170
|
[2, 7, 2, 8] //Eof
|
|
113
171
|
];
|
|
114
172
|
/*eslint-enable*/
|
|
115
|
-
|
|
116
|
-
|
|
173
|
+
(0, chai_config_spec_1.expect)(withoutWhitespace, 'Without whitespace').to.eql(expectedLocations);
|
|
174
|
+
(0, chai_config_spec_1.expect)(withWhitespace, 'With whitespace').to.eql(expectedLocations);
|
|
117
175
|
});
|
|
118
176
|
it('retains original line endings', () => {
|
|
119
177
|
let { tokens } = Lexer_1.Lexer.scan('print "hello"\r\nprint "world"\n');
|
|
120
|
-
|
|
178
|
+
(0, chai_config_spec_1.expect)([
|
|
121
179
|
tokens[2].text.charCodeAt(0),
|
|
122
180
|
tokens[2].text.charCodeAt(1)
|
|
123
181
|
], 'should contain \\r\\n').to.eql([13, 10]);
|
|
124
|
-
|
|
182
|
+
(0, chai_config_spec_1.expect)(tokens[5].text.charCodeAt(0), 'should contain \\r\\n').to.eql(10);
|
|
125
183
|
});
|
|
126
184
|
it('correctly splits the elseif token', () => {
|
|
127
185
|
let { tokens } = Lexer_1.Lexer.scan('else if elseif else if');
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
186
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
187
|
+
TokenKind_1.TokenKind.Else,
|
|
188
|
+
TokenKind_1.TokenKind.If,
|
|
189
|
+
TokenKind_1.TokenKind.Else,
|
|
190
|
+
TokenKind_1.TokenKind.If,
|
|
191
|
+
TokenKind_1.TokenKind.Else,
|
|
192
|
+
TokenKind_1.TokenKind.If,
|
|
193
|
+
TokenKind_1.TokenKind.Eof
|
|
136
194
|
]);
|
|
137
195
|
});
|
|
138
196
|
it('gives the `as` keyword its own TokenKind', () => {
|
|
139
197
|
let { tokens } = Lexer_1.Lexer.scan('as');
|
|
140
|
-
|
|
198
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.As, TokenKind_1.TokenKind.Eof]);
|
|
141
199
|
});
|
|
142
200
|
it('gives the `stop` keyword its own TokenKind', () => {
|
|
143
201
|
let { tokens } = Lexer_1.Lexer.scan('stop');
|
|
144
|
-
|
|
202
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Stop, TokenKind_1.TokenKind.Eof]);
|
|
145
203
|
});
|
|
146
204
|
it('does not alias \'?\' to \'print\' - the parser will do that', () => {
|
|
147
205
|
let { tokens } = Lexer_1.Lexer.scan('?2');
|
|
148
|
-
|
|
206
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Question, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Eof]);
|
|
149
207
|
});
|
|
150
208
|
describe('comments', () => {
|
|
151
|
-
it('
|
|
209
|
+
it('are not included in output', () => {
|
|
210
|
+
let kinds = Lexer_1.Lexer.scan(`
|
|
211
|
+
'comment
|
|
212
|
+
REM some comment
|
|
213
|
+
print 1 ' comment after
|
|
214
|
+
`).tokens
|
|
215
|
+
.map(x => x.kind);
|
|
216
|
+
(0, chai_config_spec_1.expect)(kinds.length).to.eq(7);
|
|
217
|
+
(0, chai_config_spec_1.expect)(kinds).to.eql([
|
|
218
|
+
TokenKind_1.TokenKind.Newline,
|
|
219
|
+
TokenKind_1.TokenKind.Newline,
|
|
220
|
+
TokenKind_1.TokenKind.Newline,
|
|
221
|
+
TokenKind_1.TokenKind.Print,
|
|
222
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
223
|
+
TokenKind_1.TokenKind.Newline,
|
|
224
|
+
TokenKind_1.TokenKind.Eof
|
|
225
|
+
]);
|
|
226
|
+
});
|
|
227
|
+
it('do not remove Newline token from output', () => {
|
|
152
228
|
let tokens = Lexer_1.Lexer.scan(`'someComment\r\nprint "hello"`).tokens;
|
|
153
|
-
|
|
229
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Newline);
|
|
154
230
|
});
|
|
155
|
-
it('includes
|
|
231
|
+
it('includes no comment characters in the text', () => {
|
|
156
232
|
let text = Lexer_1.Lexer.scan(`
|
|
157
233
|
'comment
|
|
158
234
|
REM some comment
|
|
159
235
|
`).tokens
|
|
160
|
-
.filter(x => ![
|
|
236
|
+
.filter(x => ![TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Eof].includes(x.kind))
|
|
161
237
|
.map(x => x.text);
|
|
162
|
-
|
|
163
|
-
`'comment`,
|
|
164
|
-
'REM some comment'
|
|
165
|
-
]);
|
|
238
|
+
(0, chai_config_spec_1.expect)(text).to.eql([]);
|
|
166
239
|
});
|
|
167
240
|
it('tracks the correct location', () => {
|
|
168
241
|
let tokens = Lexer_1.Lexer.scan(`
|
|
@@ -172,8 +245,8 @@ describe('lexer', () => {
|
|
|
172
245
|
end sub
|
|
173
246
|
`, {
|
|
174
247
|
includeWhitespace: true
|
|
175
|
-
}).tokens.map(x => [...Parser_spec_1.rangeToArray(x.range), x.text]);
|
|
176
|
-
|
|
248
|
+
}).tokens.map(x => { var _a; return [...(0, Parser_spec_1.rangeToArray)((_a = x.location) === null || _a === void 0 ? void 0 : _a.range), x.text]; });
|
|
249
|
+
(0, chai_config_spec_1.expect)(tokens).to.eql([
|
|
177
250
|
[0, 0, 0, 1, '\n'],
|
|
178
251
|
[1, 0, 1, 16, ' '],
|
|
179
252
|
[1, 16, 1, 19, 'sub'],
|
|
@@ -182,7 +255,7 @@ describe('lexer', () => {
|
|
|
182
255
|
[1, 24, 1, 25, '('],
|
|
183
256
|
[1, 25, 1, 26, ')'],
|
|
184
257
|
[1, 26, 1, 27, ' '],
|
|
185
|
-
|
|
258
|
+
// skip `'first comment`
|
|
186
259
|
[1, 41, 1, 42, '\n'],
|
|
187
260
|
[2, 0, 2, 20, ' '],
|
|
188
261
|
[2, 20, 2, 21, 'k'],
|
|
@@ -191,10 +264,10 @@ describe('lexer', () => {
|
|
|
191
264
|
[2, 23, 2, 24, ' '],
|
|
192
265
|
[2, 24, 2, 25, '2'],
|
|
193
266
|
[2, 25, 2, 26, ' '],
|
|
194
|
-
|
|
267
|
+
// skip `' second comment`
|
|
195
268
|
[2, 42, 2, 43, '\n'],
|
|
196
269
|
[3, 0, 3, 20, ' '],
|
|
197
|
-
|
|
270
|
+
// skip `REM third comment`
|
|
198
271
|
[3, 37, 3, 38, '\n'],
|
|
199
272
|
[4, 0, 4, 16, ' '],
|
|
200
273
|
[4, 16, 4, 23, 'end sub'],
|
|
@@ -203,19 +276,11 @@ describe('lexer', () => {
|
|
|
203
276
|
[5, 12, 5, 13, ''] //EOF
|
|
204
277
|
]);
|
|
205
278
|
});
|
|
206
|
-
it('tracks the correct location for comments', () => {
|
|
207
|
-
let tokens = Lexer_1.Lexer.scan(`
|
|
208
|
-
'comment
|
|
209
|
-
REM some comment
|
|
210
|
-
`).tokens.filter(x => ![_1.TokenKind.Newline, _1.TokenKind.Eof].includes(x.kind));
|
|
211
|
-
chai_1.expect(tokens[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 1, 24));
|
|
212
|
-
chai_1.expect(tokens[1].range).to.eql(vscode_languageserver_1.Range.create(2, 16, 2, 32));
|
|
213
|
-
});
|
|
214
279
|
it('finds correct location for newlines', () => {
|
|
215
280
|
let tokens = Lexer_1.Lexer.scan('sub\nsub\r\nsub\n\n').tokens
|
|
216
281
|
//ignore the Eof token
|
|
217
|
-
.filter(x => x.kind !==
|
|
218
|
-
|
|
282
|
+
.filter(x => x.kind !== TokenKind_1.TokenKind.Eof);
|
|
283
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => { var _a; return (_a = x.location) === null || _a === void 0 ? void 0 : _a.range; })).to.eql([
|
|
219
284
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
220
285
|
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
221
286
|
vscode_languageserver_1.Range.create(1, 0, 1, 3),
|
|
@@ -225,112 +290,96 @@ describe('lexer', () => {
|
|
|
225
290
|
vscode_languageserver_1.Range.create(3, 0, 3, 1) // /n
|
|
226
291
|
]);
|
|
227
292
|
});
|
|
228
|
-
it('finds correct location for comment after if statement', () => {
|
|
229
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
230
|
-
sub a()
|
|
231
|
-
if true then
|
|
232
|
-
print false
|
|
233
|
-
else if true then
|
|
234
|
-
print "true"
|
|
235
|
-
else
|
|
236
|
-
print "else"
|
|
237
|
-
end if 'comment
|
|
238
|
-
end sub
|
|
239
|
-
`);
|
|
240
|
-
let comments = tokens.filter(x => x.kind === _1.TokenKind.Comment);
|
|
241
|
-
chai_1.expect(comments).to.be.lengthOf(1);
|
|
242
|
-
chai_1.expect(comments[0].range).to.eql(vscode_languageserver_1.Range.create(8, 27, 8, 35));
|
|
243
|
-
});
|
|
244
293
|
it('ignores everything after `\'`', () => {
|
|
245
294
|
let { tokens } = Lexer_1.Lexer.scan('= \' (');
|
|
246
|
-
|
|
295
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
247
296
|
});
|
|
248
297
|
it('ignores everything after `REM`', () => {
|
|
249
298
|
let { tokens } = Lexer_1.Lexer.scan('= REM (');
|
|
250
|
-
|
|
299
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
251
300
|
});
|
|
252
301
|
it('ignores everything after `rem`', () => {
|
|
253
302
|
let { tokens } = Lexer_1.Lexer.scan('= rem (');
|
|
254
|
-
|
|
303
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
255
304
|
});
|
|
256
305
|
}); // comments
|
|
257
306
|
describe('non-literals', () => {
|
|
258
307
|
it('reads parens & braces', () => {
|
|
259
308
|
let { tokens } = Lexer_1.Lexer.scan('(){}');
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
309
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
310
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
311
|
+
TokenKind_1.TokenKind.RightParen,
|
|
312
|
+
TokenKind_1.TokenKind.LeftCurlyBrace,
|
|
313
|
+
TokenKind_1.TokenKind.RightCurlyBrace,
|
|
314
|
+
TokenKind_1.TokenKind.Eof
|
|
266
315
|
]);
|
|
267
316
|
});
|
|
268
317
|
it('reads operators', () => {
|
|
269
318
|
let { tokens } = Lexer_1.Lexer.scan('^ - + * MOD / \\ -- ++');
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
319
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
320
|
+
TokenKind_1.TokenKind.Caret,
|
|
321
|
+
TokenKind_1.TokenKind.Minus,
|
|
322
|
+
TokenKind_1.TokenKind.Plus,
|
|
323
|
+
TokenKind_1.TokenKind.Star,
|
|
324
|
+
TokenKind_1.TokenKind.Mod,
|
|
325
|
+
TokenKind_1.TokenKind.Forwardslash,
|
|
326
|
+
TokenKind_1.TokenKind.Backslash,
|
|
327
|
+
TokenKind_1.TokenKind.MinusMinus,
|
|
328
|
+
TokenKind_1.TokenKind.PlusPlus,
|
|
329
|
+
TokenKind_1.TokenKind.Eof
|
|
281
330
|
]);
|
|
282
331
|
});
|
|
283
332
|
it('reads bitshift operators', () => {
|
|
284
333
|
let { tokens } = Lexer_1.Lexer.scan('<< >> <<');
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
334
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
335
|
+
TokenKind_1.TokenKind.LeftShift,
|
|
336
|
+
TokenKind_1.TokenKind.RightShift,
|
|
337
|
+
TokenKind_1.TokenKind.LeftShift,
|
|
338
|
+
TokenKind_1.TokenKind.Eof
|
|
290
339
|
]);
|
|
291
340
|
});
|
|
292
341
|
it('reads bitshift assignment operators', () => {
|
|
293
342
|
let { tokens } = Lexer_1.Lexer.scan('<<= >>=');
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
343
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
344
|
+
TokenKind_1.TokenKind.LeftShiftEqual,
|
|
345
|
+
TokenKind_1.TokenKind.RightShiftEqual,
|
|
346
|
+
TokenKind_1.TokenKind.Eof
|
|
298
347
|
]);
|
|
299
348
|
});
|
|
300
349
|
it('reads comparators', () => {
|
|
301
350
|
let { tokens } = Lexer_1.Lexer.scan('< <= > >= = <>');
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
351
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
352
|
+
TokenKind_1.TokenKind.Less,
|
|
353
|
+
TokenKind_1.TokenKind.LessEqual,
|
|
354
|
+
TokenKind_1.TokenKind.Greater,
|
|
355
|
+
TokenKind_1.TokenKind.GreaterEqual,
|
|
356
|
+
TokenKind_1.TokenKind.Equal,
|
|
357
|
+
TokenKind_1.TokenKind.LessGreater,
|
|
358
|
+
TokenKind_1.TokenKind.Eof
|
|
310
359
|
]);
|
|
311
360
|
});
|
|
312
361
|
}); // non-literals
|
|
313
362
|
describe('string literals', () => {
|
|
314
363
|
it('produces string literal tokens', () => {
|
|
315
364
|
let { tokens } = Lexer_1.Lexer.scan(`"hello world"`);
|
|
316
|
-
|
|
365
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.StringLiteral, TokenKind_1.TokenKind.Eof]);
|
|
317
366
|
});
|
|
318
367
|
it(`safely escapes " literals`, () => {
|
|
319
368
|
let { tokens } = Lexer_1.Lexer.scan(`"the cat says ""meow"""`);
|
|
320
|
-
|
|
369
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.StringLiteral);
|
|
321
370
|
});
|
|
322
371
|
it('captures text to end of line for unterminated strings with LF', () => {
|
|
323
372
|
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\n`);
|
|
324
|
-
|
|
373
|
+
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.StringLiteral);
|
|
325
374
|
});
|
|
326
375
|
it('captures text to end of line for unterminated strings with CRLF', () => {
|
|
327
376
|
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\r\n`);
|
|
328
|
-
|
|
377
|
+
(0, chai_config_spec_1.expect)(tokens[0].text).to.equal('"unterminated!');
|
|
329
378
|
});
|
|
330
379
|
it('disallows multiline strings', () => {
|
|
331
380
|
let { diagnostics } = Lexer_1.Lexer.scan(`"multi-line\n\n`);
|
|
332
|
-
|
|
333
|
-
|
|
381
|
+
(0, chai_config_spec_1.expect)(diagnostics.map(err => err.message)).to.deep.equal([
|
|
382
|
+
DiagnosticMessages_1.DiagnosticMessages.unterminatedString().message
|
|
334
383
|
]);
|
|
335
384
|
});
|
|
336
385
|
});
|
|
@@ -338,21 +387,21 @@ describe('lexer', () => {
|
|
|
338
387
|
describe('template string literals', () => {
|
|
339
388
|
it('supports escaped chars', () => {
|
|
340
389
|
let { tokens } = Lexer_1.Lexer.scan('`\\n\\`\\r\\n`');
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
390
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
391
|
+
TokenKind_1.TokenKind.BackTick,
|
|
392
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
393
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
394
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
395
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
396
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
397
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
398
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
399
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
400
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
401
|
+
TokenKind_1.TokenKind.BackTick,
|
|
402
|
+
TokenKind_1.TokenKind.Eof
|
|
354
403
|
]);
|
|
355
|
-
|
|
404
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
356
405
|
10,
|
|
357
406
|
96,
|
|
358
407
|
13,
|
|
@@ -361,30 +410,30 @@ describe('lexer', () => {
|
|
|
361
410
|
});
|
|
362
411
|
it('prevents expressions when escaping the dollar sign', () => {
|
|
363
412
|
let { tokens } = Lexer_1.Lexer.scan('`\\${just text}`');
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
413
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
414
|
+
TokenKind_1.TokenKind.BackTick,
|
|
415
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
416
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
417
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
418
|
+
TokenKind_1.TokenKind.BackTick,
|
|
419
|
+
TokenKind_1.TokenKind.Eof
|
|
371
420
|
]);
|
|
372
421
|
});
|
|
373
422
|
it('supports escaping unicode char codes', () => {
|
|
374
423
|
let { tokens } = Lexer_1.Lexer.scan('`\\c1\\c12\\c123`');
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
424
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
425
|
+
TokenKind_1.TokenKind.BackTick,
|
|
426
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
427
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
428
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
429
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
430
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
431
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
432
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
433
|
+
TokenKind_1.TokenKind.BackTick,
|
|
434
|
+
TokenKind_1.TokenKind.Eof
|
|
386
435
|
]);
|
|
387
|
-
|
|
436
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
388
437
|
1,
|
|
389
438
|
12,
|
|
390
439
|
123
|
|
@@ -392,29 +441,29 @@ describe('lexer', () => {
|
|
|
392
441
|
});
|
|
393
442
|
it('converts doublequote to EscapedCharCodeLiteral', () => {
|
|
394
443
|
let { tokens } = Lexer_1.Lexer.scan('`"`');
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
444
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
445
|
+
TokenKind_1.TokenKind.BackTick,
|
|
446
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
447
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
448
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
449
|
+
TokenKind_1.TokenKind.BackTick,
|
|
450
|
+
TokenKind_1.TokenKind.Eof
|
|
402
451
|
]);
|
|
403
|
-
|
|
452
|
+
(0, chai_config_spec_1.expect)(tokens[2].charCode).to.equal(34);
|
|
404
453
|
});
|
|
405
454
|
it(`safely escapes \` literals`, () => {
|
|
406
455
|
let { tokens } = Lexer_1.Lexer.scan('`the cat says \\`meow\\` a lot`');
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
456
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
457
|
+
TokenKind_1.TokenKind.BackTick,
|
|
458
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
459
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
460
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
461
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
462
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
463
|
+
TokenKind_1.TokenKind.BackTick,
|
|
464
|
+
TokenKind_1.TokenKind.Eof
|
|
416
465
|
]);
|
|
417
|
-
|
|
466
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
418
467
|
'`',
|
|
419
468
|
'the cat says ',
|
|
420
469
|
'\\`',
|
|
@@ -427,27 +476,27 @@ describe('lexer', () => {
|
|
|
427
476
|
});
|
|
428
477
|
it('produces template string literal tokens', () => {
|
|
429
478
|
let { tokens } = Lexer_1.Lexer.scan('`hello world`');
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
479
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
480
|
+
TokenKind_1.TokenKind.BackTick,
|
|
481
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
482
|
+
TokenKind_1.TokenKind.BackTick,
|
|
483
|
+
TokenKind_1.TokenKind.Eof
|
|
435
484
|
]);
|
|
436
|
-
|
|
485
|
+
(0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal('hello world');
|
|
437
486
|
});
|
|
438
487
|
it('collects quasis outside and expressions inside of template strings', () => {
|
|
439
488
|
let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!`');
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
489
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
490
|
+
TokenKind_1.TokenKind.BackTick,
|
|
491
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
492
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
493
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
494
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
495
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
496
|
+
TokenKind_1.TokenKind.BackTick,
|
|
497
|
+
TokenKind_1.TokenKind.Eof
|
|
449
498
|
]);
|
|
450
|
-
|
|
499
|
+
(0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal(`hello `);
|
|
451
500
|
});
|
|
452
501
|
it('real example, which is causing issues in the formatter', () => {
|
|
453
502
|
let { tokens } = Lexer_1.Lexer.scan(`
|
|
@@ -466,133 +515,133 @@ describe('lexer', () => {
|
|
|
466
515
|
\`
|
|
467
516
|
end function
|
|
468
517
|
`);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
518
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
519
|
+
TokenKind_1.TokenKind.Newline,
|
|
520
|
+
TokenKind_1.TokenKind.Function,
|
|
521
|
+
TokenKind_1.TokenKind.Identifier,
|
|
522
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
523
|
+
TokenKind_1.TokenKind.Identifier,
|
|
524
|
+
TokenKind_1.TokenKind.RightParen,
|
|
525
|
+
TokenKind_1.TokenKind.Newline,
|
|
526
|
+
TokenKind_1.TokenKind.Return,
|
|
527
|
+
TokenKind_1.TokenKind.BackTick,
|
|
528
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
529
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
530
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
531
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
532
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
533
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
534
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
535
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
536
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
537
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
538
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
539
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
540
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
541
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
542
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
543
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
544
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
545
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
546
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
547
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
548
|
+
TokenKind_1.TokenKind.Identifier,
|
|
549
|
+
TokenKind_1.TokenKind.Dot,
|
|
550
|
+
TokenKind_1.TokenKind.Identifier,
|
|
551
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
552
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
553
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
554
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
555
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
556
|
+
TokenKind_1.TokenKind.Identifier,
|
|
557
|
+
TokenKind_1.TokenKind.Dot,
|
|
558
|
+
TokenKind_1.TokenKind.Identifier,
|
|
559
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
560
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
561
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
562
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
563
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
564
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
565
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
566
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
567
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
568
|
+
TokenKind_1.TokenKind.Identifier,
|
|
569
|
+
TokenKind_1.TokenKind.Dot,
|
|
570
|
+
TokenKind_1.TokenKind.Identifier,
|
|
571
|
+
TokenKind_1.TokenKind.Dot,
|
|
572
|
+
TokenKind_1.TokenKind.Identifier,
|
|
573
|
+
TokenKind_1.TokenKind.Dot,
|
|
574
|
+
TokenKind_1.TokenKind.Identifier,
|
|
575
|
+
TokenKind_1.TokenKind.Dot,
|
|
576
|
+
TokenKind_1.TokenKind.Identifier,
|
|
577
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
578
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
579
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
580
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
581
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
582
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
583
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
584
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
585
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
586
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
587
|
+
TokenKind_1.TokenKind.BackTick,
|
|
588
|
+
TokenKind_1.TokenKind.Newline,
|
|
589
|
+
TokenKind_1.TokenKind.EndFunction,
|
|
590
|
+
TokenKind_1.TokenKind.Newline,
|
|
591
|
+
TokenKind_1.TokenKind.Eof
|
|
543
592
|
]);
|
|
544
593
|
});
|
|
545
594
|
it('complicated example', () => {
|
|
546
595
|
let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!I am a ${"template" + "string"} and I am very ${["pleased"][0]} to meet you ${m.top.getChildCount()}.The end`');
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
596
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.eql([
|
|
597
|
+
TokenKind_1.TokenKind.BackTick,
|
|
598
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
599
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
600
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
601
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
602
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
603
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
604
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
605
|
+
TokenKind_1.TokenKind.Plus,
|
|
606
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
607
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
608
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
609
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
610
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
611
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
612
|
+
TokenKind_1.TokenKind.RightSquareBracket,
|
|
613
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
614
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
615
|
+
TokenKind_1.TokenKind.RightSquareBracket,
|
|
616
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
617
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
618
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
619
|
+
TokenKind_1.TokenKind.Identifier,
|
|
620
|
+
TokenKind_1.TokenKind.Dot,
|
|
621
|
+
TokenKind_1.TokenKind.Identifier,
|
|
622
|
+
TokenKind_1.TokenKind.Dot,
|
|
623
|
+
TokenKind_1.TokenKind.Identifier,
|
|
624
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
625
|
+
TokenKind_1.TokenKind.RightParen,
|
|
626
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
627
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
628
|
+
TokenKind_1.TokenKind.BackTick,
|
|
629
|
+
TokenKind_1.TokenKind.Eof
|
|
581
630
|
]);
|
|
582
631
|
});
|
|
583
632
|
it('allows multiline strings', () => {
|
|
584
633
|
let { tokens } = Lexer_1.Lexer.scan('`multi-line\n\n`');
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
634
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
635
|
+
TokenKind_1.TokenKind.BackTick,
|
|
636
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
637
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
638
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
639
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
640
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
641
|
+
TokenKind_1.TokenKind.BackTick,
|
|
642
|
+
TokenKind_1.TokenKind.Eof
|
|
594
643
|
]);
|
|
595
|
-
|
|
644
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
596
645
|
'`',
|
|
597
646
|
'multi-line',
|
|
598
647
|
'\n',
|
|
@@ -605,187 +654,203 @@ describe('lexer', () => {
|
|
|
605
654
|
});
|
|
606
655
|
it('maintains proper line/column locations for multiline strings', () => {
|
|
607
656
|
let { tokens } = Lexer_1.Lexer.scan('123 `multi\nline\r\nstrings` true\nfalse');
|
|
608
|
-
|
|
657
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => {
|
|
658
|
+
var _a;
|
|
609
659
|
return {
|
|
610
|
-
range: x.range,
|
|
660
|
+
range: (_a = x.location) === null || _a === void 0 ? void 0 : _a.range,
|
|
611
661
|
kind: x.kind
|
|
612
662
|
};
|
|
613
663
|
})).to.eql([
|
|
614
|
-
{ range: vscode_languageserver_1.Range.create(0, 0, 0, 3), kind:
|
|
615
|
-
{ range: vscode_languageserver_1.Range.create(0, 4, 0, 5), kind:
|
|
616
|
-
{ range: vscode_languageserver_1.Range.create(0, 5, 0, 10), kind:
|
|
617
|
-
{ range: vscode_languageserver_1.Range.create(0, 10, 0, 11), kind:
|
|
618
|
-
{ range: vscode_languageserver_1.Range.create(1, 0, 1, 4), kind:
|
|
619
|
-
{ range: vscode_languageserver_1.Range.create(1, 4, 1, 5), kind:
|
|
620
|
-
{ range: vscode_languageserver_1.Range.create(1, 5, 1, 6), kind:
|
|
621
|
-
{ range: vscode_languageserver_1.Range.create(2, 0, 2, 7), kind:
|
|
622
|
-
{ range: vscode_languageserver_1.Range.create(2, 7, 2, 8), kind:
|
|
623
|
-
{ range: vscode_languageserver_1.Range.create(2, 9, 2, 13), kind:
|
|
624
|
-
{ range: vscode_languageserver_1.Range.create(2, 13, 2, 14), kind:
|
|
625
|
-
{ range: vscode_languageserver_1.Range.create(3, 0, 3, 5), kind:
|
|
626
|
-
{ range: vscode_languageserver_1.Range.create(3, 5, 3, 6), kind:
|
|
664
|
+
{ range: vscode_languageserver_1.Range.create(0, 0, 0, 3), kind: TokenKind_1.TokenKind.IntegerLiteral },
|
|
665
|
+
{ range: vscode_languageserver_1.Range.create(0, 4, 0, 5), kind: TokenKind_1.TokenKind.BackTick },
|
|
666
|
+
{ range: vscode_languageserver_1.Range.create(0, 5, 0, 10), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
|
|
667
|
+
{ range: vscode_languageserver_1.Range.create(0, 10, 0, 11), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
|
|
668
|
+
{ range: vscode_languageserver_1.Range.create(1, 0, 1, 4), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
|
|
669
|
+
{ range: vscode_languageserver_1.Range.create(1, 4, 1, 5), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
|
|
670
|
+
{ range: vscode_languageserver_1.Range.create(1, 5, 1, 6), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
|
|
671
|
+
{ range: vscode_languageserver_1.Range.create(2, 0, 2, 7), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
|
|
672
|
+
{ range: vscode_languageserver_1.Range.create(2, 7, 2, 8), kind: TokenKind_1.TokenKind.BackTick },
|
|
673
|
+
{ range: vscode_languageserver_1.Range.create(2, 9, 2, 13), kind: TokenKind_1.TokenKind.True },
|
|
674
|
+
{ range: vscode_languageserver_1.Range.create(2, 13, 2, 14), kind: TokenKind_1.TokenKind.Newline },
|
|
675
|
+
{ range: vscode_languageserver_1.Range.create(3, 0, 3, 5), kind: TokenKind_1.TokenKind.False },
|
|
676
|
+
{ range: vscode_languageserver_1.Range.create(3, 5, 3, 6), kind: TokenKind_1.TokenKind.Eof }
|
|
627
677
|
]);
|
|
628
678
|
});
|
|
629
679
|
it('Example that tripped up the expression tests', () => {
|
|
630
680
|
let { tokens } = Lexer_1.Lexer.scan('`I am a complex example\n${a.isRunning(["a","b","c"])}\nmore ${m.finish(true)}`');
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
681
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
682
|
+
TokenKind_1.TokenKind.BackTick,
|
|
683
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
684
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
685
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
686
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
687
|
+
TokenKind_1.TokenKind.Identifier,
|
|
688
|
+
TokenKind_1.TokenKind.Dot,
|
|
689
|
+
TokenKind_1.TokenKind.Identifier,
|
|
690
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
691
|
+
TokenKind_1.TokenKind.LeftSquareBracket,
|
|
692
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
693
|
+
TokenKind_1.TokenKind.Comma,
|
|
694
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
695
|
+
TokenKind_1.TokenKind.Comma,
|
|
696
|
+
TokenKind_1.TokenKind.StringLiteral,
|
|
697
|
+
TokenKind_1.TokenKind.RightSquareBracket,
|
|
698
|
+
TokenKind_1.TokenKind.RightParen,
|
|
699
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
700
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
701
|
+
TokenKind_1.TokenKind.EscapedCharCodeLiteral,
|
|
702
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
703
|
+
TokenKind_1.TokenKind.TemplateStringExpressionBegin,
|
|
704
|
+
TokenKind_1.TokenKind.Identifier,
|
|
705
|
+
TokenKind_1.TokenKind.Dot,
|
|
706
|
+
TokenKind_1.TokenKind.Identifier,
|
|
707
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
708
|
+
TokenKind_1.TokenKind.True,
|
|
709
|
+
TokenKind_1.TokenKind.RightParen,
|
|
710
|
+
TokenKind_1.TokenKind.TemplateStringExpressionEnd,
|
|
711
|
+
TokenKind_1.TokenKind.TemplateStringQuasi,
|
|
712
|
+
TokenKind_1.TokenKind.BackTick,
|
|
713
|
+
TokenKind_1.TokenKind.Eof
|
|
664
714
|
]);
|
|
665
715
|
});
|
|
666
716
|
}); // string literals
|
|
667
717
|
describe('double literals', () => {
|
|
668
718
|
it('respects \'#\' suffix', () => {
|
|
669
719
|
let d = Lexer_1.Lexer.scan('123#').tokens[0];
|
|
670
|
-
|
|
671
|
-
|
|
720
|
+
(0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
|
|
721
|
+
(0, chai_config_spec_1.expect)(d.text).to.eql('123#');
|
|
672
722
|
});
|
|
673
723
|
it('forces literals >= 10 digits into doubles', () => {
|
|
674
724
|
let d = Lexer_1.Lexer.scan('0000000005').tokens[0];
|
|
675
|
-
|
|
676
|
-
|
|
725
|
+
(0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
|
|
726
|
+
(0, chai_config_spec_1.expect)(d.text).to.eql('0000000005');
|
|
677
727
|
});
|
|
678
728
|
it('forces literals with \'D\' in exponent into doubles', () => {
|
|
679
729
|
let d = Lexer_1.Lexer.scan('2.5d3').tokens[0];
|
|
680
|
-
|
|
681
|
-
|
|
730
|
+
(0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
|
|
731
|
+
(0, chai_config_spec_1.expect)(d.text).to.eql('2.5d3');
|
|
682
732
|
});
|
|
683
733
|
it('allows digits before `.` to be elided', () => {
|
|
684
734
|
let f = Lexer_1.Lexer.scan('.123#').tokens[0];
|
|
685
|
-
|
|
686
|
-
|
|
735
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
|
|
736
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('.123#');
|
|
687
737
|
});
|
|
688
738
|
it('allows digits after `.` to be elided', () => {
|
|
689
739
|
let f = Lexer_1.Lexer.scan('12.#').tokens[0];
|
|
690
|
-
|
|
691
|
-
|
|
740
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
|
|
741
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('12.#');
|
|
692
742
|
});
|
|
693
743
|
});
|
|
694
744
|
describe('float literals', () => {
|
|
695
745
|
it('respects \'!\' suffix', () => {
|
|
696
746
|
let f = Lexer_1.Lexer.scan('0.00000008!').tokens[0];
|
|
697
|
-
|
|
747
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
698
748
|
// Floating precision will make this *not* equal
|
|
699
|
-
|
|
700
|
-
|
|
749
|
+
(0, chai_config_spec_1.expect)(f.text).not.to.equal(8e-8);
|
|
750
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('0.00000008!');
|
|
701
751
|
});
|
|
702
752
|
it('forces literals with a decimal into floats', () => {
|
|
703
753
|
let f = Lexer_1.Lexer.scan('1.0').tokens[0];
|
|
704
|
-
|
|
705
|
-
|
|
754
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
755
|
+
(0, chai_config_spec_1.expect)(f.text).to.equal('1.0');
|
|
706
756
|
});
|
|
707
757
|
it('forces literals with \'E\' in exponent into floats', () => {
|
|
708
758
|
let f = Lexer_1.Lexer.scan('2.5e3').tokens[0];
|
|
709
|
-
|
|
710
|
-
|
|
759
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
760
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('2.5e3');
|
|
761
|
+
});
|
|
762
|
+
it('supports very long numbers with !', () => {
|
|
763
|
+
function doTest(number) {
|
|
764
|
+
let f = Lexer_1.Lexer.scan(number).tokens[0];
|
|
765
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
766
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql(number);
|
|
767
|
+
}
|
|
768
|
+
doTest('0!');
|
|
769
|
+
doTest('0!');
|
|
770
|
+
doTest('147483648!');
|
|
771
|
+
doTest('2147483648!');
|
|
772
|
+
doTest('2147483648111!');
|
|
773
|
+
doTest('2.4e-38!');
|
|
774
|
+
doTest('2.4e-32342342342342342342342342348!');
|
|
775
|
+
doTest('2.4e+32342342342342342342342342348!');
|
|
711
776
|
});
|
|
712
777
|
it('supports larger-than-supported-precision floats to be defined with exponents', () => {
|
|
713
778
|
let f = Lexer_1.Lexer.scan('2.3659475627512424e-38').tokens[0];
|
|
714
|
-
|
|
715
|
-
|
|
779
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
780
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('2.3659475627512424e-38');
|
|
716
781
|
});
|
|
717
782
|
it('allows digits before `.` to be elided', () => {
|
|
718
783
|
let f = Lexer_1.Lexer.scan('.123').tokens[0];
|
|
719
|
-
|
|
720
|
-
|
|
784
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
785
|
+
(0, chai_config_spec_1.expect)(f.text).to.equal('.123');
|
|
721
786
|
});
|
|
722
787
|
it('allows digits after `.` to be elided', () => {
|
|
723
788
|
let f = Lexer_1.Lexer.scan('12.').tokens[0];
|
|
724
|
-
|
|
725
|
-
|
|
789
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
790
|
+
(0, chai_config_spec_1.expect)(f.text).to.equal('12.');
|
|
726
791
|
});
|
|
727
792
|
});
|
|
728
793
|
describe('long integer literals', () => {
|
|
729
794
|
it('respects \'&\' suffix', () => {
|
|
730
795
|
let f = Lexer_1.Lexer.scan('1&').tokens[0];
|
|
731
|
-
|
|
732
|
-
|
|
796
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
|
|
797
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('1&');
|
|
733
798
|
});
|
|
734
799
|
it('supports hexadecimal literals', () => {
|
|
735
800
|
let i = Lexer_1.Lexer.scan('&hf00d&').tokens[0];
|
|
736
|
-
|
|
737
|
-
|
|
801
|
+
(0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
|
|
802
|
+
(0, chai_config_spec_1.expect)(i.text).to.equal('&hf00d&');
|
|
738
803
|
});
|
|
739
804
|
it('allows very long Int64 literals', () => {
|
|
740
805
|
let li = Lexer_1.Lexer.scan('9876543210&').tokens[0];
|
|
741
|
-
|
|
742
|
-
|
|
806
|
+
(0, chai_config_spec_1.expect)(li.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
|
|
807
|
+
(0, chai_config_spec_1.expect)(li.text).to.equal('9876543210&');
|
|
743
808
|
});
|
|
744
809
|
it('forces literals with \'&\' suffix into Int64s', () => {
|
|
745
810
|
let li = Lexer_1.Lexer.scan('123&').tokens[0];
|
|
746
|
-
|
|
747
|
-
|
|
811
|
+
(0, chai_config_spec_1.expect)(li.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
|
|
812
|
+
(0, chai_config_spec_1.expect)(li.text).to.deep.equal('123&');
|
|
748
813
|
});
|
|
749
814
|
});
|
|
750
815
|
describe('integer literals', () => {
|
|
751
816
|
it('respects \'%\' suffix', () => {
|
|
752
817
|
let f = Lexer_1.Lexer.scan('1%').tokens[0];
|
|
753
|
-
|
|
754
|
-
|
|
818
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
|
|
819
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('1%');
|
|
755
820
|
});
|
|
756
821
|
it('does not allow decimal numbers to end with %', () => {
|
|
757
822
|
let f = Lexer_1.Lexer.scan('1.2%').tokens[0];
|
|
758
|
-
|
|
759
|
-
|
|
823
|
+
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
824
|
+
(0, chai_config_spec_1.expect)(f.text).to.eql('1.2');
|
|
760
825
|
});
|
|
761
826
|
it('supports hexadecimal literals', () => {
|
|
762
827
|
let i = Lexer_1.Lexer.scan('&hFf').tokens[0];
|
|
763
|
-
|
|
764
|
-
|
|
828
|
+
(0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
|
|
829
|
+
(0, chai_config_spec_1.expect)(i.text).to.deep.equal('&hFf');
|
|
765
830
|
});
|
|
766
831
|
it('falls back to a regular integer', () => {
|
|
767
832
|
let i = Lexer_1.Lexer.scan('123').tokens[0];
|
|
768
|
-
|
|
769
|
-
|
|
833
|
+
(0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
|
|
834
|
+
(0, chai_config_spec_1.expect)(i.text).to.deep.equal('123');
|
|
770
835
|
});
|
|
771
836
|
});
|
|
772
837
|
describe('types', () => {
|
|
773
838
|
it('captures type tokens', () => {
|
|
774
|
-
|
|
839
|
+
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan(`
|
|
775
840
|
void boolean integer longinteger float double string object interface invalid dynamic
|
|
776
841
|
`.trim()).tokens.map(x => x.kind)).to.eql([
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
842
|
+
TokenKind_1.TokenKind.Void,
|
|
843
|
+
TokenKind_1.TokenKind.Boolean,
|
|
844
|
+
TokenKind_1.TokenKind.Integer,
|
|
845
|
+
TokenKind_1.TokenKind.LongInteger,
|
|
846
|
+
TokenKind_1.TokenKind.Float,
|
|
847
|
+
TokenKind_1.TokenKind.Double,
|
|
848
|
+
TokenKind_1.TokenKind.String,
|
|
849
|
+
TokenKind_1.TokenKind.Object,
|
|
850
|
+
TokenKind_1.TokenKind.Interface,
|
|
851
|
+
TokenKind_1.TokenKind.Invalid,
|
|
852
|
+
TokenKind_1.TokenKind.Dynamic,
|
|
853
|
+
TokenKind_1.TokenKind.Eof
|
|
789
854
|
]);
|
|
790
855
|
});
|
|
791
856
|
});
|
|
@@ -793,60 +858,63 @@ describe('lexer', () => {
|
|
|
793
858
|
it('matches single-word keywords', () => {
|
|
794
859
|
// test just a sample of single-word reserved words for now.
|
|
795
860
|
// if we find any that we've missed
|
|
796
|
-
let { tokens } = Lexer_1.Lexer.scan('and then or if else endif return true false line_num');
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
861
|
+
let { tokens } = Lexer_1.Lexer.scan('and then or if else endif return true false line_num exitwhile');
|
|
862
|
+
(0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
863
|
+
TokenKind_1.TokenKind.And,
|
|
864
|
+
TokenKind_1.TokenKind.Then,
|
|
865
|
+
TokenKind_1.TokenKind.Or,
|
|
866
|
+
TokenKind_1.TokenKind.If,
|
|
867
|
+
TokenKind_1.TokenKind.Else,
|
|
868
|
+
TokenKind_1.TokenKind.EndIf,
|
|
869
|
+
TokenKind_1.TokenKind.Return,
|
|
870
|
+
TokenKind_1.TokenKind.True,
|
|
871
|
+
TokenKind_1.TokenKind.False,
|
|
872
|
+
TokenKind_1.TokenKind.LineNumLiteral,
|
|
873
|
+
TokenKind_1.TokenKind.ExitWhile,
|
|
874
|
+
TokenKind_1.TokenKind.Eof
|
|
809
875
|
]);
|
|
810
876
|
});
|
|
811
877
|
it('matches multi-word keywords', () => {
|
|
812
878
|
let { tokens } = Lexer_1.Lexer.scan('end if end while End Sub end Function Exit wHILe');
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
879
|
+
(0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
880
|
+
TokenKind_1.TokenKind.EndIf,
|
|
881
|
+
TokenKind_1.TokenKind.EndWhile,
|
|
882
|
+
TokenKind_1.TokenKind.EndSub,
|
|
883
|
+
TokenKind_1.TokenKind.EndFunction,
|
|
884
|
+
TokenKind_1.TokenKind.Exit,
|
|
885
|
+
TokenKind_1.TokenKind.While,
|
|
886
|
+
TokenKind_1.TokenKind.Eof
|
|
820
887
|
]);
|
|
821
888
|
});
|
|
822
889
|
it('accepts \'exit for\' but not \'exitfor\'', () => {
|
|
823
890
|
let { tokens } = Lexer_1.Lexer.scan('exit for exitfor');
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
891
|
+
(0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
892
|
+
TokenKind_1.TokenKind.Exit,
|
|
893
|
+
TokenKind_1.TokenKind.For,
|
|
894
|
+
TokenKind_1.TokenKind.Identifier,
|
|
895
|
+
TokenKind_1.TokenKind.Eof
|
|
828
896
|
]);
|
|
829
897
|
});
|
|
830
898
|
it('matches keywords with silly capitalization', () => {
|
|
831
899
|
let { tokens } = Lexer_1.Lexer.scan('iF ELSE eNDIf FUncTioN');
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
900
|
+
(0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
901
|
+
TokenKind_1.TokenKind.If,
|
|
902
|
+
TokenKind_1.TokenKind.Else,
|
|
903
|
+
TokenKind_1.TokenKind.EndIf,
|
|
904
|
+
TokenKind_1.TokenKind.Function,
|
|
905
|
+
TokenKind_1.TokenKind.Eof
|
|
838
906
|
]);
|
|
839
907
|
});
|
|
840
908
|
it('allows alpha-numeric (plus \'_\') identifiers', () => {
|
|
841
909
|
let identifier = Lexer_1.Lexer.scan('_abc_123_').tokens[0];
|
|
842
|
-
|
|
843
|
-
|
|
910
|
+
(0, chai_config_spec_1.expect)(identifier.kind).to.equal(TokenKind_1.TokenKind.Identifier);
|
|
911
|
+
(0, chai_config_spec_1.expect)(identifier.text).to.equal('_abc_123_');
|
|
844
912
|
});
|
|
845
913
|
it('allows identifiers with trailing type designators', () => {
|
|
846
914
|
let { tokens } = Lexer_1.Lexer.scan('lorem$ ipsum% dolor! sit# amet&');
|
|
847
|
-
let identifiers = tokens.filter(t => t.kind !==
|
|
848
|
-
|
|
849
|
-
|
|
915
|
+
let identifiers = tokens.filter(t => t.kind !== TokenKind_1.TokenKind.Eof);
|
|
916
|
+
(0, chai_config_spec_1.expect)(identifiers.every(t => t.kind === TokenKind_1.TokenKind.Identifier));
|
|
917
|
+
(0, chai_config_spec_1.expect)(identifiers.map(t => t.text)).to.deep.equal([
|
|
850
918
|
'lorem$',
|
|
851
919
|
'ipsum%',
|
|
852
920
|
'dolor!',
|
|
@@ -858,20 +926,61 @@ describe('lexer', () => {
|
|
|
858
926
|
describe('conditional compilation', () => {
|
|
859
927
|
it('reads constant declarations', () => {
|
|
860
928
|
let { tokens } = Lexer_1.Lexer.scan('#const foo true');
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
929
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
930
|
+
TokenKind_1.TokenKind.HashConst,
|
|
931
|
+
TokenKind_1.TokenKind.Identifier,
|
|
932
|
+
TokenKind_1.TokenKind.True,
|
|
933
|
+
TokenKind_1.TokenKind.Eof
|
|
866
934
|
]);
|
|
867
935
|
});
|
|
936
|
+
it('handles whitespace between hash and keywords', () => {
|
|
937
|
+
function doTest(text, ...expected) {
|
|
938
|
+
let { tokens } = Lexer_1.Lexer.scan(text);
|
|
939
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
940
|
+
...expected,
|
|
941
|
+
TokenKind_1.TokenKind.Eof
|
|
942
|
+
]);
|
|
943
|
+
}
|
|
944
|
+
//#if
|
|
945
|
+
doTest('# if true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
|
|
946
|
+
doTest('#\tif true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
|
|
947
|
+
doTest('#\t \t\t \tif true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
|
|
948
|
+
//#else
|
|
949
|
+
doTest('# else', TokenKind_1.TokenKind.HashElse);
|
|
950
|
+
doTest('#\telse', TokenKind_1.TokenKind.HashElse);
|
|
951
|
+
doTest('#\t \t\t \telse', TokenKind_1.TokenKind.HashElse);
|
|
952
|
+
//#elseif
|
|
953
|
+
doTest('# elseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
954
|
+
doTest('#\telseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
955
|
+
doTest('#\t \t\t \telseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
956
|
+
//#else if
|
|
957
|
+
doTest('# else if true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
958
|
+
doTest('#\t elseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
959
|
+
doTest('#\t \t\t \t else if true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
|
|
960
|
+
//#endif
|
|
961
|
+
doTest('# endif', TokenKind_1.TokenKind.HashEndIf);
|
|
962
|
+
doTest('#\tendif', TokenKind_1.TokenKind.HashEndIf);
|
|
963
|
+
doTest('#\t \t\t \tendif', TokenKind_1.TokenKind.HashEndIf);
|
|
964
|
+
//#end if
|
|
965
|
+
doTest('# end if', TokenKind_1.TokenKind.HashEndIf);
|
|
966
|
+
doTest('#\tend if', TokenKind_1.TokenKind.HashEndIf);
|
|
967
|
+
doTest('#\t \t\t \tend if', TokenKind_1.TokenKind.HashEndIf);
|
|
968
|
+
//#const
|
|
969
|
+
doTest('# const thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
|
|
970
|
+
doTest('#\tconst thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
|
|
971
|
+
doTest('#\t \t\t \tconst thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
|
|
972
|
+
//#error
|
|
973
|
+
doTest('# error', TokenKind_1.TokenKind.HashError);
|
|
974
|
+
doTest('#\terror', TokenKind_1.TokenKind.HashError);
|
|
975
|
+
doTest('#\t \t\t \terror', TokenKind_1.TokenKind.HashError);
|
|
976
|
+
});
|
|
868
977
|
it('reads constant aliases', () => {
|
|
869
978
|
let { tokens } = Lexer_1.Lexer.scan('#const bar foo');
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
979
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
980
|
+
TokenKind_1.TokenKind.HashConst,
|
|
981
|
+
TokenKind_1.TokenKind.Identifier,
|
|
982
|
+
TokenKind_1.TokenKind.Identifier,
|
|
983
|
+
TokenKind_1.TokenKind.Eof
|
|
875
984
|
]);
|
|
876
985
|
});
|
|
877
986
|
it('reads conditional directives', () => {
|
|
@@ -885,19 +994,19 @@ describe('lexer', () => {
|
|
|
885
994
|
`, {
|
|
886
995
|
includeWhitespace: false
|
|
887
996
|
});
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
997
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind).filter(x => x !== TokenKind_1.TokenKind.Newline)).to.deep.equal([
|
|
998
|
+
TokenKind_1.TokenKind.HashIf,
|
|
999
|
+
TokenKind_1.TokenKind.HashElseIf,
|
|
1000
|
+
TokenKind_1.TokenKind.HashElseIf,
|
|
1001
|
+
TokenKind_1.TokenKind.HashElse,
|
|
1002
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1003
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1004
|
+
TokenKind_1.TokenKind.Eof
|
|
896
1005
|
]);
|
|
897
1006
|
});
|
|
898
1007
|
it('treats text "constructor" as an identifier', () => {
|
|
899
1008
|
let lexer = Lexer_1.Lexer.scan(`function constructor()\nend function`);
|
|
900
|
-
|
|
1009
|
+
(0, chai_config_spec_1.expect)(lexer.tokens[1].kind).to.equal(TokenKind_1.TokenKind.Identifier);
|
|
901
1010
|
});
|
|
902
1011
|
it('reads upper case conditional directives', () => {
|
|
903
1012
|
let { tokens } = Lexer_1.Lexer.scan(`
|
|
@@ -910,45 +1019,52 @@ describe('lexer', () => {
|
|
|
910
1019
|
`, {
|
|
911
1020
|
includeWhitespace: false
|
|
912
1021
|
});
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1022
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind).filter(x => x !== TokenKind_1.TokenKind.Newline)).to.deep.equal([
|
|
1023
|
+
TokenKind_1.TokenKind.HashIf,
|
|
1024
|
+
TokenKind_1.TokenKind.HashElseIf,
|
|
1025
|
+
TokenKind_1.TokenKind.HashElseIf,
|
|
1026
|
+
TokenKind_1.TokenKind.HashElse,
|
|
1027
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1028
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1029
|
+
TokenKind_1.TokenKind.Eof
|
|
921
1030
|
]);
|
|
922
1031
|
});
|
|
923
1032
|
it('supports various spacings between #endif', () => {
|
|
924
1033
|
let { tokens } = Lexer_1.Lexer.scan('#endif #end if #end\tif #end if #end\t\t if');
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1034
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
1035
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1036
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1037
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1038
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1039
|
+
TokenKind_1.TokenKind.HashEndIf,
|
|
1040
|
+
TokenKind_1.TokenKind.Eof
|
|
1041
|
+
]);
|
|
1042
|
+
});
|
|
1043
|
+
it('does not require a message after #error', () => {
|
|
1044
|
+
let { tokens } = Lexer_1.Lexer.scan('#error');
|
|
1045
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1046
|
+
TokenKind_1.TokenKind.HashError,
|
|
1047
|
+
TokenKind_1.TokenKind.Eof
|
|
932
1048
|
]);
|
|
933
1049
|
});
|
|
934
1050
|
it('reads forced compilation diagnostics with messages', () => {
|
|
935
1051
|
let { tokens } = Lexer_1.Lexer.scan('#error a message goes here\n', {
|
|
936
1052
|
includeWhitespace: true
|
|
937
1053
|
});
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1054
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
1055
|
+
TokenKind_1.TokenKind.HashError,
|
|
1056
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1057
|
+
TokenKind_1.TokenKind.HashErrorMessage,
|
|
1058
|
+
TokenKind_1.TokenKind.Newline,
|
|
1059
|
+
TokenKind_1.TokenKind.Eof
|
|
944
1060
|
]);
|
|
945
|
-
|
|
1061
|
+
(0, chai_config_spec_1.expect)(tokens[2].text).to.equal('a message goes here');
|
|
946
1062
|
});
|
|
947
1063
|
});
|
|
948
1064
|
describe('location tracking', () => {
|
|
949
1065
|
it('tracks starting and ending locations including whitespace', () => {
|
|
950
1066
|
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: true });
|
|
951
|
-
|
|
1067
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => { var _a; return (_a = t.location) === null || _a === void 0 ? void 0 : _a.range; })).to.eql([
|
|
952
1068
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
953
1069
|
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
954
1070
|
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
@@ -966,7 +1082,7 @@ describe('lexer', () => {
|
|
|
966
1082
|
});
|
|
967
1083
|
it('tracks starting and ending locations excluding whitespace', () => {
|
|
968
1084
|
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: false });
|
|
969
|
-
|
|
1085
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => { var _a; return (_a = t.location) === null || _a === void 0 ? void 0 : _a.range; })).to.eql([
|
|
970
1086
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
971
1087
|
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
972
1088
|
vscode_languageserver_1.Range.create(0, 7, 0, 8),
|
|
@@ -983,30 +1099,30 @@ describe('lexer', () => {
|
|
|
983
1099
|
describe('two word keywords', () => {
|
|
984
1100
|
it('supports various spacing between for each', () => {
|
|
985
1101
|
let { tokens } = Lexer_1.Lexer.scan('for each for each for each for\teach for\t each for \teach for \t each');
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1102
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
1103
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1104
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1105
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1106
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1107
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1108
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1109
|
+
TokenKind_1.TokenKind.ForEach,
|
|
1110
|
+
TokenKind_1.TokenKind.Eof
|
|
995
1111
|
]);
|
|
996
1112
|
});
|
|
997
1113
|
});
|
|
998
1114
|
it('detects rem when used as keyword', () => {
|
|
999
1115
|
let { tokens } = Lexer_1.Lexer.scan('person.rem=true');
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1116
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.eql([
|
|
1117
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1118
|
+
TokenKind_1.TokenKind.Dot,
|
|
1119
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1120
|
+
TokenKind_1.TokenKind.Equal,
|
|
1121
|
+
TokenKind_1.TokenKind.True,
|
|
1122
|
+
TokenKind_1.TokenKind.Eof
|
|
1007
1123
|
]);
|
|
1008
1124
|
//verify the location of `rem`
|
|
1009
|
-
|
|
1125
|
+
(0, chai_config_spec_1.expect)(tokens.map(t => { var _a, _b; return [(_a = t.location) === null || _a === void 0 ? void 0 : _a.range.start.character, (_b = t.location) === null || _b === void 0 ? void 0 : _b.range.end.character]; })).to.eql([
|
|
1010
1126
|
[0, 6],
|
|
1011
1127
|
[6, 7],
|
|
1012
1128
|
[7, 10],
|
|
@@ -1018,64 +1134,85 @@ describe('lexer', () => {
|
|
|
1018
1134
|
describe('isToken', () => {
|
|
1019
1135
|
it('works', () => {
|
|
1020
1136
|
let range = vscode_languageserver_1.Range.create(0, 0, 0, 2);
|
|
1021
|
-
|
|
1022
|
-
|
|
1137
|
+
(0, chai_config_spec_1.expect)((0, Token_1.isToken)({ kind: TokenKind_1.TokenKind.And, text: 'and', range: range })).is.true;
|
|
1138
|
+
(0, chai_config_spec_1.expect)((0, Token_1.isToken)({ text: 'and', range: range })).is.false;
|
|
1023
1139
|
});
|
|
1024
1140
|
});
|
|
1141
|
+
it('recognizes enum-related keywords', () => {
|
|
1142
|
+
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('enum end enum endenum').tokens.map(x => x.kind)).to.eql([
|
|
1143
|
+
TokenKind_1.TokenKind.Enum,
|
|
1144
|
+
TokenKind_1.TokenKind.EndEnum,
|
|
1145
|
+
TokenKind_1.TokenKind.EndEnum,
|
|
1146
|
+
TokenKind_1.TokenKind.Eof
|
|
1147
|
+
]);
|
|
1148
|
+
});
|
|
1025
1149
|
it('recognizes class-related keywords', () => {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1150
|
+
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('class public protected private end class endclass new override').tokens.map(x => x.kind)).to.eql([
|
|
1151
|
+
TokenKind_1.TokenKind.Class,
|
|
1152
|
+
TokenKind_1.TokenKind.Public,
|
|
1153
|
+
TokenKind_1.TokenKind.Protected,
|
|
1154
|
+
TokenKind_1.TokenKind.Private,
|
|
1155
|
+
TokenKind_1.TokenKind.EndClass,
|
|
1156
|
+
TokenKind_1.TokenKind.EndClass,
|
|
1157
|
+
TokenKind_1.TokenKind.New,
|
|
1158
|
+
TokenKind_1.TokenKind.Override,
|
|
1159
|
+
TokenKind_1.TokenKind.Eof
|
|
1036
1160
|
]);
|
|
1037
1161
|
});
|
|
1038
1162
|
describe('whitespace', () => {
|
|
1039
1163
|
it('preserves the exact number of whitespace characterswhitespace', () => {
|
|
1040
1164
|
let { tokens } = Lexer_1.Lexer.scan(' ', { includeWhitespace: true });
|
|
1041
|
-
|
|
1042
|
-
kind:
|
|
1165
|
+
(0, chai_config_spec_1.expect)(tokens[0]).to.include({
|
|
1166
|
+
kind: TokenKind_1.TokenKind.Whitespace,
|
|
1043
1167
|
text: ' '
|
|
1044
1168
|
});
|
|
1045
1169
|
});
|
|
1046
1170
|
it('tokenizes whitespace between things', () => {
|
|
1047
1171
|
let { tokens } = Lexer_1.Lexer.scan('sub main ( ) \n end sub', { includeWhitespace: true });
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1172
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1173
|
+
TokenKind_1.TokenKind.Sub,
|
|
1174
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1175
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1176
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1177
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
1178
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1179
|
+
TokenKind_1.TokenKind.RightParen,
|
|
1180
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1181
|
+
TokenKind_1.TokenKind.Newline,
|
|
1182
|
+
TokenKind_1.TokenKind.Whitespace,
|
|
1183
|
+
TokenKind_1.TokenKind.EndSub,
|
|
1184
|
+
TokenKind_1.TokenKind.Eof
|
|
1061
1185
|
]);
|
|
1062
1186
|
});
|
|
1063
1187
|
});
|
|
1064
1188
|
it('identifies brighterscript source literals', () => {
|
|
1065
|
-
let { tokens } = Lexer_1.Lexer.scan('LINE_NUM SOURCE_FILE_PATH SOURCE_LINE_NUM FUNCTION_NAME SOURCE_FUNCTION_NAME SOURCE_LOCATION PKG_PATH PKG_LOCATION');
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1189
|
+
let { tokens } = Lexer_1.Lexer.scan('LINE_NUM SOURCE_FILE_PATH SOURCE_LINE_NUM FUNCTION_NAME SOURCE_FUNCTION_NAME SOURCE_NAMESPACE_NAME SOURCE_NAMESPACE_ROOT_NAME SOURCE_LOCATION PKG_PATH PKG_LOCATION');
|
|
1190
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1191
|
+
TokenKind_1.TokenKind.LineNumLiteral,
|
|
1192
|
+
TokenKind_1.TokenKind.SourceFilePathLiteral,
|
|
1193
|
+
TokenKind_1.TokenKind.SourceLineNumLiteral,
|
|
1194
|
+
TokenKind_1.TokenKind.FunctionNameLiteral,
|
|
1195
|
+
TokenKind_1.TokenKind.SourceFunctionNameLiteral,
|
|
1196
|
+
TokenKind_1.TokenKind.SourceNamespaceNameLiteral,
|
|
1197
|
+
TokenKind_1.TokenKind.SourceNamespaceRootNameLiteral,
|
|
1198
|
+
TokenKind_1.TokenKind.SourceLocationLiteral,
|
|
1199
|
+
TokenKind_1.TokenKind.PkgPathLiteral,
|
|
1200
|
+
TokenKind_1.TokenKind.PkgLocationLiteral,
|
|
1201
|
+
TokenKind_1.TokenKind.Eof
|
|
1076
1202
|
]);
|
|
1077
1203
|
});
|
|
1078
1204
|
it('properly tracks leadingWhitespace', () => {
|
|
1205
|
+
/**
|
|
1206
|
+
* Convert a list of tokens into a string, including their leading whitespace
|
|
1207
|
+
*/
|
|
1208
|
+
function tokensToString(tokens) {
|
|
1209
|
+
let result = '';
|
|
1210
|
+
//skip iterating the final token
|
|
1211
|
+
for (let token of tokens) {
|
|
1212
|
+
result += token.leadingWhitespace + token.text;
|
|
1213
|
+
}
|
|
1214
|
+
return result;
|
|
1215
|
+
}
|
|
1079
1216
|
const text = `
|
|
1080
1217
|
sub main()
|
|
1081
1218
|
|
|
@@ -1084,18 +1221,125 @@ describe('lexer', () => {
|
|
|
1084
1221
|
end sub
|
|
1085
1222
|
`;
|
|
1086
1223
|
const { tokens } = Lexer_1.Lexer.scan(text, { includeWhitespace: false });
|
|
1087
|
-
|
|
1224
|
+
(0, chai_config_spec_1.expect)(tokensToString(tokens)).to.equal(text);
|
|
1088
1225
|
});
|
|
1089
1226
|
it('properly detects try/catch tokens', () => {
|
|
1090
1227
|
const { tokens } = Lexer_1.Lexer.scan(`try catch endtry end try throw`, { includeWhitespace: false });
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1228
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1229
|
+
TokenKind_1.TokenKind.Try,
|
|
1230
|
+
TokenKind_1.TokenKind.Catch,
|
|
1231
|
+
TokenKind_1.TokenKind.EndTry,
|
|
1232
|
+
TokenKind_1.TokenKind.EndTry,
|
|
1233
|
+
TokenKind_1.TokenKind.Throw,
|
|
1234
|
+
TokenKind_1.TokenKind.Eof
|
|
1098
1235
|
]);
|
|
1099
1236
|
});
|
|
1237
|
+
describe('regular expression literals', () => {
|
|
1238
|
+
function testRegex(...regexps) {
|
|
1239
|
+
regexps = regexps.map(x => x.toString());
|
|
1240
|
+
const results = [];
|
|
1241
|
+
for (const regexp of regexps) {
|
|
1242
|
+
const { tokens } = Lexer_1.Lexer.scan(regexp);
|
|
1243
|
+
results.push(tokens[0].text);
|
|
1244
|
+
}
|
|
1245
|
+
(0, chai_config_spec_1.expect)(results).to.eql(regexps);
|
|
1246
|
+
}
|
|
1247
|
+
it('recognizes regex literals', () => {
|
|
1248
|
+
testRegex(/simple/, /SimpleWithValidFlags/g, /UnknownFlags/gi, /with(parens)and[squarebraces]/,
|
|
1249
|
+
//lots of special characters
|
|
1250
|
+
/.*()^$@/,
|
|
1251
|
+
//captures quote char
|
|
1252
|
+
/"/);
|
|
1253
|
+
});
|
|
1254
|
+
it('does not capture multiple divisions on one line as regex', () => {
|
|
1255
|
+
const { tokens } = Lexer_1.Lexer.scan(`one = 1/2 + 1/4 + 1/4`, {
|
|
1256
|
+
includeWhitespace: false
|
|
1257
|
+
});
|
|
1258
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1259
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1260
|
+
TokenKind_1.TokenKind.Equal,
|
|
1261
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1262
|
+
TokenKind_1.TokenKind.Forwardslash,
|
|
1263
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1264
|
+
TokenKind_1.TokenKind.Plus,
|
|
1265
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1266
|
+
TokenKind_1.TokenKind.Forwardslash,
|
|
1267
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1268
|
+
TokenKind_1.TokenKind.Plus,
|
|
1269
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1270
|
+
TokenKind_1.TokenKind.Forwardslash,
|
|
1271
|
+
TokenKind_1.TokenKind.IntegerLiteral,
|
|
1272
|
+
TokenKind_1.TokenKind.Eof
|
|
1273
|
+
]);
|
|
1274
|
+
});
|
|
1275
|
+
it('only captures alphanumeric flags', () => {
|
|
1276
|
+
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('speak(/a/)').tokens.map(x => x.kind)).to.eql([
|
|
1277
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1278
|
+
TokenKind_1.TokenKind.LeftParen,
|
|
1279
|
+
TokenKind_1.TokenKind.RegexLiteral,
|
|
1280
|
+
TokenKind_1.TokenKind.RightParen,
|
|
1281
|
+
TokenKind_1.TokenKind.Eof
|
|
1282
|
+
]);
|
|
1283
|
+
});
|
|
1284
|
+
it('handles escape characters properly', () => {
|
|
1285
|
+
testRegex(
|
|
1286
|
+
//an escaped forward slash right next to the end-regexp forwardslash
|
|
1287
|
+
/\//, /\r/, /\n/, /\r\n/,
|
|
1288
|
+
//a literal backslash in front of an escape backslash
|
|
1289
|
+
/\\\n/);
|
|
1290
|
+
});
|
|
1291
|
+
});
|
|
1292
|
+
it('detects "continue" as a keyword', () => {
|
|
1293
|
+
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('continue').tokens.map(x => x.kind)).to.eql([
|
|
1294
|
+
TokenKind_1.TokenKind.Continue,
|
|
1295
|
+
TokenKind_1.TokenKind.Eof
|
|
1296
|
+
]);
|
|
1297
|
+
});
|
|
1298
|
+
describe('trivia', () => {
|
|
1299
|
+
function stringify(tokens) {
|
|
1300
|
+
return tokens
|
|
1301
|
+
//exclude the explicit triva tokens since they'll be included in the leading/trailing arrays
|
|
1302
|
+
.filter(x => !TokenKind_1.AllowedTriviaTokens.includes(x.kind))
|
|
1303
|
+
.flatMap(x => [...x.leadingTrivia, x])
|
|
1304
|
+
.map(x => x.text)
|
|
1305
|
+
.join('');
|
|
1306
|
+
}
|
|
1307
|
+
it('combining token text and trivia can reproduce full input', () => {
|
|
1308
|
+
const input = `
|
|
1309
|
+
function test( )
|
|
1310
|
+
'comment
|
|
1311
|
+
print alpha ' blabla
|
|
1312
|
+
end function 'trailing
|
|
1313
|
+
'trailing2
|
|
1314
|
+
`;
|
|
1315
|
+
(0, chai_config_spec_1.expect)(stringify(Lexer_1.Lexer.scan(input).tokens)).to.eql(input);
|
|
1316
|
+
});
|
|
1317
|
+
function expectTrivia(text, expected) {
|
|
1318
|
+
const tokens = Lexer_1.Lexer.scan(text).tokens.filter(x => !TokenKind_1.AllowedTriviaTokens.includes(x.kind));
|
|
1319
|
+
(0, chai_config_spec_1.expect)(tokens.map(x => {
|
|
1320
|
+
return {
|
|
1321
|
+
text: x.text,
|
|
1322
|
+
leadingTrivia: x.leadingTrivia.map(x => x.text)
|
|
1323
|
+
};
|
|
1324
|
+
})).to.eql(expected.map(x => (Object.assign({ leadingTrivia: [] }, x))));
|
|
1325
|
+
}
|
|
1326
|
+
it('associates trailing items on same line with the preceeding token', () => {
|
|
1327
|
+
expectTrivia(`'leading\n` +
|
|
1328
|
+
`alpha = true 'trueComment\n` +
|
|
1329
|
+
`'eof`, [
|
|
1330
|
+
{ leadingTrivia: [`'leading`, `\n`], text: `alpha` },
|
|
1331
|
+
{ leadingTrivia: [` `], text: `=` },
|
|
1332
|
+
{ leadingTrivia: [` `], text: `true` },
|
|
1333
|
+
//EOF
|
|
1334
|
+
{ leadingTrivia: [` `, `'trueComment`, `\n`, `'eof`], text: `` }
|
|
1335
|
+
]);
|
|
1336
|
+
});
|
|
1337
|
+
});
|
|
1100
1338
|
});
|
|
1339
|
+
function expectKinds(text, tokenKinds) {
|
|
1340
|
+
let actual = Lexer_1.Lexer.scan(text).tokens.map(x => x.kind);
|
|
1341
|
+
//remove the EOF token
|
|
1342
|
+
actual.pop();
|
|
1343
|
+
(0, chai_config_spec_1.expect)(actual).to.eql(tokenKinds);
|
|
1344
|
+
}
|
|
1101
1345
|
//# sourceMappingURL=Lexer.spec.js.map
|