brighterscript 0.57.2 → 0.59.0
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/CHANGELOG.md +31 -0
- package/README.md +16 -6
- package/bsconfig.schema.json +11 -0
- package/dist/BsConfig.d.ts +11 -0
- package/dist/DiagnosticMessages.d.ts +7 -2
- package/dist/DiagnosticMessages.js +7 -2
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Program.d.ts +12 -2
- package/dist/Program.js +69 -24
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +1 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +6 -3
- package/dist/Scope.js +24 -17
- package/dist/Scope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +2 -3
- package/dist/astUtils/AstEditor.js.map +1 -1
- package/dist/astUtils/creators.d.ts +4 -4
- package/dist/astUtils/creators.js +6 -6
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +67 -64
- package/dist/astUtils/reflection.js +10 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +8 -3
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +33 -31
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +6 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +40 -34
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +4 -5
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +2 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +166 -12
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +21 -19
- package/dist/bscPlugin/validation/ScopeValidator.js +164 -179
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +33 -35
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +11 -5
- package/dist/files/BrsFile.js +15 -47
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +107 -79
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +9 -4
- package/dist/files/XmlFile.js +6 -30
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +57 -90
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +13 -15
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +10 -12
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +2 -3
- package/dist/lexer/Lexer.spec.js +6 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +6 -2
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +65 -0
- package/dist/parser/AstNode.js +93 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +42 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/Expression.d.ts +6 -43
- package/dist/parser/Expression.js +53 -81
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +15 -12
- package/dist/parser/Parser.js +130 -117
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +1 -1
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.spec.js +2 -3
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +28 -44
- package/dist/parser/Statement.js +118 -104
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +16 -10
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +37 -0
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +41 -0
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +109 -1
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +49 -4
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +7 -7
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +92 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +36 -9
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +3 -4
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +4 -5
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +4 -5
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +3 -4
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/util.d.ts +11 -5
- package/dist/util.js +57 -6
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +22 -19
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -2
package/dist/parser/Parser.js
CHANGED
|
@@ -13,8 +13,6 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
13
13
|
const visitors_1 = require("../astUtils/visitors");
|
|
14
14
|
const creators_1 = require("../astUtils/creators");
|
|
15
15
|
const Cache_1 = require("../Cache");
|
|
16
|
-
const SymbolTable_1 = require("../SymbolTable");
|
|
17
|
-
const DynamicType_1 = require("../types/DynamicType");
|
|
18
16
|
class Parser {
|
|
19
17
|
constructor() {
|
|
20
18
|
/**
|
|
@@ -25,10 +23,6 @@ class Parser {
|
|
|
25
23
|
* The list of statements for the parsed file
|
|
26
24
|
*/
|
|
27
25
|
this.ast = new Statement_1.Body([]);
|
|
28
|
-
/**
|
|
29
|
-
* The top-level symbol table for this file. Things like top-level namespaces, non-namespaced classes, enums, interfaces, and functions beling here.
|
|
30
|
-
*/
|
|
31
|
-
this.symbolTable = new SymbolTable_1.SymbolTable();
|
|
32
26
|
this._references = new References();
|
|
33
27
|
this.globalTerminators = [];
|
|
34
28
|
/**
|
|
@@ -39,9 +33,11 @@ class Parser {
|
|
|
39
33
|
get statements() {
|
|
40
34
|
return this.ast.statements;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The top-level symbol table for the body of this file.
|
|
38
|
+
*/
|
|
39
|
+
get symbolTable() {
|
|
40
|
+
return this.ast.symbolTable;
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
43
|
* References for significant statements/expressions in the parser.
|
|
@@ -78,10 +74,6 @@ class Parser {
|
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
|
-
get currentNamespaceName() {
|
|
82
|
-
var _a;
|
|
83
|
-
return (_a = this.currentNamespace) === null || _a === void 0 ? void 0 : _a.nameExpression;
|
|
84
|
-
}
|
|
85
77
|
/**
|
|
86
78
|
* Get the currently active global terminators
|
|
87
79
|
*/
|
|
@@ -126,7 +118,7 @@ class Parser {
|
|
|
126
118
|
}
|
|
127
119
|
body() {
|
|
128
120
|
const parentAnnotations = this.enterAnnotationBlock();
|
|
129
|
-
let body = new Statement_1.Body([]
|
|
121
|
+
let body = new Statement_1.Body([]);
|
|
130
122
|
if (this.tokens.length > 0) {
|
|
131
123
|
this.consumeStatementSeparators(true);
|
|
132
124
|
try {
|
|
@@ -333,13 +325,13 @@ class Parser {
|
|
|
333
325
|
}
|
|
334
326
|
//consume the final `end interface` token
|
|
335
327
|
const endInterfaceToken = this.consumeToken(TokenKind_1.TokenKind.EndInterface);
|
|
336
|
-
const statement = new Statement_1.InterfaceStatement(interfaceToken, nameToken, extendsToken, parentInterfaceName, body, endInterfaceToken
|
|
328
|
+
const statement = new Statement_1.InterfaceStatement(interfaceToken, nameToken, extendsToken, parentInterfaceName, body, endInterfaceToken);
|
|
337
329
|
this._references.interfaceStatements.push(statement);
|
|
338
330
|
this.exitAnnotationBlock(parentAnnotations);
|
|
339
331
|
return statement;
|
|
340
332
|
}
|
|
341
333
|
enumDeclaration() {
|
|
342
|
-
const result = new Statement_1.EnumStatement({}, []
|
|
334
|
+
const result = new Statement_1.EnumStatement({}, []);
|
|
343
335
|
this.warnIfNotBrighterScriptMode('enum declarations');
|
|
344
336
|
const parentAnnotations = this.enterAnnotationBlock();
|
|
345
337
|
result.tokens.enum = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedKeyword(TokenKind_1.TokenKind.Enum), TokenKind_1.TokenKind.Enum);
|
|
@@ -383,9 +375,6 @@ class Parser {
|
|
|
383
375
|
}
|
|
384
376
|
//consume the final `end interface` token
|
|
385
377
|
result.tokens.endEnum = this.consumeToken(TokenKind_1.TokenKind.EndEnum);
|
|
386
|
-
if (result.name) {
|
|
387
|
-
this.currentSymbolTable.addSymbol(result.tokens.name.text, result.tokens.name.range, DynamicType_1.DynamicType.instance);
|
|
388
|
-
}
|
|
389
378
|
this._references.enumStatements.push(result);
|
|
390
379
|
this.exitAnnotationBlock(parentAnnotations);
|
|
391
380
|
return result;
|
|
@@ -437,8 +426,6 @@ class Parser {
|
|
|
437
426
|
decl = new Statement_1.MethodStatement(accessModifier, funcDeclaration.name, funcDeclaration.func, overrideKeyword);
|
|
438
427
|
//refer to this statement as parent of the expression
|
|
439
428
|
functionStatement.func.functionStatement = decl;
|
|
440
|
-
//add the `super` symbol to class methods
|
|
441
|
-
funcDeclaration.func.symbolTable.addSymbol('super', undefined, DynamicType_1.DynamicType.instance);
|
|
442
429
|
//fields
|
|
443
430
|
}
|
|
444
431
|
else if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties)) {
|
|
@@ -468,10 +455,7 @@ class Parser {
|
|
|
468
455
|
if (endingKeyword.kind !== TokenKind_1.TokenKind.EndClass) {
|
|
469
456
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('class')), { range: endingKeyword.range }));
|
|
470
457
|
}
|
|
471
|
-
const result = new Statement_1.ClassStatement(classKeyword, className, body, endingKeyword, extendsKeyword, parentClassName
|
|
472
|
-
if (className) {
|
|
473
|
-
this.currentSymbolTable.addSymbol(className.text, className.range, DynamicType_1.DynamicType.instance);
|
|
474
|
-
}
|
|
458
|
+
const result = new Statement_1.ClassStatement(classKeyword, className, body, endingKeyword, extendsKeyword, parentClassName);
|
|
475
459
|
this._references.classStatements.push(result);
|
|
476
460
|
this.exitAnnotationBlock(parentAnnotations);
|
|
477
461
|
return result;
|
|
@@ -572,10 +556,7 @@ class Parser {
|
|
|
572
556
|
this.consumeStatementSeparators(true);
|
|
573
557
|
let func = new Expression_1.FunctionExpression(params, undefined, //body
|
|
574
558
|
functionType, undefined, //ending keyword
|
|
575
|
-
leftParen, rightParen, asToken, typeToken, this.currentFunctionExpression
|
|
576
|
-
if (!func.symbolTable.hasSymbol('m')) {
|
|
577
|
-
func.symbolTable.addSymbol('m', undefined, DynamicType_1.DynamicType.instance);
|
|
578
|
-
}
|
|
559
|
+
leftParen, rightParen, asToken, typeToken, this.currentFunctionExpression);
|
|
579
560
|
//if there is a parent function, register this function with the parent
|
|
580
561
|
if (this.currentFunctionExpression) {
|
|
581
562
|
this.currentFunctionExpression.childFunctionExpressions.push(func);
|
|
@@ -584,8 +565,6 @@ class Parser {
|
|
|
584
565
|
if (!onlyCallableAsMember && name) {
|
|
585
566
|
const funcType = func.getFunctionType();
|
|
586
567
|
funcType.setName(name.text);
|
|
587
|
-
// add the function as declared to the current symbol table
|
|
588
|
-
this.currentSymbolTable.addSymbol(name.text, name.range, funcType);
|
|
589
568
|
}
|
|
590
569
|
this._references.functionExpressions.push(func);
|
|
591
570
|
let previousFunctionExpression = this.currentFunctionExpression;
|
|
@@ -615,18 +594,9 @@ class Parser {
|
|
|
615
594
|
return func;
|
|
616
595
|
}
|
|
617
596
|
else {
|
|
618
|
-
let result = new Statement_1.FunctionStatement(name, func
|
|
597
|
+
let result = new Statement_1.FunctionStatement(name, func);
|
|
619
598
|
func.functionStatement = result;
|
|
620
599
|
this._references.functionStatements.push(result);
|
|
621
|
-
// Add the transpiled name for namespace functions
|
|
622
|
-
// to consider an edge case when defining namespaces in .bs files
|
|
623
|
-
// and using them in .brs files.
|
|
624
|
-
if (func.namespaceName) {
|
|
625
|
-
const transpiledNamespaceFunctionName = result.getName(ParseMode.BrightScript);
|
|
626
|
-
const funcType = func.getFunctionType();
|
|
627
|
-
funcType.setName(transpiledNamespaceFunctionName);
|
|
628
|
-
this.symbolTable.addSymbol(transpiledNamespaceFunctionName, name.range, funcType);
|
|
629
|
-
}
|
|
630
600
|
return result;
|
|
631
601
|
}
|
|
632
602
|
}
|
|
@@ -660,7 +630,7 @@ class Parser {
|
|
|
660
630
|
throw this.lastDiagnosticAsError();
|
|
661
631
|
}
|
|
662
632
|
}
|
|
663
|
-
return new Expression_1.FunctionParameterExpression(name, typeToken, defaultValue, asToken
|
|
633
|
+
return new Expression_1.FunctionParameterExpression(name, typeToken, defaultValue, asToken);
|
|
664
634
|
}
|
|
665
635
|
assignment() {
|
|
666
636
|
let name = this.advance();
|
|
@@ -675,7 +645,7 @@ class Parser {
|
|
|
675
645
|
result = new Statement_1.AssignmentStatement(operator, name, value, this.currentFunctionExpression);
|
|
676
646
|
}
|
|
677
647
|
else {
|
|
678
|
-
const nameExpression = new Expression_1.VariableExpression(name
|
|
648
|
+
const nameExpression = new Expression_1.VariableExpression(name);
|
|
679
649
|
result = new Statement_1.AssignmentStatement(operator, name, new Expression_1.BinaryExpression(nameExpression, operator, value), this.currentFunctionExpression);
|
|
680
650
|
this.addExpressionsToReferences(nameExpression);
|
|
681
651
|
if ((0, reflection_1.isBinaryExpression)(value)) {
|
|
@@ -684,7 +654,6 @@ class Parser {
|
|
|
684
654
|
}
|
|
685
655
|
this._references.expressions.add(result);
|
|
686
656
|
}
|
|
687
|
-
this.currentSymbolTable.addSymbol(name.text, name.range, DynamicType_1.DynamicType.instance);
|
|
688
657
|
this._references.assignmentStatements.push(result);
|
|
689
658
|
return result;
|
|
690
659
|
}
|
|
@@ -754,6 +723,9 @@ class Parser {
|
|
|
754
723
|
if (this.check(TokenKind_1.TokenKind.Goto)) {
|
|
755
724
|
return this.gotoStatement();
|
|
756
725
|
}
|
|
726
|
+
if (this.check(TokenKind_1.TokenKind.Continue)) {
|
|
727
|
+
return this.continueStatement();
|
|
728
|
+
}
|
|
757
729
|
//does this line look like a label? (i.e. `someIdentifier:` )
|
|
758
730
|
if (this.check(TokenKind_1.TokenKind.Identifier) && this.checkNext(TokenKind_1.TokenKind.Colon) && this.checkPrevious(TokenKind_1.TokenKind.Newline)) {
|
|
759
731
|
try {
|
|
@@ -857,7 +829,6 @@ class Parser {
|
|
|
857
829
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedExpressionAfterForEachIn()), { range: this.peek().range }));
|
|
858
830
|
throw this.lastDiagnosticAsError();
|
|
859
831
|
}
|
|
860
|
-
this.currentSymbolTable.addSymbol(name.text, name.range, DynamicType_1.DynamicType.instance);
|
|
861
832
|
this.consumeStatementSeparators();
|
|
862
833
|
let body = this.block(TokenKind_1.TokenKind.EndFor, TokenKind_1.TokenKind.Next);
|
|
863
834
|
if (!body) {
|
|
@@ -900,13 +871,10 @@ class Parser {
|
|
|
900
871
|
this.namespaceAndFunctionDepth++;
|
|
901
872
|
let name = this.getNamespacedVariableNameExpression();
|
|
902
873
|
//set the current namespace name
|
|
903
|
-
let result = new Statement_1.NamespaceStatement(keyword, name, null, null
|
|
904
|
-
this.currentNamespace = result;
|
|
874
|
+
let result = new Statement_1.NamespaceStatement(keyword, name, null, null);
|
|
905
875
|
this.globalTerminators.push([TokenKind_1.TokenKind.EndNamespace]);
|
|
906
876
|
let body = this.body();
|
|
907
877
|
this.globalTerminators.pop();
|
|
908
|
-
//unset the current namespace name
|
|
909
|
-
this.currentNamespace = undefined;
|
|
910
878
|
let endKeyword;
|
|
911
879
|
if (this.check(TokenKind_1.TokenKind.EndNamespace)) {
|
|
912
880
|
endKeyword = this.advance();
|
|
@@ -921,9 +889,6 @@ class Parser {
|
|
|
921
889
|
this._references.namespaceStatements.push(result);
|
|
922
890
|
//cache the range property so that plugins can't affect it
|
|
923
891
|
result.cacheRange();
|
|
924
|
-
if (result.name) {
|
|
925
|
-
this.symbolTable.addSymbol(result.name.split('.')[0], result.nameExpression.range, DynamicType_1.DynamicType.instance);
|
|
926
|
-
}
|
|
927
892
|
return result;
|
|
928
893
|
}
|
|
929
894
|
/**
|
|
@@ -935,7 +900,7 @@ class Parser {
|
|
|
935
900
|
if (firstIdentifier) {
|
|
936
901
|
// force it into an identifier so the AST makes some sense
|
|
937
902
|
firstIdentifier.kind = TokenKind_1.TokenKind.Identifier;
|
|
938
|
-
const varExpr = new Expression_1.VariableExpression(firstIdentifier
|
|
903
|
+
const varExpr = new Expression_1.VariableExpression(firstIdentifier);
|
|
939
904
|
expr = varExpr;
|
|
940
905
|
//consume multiple dot identifiers (i.e. `Name.Space.Can.Have.Many.Parts`)
|
|
941
906
|
while (this.check(TokenKind_1.TokenKind.Dot)) {
|
|
@@ -986,10 +951,7 @@ class Parser {
|
|
|
986
951
|
const: constToken,
|
|
987
952
|
name: nameToken,
|
|
988
953
|
equals: equalToken
|
|
989
|
-
}, expression
|
|
990
|
-
if (nameToken) {
|
|
991
|
-
this.currentSymbolTable.addSymbol(nameToken.text, nameToken.range, DynamicType_1.DynamicType.instance);
|
|
992
|
-
}
|
|
954
|
+
}, expression);
|
|
993
955
|
this._references.constStatements.push(statement);
|
|
994
956
|
return statement;
|
|
995
957
|
}
|
|
@@ -1161,9 +1123,6 @@ class Parser {
|
|
|
1161
1123
|
else {
|
|
1162
1124
|
statement.tokens.endTry = this.advance();
|
|
1163
1125
|
}
|
|
1164
|
-
if (exceptionVarToken) {
|
|
1165
|
-
this.currentSymbolTable.addSymbol(exceptionVarToken.text, exceptionVarToken.range, DynamicType_1.DynamicType.instance);
|
|
1166
|
-
}
|
|
1167
1126
|
return statement;
|
|
1168
1127
|
}
|
|
1169
1128
|
throwStatement() {
|
|
@@ -1206,9 +1165,6 @@ class Parser {
|
|
|
1206
1165
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.missingExpressionsInDimStatement()), { range: this.peek().range }));
|
|
1207
1166
|
}
|
|
1208
1167
|
let rightSquareBracket = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.missingRightSquareBracketAfterDimIdentifier(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1209
|
-
if (identifier) {
|
|
1210
|
-
this.currentSymbolTable.addSymbol(identifier.text, identifier.range, DynamicType_1.DynamicType.instance);
|
|
1211
|
-
}
|
|
1212
1168
|
return new Statement_1.DimStatement(dim, identifier, leftSquareBracket, expressions, rightSquareBracket);
|
|
1213
1169
|
}
|
|
1214
1170
|
ifStatement() {
|
|
@@ -1499,6 +1455,15 @@ class Parser {
|
|
|
1499
1455
|
}
|
|
1500
1456
|
return new Statement_1.LabelStatement(tokens);
|
|
1501
1457
|
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Parses a `continue` statement
|
|
1460
|
+
*/
|
|
1461
|
+
continueStatement() {
|
|
1462
|
+
return new Statement_1.ContinueStatement({
|
|
1463
|
+
continue: this.advance(),
|
|
1464
|
+
loopType: this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedToken(TokenKind_1.TokenKind.While, TokenKind_1.TokenKind.For), TokenKind_1.TokenKind.While, TokenKind_1.TokenKind.For)
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1502
1467
|
/**
|
|
1503
1468
|
* Parses a `goto` statement
|
|
1504
1469
|
* @returns an AST representation of an `goto` statement.
|
|
@@ -1700,10 +1665,17 @@ class Parser {
|
|
|
1700
1665
|
indexedGet(expr) {
|
|
1701
1666
|
let openingSquare = this.previous();
|
|
1702
1667
|
let questionDotToken = this.getMatchingTokenAtOffset(-2, TokenKind_1.TokenKind.QuestionDot);
|
|
1668
|
+
let index;
|
|
1669
|
+
let closingSquare;
|
|
1703
1670
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1704
|
-
|
|
1671
|
+
try {
|
|
1672
|
+
index = this.expression();
|
|
1673
|
+
}
|
|
1674
|
+
catch (error) {
|
|
1675
|
+
this.rethrowNonDiagnosticError(error);
|
|
1676
|
+
}
|
|
1705
1677
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1706
|
-
|
|
1678
|
+
closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightSquareBraceAfterArrayOrObjectIndex(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1707
1679
|
return new Expression_1.IndexedGetExpression(expr, index, openingSquare, closingSquare, questionDotToken);
|
|
1708
1680
|
}
|
|
1709
1681
|
newExpression() {
|
|
@@ -1758,7 +1730,10 @@ class Parser {
|
|
|
1758
1730
|
}
|
|
1759
1731
|
else {
|
|
1760
1732
|
let dot = this.previous();
|
|
1761
|
-
let name = this.
|
|
1733
|
+
let name = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedPropertyNameAfterPeriod(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
|
|
1734
|
+
if (!name) {
|
|
1735
|
+
break;
|
|
1736
|
+
}
|
|
1762
1737
|
// force it into an identifier so the AST makes some sense
|
|
1763
1738
|
name.kind = TokenKind_1.TokenKind.Identifier;
|
|
1764
1739
|
expr = new Expression_1.DottedGetExpression(expr, name, dot);
|
|
@@ -1767,9 +1742,12 @@ class Parser {
|
|
|
1767
1742
|
}
|
|
1768
1743
|
else if (this.checkAny(TokenKind_1.TokenKind.At, TokenKind_1.TokenKind.QuestionAt)) {
|
|
1769
1744
|
let dot = this.advance();
|
|
1770
|
-
let name = this.
|
|
1745
|
+
let name = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedAttributeNameAfterAtSymbol(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
|
|
1771
1746
|
// force it into an identifier so the AST makes some sense
|
|
1772
1747
|
name.kind = TokenKind_1.TokenKind.Identifier;
|
|
1748
|
+
if (!name) {
|
|
1749
|
+
break;
|
|
1750
|
+
}
|
|
1773
1751
|
expr = new Expression_1.XmlAttributeGetExpression(expr, name, dot);
|
|
1774
1752
|
//only allow a single `@` expression
|
|
1775
1753
|
break;
|
|
@@ -1794,12 +1772,19 @@ class Parser {
|
|
|
1794
1772
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.tooManyCallableArguments(args.length, Expression_1.CallExpression.MaximumArguments)), { range: this.peek().range }));
|
|
1795
1773
|
throw this.lastDiagnosticAsError();
|
|
1796
1774
|
}
|
|
1797
|
-
|
|
1775
|
+
try {
|
|
1776
|
+
args.push(this.expression());
|
|
1777
|
+
}
|
|
1778
|
+
catch (error) {
|
|
1779
|
+
this.rethrowNonDiagnosticError(error);
|
|
1780
|
+
// we were unable to get an expression, so don't continue
|
|
1781
|
+
break;
|
|
1782
|
+
}
|
|
1798
1783
|
} while (this.match(TokenKind_1.TokenKind.Comma));
|
|
1799
1784
|
}
|
|
1800
1785
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1801
|
-
const closingParen = this.
|
|
1802
|
-
let expression = new Expression_1.CallExpression(callee, openingParen, closingParen, args
|
|
1786
|
+
const closingParen = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(), TokenKind_1.TokenKind.RightParen);
|
|
1787
|
+
let expression = new Expression_1.CallExpression(callee, openingParen, closingParen, args);
|
|
1803
1788
|
if (addToCallExpressionList) {
|
|
1804
1789
|
this.callExpressions.push(expression);
|
|
1805
1790
|
}
|
|
@@ -1847,7 +1832,7 @@ class Parser {
|
|
|
1847
1832
|
case this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedLocalIdentifiers) && this.checkNext(TokenKind_1.TokenKind.BackTick):
|
|
1848
1833
|
return this.templateString(true);
|
|
1849
1834
|
case this.matchAny(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers):
|
|
1850
|
-
return new Expression_1.VariableExpression(this.previous()
|
|
1835
|
+
return new Expression_1.VariableExpression(this.previous());
|
|
1851
1836
|
case this.match(TokenKind_1.TokenKind.LeftParen):
|
|
1852
1837
|
let left = this.previous();
|
|
1853
1838
|
let expr = this.expression();
|
|
@@ -1861,7 +1846,7 @@ class Parser {
|
|
|
1861
1846
|
let token = Object.assign(this.previous(), {
|
|
1862
1847
|
kind: TokenKind_1.TokenKind.Identifier
|
|
1863
1848
|
});
|
|
1864
|
-
return new Expression_1.VariableExpression(token
|
|
1849
|
+
return new Expression_1.VariableExpression(token);
|
|
1865
1850
|
case this.checkAny(TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Sub):
|
|
1866
1851
|
return this.anonymousFunction();
|
|
1867
1852
|
case this.check(TokenKind_1.TokenKind.RegexLiteral):
|
|
@@ -1889,23 +1874,31 @@ class Parser {
|
|
|
1889
1874
|
}
|
|
1890
1875
|
while (this.match(TokenKind_1.TokenKind.Newline)) {
|
|
1891
1876
|
}
|
|
1877
|
+
let closingSquare;
|
|
1892
1878
|
if (!this.match(TokenKind_1.TokenKind.RightSquareBracket)) {
|
|
1893
|
-
|
|
1894
|
-
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Comment)) {
|
|
1895
|
-
if (this.checkPrevious(TokenKind_1.TokenKind.Comment) || this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1896
|
-
let comment = this.check(TokenKind_1.TokenKind.Comment) ? this.advance() : this.previous();
|
|
1897
|
-
elements.push(new Statement_1.CommentStatement([comment]));
|
|
1898
|
-
}
|
|
1899
|
-
while (this.match(TokenKind_1.TokenKind.Newline)) {
|
|
1900
|
-
}
|
|
1901
|
-
if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
|
|
1902
|
-
break;
|
|
1903
|
-
}
|
|
1879
|
+
try {
|
|
1904
1880
|
elements.push(this.expression());
|
|
1881
|
+
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Comment)) {
|
|
1882
|
+
if (this.checkPrevious(TokenKind_1.TokenKind.Comment) || this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1883
|
+
let comment = this.check(TokenKind_1.TokenKind.Comment) ? this.advance() : this.previous();
|
|
1884
|
+
elements.push(new Statement_1.CommentStatement([comment]));
|
|
1885
|
+
}
|
|
1886
|
+
while (this.match(TokenKind_1.TokenKind.Newline)) {
|
|
1887
|
+
}
|
|
1888
|
+
if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
|
|
1889
|
+
break;
|
|
1890
|
+
}
|
|
1891
|
+
elements.push(this.expression());
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
catch (error) {
|
|
1895
|
+
this.rethrowNonDiagnosticError(error);
|
|
1905
1896
|
}
|
|
1906
|
-
this.
|
|
1897
|
+
closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftSquareBraceAfterArrayLiteral(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
closingSquare = this.previous();
|
|
1907
1901
|
}
|
|
1908
|
-
let closingSquare = this.previous();
|
|
1909
1902
|
//this.consume("Expected newline or ':' after array literal", TokenKind.Newline, TokenKind.Colon, TokenKind.Eof);
|
|
1910
1903
|
return new Expression_1.ArrayLiteralExpression(elements, openingSquare, closingSquare);
|
|
1911
1904
|
}
|
|
@@ -1933,49 +1926,57 @@ class Parser {
|
|
|
1933
1926
|
return result;
|
|
1934
1927
|
};
|
|
1935
1928
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1929
|
+
let closingBrace;
|
|
1936
1930
|
if (!this.match(TokenKind_1.TokenKind.RightCurlyBrace)) {
|
|
1937
1931
|
let lastAAMember;
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
else {
|
|
1943
|
-
let k = key();
|
|
1944
|
-
let expr = this.expression();
|
|
1945
|
-
lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
|
|
1946
|
-
members.push(lastAAMember);
|
|
1947
|
-
}
|
|
1948
|
-
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Colon, TokenKind_1.TokenKind.Comment)) {
|
|
1949
|
-
// collect comma at end of expression
|
|
1950
|
-
if (lastAAMember && this.checkPrevious(TokenKind_1.TokenKind.Comma)) {
|
|
1951
|
-
lastAAMember.commaToken = this.previous();
|
|
1952
|
-
}
|
|
1953
|
-
//check for comment at the end of the current line
|
|
1954
|
-
if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
|
|
1955
|
-
let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
|
|
1956
|
-
members.push(new Statement_1.CommentStatement([token]));
|
|
1932
|
+
try {
|
|
1933
|
+
if (this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1934
|
+
lastAAMember = null;
|
|
1935
|
+
members.push(new Statement_1.CommentStatement([this.advance()]));
|
|
1957
1936
|
}
|
|
1958
1937
|
else {
|
|
1959
|
-
|
|
1960
|
-
|
|
1938
|
+
let k = key();
|
|
1939
|
+
let expr = this.expression();
|
|
1940
|
+
lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
|
|
1941
|
+
members.push(lastAAMember);
|
|
1942
|
+
}
|
|
1943
|
+
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Colon, TokenKind_1.TokenKind.Comment)) {
|
|
1944
|
+
// collect comma at end of expression
|
|
1945
|
+
if (lastAAMember && this.checkPrevious(TokenKind_1.TokenKind.Comma)) {
|
|
1946
|
+
lastAAMember.commaToken = this.previous();
|
|
1947
|
+
}
|
|
1948
|
+
//check for comment at the end of the current line
|
|
1961
1949
|
if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
|
|
1962
1950
|
let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
|
|
1963
|
-
lastAAMember = null;
|
|
1964
1951
|
members.push(new Statement_1.CommentStatement([token]));
|
|
1965
|
-
continue;
|
|
1966
1952
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1953
|
+
else {
|
|
1954
|
+
this.consumeStatementSeparators(true);
|
|
1955
|
+
//check for a comment on its own line
|
|
1956
|
+
if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
|
|
1957
|
+
let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
|
|
1958
|
+
lastAAMember = null;
|
|
1959
|
+
members.push(new Statement_1.CommentStatement([token]));
|
|
1960
|
+
continue;
|
|
1961
|
+
}
|
|
1962
|
+
if (this.check(TokenKind_1.TokenKind.RightCurlyBrace)) {
|
|
1963
|
+
break;
|
|
1964
|
+
}
|
|
1965
|
+
let k = key();
|
|
1966
|
+
let expr = this.expression();
|
|
1967
|
+
lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
|
|
1968
|
+
members.push(lastAAMember);
|
|
1969
1969
|
}
|
|
1970
|
-
let k = key();
|
|
1971
|
-
let expr = this.expression();
|
|
1972
|
-
lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
|
|
1973
|
-
members.push(lastAAMember);
|
|
1974
1970
|
}
|
|
1975
1971
|
}
|
|
1976
|
-
|
|
1972
|
+
catch (error) {
|
|
1973
|
+
this.rethrowNonDiagnosticError(error);
|
|
1974
|
+
}
|
|
1975
|
+
closingBrace = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftCurlyAfterAALiteral(), TokenKind_1.TokenKind.RightCurlyBrace);
|
|
1976
|
+
}
|
|
1977
|
+
else {
|
|
1978
|
+
closingBrace = this.previous();
|
|
1977
1979
|
}
|
|
1978
|
-
let closingBrace = this.previous();
|
|
1979
1980
|
const aaExpr = new Expression_1.AALiteralExpression(members, openingBrace, closingBrace);
|
|
1980
1981
|
this.addPropertyHints(aaExpr);
|
|
1981
1982
|
return aaExpr;
|
|
@@ -2120,6 +2121,18 @@ class Parser {
|
|
|
2120
2121
|
previous() {
|
|
2121
2122
|
return this.tokens[this.current - 1];
|
|
2122
2123
|
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Sometimes we catch an error that is a diagnostic.
|
|
2126
|
+
* If that's the case, we want to continue parsing.
|
|
2127
|
+
* Otherwise, re-throw the error
|
|
2128
|
+
*
|
|
2129
|
+
* @param error error caught in a try/catch
|
|
2130
|
+
*/
|
|
2131
|
+
rethrowNonDiagnosticError(error) {
|
|
2132
|
+
if (!error.isDiagnostic) {
|
|
2133
|
+
throw error;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2123
2136
|
/**
|
|
2124
2137
|
* Get the token that is {offset} indexes away from {this.current}
|
|
2125
2138
|
* @param offset the number of index steps away from current index to fetch
|
|
@@ -2229,7 +2242,7 @@ class Parser {
|
|
|
2229
2242
|
this._references.libraryStatements.push(s);
|
|
2230
2243
|
},
|
|
2231
2244
|
FunctionExpression: (expression, parent) => {
|
|
2232
|
-
if (!(0, reflection_1.
|
|
2245
|
+
if (!(0, reflection_1.isMethodStatement)(parent)) {
|
|
2233
2246
|
this._references.functionExpressions.push(expression);
|
|
2234
2247
|
}
|
|
2235
2248
|
},
|