brighterscript 1.0.0-alpha.50 → 1.0.0-alpha.51
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 +3 -0
- package/bsconfig.schema.json +75 -0
- package/dist/BsConfig.d.ts +90 -5
- package/dist/CodeActionUtil.d.ts +17 -0
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +16 -12
- package/dist/CommentFlagProcessor.js +141 -59
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.js +13 -5
- package/dist/CrossScopeValidator.js.map +1 -1
- package/dist/DiagnosticManager.d.ts +1 -0
- package/dist/DiagnosticManager.js +25 -9
- package/dist/DiagnosticManager.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +61 -17
- package/dist/DiagnosticMessages.js +78 -24
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +39 -2
- package/dist/LanguageServer.js +142 -5
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +62 -1
- package/dist/Program.js +185 -13
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +1 -8
- package/dist/ProgramBuilder.js +31 -11
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +87 -6
- package/dist/Scope.js +76 -31
- package/dist/Scope.js.map +1 -1
- package/dist/ScopeNamespaceLookup.d.ts +73 -0
- package/dist/ScopeNamespaceLookup.js +242 -0
- package/dist/ScopeNamespaceLookup.js.map +1 -0
- package/dist/SymbolTable.d.ts +9 -2
- package/dist/SymbolTable.js +24 -14
- package/dist/SymbolTable.js.map +1 -1
- package/dist/astUtils/CachedLookups.js +3 -0
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +4 -1
- package/dist/astUtils/reflection.js +24 -4
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +4 -2
- package/dist/bscPlugin/BscPlugin.js +10 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +1 -2
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/FileWriter.d.ts +13 -0
- package/dist/bscPlugin/FileWriter.js +56 -1
- package/dist/bscPlugin/FileWriter.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +106 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +630 -126
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.d.ts +17 -0
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.js +66 -0
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.js.map +1 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.d.ts +18 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.js +31 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.js.map +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +5 -5
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/definition/DefinitionProvider.js +8 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +11 -3
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.d.ts +7 -0
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.js +77 -0
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +1 -1
- package/dist/bscPlugin/serialize/FileSerializer.js +12 -7
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +7 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +87 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +14 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +97 -21
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +17 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +162 -4
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.js +14 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/cli.js +13 -0
- package/dist/cli.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +51 -1
- package/dist/diagnosticUtils.js +222 -1
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/files/BrsFile.d.ts +18 -2
- package/dist/files/BrsFile.js +87 -6
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/XmlFile.js +2 -1
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/interfaces.d.ts +68 -23
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.js +4 -5
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Token.d.ts +1 -1
- package/dist/lexer/TokenKind.d.ts +8 -0
- package/dist/lexer/TokenKind.js +21 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lsp/LspProject.d.ts +49 -1
- package/dist/lsp/Project.d.ts +33 -1
- package/dist/lsp/Project.js +129 -4
- package/dist/lsp/Project.js.map +1 -1
- package/dist/lsp/ProjectManager.d.ts +48 -2
- package/dist/lsp/ProjectManager.js +152 -9
- package/dist/lsp/ProjectManager.js.map +1 -1
- package/dist/lsp/worker/WorkerThreadProject.d.ts +27 -2
- package/dist/lsp/worker/WorkerThreadProject.js +16 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
- package/dist/parser/AstNode.d.ts +3 -1
- package/dist/parser/AstNode.js +2 -0
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/Expression.d.ts +54 -5
- package/dist/parser/Expression.js +112 -7
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +24 -1
- package/dist/parser/Parser.js +180 -41
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/SGParser.d.ts +1 -0
- package/dist/parser/SGParser.js +9 -0
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/Statement.d.ts +6 -1
- package/dist/parser/Statement.js +22 -14
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +4 -2
- package/dist/parser/TranspileState.js +10 -4
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/roku-types/data.json +210 -3
- package/dist/types/ArrayType.js +6 -1
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BooleanType.js +1 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/CallFuncableType.d.ts +1 -1
- package/dist/types/ClassType.js +3 -0
- package/dist/types/ClassType.js.map +1 -1
- package/dist/types/ComponentType.js +3 -0
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/EnumType.js +3 -0
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/IntersectionType.js +3 -0
- package/dist/types/IntersectionType.js.map +1 -1
- package/dist/types/ReferenceType.js +6 -0
- package/dist/types/ReferenceType.js.map +1 -1
- package/dist/types/TypeStatementType.d.ts +1 -0
- package/dist/types/TypeStatementType.js +12 -1
- package/dist/types/TypeStatementType.js.map +1 -1
- package/dist/types/TypedFunctionType.js +20 -10
- package/dist/types/TypedFunctionType.js.map +1 -1
- package/dist/types/UnionType.js +3 -0
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/helpers.js +6 -0
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +42 -3
- package/dist/util.js +131 -7
- package/dist/util.js.map +1 -1
- package/package.json +24 -26
- package/dist/astUtils/CachedLookups.spec.d.ts +0 -1
- package/dist/astUtils/CachedLookups.spec.js +0 -39
- package/dist/astUtils/CachedLookups.spec.js.map +0 -1
- package/dist/astUtils/Editor.spec.d.ts +0 -1
- package/dist/astUtils/Editor.spec.js +0 -258
- package/dist/astUtils/Editor.spec.js.map +0 -1
- package/dist/astUtils/creators.spec.d.ts +0 -1
- package/dist/astUtils/creators.spec.js +0 -21
- package/dist/astUtils/creators.spec.js.map +0 -1
- package/dist/astUtils/reflection.spec.d.ts +0 -1
- package/dist/astUtils/reflection.spec.js +0 -392
- package/dist/astUtils/reflection.spec.js.map +0 -1
- package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
- package/dist/astUtils/stackedVisitor.spec.js +0 -79
- package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
- package/dist/astUtils/visitors.spec.d.ts +0 -1
- package/dist/astUtils/visitors.spec.js +0 -1432
- package/dist/astUtils/visitors.spec.js.map +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -311
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +0 -2512
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -87
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -991
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -564
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +0 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +0 -33
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -291
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +0 -75
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -1517
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +0 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +0 -6135
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +0 -1
- package/dist/common/Sequencer.spec.d.ts +0 -1
- package/dist/common/Sequencer.spec.js +0 -75
- package/dist/common/Sequencer.spec.js.map +0 -1
- package/dist/files/BrsFile.Class.spec.d.ts +0 -1
- package/dist/files/BrsFile.Class.spec.js +0 -2035
- package/dist/files/BrsFile.Class.spec.js.map +0 -1
- package/dist/files/BrsFile.spec.d.ts +0 -1
- package/dist/files/BrsFile.spec.js +0 -5848
- package/dist/files/BrsFile.spec.js.map +0 -1
- package/dist/files/LazyFileData.spec.d.ts +0 -1
- package/dist/files/LazyFileData.spec.js +0 -27
- package/dist/files/LazyFileData.spec.js.map +0 -1
- package/dist/files/XmlFile.spec.d.ts +0 -1
- package/dist/files/XmlFile.spec.js +0 -1173
- package/dist/files/XmlFile.spec.js.map +0 -1
- package/dist/files/tests/imports.spec.d.ts +0 -1
- package/dist/files/tests/imports.spec.js +0 -251
- package/dist/files/tests/imports.spec.js.map +0 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
- package/dist/files/tests/optionalChaning.spec.js +0 -152
- package/dist/files/tests/optionalChaning.spec.js.map +0 -1
- package/dist/lexer/Character.spec.d.ts +0 -1
- package/dist/lexer/Character.spec.js +0 -27
- package/dist/lexer/Character.spec.js.map +0 -1
- package/dist/lexer/Lexer.spec.d.ts +0 -1
- package/dist/lexer/Lexer.spec.js +0 -1345
- package/dist/lexer/Lexer.spec.js.map +0 -1
- package/dist/lsp/ActionQueue.spec.d.ts +0 -1
- package/dist/lsp/ActionQueue.spec.js +0 -80
- package/dist/lsp/ActionQueue.spec.js.map +0 -1
- package/dist/lsp/DocumentManager.spec.d.ts +0 -1
- package/dist/lsp/DocumentManager.spec.js +0 -103
- package/dist/lsp/DocumentManager.spec.js.map +0 -1
- package/dist/lsp/PathFilterer.spec.d.ts +0 -1
- package/dist/lsp/PathFilterer.spec.js +0 -182
- package/dist/lsp/PathFilterer.spec.js.map +0 -1
- package/dist/lsp/Project.spec.d.ts +0 -1
- package/dist/lsp/Project.spec.js +0 -267
- package/dist/lsp/Project.spec.js.map +0 -1
- package/dist/lsp/ProjectManager.spec.d.ts +0 -1
- package/dist/lsp/ProjectManager.spec.js +0 -913
- package/dist/lsp/ProjectManager.spec.js.map +0 -1
- package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
- package/dist/lsp/worker/MessageHandler.spec.js +0 -64
- package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
- package/dist/lsp/worker/WorkerPool.spec.js +0 -59
- package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
- package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -71
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
- package/dist/parser/AstNode.spec.d.ts +0 -1
- package/dist/parser/AstNode.spec.js +0 -1455
- package/dist/parser/AstNode.spec.js.map +0 -1
- package/dist/parser/BrightScriptDocParser.spec.d.ts +0 -1
- package/dist/parser/BrightScriptDocParser.spec.js +0 -310
- package/dist/parser/BrightScriptDocParser.spec.js.map +0 -1
- package/dist/parser/Expression.spec.d.ts +0 -1
- package/dist/parser/Expression.spec.js +0 -40
- package/dist/parser/Expression.spec.js.map +0 -1
- package/dist/parser/Parser.Class.spec.d.ts +0 -1
- package/dist/parser/Parser.Class.spec.js +0 -520
- package/dist/parser/Parser.Class.spec.js.map +0 -1
- package/dist/parser/Parser.spec.d.ts +0 -6
- package/dist/parser/Parser.spec.js +0 -2802
- package/dist/parser/Parser.spec.js.map +0 -1
- package/dist/parser/SGParser.spec.d.ts +0 -1
- package/dist/parser/SGParser.spec.js +0 -130
- package/dist/parser/SGParser.spec.js.map +0 -1
- package/dist/parser/Statement.spec.d.ts +0 -1
- package/dist/parser/Statement.spec.js +0 -191
- package/dist/parser/Statement.spec.js.map +0 -1
- package/dist/parser/tests/Parser.spec.d.ts +0 -12
- package/dist/parser/tests/Parser.spec.js +0 -29
- package/dist/parser/tests/Parser.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/For.spec.js +0 -169
- package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -140
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/If.spec.js +0 -694
- package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/While.spec.js +0 -114
- package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
- package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Additive.spec.js +0 -107
- package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -304
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -342
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Boolean.spec.js +0 -90
- package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
- package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Call.spec.js +0 -252
- package/dist/parser/tests/expression/Call.spec.js.map +0 -1
- package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Exponential.spec.js +0 -37
- package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
- package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Function.spec.js +0 -412
- package/dist/parser/tests/expression/Function.spec.js.map +0 -1
- package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Indexing.spec.js +0 -302
- package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -111
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
- package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Primary.spec.js +0 -165
- package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Relational.spec.js +0 -83
- package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -878
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TypeExpression.spec.js +0 -126
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +0 -500
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Continue.spec.js +0 -119
- package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
- package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Declaration.spec.js +0 -114
- package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
- package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Dim.spec.js +0 -80
- package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Enum.spec.js +0 -744
- package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
- package/dist/parser/tests/statement/For.spec.d.ts +0 -1
- package/dist/parser/tests/statement/For.spec.js +0 -45
- package/dist/parser/tests/statement/For.spec.js.map +0 -1
- package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ForEach.spec.js +0 -36
- package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
- package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Function.spec.js +0 -343
- package/dist/parser/tests/statement/Function.spec.js.map +0 -1
- package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Goto.spec.js +0 -51
- package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
- package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Increment.spec.js +0 -120
- package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -110
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Misc.spec.js +0 -292
- package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +0 -200
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -97
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Set.spec.js +0 -232
- package/dist/parser/tests/statement/Set.spec.js.map +0 -1
- package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Stop.spec.js +0 -38
- package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
- package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Throw.spec.js +0 -38
- package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +0 -151
- package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
- package/dist/preprocessor/Manifest.spec.d.ts +0 -1
- package/dist/preprocessor/Manifest.spec.js +0 -80
- package/dist/preprocessor/Manifest.spec.js.map +0 -1
- package/dist/types/ArrayType.spec.d.ts +0 -1
- package/dist/types/ArrayType.spec.js +0 -58
- package/dist/types/ArrayType.spec.js.map +0 -1
- package/dist/types/BooleanType.spec.d.ts +0 -1
- package/dist/types/BooleanType.spec.js +0 -18
- package/dist/types/BooleanType.spec.js.map +0 -1
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +0 -1
- package/dist/types/BuiltInInterfaceAdder.spec.js +0 -115
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +0 -1
- package/dist/types/ClassType.spec.d.ts +0 -1
- package/dist/types/ClassType.spec.js +0 -76
- package/dist/types/ClassType.spec.js.map +0 -1
- package/dist/types/DoubleType.spec.d.ts +0 -1
- package/dist/types/DoubleType.spec.js +0 -20
- package/dist/types/DoubleType.spec.js.map +0 -1
- package/dist/types/DynamicType.spec.d.ts +0 -1
- package/dist/types/DynamicType.spec.js +0 -23
- package/dist/types/DynamicType.spec.js.map +0 -1
- package/dist/types/EnumType.spec.d.ts +0 -1
- package/dist/types/EnumType.spec.js +0 -33
- package/dist/types/EnumType.spec.js.map +0 -1
- package/dist/types/FloatType.spec.d.ts +0 -1
- package/dist/types/FloatType.spec.js +0 -12
- package/dist/types/FloatType.spec.js.map +0 -1
- package/dist/types/IntegerType.spec.d.ts +0 -1
- package/dist/types/IntegerType.spec.js +0 -16
- package/dist/types/IntegerType.spec.js.map +0 -1
- package/dist/types/InterfaceType.spec.d.ts +0 -1
- package/dist/types/InterfaceType.spec.js +0 -227
- package/dist/types/InterfaceType.spec.js.map +0 -1
- package/dist/types/IntersectionType.spec.d.ts +0 -1
- package/dist/types/IntersectionType.spec.js +0 -150
- package/dist/types/IntersectionType.spec.js.map +0 -1
- package/dist/types/InvalidType.spec.d.ts +0 -1
- package/dist/types/InvalidType.spec.js +0 -16
- package/dist/types/InvalidType.spec.js.map +0 -1
- package/dist/types/LongIntegerType.spec.d.ts +0 -1
- package/dist/types/LongIntegerType.spec.js +0 -18
- package/dist/types/LongIntegerType.spec.js.map +0 -1
- package/dist/types/ObjectType.spec.d.ts +0 -1
- package/dist/types/ObjectType.spec.js +0 -12
- package/dist/types/ObjectType.spec.js.map +0 -1
- package/dist/types/ReferenceType.spec.d.ts +0 -1
- package/dist/types/ReferenceType.spec.js +0 -151
- package/dist/types/ReferenceType.spec.js.map +0 -1
- package/dist/types/StringType.spec.d.ts +0 -1
- package/dist/types/StringType.spec.js +0 -12
- package/dist/types/StringType.spec.js.map +0 -1
- package/dist/types/TypedFunctionType.spec.d.ts +0 -1
- package/dist/types/TypedFunctionType.spec.js +0 -122
- package/dist/types/TypedFunctionType.spec.js.map +0 -1
- package/dist/types/UnionType.spec.d.ts +0 -1
- package/dist/types/UnionType.spec.js +0 -205
- package/dist/types/UnionType.spec.js.map +0 -1
- package/dist/types/VoidType.spec.d.ts +0 -1
- package/dist/types/VoidType.spec.js +0 -12
- package/dist/types/VoidType.spec.js.map +0 -1
- package/dist/types/helper.spec.d.ts +0 -1
- package/dist/types/helper.spec.js +0 -174
- package/dist/types/helper.spec.js.map +0 -1
- package/dist/types/roFunctionType.spec.d.ts +0 -1
- package/dist/types/roFunctionType.spec.js +0 -20
- package/dist/types/roFunctionType.spec.js.map +0 -1
package/dist/lexer/Lexer.spec.js
DELETED
|
@@ -1,1345 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint no-template-curly-in-string: 0 */
|
|
4
|
-
const chai_config_spec_1 = require("../chai-config.spec");
|
|
5
|
-
const TokenKind_1 = require("./TokenKind");
|
|
6
|
-
const Lexer_1 = require("./Lexer");
|
|
7
|
-
const Token_1 = require("./Token");
|
|
8
|
-
const Parser_spec_1 = require("../parser/Parser.spec");
|
|
9
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
10
|
-
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
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
|
-
});
|
|
19
|
-
it('recognizes namespace keywords', () => {
|
|
20
|
-
let { tokens } = Lexer_1.Lexer.scan('namespace end namespace endnamespace end namespace');
|
|
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
|
|
83
|
-
]);
|
|
84
|
-
});
|
|
85
|
-
it('recognizes the callfunc operator', () => {
|
|
86
|
-
let { tokens } = Lexer_1.Lexer.scan('@.');
|
|
87
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Callfunc);
|
|
88
|
-
});
|
|
89
|
-
it('recognizes the import token', () => {
|
|
90
|
-
let { tokens } = Lexer_1.Lexer.scan('import');
|
|
91
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Import);
|
|
92
|
-
});
|
|
93
|
-
it('recognizes library token', () => {
|
|
94
|
-
let { tokens } = Lexer_1.Lexer.scan('library');
|
|
95
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Library);
|
|
96
|
-
});
|
|
97
|
-
it('produces an at symbol token', () => {
|
|
98
|
-
let { tokens } = Lexer_1.Lexer.scan('@');
|
|
99
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.At);
|
|
100
|
-
});
|
|
101
|
-
it('produces a semicolon token', () => {
|
|
102
|
-
let { tokens } = Lexer_1.Lexer.scan(';');
|
|
103
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Semicolon);
|
|
104
|
-
});
|
|
105
|
-
it('emits error on unknown character type', () => {
|
|
106
|
-
let { diagnostics } = Lexer_1.Lexer.scan('\0');
|
|
107
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1);
|
|
108
|
-
});
|
|
109
|
-
it('includes an end-of-file marker', () => {
|
|
110
|
-
let { tokens } = Lexer_1.Lexer.scan('');
|
|
111
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
|
|
112
|
-
});
|
|
113
|
-
it('ignores tabs and spaces', () => {
|
|
114
|
-
let { tokens } = Lexer_1.Lexer.scan('\t\t \t \t');
|
|
115
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
|
|
116
|
-
});
|
|
117
|
-
it('retains every single newline', () => {
|
|
118
|
-
let { tokens } = Lexer_1.Lexer.scan('\n\n\'foo\n\n\nprint 2\n\n');
|
|
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
|
|
130
|
-
]);
|
|
131
|
-
});
|
|
132
|
-
it('does not insert double newlines with the windows \\r\\n newline', () => {
|
|
133
|
-
let kinds = Lexer_1.Lexer.scan('function boolToNumber() as string\r\n' +
|
|
134
|
-
' if true then\r\n' +
|
|
135
|
-
' print 1\r\n' +
|
|
136
|
-
' else\r\n' +
|
|
137
|
-
' print 0\r\n' +
|
|
138
|
-
' end if\r\n' +
|
|
139
|
-
'end function\r\n').tokens.map(x => x.kind);
|
|
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
|
|
149
|
-
]);
|
|
150
|
-
});
|
|
151
|
-
it('computes range properly both with and without whitespace', () => {
|
|
152
|
-
let withoutWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
153
|
-
.map(x => { var _a; return (0, Parser_spec_1.rangeToArray)((_a = x.location) === null || _a === void 0 ? void 0 : _a.range); });
|
|
154
|
-
let withWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
155
|
-
//filter out the whitespace...we only care that it was computed during the scan
|
|
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); });
|
|
158
|
-
/*eslint-disable */
|
|
159
|
-
let expectedLocations = [
|
|
160
|
-
[0, 0, 0, 3],
|
|
161
|
-
[0, 4, 0, 8],
|
|
162
|
-
[0, 8, 0, 9],
|
|
163
|
-
[0, 9, 0, 10],
|
|
164
|
-
[0, 10, 0, 11],
|
|
165
|
-
[1, 4, 1, 7],
|
|
166
|
-
[1, 8, 1, 9],
|
|
167
|
-
[1, 10, 1, 14],
|
|
168
|
-
[1, 14, 1, 15],
|
|
169
|
-
[2, 0, 2, 7],
|
|
170
|
-
[2, 7, 2, 8] //Eof
|
|
171
|
-
];
|
|
172
|
-
/*eslint-enable*/
|
|
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);
|
|
175
|
-
});
|
|
176
|
-
it('retains original line endings', () => {
|
|
177
|
-
let { tokens } = Lexer_1.Lexer.scan('print "hello"\r\nprint "world"\n');
|
|
178
|
-
(0, chai_config_spec_1.expect)([
|
|
179
|
-
tokens[2].text.charCodeAt(0),
|
|
180
|
-
tokens[2].text.charCodeAt(1)
|
|
181
|
-
], 'should contain \\r\\n').to.eql([13, 10]);
|
|
182
|
-
(0, chai_config_spec_1.expect)(tokens[5].text.charCodeAt(0), 'should contain \\r\\n').to.eql(10);
|
|
183
|
-
});
|
|
184
|
-
it('correctly splits the elseif token', () => {
|
|
185
|
-
let { tokens } = Lexer_1.Lexer.scan('else if elseif else if');
|
|
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
|
|
194
|
-
]);
|
|
195
|
-
});
|
|
196
|
-
it('gives the `as` keyword its own TokenKind', () => {
|
|
197
|
-
let { tokens } = Lexer_1.Lexer.scan('as');
|
|
198
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.As, TokenKind_1.TokenKind.Eof]);
|
|
199
|
-
});
|
|
200
|
-
it('gives the `stop` keyword its own TokenKind', () => {
|
|
201
|
-
let { tokens } = Lexer_1.Lexer.scan('stop');
|
|
202
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Stop, TokenKind_1.TokenKind.Eof]);
|
|
203
|
-
});
|
|
204
|
-
it('does not alias \'?\' to \'print\' - the parser will do that', () => {
|
|
205
|
-
let { tokens } = Lexer_1.Lexer.scan('?2');
|
|
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]);
|
|
207
|
-
});
|
|
208
|
-
describe('comments', () => {
|
|
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', () => {
|
|
228
|
-
let tokens = Lexer_1.Lexer.scan(`'someComment\r\nprint "hello"`).tokens;
|
|
229
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Newline);
|
|
230
|
-
});
|
|
231
|
-
it('includes no comment characters in the text', () => {
|
|
232
|
-
let text = Lexer_1.Lexer.scan(`
|
|
233
|
-
'comment
|
|
234
|
-
REM some comment
|
|
235
|
-
`).tokens
|
|
236
|
-
.filter(x => ![TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Eof].includes(x.kind))
|
|
237
|
-
.map(x => x.text);
|
|
238
|
-
(0, chai_config_spec_1.expect)(text).to.eql([]);
|
|
239
|
-
});
|
|
240
|
-
it('tracks the correct location', () => {
|
|
241
|
-
let tokens = Lexer_1.Lexer.scan(`
|
|
242
|
-
sub main() 'first comment
|
|
243
|
-
k = 2 ' second comment
|
|
244
|
-
REM third comment
|
|
245
|
-
end sub
|
|
246
|
-
`, {
|
|
247
|
-
includeWhitespace: true
|
|
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([
|
|
250
|
-
[0, 0, 0, 1, '\n'],
|
|
251
|
-
[1, 0, 1, 16, ' '],
|
|
252
|
-
[1, 16, 1, 19, 'sub'],
|
|
253
|
-
[1, 19, 1, 20, ' '],
|
|
254
|
-
[1, 20, 1, 24, 'main'],
|
|
255
|
-
[1, 24, 1, 25, '('],
|
|
256
|
-
[1, 25, 1, 26, ')'],
|
|
257
|
-
[1, 26, 1, 27, ' '],
|
|
258
|
-
// skip `'first comment`
|
|
259
|
-
[1, 41, 1, 42, '\n'],
|
|
260
|
-
[2, 0, 2, 20, ' '],
|
|
261
|
-
[2, 20, 2, 21, 'k'],
|
|
262
|
-
[2, 21, 2, 22, ' '],
|
|
263
|
-
[2, 22, 2, 23, '='],
|
|
264
|
-
[2, 23, 2, 24, ' '],
|
|
265
|
-
[2, 24, 2, 25, '2'],
|
|
266
|
-
[2, 25, 2, 26, ' '],
|
|
267
|
-
// skip `' second comment`
|
|
268
|
-
[2, 42, 2, 43, '\n'],
|
|
269
|
-
[3, 0, 3, 20, ' '],
|
|
270
|
-
// skip `REM third comment`
|
|
271
|
-
[3, 37, 3, 38, '\n'],
|
|
272
|
-
[4, 0, 4, 16, ' '],
|
|
273
|
-
[4, 16, 4, 23, 'end sub'],
|
|
274
|
-
[4, 23, 4, 24, '\n'],
|
|
275
|
-
[5, 0, 5, 12, ' '],
|
|
276
|
-
[5, 12, 5, 13, ''] //EOF
|
|
277
|
-
]);
|
|
278
|
-
});
|
|
279
|
-
it('finds correct location for newlines', () => {
|
|
280
|
-
let tokens = Lexer_1.Lexer.scan('sub\nsub\r\nsub\n\n').tokens
|
|
281
|
-
//ignore the Eof token
|
|
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([
|
|
284
|
-
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
285
|
-
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
286
|
-
vscode_languageserver_1.Range.create(1, 0, 1, 3),
|
|
287
|
-
vscode_languageserver_1.Range.create(1, 3, 1, 5),
|
|
288
|
-
vscode_languageserver_1.Range.create(2, 0, 2, 3),
|
|
289
|
-
vscode_languageserver_1.Range.create(2, 3, 2, 4),
|
|
290
|
-
vscode_languageserver_1.Range.create(3, 0, 3, 1) // /n
|
|
291
|
-
]);
|
|
292
|
-
});
|
|
293
|
-
it('ignores everything after `\'`', () => {
|
|
294
|
-
let { tokens } = Lexer_1.Lexer.scan('= \' (');
|
|
295
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
296
|
-
});
|
|
297
|
-
it('ignores everything after `REM`', () => {
|
|
298
|
-
let { tokens } = Lexer_1.Lexer.scan('= REM (');
|
|
299
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
300
|
-
});
|
|
301
|
-
it('ignores everything after `rem`', () => {
|
|
302
|
-
let { tokens } = Lexer_1.Lexer.scan('= rem (');
|
|
303
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Eof]);
|
|
304
|
-
});
|
|
305
|
-
}); // comments
|
|
306
|
-
describe('non-literals', () => {
|
|
307
|
-
it('reads parens & braces', () => {
|
|
308
|
-
let { tokens } = Lexer_1.Lexer.scan('(){}');
|
|
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
|
|
315
|
-
]);
|
|
316
|
-
});
|
|
317
|
-
it('reads operators', () => {
|
|
318
|
-
let { tokens } = Lexer_1.Lexer.scan('^ - + * MOD / \\ -- ++');
|
|
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
|
|
330
|
-
]);
|
|
331
|
-
});
|
|
332
|
-
it('reads bitshift operators', () => {
|
|
333
|
-
let { tokens } = Lexer_1.Lexer.scan('<< >> <<');
|
|
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
|
|
339
|
-
]);
|
|
340
|
-
});
|
|
341
|
-
it('reads bitshift assignment operators', () => {
|
|
342
|
-
let { tokens } = Lexer_1.Lexer.scan('<<= >>=');
|
|
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
|
|
347
|
-
]);
|
|
348
|
-
});
|
|
349
|
-
it('reads comparators', () => {
|
|
350
|
-
let { tokens } = Lexer_1.Lexer.scan('< <= > >= = <>');
|
|
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
|
|
359
|
-
]);
|
|
360
|
-
});
|
|
361
|
-
}); // non-literals
|
|
362
|
-
describe('string literals', () => {
|
|
363
|
-
it('produces string literal tokens', () => {
|
|
364
|
-
let { tokens } = Lexer_1.Lexer.scan(`"hello world"`);
|
|
365
|
-
(0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.StringLiteral, TokenKind_1.TokenKind.Eof]);
|
|
366
|
-
});
|
|
367
|
-
it(`safely escapes " literals`, () => {
|
|
368
|
-
let { tokens } = Lexer_1.Lexer.scan(`"the cat says ""meow"""`);
|
|
369
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.StringLiteral);
|
|
370
|
-
});
|
|
371
|
-
it('captures text to end of line for unterminated strings with LF', () => {
|
|
372
|
-
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\n`);
|
|
373
|
-
(0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.StringLiteral);
|
|
374
|
-
});
|
|
375
|
-
it('captures text to end of line for unterminated strings with CRLF', () => {
|
|
376
|
-
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\r\n`);
|
|
377
|
-
(0, chai_config_spec_1.expect)(tokens[0].text).to.equal('"unterminated!');
|
|
378
|
-
});
|
|
379
|
-
it('disallows multiline strings', () => {
|
|
380
|
-
let { diagnostics } = Lexer_1.Lexer.scan(`"multi-line\n\n`);
|
|
381
|
-
(0, chai_config_spec_1.expect)(diagnostics.map(err => err.message)).to.deep.equal([
|
|
382
|
-
DiagnosticMessages_1.DiagnosticMessages.unterminatedString().message
|
|
383
|
-
]);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
// template string literals
|
|
387
|
-
describe('template string literals', () => {
|
|
388
|
-
it('supports escaped chars', () => {
|
|
389
|
-
let { tokens } = Lexer_1.Lexer.scan('`\\n\\`\\r\\n`');
|
|
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
|
|
403
|
-
]);
|
|
404
|
-
(0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
405
|
-
10,
|
|
406
|
-
96,
|
|
407
|
-
13,
|
|
408
|
-
10
|
|
409
|
-
]);
|
|
410
|
-
});
|
|
411
|
-
it('prevents expressions when escaping the dollar sign', () => {
|
|
412
|
-
let { tokens } = Lexer_1.Lexer.scan('`\\${just text}`');
|
|
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
|
|
420
|
-
]);
|
|
421
|
-
});
|
|
422
|
-
it('supports escaping unicode char codes', () => {
|
|
423
|
-
let { tokens } = Lexer_1.Lexer.scan('`\\c1\\c12\\c123`');
|
|
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
|
|
435
|
-
]);
|
|
436
|
-
(0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
437
|
-
1,
|
|
438
|
-
12,
|
|
439
|
-
123
|
|
440
|
-
]);
|
|
441
|
-
});
|
|
442
|
-
it('converts doublequote to EscapedCharCodeLiteral', () => {
|
|
443
|
-
let { tokens } = Lexer_1.Lexer.scan('`"`');
|
|
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
|
|
451
|
-
]);
|
|
452
|
-
(0, chai_config_spec_1.expect)(tokens[2].charCode).to.equal(34);
|
|
453
|
-
});
|
|
454
|
-
it(`safely escapes \` literals`, () => {
|
|
455
|
-
let { tokens } = Lexer_1.Lexer.scan('`the cat says \\`meow\\` a lot`');
|
|
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
|
|
465
|
-
]);
|
|
466
|
-
(0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
467
|
-
'`',
|
|
468
|
-
'the cat says ',
|
|
469
|
-
'\\`',
|
|
470
|
-
'meow',
|
|
471
|
-
'\\`',
|
|
472
|
-
' a lot',
|
|
473
|
-
'`',
|
|
474
|
-
'' //EOF
|
|
475
|
-
]);
|
|
476
|
-
});
|
|
477
|
-
it('produces template string literal tokens', () => {
|
|
478
|
-
let { tokens } = Lexer_1.Lexer.scan('`hello world`');
|
|
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
|
|
484
|
-
]);
|
|
485
|
-
(0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal('hello world');
|
|
486
|
-
});
|
|
487
|
-
it('collects quasis outside and expressions inside of template strings', () => {
|
|
488
|
-
let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!`');
|
|
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
|
|
498
|
-
]);
|
|
499
|
-
(0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal(`hello `);
|
|
500
|
-
});
|
|
501
|
-
it('real example, which is causing issues in the formatter', () => {
|
|
502
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
503
|
-
function getItemXML(item)
|
|
504
|
-
return \`
|
|
505
|
-
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
|
|
506
|
-
<channel>
|
|
507
|
-
<title>smithsonian</title>
|
|
508
|
-
<item>
|
|
509
|
-
<title>\${item.title}</title>
|
|
510
|
-
<guid>\${item.vamsId}</guid>
|
|
511
|
-
<media:rating scheme="urn:v-chip">\${item.ratings.first.code.name}</media:rating>
|
|
512
|
-
</item>
|
|
513
|
-
</channel>
|
|
514
|
-
</rss>
|
|
515
|
-
\`
|
|
516
|
-
end function
|
|
517
|
-
`);
|
|
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
|
|
592
|
-
]);
|
|
593
|
-
});
|
|
594
|
-
it('complicated example', () => {
|
|
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`');
|
|
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
|
|
630
|
-
]);
|
|
631
|
-
});
|
|
632
|
-
it('allows multiline strings', () => {
|
|
633
|
-
let { tokens } = Lexer_1.Lexer.scan('`multi-line\n\n`');
|
|
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
|
|
643
|
-
]);
|
|
644
|
-
(0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
645
|
-
'`',
|
|
646
|
-
'multi-line',
|
|
647
|
-
'\n',
|
|
648
|
-
'',
|
|
649
|
-
'\n',
|
|
650
|
-
'',
|
|
651
|
-
'`',
|
|
652
|
-
'' //EOF
|
|
653
|
-
]);
|
|
654
|
-
});
|
|
655
|
-
it('maintains proper line/column locations for multiline strings', () => {
|
|
656
|
-
let { tokens } = Lexer_1.Lexer.scan('123 `multi\nline\r\nstrings` true\nfalse');
|
|
657
|
-
(0, chai_config_spec_1.expect)(tokens.map(x => {
|
|
658
|
-
var _a;
|
|
659
|
-
return {
|
|
660
|
-
range: (_a = x.location) === null || _a === void 0 ? void 0 : _a.range,
|
|
661
|
-
kind: x.kind
|
|
662
|
-
};
|
|
663
|
-
})).to.eql([
|
|
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 }
|
|
677
|
-
]);
|
|
678
|
-
});
|
|
679
|
-
it('Example that tripped up the expression tests', () => {
|
|
680
|
-
let { tokens } = Lexer_1.Lexer.scan('`I am a complex example\n${a.isRunning(["a","b","c"])}\nmore ${m.finish(true)}`');
|
|
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
|
|
714
|
-
]);
|
|
715
|
-
});
|
|
716
|
-
}); // string literals
|
|
717
|
-
describe('double literals', () => {
|
|
718
|
-
it('respects \'#\' suffix', () => {
|
|
719
|
-
let d = Lexer_1.Lexer.scan('123#').tokens[0];
|
|
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#');
|
|
722
|
-
});
|
|
723
|
-
it('forces literals >= 10 digits into doubles', () => {
|
|
724
|
-
let d = Lexer_1.Lexer.scan('0000000005').tokens[0];
|
|
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');
|
|
727
|
-
});
|
|
728
|
-
it('forces literals with \'D\' in exponent into doubles', () => {
|
|
729
|
-
let d = Lexer_1.Lexer.scan('2.5d3').tokens[0];
|
|
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');
|
|
732
|
-
});
|
|
733
|
-
it('allows digits before `.` to be elided', () => {
|
|
734
|
-
let f = Lexer_1.Lexer.scan('.123#').tokens[0];
|
|
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#');
|
|
737
|
-
});
|
|
738
|
-
it('allows digits after `.` to be elided', () => {
|
|
739
|
-
let f = Lexer_1.Lexer.scan('12.#').tokens[0];
|
|
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.#');
|
|
742
|
-
});
|
|
743
|
-
});
|
|
744
|
-
describe('float literals', () => {
|
|
745
|
-
it('respects \'!\' suffix', () => {
|
|
746
|
-
let f = Lexer_1.Lexer.scan('0.00000008!').tokens[0];
|
|
747
|
-
(0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
|
|
748
|
-
// Floating precision will make this *not* equal
|
|
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!');
|
|
751
|
-
});
|
|
752
|
-
it('forces literals with a decimal into floats', () => {
|
|
753
|
-
let f = Lexer_1.Lexer.scan('1.0').tokens[0];
|
|
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');
|
|
756
|
-
});
|
|
757
|
-
it('forces literals with \'E\' in exponent into floats', () => {
|
|
758
|
-
let f = Lexer_1.Lexer.scan('2.5e3').tokens[0];
|
|
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!');
|
|
776
|
-
});
|
|
777
|
-
it('supports larger-than-supported-precision floats to be defined with exponents', () => {
|
|
778
|
-
let f = Lexer_1.Lexer.scan('2.3659475627512424e-38').tokens[0];
|
|
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');
|
|
781
|
-
});
|
|
782
|
-
it('allows digits before `.` to be elided', () => {
|
|
783
|
-
let f = Lexer_1.Lexer.scan('.123').tokens[0];
|
|
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');
|
|
786
|
-
});
|
|
787
|
-
it('allows digits after `.` to be elided', () => {
|
|
788
|
-
let f = Lexer_1.Lexer.scan('12.').tokens[0];
|
|
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.');
|
|
791
|
-
});
|
|
792
|
-
});
|
|
793
|
-
describe('long integer literals', () => {
|
|
794
|
-
it('respects \'&\' suffix', () => {
|
|
795
|
-
let f = Lexer_1.Lexer.scan('1&').tokens[0];
|
|
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&');
|
|
798
|
-
});
|
|
799
|
-
it('supports hexadecimal literals', () => {
|
|
800
|
-
let i = Lexer_1.Lexer.scan('&hf00d&').tokens[0];
|
|
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&');
|
|
803
|
-
});
|
|
804
|
-
it('allows very long Int64 literals', () => {
|
|
805
|
-
let li = Lexer_1.Lexer.scan('9876543210&').tokens[0];
|
|
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&');
|
|
808
|
-
});
|
|
809
|
-
it('forces literals with \'&\' suffix into Int64s', () => {
|
|
810
|
-
let li = Lexer_1.Lexer.scan('123&').tokens[0];
|
|
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&');
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
describe('integer literals', () => {
|
|
816
|
-
it('respects \'%\' suffix', () => {
|
|
817
|
-
let f = Lexer_1.Lexer.scan('1%').tokens[0];
|
|
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%');
|
|
820
|
-
});
|
|
821
|
-
it('does not allow decimal numbers to end with %', () => {
|
|
822
|
-
let f = Lexer_1.Lexer.scan('1.2%').tokens[0];
|
|
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');
|
|
825
|
-
});
|
|
826
|
-
it('supports hexadecimal literals', () => {
|
|
827
|
-
let i = Lexer_1.Lexer.scan('&hFf').tokens[0];
|
|
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');
|
|
830
|
-
});
|
|
831
|
-
it('falls back to a regular integer', () => {
|
|
832
|
-
let i = Lexer_1.Lexer.scan('123').tokens[0];
|
|
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');
|
|
835
|
-
});
|
|
836
|
-
});
|
|
837
|
-
describe('types', () => {
|
|
838
|
-
it('captures type tokens', () => {
|
|
839
|
-
(0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan(`
|
|
840
|
-
void boolean integer longinteger float double string object interface invalid dynamic
|
|
841
|
-
`.trim()).tokens.map(x => x.kind)).to.eql([
|
|
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
|
|
854
|
-
]);
|
|
855
|
-
});
|
|
856
|
-
});
|
|
857
|
-
describe('identifiers', () => {
|
|
858
|
-
it('matches single-word keywords', () => {
|
|
859
|
-
// test just a sample of single-word reserved words for now.
|
|
860
|
-
// if we find any that we've missed
|
|
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
|
|
875
|
-
]);
|
|
876
|
-
});
|
|
877
|
-
it('matches multi-word keywords', () => {
|
|
878
|
-
let { tokens } = Lexer_1.Lexer.scan('end if end while End Sub end Function Exit wHILe');
|
|
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
|
|
887
|
-
]);
|
|
888
|
-
});
|
|
889
|
-
it('accepts \'exit for\' but not \'exitfor\'', () => {
|
|
890
|
-
let { tokens } = Lexer_1.Lexer.scan('exit for exitfor');
|
|
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
|
|
896
|
-
]);
|
|
897
|
-
});
|
|
898
|
-
it('matches keywords with silly capitalization', () => {
|
|
899
|
-
let { tokens } = Lexer_1.Lexer.scan('iF ELSE eNDIf FUncTioN');
|
|
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
|
|
906
|
-
]);
|
|
907
|
-
});
|
|
908
|
-
it('allows alpha-numeric (plus \'_\') identifiers', () => {
|
|
909
|
-
let identifier = Lexer_1.Lexer.scan('_abc_123_').tokens[0];
|
|
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_');
|
|
912
|
-
});
|
|
913
|
-
it('allows identifiers with trailing type designators', () => {
|
|
914
|
-
let { tokens } = Lexer_1.Lexer.scan('lorem$ ipsum% dolor! sit# amet&');
|
|
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([
|
|
918
|
-
'lorem$',
|
|
919
|
-
'ipsum%',
|
|
920
|
-
'dolor!',
|
|
921
|
-
'sit#',
|
|
922
|
-
'amet&'
|
|
923
|
-
]);
|
|
924
|
-
});
|
|
925
|
-
});
|
|
926
|
-
describe('conditional compilation', () => {
|
|
927
|
-
it('reads constant declarations', () => {
|
|
928
|
-
let { tokens } = Lexer_1.Lexer.scan('#const foo true');
|
|
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
|
|
934
|
-
]);
|
|
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
|
-
});
|
|
977
|
-
it('reads constant aliases', () => {
|
|
978
|
-
let { tokens } = Lexer_1.Lexer.scan('#const bar foo');
|
|
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
|
|
984
|
-
]);
|
|
985
|
-
});
|
|
986
|
-
it('reads conditional directives', () => {
|
|
987
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
988
|
-
#if
|
|
989
|
-
#else if
|
|
990
|
-
#elseif
|
|
991
|
-
#else
|
|
992
|
-
#end if
|
|
993
|
-
#endif
|
|
994
|
-
`, {
|
|
995
|
-
includeWhitespace: false
|
|
996
|
-
});
|
|
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
|
|
1005
|
-
]);
|
|
1006
|
-
});
|
|
1007
|
-
it('treats text "constructor" as an identifier', () => {
|
|
1008
|
-
let lexer = Lexer_1.Lexer.scan(`function constructor()\nend function`);
|
|
1009
|
-
(0, chai_config_spec_1.expect)(lexer.tokens[1].kind).to.equal(TokenKind_1.TokenKind.Identifier);
|
|
1010
|
-
});
|
|
1011
|
-
it('reads upper case conditional directives', () => {
|
|
1012
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
1013
|
-
#IF
|
|
1014
|
-
#ELSE IF
|
|
1015
|
-
#ELSEIF
|
|
1016
|
-
#ELSE
|
|
1017
|
-
#END IF
|
|
1018
|
-
#ENDIF
|
|
1019
|
-
`, {
|
|
1020
|
-
includeWhitespace: false
|
|
1021
|
-
});
|
|
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
|
|
1030
|
-
]);
|
|
1031
|
-
});
|
|
1032
|
-
it('supports various spacings between #endif', () => {
|
|
1033
|
-
let { tokens } = Lexer_1.Lexer.scan('#endif #end if #end\tif #end if #end\t\t if');
|
|
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
|
|
1048
|
-
]);
|
|
1049
|
-
});
|
|
1050
|
-
it('reads forced compilation diagnostics with messages', () => {
|
|
1051
|
-
let { tokens } = Lexer_1.Lexer.scan('#error a message goes here\n', {
|
|
1052
|
-
includeWhitespace: true
|
|
1053
|
-
});
|
|
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
|
|
1060
|
-
]);
|
|
1061
|
-
(0, chai_config_spec_1.expect)(tokens[2].text).to.equal('a message goes here');
|
|
1062
|
-
});
|
|
1063
|
-
});
|
|
1064
|
-
describe('location tracking', () => {
|
|
1065
|
-
it('tracks starting and ending locations including whitespace', () => {
|
|
1066
|
-
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: true });
|
|
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([
|
|
1068
|
-
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
1069
|
-
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
1070
|
-
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
1071
|
-
vscode_languageserver_1.Range.create(0, 7, 0, 8),
|
|
1072
|
-
vscode_languageserver_1.Range.create(0, 8, 0, 9),
|
|
1073
|
-
vscode_languageserver_1.Range.create(0, 9, 0, 10),
|
|
1074
|
-
vscode_languageserver_1.Range.create(1, 0, 1, 4),
|
|
1075
|
-
vscode_languageserver_1.Range.create(1, 4, 1, 9),
|
|
1076
|
-
vscode_languageserver_1.Range.create(1, 9, 1, 10),
|
|
1077
|
-
vscode_languageserver_1.Range.create(1, 10, 1, 15),
|
|
1078
|
-
vscode_languageserver_1.Range.create(1, 15, 1, 17),
|
|
1079
|
-
vscode_languageserver_1.Range.create(2, 0, 2, 7),
|
|
1080
|
-
vscode_languageserver_1.Range.create(2, 7, 2, 8) // EOF
|
|
1081
|
-
]);
|
|
1082
|
-
});
|
|
1083
|
-
it('tracks starting and ending locations excluding whitespace', () => {
|
|
1084
|
-
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: false });
|
|
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([
|
|
1086
|
-
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
1087
|
-
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
1088
|
-
vscode_languageserver_1.Range.create(0, 7, 0, 8),
|
|
1089
|
-
vscode_languageserver_1.Range.create(0, 8, 0, 9),
|
|
1090
|
-
vscode_languageserver_1.Range.create(0, 9, 0, 10),
|
|
1091
|
-
vscode_languageserver_1.Range.create(1, 4, 1, 9),
|
|
1092
|
-
vscode_languageserver_1.Range.create(1, 10, 1, 15),
|
|
1093
|
-
vscode_languageserver_1.Range.create(1, 15, 1, 17),
|
|
1094
|
-
vscode_languageserver_1.Range.create(2, 0, 2, 7),
|
|
1095
|
-
vscode_languageserver_1.Range.create(2, 7, 2, 8) // EOF
|
|
1096
|
-
]);
|
|
1097
|
-
});
|
|
1098
|
-
});
|
|
1099
|
-
describe('two word keywords', () => {
|
|
1100
|
-
it('supports various spacing between for each', () => {
|
|
1101
|
-
let { tokens } = Lexer_1.Lexer.scan('for each for each for each for\teach for\t each for \teach for \t each');
|
|
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
|
|
1111
|
-
]);
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
it('detects rem when used as keyword', () => {
|
|
1115
|
-
let { tokens } = Lexer_1.Lexer.scan('person.rem=true');
|
|
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
|
|
1123
|
-
]);
|
|
1124
|
-
//verify the location of `rem`
|
|
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([
|
|
1126
|
-
[0, 6],
|
|
1127
|
-
[6, 7],
|
|
1128
|
-
[7, 10],
|
|
1129
|
-
[10, 11],
|
|
1130
|
-
[11, 15],
|
|
1131
|
-
[15, 16] // EOF
|
|
1132
|
-
]);
|
|
1133
|
-
});
|
|
1134
|
-
describe('isToken', () => {
|
|
1135
|
-
it('works', () => {
|
|
1136
|
-
let range = vscode_languageserver_1.Range.create(0, 0, 0, 2);
|
|
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;
|
|
1139
|
-
});
|
|
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
|
-
});
|
|
1149
|
-
it('recognizes class-related keywords', () => {
|
|
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
|
|
1160
|
-
]);
|
|
1161
|
-
});
|
|
1162
|
-
describe('whitespace', () => {
|
|
1163
|
-
it('preserves the exact number of whitespace characterswhitespace', () => {
|
|
1164
|
-
let { tokens } = Lexer_1.Lexer.scan(' ', { includeWhitespace: true });
|
|
1165
|
-
(0, chai_config_spec_1.expect)(tokens[0]).to.include({
|
|
1166
|
-
kind: TokenKind_1.TokenKind.Whitespace,
|
|
1167
|
-
text: ' '
|
|
1168
|
-
});
|
|
1169
|
-
});
|
|
1170
|
-
it('tokenizes whitespace between things', () => {
|
|
1171
|
-
let { tokens } = Lexer_1.Lexer.scan('sub main ( ) \n end sub', { includeWhitespace: true });
|
|
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
|
|
1185
|
-
]);
|
|
1186
|
-
});
|
|
1187
|
-
});
|
|
1188
|
-
it('identifies brighterscript source literals', () => {
|
|
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
|
|
1202
|
-
]);
|
|
1203
|
-
});
|
|
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
|
-
}
|
|
1216
|
-
const text = `
|
|
1217
|
-
sub main()
|
|
1218
|
-
|
|
1219
|
-
print "main"\r\n\n
|
|
1220
|
-
|
|
1221
|
-
end sub
|
|
1222
|
-
`;
|
|
1223
|
-
const { tokens } = Lexer_1.Lexer.scan(text, { includeWhitespace: false });
|
|
1224
|
-
(0, chai_config_spec_1.expect)(tokensToString(tokens)).to.equal(text);
|
|
1225
|
-
});
|
|
1226
|
-
it('properly detects try/catch tokens', () => {
|
|
1227
|
-
const { tokens } = Lexer_1.Lexer.scan(`try catch endtry end try throw`, { includeWhitespace: false });
|
|
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
|
|
1235
|
-
]);
|
|
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
|
-
});
|
|
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
|
-
}
|
|
1345
|
-
//# sourceMappingURL=Lexer.spec.js.map
|