brighterscript 1.0.0-alpha.25 → 1.0.0-alpha.27
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 +44 -0
- package/bsconfig.schema.json +5 -0
- package/dist/AstValidationSegmenter.d.ts +1 -1
- package/dist/AstValidationSegmenter.js +6 -7
- package/dist/AstValidationSegmenter.js.map +1 -1
- package/dist/BsConfig.d.ts +1 -0
- package/dist/DiagnosticMessages.d.ts +1 -3
- package/dist/DiagnosticMessages.js +5 -8
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Program.d.ts +1 -1
- package/dist/Program.js +40 -42
- package/dist/Program.js.map +1 -1
- package/dist/Scope.d.ts +2 -13
- package/dist/Scope.js +27 -35
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -8
- package/dist/SymbolTable.js +1 -10
- package/dist/SymbolTable.js.map +1 -1
- package/dist/SymbolTableFlag.d.ts +8 -0
- package/dist/SymbolTableFlag.js +13 -0
- package/dist/SymbolTableFlag.js.map +1 -0
- package/dist/XmlScope.d.ts +1 -6
- package/dist/XmlScope.js +6 -25
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +1 -2
- package/dist/astUtils/CachedLookups.js +3 -14
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/Editor.spec.js +1 -1
- package/dist/astUtils/Editor.spec.js.map +1 -1
- package/dist/astUtils/creators.js +77 -18
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +3 -1
- package/dist/astUtils/reflection.js +12 -4
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +59 -42
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +30 -19
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +7 -3
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +7 -7
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/SignatureHelpUtil.js +5 -4
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +2 -2
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +23 -23
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +28 -8
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +74 -2
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +8 -6
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +46 -47
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +10 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +120 -39
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +165 -10
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +1 -1
- package/dist/files/BrsFile.Class.spec.js +7 -6
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +7 -15
- package/dist/files/BrsFile.js +49 -309
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +111 -157
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +2 -3
- package/dist/files/XmlFile.js +0 -2
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/interfaces.d.ts +109 -84
- package/dist/interfaces.js +9 -9
- package/dist/interfaces.js.map +1 -1
- package/dist/parser/AstNode.spec.js +6 -6
- package/dist/parser/AstNode.spec.js.map +1 -1
- package/dist/parser/Expression.d.ts +301 -164
- package/dist/parser/Expression.js +355 -294
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +26 -27
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +6 -2
- package/dist/parser/Parser.js +361 -160
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +69 -213
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.js +49 -35
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +36 -24
- package/dist/parser/SGTypes.js +26 -55
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +381 -238
- package/dist/parser/Statement.js +510 -386
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +2 -2
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +2 -2
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +11 -11
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +30 -5
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +2 -2
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +2 -2
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.js +8 -9
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +8 -8
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +2 -2
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +2 -2
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +2 -2
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +10 -3
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/roku-types/data.json +70 -52
- package/dist/roku-types/index.d.ts +43 -21
- package/dist/types/ArrayType.js +1 -2
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +7 -8
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.js +2 -3
- package/dist/types/AssociativeArrayType.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +2 -3
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.js +15 -9
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.spec.js +31 -32
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -1
- package/dist/types/ClassType.spec.js +10 -11
- package/dist/types/ClassType.spec.js.map +1 -1
- package/dist/types/ComponentType.d.ts +2 -1
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/EnumType.js +2 -3
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/InheritableType.js +3 -4
- package/dist/types/InheritableType.js.map +1 -1
- package/dist/types/InterfaceType.js +2 -3
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +3 -4
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/ObjectType.js +1 -2
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +1 -1
- package/dist/types/ReferenceType.spec.js +21 -22
- package/dist/types/ReferenceType.spec.js.map +1 -1
- package/dist/types/UnionType.js +3 -3
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/UnionType.spec.js +37 -38
- package/dist/types/UnionType.spec.js.map +1 -1
- package/dist/types/helper.spec.js +4 -5
- package/dist/types/helper.spec.js.map +1 -1
- package/dist/util.d.ts +16 -7
- package/dist/util.js +89 -43
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -9
- package/dist/validators/ClassValidator.js +9 -52
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +1 -1
package/dist/parser/Parser.js
CHANGED
|
@@ -11,7 +11,6 @@ const Expression_1 = require("./Expression");
|
|
|
11
11
|
const Logger_1 = require("../Logger");
|
|
12
12
|
const reflection_1 = require("../astUtils/reflection");
|
|
13
13
|
const creators_1 = require("../astUtils/creators");
|
|
14
|
-
const SymbolTable_1 = require("../SymbolTable");
|
|
15
14
|
class Parser {
|
|
16
15
|
constructor() {
|
|
17
16
|
/**
|
|
@@ -21,7 +20,7 @@ class Parser {
|
|
|
21
20
|
/**
|
|
22
21
|
* The list of statements for the parsed file
|
|
23
22
|
*/
|
|
24
|
-
this.ast = new Statement_1.Body([]);
|
|
23
|
+
this.ast = new Statement_1.Body({ statements: [] });
|
|
25
24
|
this.globalTerminators = [];
|
|
26
25
|
/**
|
|
27
26
|
* An array of CallExpression for the current function body
|
|
@@ -83,7 +82,7 @@ class Parser {
|
|
|
83
82
|
}
|
|
84
83
|
body() {
|
|
85
84
|
const parentAnnotations = this.enterAnnotationBlock();
|
|
86
|
-
let body = new Statement_1.Body([]);
|
|
85
|
+
let body = new Statement_1.Body({ statements: [] });
|
|
87
86
|
if (this.tokens.length > 0) {
|
|
88
87
|
this.consumeStatementSeparators(true);
|
|
89
88
|
try {
|
|
@@ -190,13 +189,15 @@ class Parser {
|
|
|
190
189
|
return identifier;
|
|
191
190
|
}
|
|
192
191
|
enumMemberStatement() {
|
|
193
|
-
const
|
|
194
|
-
|
|
192
|
+
const name = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedClassFieldIdentifier(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
|
|
193
|
+
let equalsToken;
|
|
194
|
+
let value;
|
|
195
195
|
//look for `= SOME_EXPRESSION`
|
|
196
196
|
if (this.check(TokenKind_1.TokenKind.Equal)) {
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
equalsToken = this.advance();
|
|
198
|
+
value = this.expression();
|
|
199
199
|
}
|
|
200
|
+
const statement = new Statement_1.EnumMemberStatement({ name: name, equals: equalsToken, value: value });
|
|
200
201
|
return statement;
|
|
201
202
|
}
|
|
202
203
|
/**
|
|
@@ -209,20 +210,24 @@ class Parser {
|
|
|
209
210
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
210
211
|
[asToken, typeExpression] = this.consumeAsTokenAndTypeExpression();
|
|
211
212
|
}
|
|
212
|
-
return new Statement_1.InterfaceFieldStatement(name, asToken, typeExpression, optionalKeyword);
|
|
213
|
+
return new Statement_1.InterfaceFieldStatement({ name: name, as: asToken, typeExpression: typeExpression, optional: optionalKeyword });
|
|
213
214
|
}
|
|
214
|
-
consumeAsTokenAndTypeExpression() {
|
|
215
|
+
consumeAsTokenAndTypeExpression(ignoreDiagnostics = false) {
|
|
215
216
|
let asToken = this.consumeToken(TokenKind_1.TokenKind.As);
|
|
216
217
|
let typeExpression;
|
|
217
218
|
if (asToken) {
|
|
218
219
|
//if there's nothing after the `as`, add a diagnostic and continue
|
|
219
220
|
if (this.checkEndOfStatement()) {
|
|
220
|
-
|
|
221
|
+
if (!ignoreDiagnostics) {
|
|
222
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword(asToken.text)), { range: asToken.range }));
|
|
223
|
+
}
|
|
221
224
|
//consume the statement separator
|
|
222
225
|
this.consumeStatementSeparators();
|
|
223
226
|
}
|
|
224
227
|
else if (this.peek().kind !== TokenKind_1.TokenKind.Identifier && !this.checkAny(...TokenKind_1.DeclarableTypes, ...TokenKind_1.AllowedTypeIdentifiers)) {
|
|
225
|
-
|
|
228
|
+
if (!ignoreDiagnostics) {
|
|
229
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword(asToken.text)), { range: asToken.range }));
|
|
230
|
+
}
|
|
226
231
|
}
|
|
227
232
|
else {
|
|
228
233
|
typeExpression = this.typeExpression();
|
|
@@ -254,7 +259,16 @@ class Parser {
|
|
|
254
259
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
255
260
|
[asToken, returnTypeExpression] = this.consumeAsTokenAndTypeExpression();
|
|
256
261
|
}
|
|
257
|
-
return new Statement_1.InterfaceMethodStatement(
|
|
262
|
+
return new Statement_1.InterfaceMethodStatement({
|
|
263
|
+
functionType: functionType,
|
|
264
|
+
name: name,
|
|
265
|
+
leftParen: leftParen,
|
|
266
|
+
params: params,
|
|
267
|
+
rightParen: rightParen,
|
|
268
|
+
as: asToken,
|
|
269
|
+
returnTypeExpression: returnTypeExpression,
|
|
270
|
+
optional: optionalKeyword
|
|
271
|
+
});
|
|
258
272
|
}
|
|
259
273
|
interfaceDeclaration() {
|
|
260
274
|
this.warnIfNotBrighterScriptMode('interface declarations');
|
|
@@ -323,17 +337,24 @@ class Parser {
|
|
|
323
337
|
}
|
|
324
338
|
//consume the final `end interface` token
|
|
325
339
|
const endInterfaceToken = this.consumeToken(TokenKind_1.TokenKind.EndInterface);
|
|
326
|
-
const statement = new Statement_1.InterfaceStatement(
|
|
340
|
+
const statement = new Statement_1.InterfaceStatement({
|
|
341
|
+
interface: interfaceToken,
|
|
342
|
+
name: nameToken,
|
|
343
|
+
extends: extendsToken,
|
|
344
|
+
parentInterfaceName: parentInterfaceName,
|
|
345
|
+
body: body,
|
|
346
|
+
endInterface: endInterfaceToken
|
|
347
|
+
});
|
|
327
348
|
this.exitAnnotationBlock(parentAnnotations);
|
|
328
349
|
return statement;
|
|
329
350
|
}
|
|
330
351
|
enumDeclaration() {
|
|
331
|
-
const
|
|
352
|
+
const enumToken = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedKeyword(TokenKind_1.TokenKind.Enum), TokenKind_1.TokenKind.Enum);
|
|
353
|
+
const nameToken = this.tryIdentifier(...this.allowedLocalIdentifiers);
|
|
332
354
|
this.warnIfNotBrighterScriptMode('enum declarations');
|
|
333
355
|
const parentAnnotations = this.enterAnnotationBlock();
|
|
334
|
-
result.tokens.enum = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedKeyword(TokenKind_1.TokenKind.Enum), TokenKind_1.TokenKind.Enum);
|
|
335
|
-
result.tokens.name = this.tryIdentifier(...this.allowedLocalIdentifiers);
|
|
336
356
|
this.consumeStatementSeparators();
|
|
357
|
+
const body = [];
|
|
337
358
|
//gather up all members
|
|
338
359
|
while (this.checkAny(TokenKind_1.TokenKind.Comment, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.At, ...TokenKind_1.AllowedProperties)) {
|
|
339
360
|
try {
|
|
@@ -352,7 +373,7 @@ class Parser {
|
|
|
352
373
|
}
|
|
353
374
|
if (decl) {
|
|
354
375
|
this.consumePendingAnnotations(decl);
|
|
355
|
-
|
|
376
|
+
body.push(decl);
|
|
356
377
|
}
|
|
357
378
|
else {
|
|
358
379
|
//we didn't find a declaration...flag tokens until next line
|
|
@@ -371,7 +392,13 @@ class Parser {
|
|
|
371
392
|
}
|
|
372
393
|
}
|
|
373
394
|
//consume the final `end interface` token
|
|
374
|
-
|
|
395
|
+
const endEnumToken = this.consumeToken(TokenKind_1.TokenKind.EndEnum);
|
|
396
|
+
const result = new Statement_1.EnumStatement({
|
|
397
|
+
enum: enumToken,
|
|
398
|
+
name: nameToken,
|
|
399
|
+
body: body,
|
|
400
|
+
endEnum: endEnumToken
|
|
401
|
+
});
|
|
375
402
|
this.exitAnnotationBlock(parentAnnotations);
|
|
376
403
|
return result;
|
|
377
404
|
}
|
|
@@ -419,12 +446,15 @@ class Parser {
|
|
|
419
446
|
if (this.checkAny(TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Sub) || (this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties) && this.checkNext(TokenKind_1.TokenKind.LeftParen))) {
|
|
420
447
|
const funcDeclaration = this.functionDeclaration(false, false);
|
|
421
448
|
//if we have an overrides keyword AND this method is called 'new', that's not allowed
|
|
422
|
-
if (overrideKeyword && funcDeclaration.name.text.toLowerCase() === 'new') {
|
|
449
|
+
if (overrideKeyword && funcDeclaration.tokens.name.text.toLowerCase() === 'new') {
|
|
423
450
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotUseOverrideKeywordOnConstructorFunction()), { range: overrideKeyword.range }));
|
|
424
451
|
}
|
|
425
|
-
decl = new Statement_1.MethodStatement(
|
|
426
|
-
|
|
427
|
-
|
|
452
|
+
decl = new Statement_1.MethodStatement({
|
|
453
|
+
modifiers: accessModifier,
|
|
454
|
+
name: funcDeclaration.tokens.name,
|
|
455
|
+
func: funcDeclaration.func,
|
|
456
|
+
override: overrideKeyword
|
|
457
|
+
});
|
|
428
458
|
//fields
|
|
429
459
|
}
|
|
430
460
|
else if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties)) {
|
|
@@ -454,7 +484,14 @@ class Parser {
|
|
|
454
484
|
if (endingKeyword.kind !== TokenKind_1.TokenKind.EndClass) {
|
|
455
485
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('class')), { range: endingKeyword.range }));
|
|
456
486
|
}
|
|
457
|
-
const result = new Statement_1.ClassStatement(
|
|
487
|
+
const result = new Statement_1.ClassStatement({
|
|
488
|
+
class: classKeyword,
|
|
489
|
+
name: className,
|
|
490
|
+
body: body,
|
|
491
|
+
endClass: endingKeyword,
|
|
492
|
+
extends: extendsKeyword,
|
|
493
|
+
parentClassName: parentClassName
|
|
494
|
+
});
|
|
458
495
|
this.exitAnnotationBlock(parentAnnotations);
|
|
459
496
|
return result;
|
|
460
497
|
}
|
|
@@ -499,10 +536,17 @@ class Parser {
|
|
|
499
536
|
equal = this.advance();
|
|
500
537
|
initialValue = this.expression();
|
|
501
538
|
}
|
|
502
|
-
return new Statement_1.FieldStatement(
|
|
539
|
+
return new Statement_1.FieldStatement({
|
|
540
|
+
accessModifier: accessModifier,
|
|
541
|
+
name: name,
|
|
542
|
+
as: asToken,
|
|
543
|
+
typeExpression: fieldTypeExpression,
|
|
544
|
+
equals: equal,
|
|
545
|
+
initialValue: initialValue,
|
|
546
|
+
optional: optionalKeyword
|
|
547
|
+
});
|
|
503
548
|
}
|
|
504
549
|
functionDeclaration(isAnonymous, checkIdentifier = true, onlyCallableAsMember = false) {
|
|
505
|
-
var _a;
|
|
506
550
|
let previousCallExpressions = this.callExpressions;
|
|
507
551
|
this.callExpressions = [];
|
|
508
552
|
try {
|
|
@@ -565,41 +609,43 @@ class Parser {
|
|
|
565
609
|
}
|
|
566
610
|
params.reduce((haveFoundOptional, param) => {
|
|
567
611
|
if (haveFoundOptional && !param.defaultValue) {
|
|
568
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.requiredParameterMayNotFollowOptionalParameter(param.name.text)), { range: param.range }));
|
|
612
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.requiredParameterMayNotFollowOptionalParameter(param.tokens.name.text)), { range: param.range }));
|
|
569
613
|
}
|
|
570
614
|
return haveFoundOptional || !!param.defaultValue;
|
|
571
615
|
}, false);
|
|
572
616
|
this.consumeStatementSeparators(true);
|
|
573
|
-
let func = new Expression_1.FunctionExpression(params, undefined, //body
|
|
574
|
-
functionType, undefined, //ending keyword
|
|
575
|
-
leftParen, rightParen, asToken, typeExpression);
|
|
576
617
|
//support ending the function with `end sub` OR `end function`
|
|
577
|
-
|
|
618
|
+
let body = this.block();
|
|
578
619
|
//if the parser was unable to produce a block, make an empty one so the AST makes some sense...
|
|
579
|
-
if (!func.body) {
|
|
580
|
-
func.body = new Statement_1.Block([], util_1.util.createRangeFromPositions(func.range.start, func.range.start));
|
|
581
|
-
}
|
|
582
|
-
func.body.symbolTable = new SymbolTable_1.SymbolTable(`Block: Function '${(_a = name === null || name === void 0 ? void 0 : name.text) !== null && _a !== void 0 ? _a : ''}'`, () => func.getSymbolTable());
|
|
583
|
-
if (!func.body) {
|
|
584
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.callableBlockMissingEndKeyword(functionTypeText)), { range: this.peek().range }));
|
|
585
|
-
throw this.lastDiagnosticAsError();
|
|
586
|
-
}
|
|
587
620
|
// consume 'end sub' or 'end function'
|
|
588
|
-
|
|
621
|
+
const endFunctionType = this.advance();
|
|
589
622
|
let expectedEndKind = isSub ? TokenKind_1.TokenKind.EndSub : TokenKind_1.TokenKind.EndFunction;
|
|
590
623
|
//if `function` is ended with `end sub`, or `sub` is ended with `end function`, then
|
|
591
624
|
//add an error but don't hard-fail so the AST can continue more gracefully
|
|
592
|
-
if (
|
|
593
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedEndCallableKeyword(functionTypeText,
|
|
625
|
+
if (endFunctionType.kind !== expectedEndKind) {
|
|
626
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedEndCallableKeyword(functionTypeText, endFunctionType.text)), { range: endFunctionType.range }));
|
|
627
|
+
}
|
|
628
|
+
if (!body) {
|
|
629
|
+
body = new Statement_1.Block({
|
|
630
|
+
statements: [],
|
|
631
|
+
startingRange: util_1.util.createBoundingRange(functionType, name, leftParen, ...params, rightParen, asToken, typeExpression, endFunctionType)
|
|
632
|
+
});
|
|
594
633
|
}
|
|
595
|
-
func
|
|
634
|
+
let func = new Expression_1.FunctionExpression({
|
|
635
|
+
parameters: params,
|
|
636
|
+
body: body,
|
|
637
|
+
functionType: functionType,
|
|
638
|
+
endFunctionType: endFunctionType,
|
|
639
|
+
leftParen: leftParen,
|
|
640
|
+
rightParen: rightParen,
|
|
641
|
+
as: asToken,
|
|
642
|
+
returnTypeExpression: typeExpression
|
|
643
|
+
});
|
|
596
644
|
if (isAnonymous) {
|
|
597
645
|
return func;
|
|
598
646
|
}
|
|
599
647
|
else {
|
|
600
|
-
let result = new Statement_1.FunctionStatement(name, func);
|
|
601
|
-
func.symbolTable.name += `: '${name === null || name === void 0 ? void 0 : name.text}'`;
|
|
602
|
-
func.functionStatement = result;
|
|
648
|
+
let result = new Statement_1.FunctionStatement({ name: name, func: func });
|
|
603
649
|
return result;
|
|
604
650
|
}
|
|
605
651
|
}
|
|
@@ -629,7 +675,13 @@ class Parser {
|
|
|
629
675
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
630
676
|
[asToken, typeExpression] = this.consumeAsTokenAndTypeExpression();
|
|
631
677
|
}
|
|
632
|
-
return new Expression_1.FunctionParameterExpression(
|
|
678
|
+
return new Expression_1.FunctionParameterExpression({
|
|
679
|
+
name: name,
|
|
680
|
+
equals: equalToken,
|
|
681
|
+
defaultValue: defaultValue,
|
|
682
|
+
as: asToken,
|
|
683
|
+
typeExpression: typeExpression
|
|
684
|
+
});
|
|
633
685
|
}
|
|
634
686
|
assignment() {
|
|
635
687
|
let name = this.advance();
|
|
@@ -637,15 +689,32 @@ class Parser {
|
|
|
637
689
|
if (TokenKind_1.DisallowedLocalIdentifiersText.has(name.text.toLowerCase())) {
|
|
638
690
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier(name.text)), { range: name.range }));
|
|
639
691
|
}
|
|
692
|
+
let asToken;
|
|
693
|
+
let typeExpression;
|
|
694
|
+
//look for `as SOME_TYPE`
|
|
695
|
+
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
696
|
+
this.warnIfNotBrighterScriptMode('typed assignment');
|
|
697
|
+
[asToken, typeExpression] = this.consumeAsTokenAndTypeExpression();
|
|
698
|
+
}
|
|
640
699
|
let operator = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedOperatorAfterIdentifier(TokenKind_1.AssignmentOperators, name.text), ...TokenKind_1.AssignmentOperators);
|
|
641
700
|
let value = this.expression();
|
|
642
701
|
let result;
|
|
643
702
|
if (operator.kind === TokenKind_1.TokenKind.Equal) {
|
|
644
|
-
result = new Statement_1.AssignmentStatement(operator, name, value);
|
|
703
|
+
result = new Statement_1.AssignmentStatement({ equals: operator, name: name, value: value, as: asToken, typeExpression: typeExpression });
|
|
645
704
|
}
|
|
646
705
|
else {
|
|
647
|
-
const nameExpression = new Expression_1.VariableExpression(name);
|
|
648
|
-
result = new Statement_1.AssignmentStatement(
|
|
706
|
+
const nameExpression = new Expression_1.VariableExpression({ name: name });
|
|
707
|
+
result = new Statement_1.AssignmentStatement({
|
|
708
|
+
equals: operator,
|
|
709
|
+
name: name,
|
|
710
|
+
value: new Expression_1.BinaryExpression({
|
|
711
|
+
left: nameExpression,
|
|
712
|
+
operator: operator,
|
|
713
|
+
right: value
|
|
714
|
+
}),
|
|
715
|
+
as: asToken,
|
|
716
|
+
typeExpression: typeExpression
|
|
717
|
+
});
|
|
649
718
|
}
|
|
650
719
|
return result;
|
|
651
720
|
}
|
|
@@ -734,9 +803,31 @@ class Parser {
|
|
|
734
803
|
// BrightScript is like python, in that variables can be declared without a `var`,
|
|
735
804
|
// `let`, (...) keyword. As such, we must check the token *after* an identifier to figure
|
|
736
805
|
// out what to do with it.
|
|
737
|
-
if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers)
|
|
738
|
-
this.checkAnyNext(...TokenKind_1.AssignmentOperators)) {
|
|
739
|
-
|
|
806
|
+
if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers)) {
|
|
807
|
+
if (this.checkAnyNext(...TokenKind_1.AssignmentOperators)) {
|
|
808
|
+
return this.assignment();
|
|
809
|
+
}
|
|
810
|
+
else if (this.checkNext(TokenKind_1.TokenKind.As)) {
|
|
811
|
+
// may be a typed assignment
|
|
812
|
+
const backtrack = this.current;
|
|
813
|
+
let validTypeExpression = false;
|
|
814
|
+
try {
|
|
815
|
+
// skip the identifier, and check for valid type expression
|
|
816
|
+
this.advance();
|
|
817
|
+
const parts = this.consumeAsTokenAndTypeExpression(true);
|
|
818
|
+
validTypeExpression = !!((parts === null || parts === void 0 ? void 0 : parts[0]) && (parts === null || parts === void 0 ? void 0 : parts[1]));
|
|
819
|
+
}
|
|
820
|
+
catch (e) {
|
|
821
|
+
// ignore any errors
|
|
822
|
+
}
|
|
823
|
+
finally {
|
|
824
|
+
this.current = backtrack;
|
|
825
|
+
}
|
|
826
|
+
if (validTypeExpression) {
|
|
827
|
+
// there is a valid 'as' and type expression
|
|
828
|
+
return this.assignment();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
740
831
|
}
|
|
741
832
|
//some BrighterScript keywords are allowed as a local identifiers, so we need to check for them AFTER the assignment check
|
|
742
833
|
if (this.check(TokenKind_1.TokenKind.Interface)) {
|
|
@@ -769,7 +860,12 @@ class Parser {
|
|
|
769
860
|
else {
|
|
770
861
|
endWhile = this.advance();
|
|
771
862
|
}
|
|
772
|
-
return new Statement_1.WhileStatement({
|
|
863
|
+
return new Statement_1.WhileStatement({
|
|
864
|
+
while: whileKeyword,
|
|
865
|
+
endWhile: endWhile,
|
|
866
|
+
condition: condition,
|
|
867
|
+
body: whileBlock
|
|
868
|
+
});
|
|
773
869
|
}
|
|
774
870
|
exitWhile() {
|
|
775
871
|
let keyword = this.advance();
|
|
@@ -804,7 +900,16 @@ class Parser {
|
|
|
804
900
|
}
|
|
805
901
|
// WARNING: BrightScript doesn't delete the loop initial value after a for/to loop! It just
|
|
806
902
|
// stays around in scope with whatever value it was when the loop exited.
|
|
807
|
-
return new Statement_1.ForStatement(
|
|
903
|
+
return new Statement_1.ForStatement({
|
|
904
|
+
for: forToken,
|
|
905
|
+
counterDeclaration: initializer,
|
|
906
|
+
to: toToken,
|
|
907
|
+
finalValue: finalValue,
|
|
908
|
+
body: body,
|
|
909
|
+
endFor: endForToken,
|
|
910
|
+
step: stepToken,
|
|
911
|
+
increment: incrementExpression
|
|
912
|
+
});
|
|
808
913
|
}
|
|
809
914
|
forEachStatement() {
|
|
810
915
|
let forEach = this.advance();
|
|
@@ -832,8 +937,11 @@ class Parser {
|
|
|
832
937
|
return new Statement_1.ForEachStatement({
|
|
833
938
|
forEach: forEach,
|
|
834
939
|
in: maybeIn,
|
|
835
|
-
endFor: endFor
|
|
836
|
-
|
|
940
|
+
endFor: endFor,
|
|
941
|
+
item: name,
|
|
942
|
+
target: target,
|
|
943
|
+
body: body
|
|
944
|
+
});
|
|
837
945
|
}
|
|
838
946
|
exitFor() {
|
|
839
947
|
let keyword = this.advance();
|
|
@@ -844,7 +952,7 @@ class Parser {
|
|
|
844
952
|
//then this comment should be treated as a single-line comment
|
|
845
953
|
let prev = this.previous();
|
|
846
954
|
if ((prev === null || prev === void 0 ? void 0 : prev.range.end.line) === this.peek().range.start.line) {
|
|
847
|
-
return new Statement_1.CommentStatement([this.advance()]);
|
|
955
|
+
return new Statement_1.CommentStatement({ comments: [this.advance()] });
|
|
848
956
|
}
|
|
849
957
|
else {
|
|
850
958
|
let comments = [this.advance()];
|
|
@@ -852,7 +960,7 @@ class Parser {
|
|
|
852
960
|
this.advance();
|
|
853
961
|
comments.push(this.advance());
|
|
854
962
|
}
|
|
855
|
-
return new Statement_1.CommentStatement(comments);
|
|
963
|
+
return new Statement_1.CommentStatement({ comments: comments });
|
|
856
964
|
}
|
|
857
965
|
}
|
|
858
966
|
namespaceStatement() {
|
|
@@ -861,7 +969,6 @@ class Parser {
|
|
|
861
969
|
this.namespaceAndFunctionDepth++;
|
|
862
970
|
let name = this.identifyingExpression();
|
|
863
971
|
//set the current namespace name
|
|
864
|
-
let result = new Statement_1.NamespaceStatement(keyword, name, null, null);
|
|
865
972
|
this.globalTerminators.push([TokenKind_1.TokenKind.EndNamespace]);
|
|
866
973
|
let body = this.body();
|
|
867
974
|
this.globalTerminators.pop();
|
|
@@ -874,8 +981,12 @@ class Parser {
|
|
|
874
981
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace')), { range: keyword.range }));
|
|
875
982
|
}
|
|
876
983
|
this.namespaceAndFunctionDepth--;
|
|
877
|
-
result
|
|
878
|
-
|
|
984
|
+
let result = new Statement_1.NamespaceStatement({
|
|
985
|
+
namespace: keyword,
|
|
986
|
+
nameExpression: name,
|
|
987
|
+
body: body,
|
|
988
|
+
endNamespace: endKeyword
|
|
989
|
+
});
|
|
879
990
|
//cache the range property so that plugins can't affect it
|
|
880
991
|
result.cacheRange();
|
|
881
992
|
result.body.symbolTable.name += `: namespace '${result.name}'`;
|
|
@@ -891,7 +1002,7 @@ class Parser {
|
|
|
891
1002
|
if (firstIdentifier) {
|
|
892
1003
|
// force it into an identifier so the AST makes some sense
|
|
893
1004
|
firstIdentifier.kind = TokenKind_1.TokenKind.Identifier;
|
|
894
|
-
const varExpr = new Expression_1.VariableExpression(firstIdentifier);
|
|
1005
|
+
const varExpr = new Expression_1.VariableExpression({ name: firstIdentifier });
|
|
895
1006
|
expr = varExpr;
|
|
896
1007
|
//consume multiple dot identifiers (i.e. `Name.Space.Can.Have.Many.Parts`)
|
|
897
1008
|
while (this.check(TokenKind_1.TokenKind.Dot)) {
|
|
@@ -905,7 +1016,7 @@ class Parser {
|
|
|
905
1016
|
}
|
|
906
1017
|
// force it into an identifier so the AST makes some sense
|
|
907
1018
|
identifier.kind = TokenKind_1.TokenKind.Identifier;
|
|
908
|
-
expr = new Expression_1.DottedGetExpression(expr, identifier, dot);
|
|
1019
|
+
expr = new Expression_1.DottedGetExpression({ obj: expr, name: identifier, dot: dot });
|
|
909
1020
|
}
|
|
910
1021
|
}
|
|
911
1022
|
return expr;
|
|
@@ -941,8 +1052,9 @@ class Parser {
|
|
|
941
1052
|
const statement = new Statement_1.ConstStatement({
|
|
942
1053
|
const: constToken,
|
|
943
1054
|
name: nameToken,
|
|
944
|
-
equals: equalToken
|
|
945
|
-
|
|
1055
|
+
equals: equalToken,
|
|
1056
|
+
value: expression
|
|
1057
|
+
});
|
|
946
1058
|
return statement;
|
|
947
1059
|
}
|
|
948
1060
|
libraryStatement() {
|
|
@@ -955,9 +1067,11 @@ class Parser {
|
|
|
955
1067
|
}
|
|
956
1068
|
importStatement() {
|
|
957
1069
|
this.warnIfNotBrighterScriptMode('import statements');
|
|
958
|
-
let importStatement = new Statement_1.ImportStatement(
|
|
959
|
-
|
|
960
|
-
|
|
1070
|
+
let importStatement = new Statement_1.ImportStatement({
|
|
1071
|
+
import: this.advance(),
|
|
1072
|
+
//grab the next token only if it's a string
|
|
1073
|
+
path: this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import'), TokenKind_1.TokenKind.StringLiteral)
|
|
1074
|
+
});
|
|
961
1075
|
return importStatement;
|
|
962
1076
|
}
|
|
963
1077
|
annotationExpression() {
|
|
@@ -966,7 +1080,7 @@ class Parser {
|
|
|
966
1080
|
if (identifier) {
|
|
967
1081
|
identifier.kind = TokenKind_1.TokenKind.Identifier;
|
|
968
1082
|
}
|
|
969
|
-
let annotation = new Expression_1.AnnotationExpression(atToken, identifier);
|
|
1083
|
+
let annotation = new Expression_1.AnnotationExpression({ at: atToken, name: identifier });
|
|
970
1084
|
this.pendingAnnotations.push(annotation);
|
|
971
1085
|
//optional arguments
|
|
972
1086
|
if (this.check(TokenKind_1.TokenKind.LeftParen)) {
|
|
@@ -1004,13 +1118,23 @@ class Parser {
|
|
|
1004
1118
|
alternate = this.expression();
|
|
1005
1119
|
}
|
|
1006
1120
|
catch (_b) { }
|
|
1007
|
-
return new Expression_1.TernaryExpression(
|
|
1121
|
+
return new Expression_1.TernaryExpression({
|
|
1122
|
+
test: test,
|
|
1123
|
+
questionMark: questionMarkToken,
|
|
1124
|
+
consequent: consequent,
|
|
1125
|
+
colon: colonToken,
|
|
1126
|
+
alternate: alternate
|
|
1127
|
+
});
|
|
1008
1128
|
}
|
|
1009
1129
|
nullCoalescingExpression(test) {
|
|
1010
1130
|
this.warnIfNotBrighterScriptMode('null coalescing operator');
|
|
1011
1131
|
const questionQuestionToken = this.advance();
|
|
1012
1132
|
const alternate = this.expression();
|
|
1013
|
-
return new Expression_1.NullCoalescingExpression(
|
|
1133
|
+
return new Expression_1.NullCoalescingExpression({
|
|
1134
|
+
consequent: test,
|
|
1135
|
+
questionQuestion: questionQuestionToken,
|
|
1136
|
+
alternate: alternate
|
|
1137
|
+
});
|
|
1014
1138
|
}
|
|
1015
1139
|
regexLiteralExpression() {
|
|
1016
1140
|
this.warnIfNotBrighterScriptMode('regular expression literal');
|
|
@@ -1036,16 +1160,16 @@ class Parser {
|
|
|
1036
1160
|
let next = this.peek();
|
|
1037
1161
|
if (next.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
1038
1162
|
//a quasi can actually be made up of multiple quasis when it includes char literals
|
|
1039
|
-
currentQuasiExpressionParts.push(new Expression_1.LiteralExpression(next));
|
|
1163
|
+
currentQuasiExpressionParts.push(new Expression_1.LiteralExpression({ value: next }));
|
|
1040
1164
|
this.advance();
|
|
1041
1165
|
}
|
|
1042
1166
|
else if (next.kind === TokenKind_1.TokenKind.EscapedCharCodeLiteral) {
|
|
1043
|
-
currentQuasiExpressionParts.push(new Expression_1.EscapedCharCodeLiteralExpression(next));
|
|
1167
|
+
currentQuasiExpressionParts.push(new Expression_1.EscapedCharCodeLiteralExpression({ value: next }));
|
|
1044
1168
|
this.advance();
|
|
1045
1169
|
}
|
|
1046
1170
|
else {
|
|
1047
1171
|
//finish up the current quasi
|
|
1048
|
-
quasis.push(new Expression_1.TemplateStringQuasiExpression(currentQuasiExpressionParts));
|
|
1172
|
+
quasis.push(new Expression_1.TemplateStringQuasiExpression({ expressions: currentQuasiExpressionParts }));
|
|
1049
1173
|
currentQuasiExpressionParts = [];
|
|
1050
1174
|
if (next.kind === TokenKind_1.TokenKind.TemplateStringExpressionBegin) {
|
|
1051
1175
|
this.advance();
|
|
@@ -1063,7 +1187,7 @@ class Parser {
|
|
|
1063
1187
|
}
|
|
1064
1188
|
}
|
|
1065
1189
|
//store the final set of quasis
|
|
1066
|
-
quasis.push(new Expression_1.TemplateStringQuasiExpression(currentQuasiExpressionParts));
|
|
1190
|
+
quasis.push(new Expression_1.TemplateStringQuasiExpression({ expressions: currentQuasiExpressionParts }));
|
|
1067
1191
|
if (this.isAtEnd()) {
|
|
1068
1192
|
//error - missing backtick
|
|
1069
1193
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unterminatedTemplateStringAtEndOfFile()), { range: util_1.util.getRange(openingBacktick, this.peek()) }));
|
|
@@ -1072,45 +1196,63 @@ class Parser {
|
|
|
1072
1196
|
else {
|
|
1073
1197
|
let closingBacktick = this.advance();
|
|
1074
1198
|
if (isTagged) {
|
|
1075
|
-
return new Expression_1.TaggedTemplateStringExpression(
|
|
1199
|
+
return new Expression_1.TaggedTemplateStringExpression({
|
|
1200
|
+
tagName: tagName,
|
|
1201
|
+
openingBacktick: openingBacktick,
|
|
1202
|
+
quasis: quasis,
|
|
1203
|
+
expressions: expressions,
|
|
1204
|
+
closingBacktick: closingBacktick
|
|
1205
|
+
});
|
|
1076
1206
|
}
|
|
1077
1207
|
else {
|
|
1078
|
-
return new Expression_1.TemplateStringExpression(
|
|
1208
|
+
return new Expression_1.TemplateStringExpression({
|
|
1209
|
+
openingBacktick: openingBacktick,
|
|
1210
|
+
quasis: quasis,
|
|
1211
|
+
expressions: expressions,
|
|
1212
|
+
closingBacktick: closingBacktick
|
|
1213
|
+
});
|
|
1079
1214
|
}
|
|
1080
1215
|
}
|
|
1081
1216
|
}
|
|
1082
1217
|
tryCatchStatement() {
|
|
1083
1218
|
const tryToken = this.advance();
|
|
1084
|
-
|
|
1219
|
+
let endTryToken;
|
|
1220
|
+
let catchStmt;
|
|
1085
1221
|
//ensure statement separator
|
|
1086
1222
|
this.consumeStatementSeparators();
|
|
1087
|
-
|
|
1223
|
+
let tryBranch = this.block(TokenKind_1.TokenKind.Catch, TokenKind_1.TokenKind.EndTry);
|
|
1088
1224
|
const peek = this.peek();
|
|
1089
1225
|
if (peek.kind !== TokenKind_1.TokenKind.Catch) {
|
|
1090
1226
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedCatchBlockInTryCatch()), { range: this.peek().range }));
|
|
1091
|
-
//gracefully handle end-try
|
|
1092
|
-
if (peek.kind === TokenKind_1.TokenKind.EndTry) {
|
|
1093
|
-
statement.tokens.endTry = this.advance();
|
|
1094
|
-
}
|
|
1095
|
-
return statement;
|
|
1096
1227
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1228
|
+
else {
|
|
1229
|
+
const catchToken = this.advance();
|
|
1230
|
+
const exceptionVarToken = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.missingExceptionVarToFollowCatch(), TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers);
|
|
1231
|
+
if (exceptionVarToken) {
|
|
1232
|
+
// force it into an identifier so the AST makes some sense
|
|
1233
|
+
exceptionVarToken.kind = TokenKind_1.TokenKind.Identifier;
|
|
1234
|
+
}
|
|
1235
|
+
//ensure statement sepatator
|
|
1236
|
+
this.consumeStatementSeparators();
|
|
1237
|
+
const catchBranch = this.block(TokenKind_1.TokenKind.EndTry);
|
|
1238
|
+
catchStmt = new Statement_1.CatchStatement({
|
|
1239
|
+
catch: catchToken,
|
|
1240
|
+
exceptionVariable: exceptionVarToken,
|
|
1241
|
+
catchBranch: catchBranch
|
|
1242
|
+
});
|
|
1104
1243
|
}
|
|
1105
|
-
//ensure statement sepatator
|
|
1106
|
-
this.consumeStatementSeparators();
|
|
1107
|
-
catchStmt.catchBranch = this.block(TokenKind_1.TokenKind.EndTry);
|
|
1108
1244
|
if (this.peek().kind !== TokenKind_1.TokenKind.EndTry) {
|
|
1109
1245
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedEndTryToTerminateTryCatch()), { range: this.peek().range }));
|
|
1110
1246
|
}
|
|
1111
1247
|
else {
|
|
1112
|
-
|
|
1248
|
+
endTryToken = this.advance();
|
|
1113
1249
|
}
|
|
1250
|
+
const statement = new Statement_1.TryCatchStatement({
|
|
1251
|
+
try: tryToken,
|
|
1252
|
+
tryBranch: tryBranch,
|
|
1253
|
+
catchStatement: catchStmt,
|
|
1254
|
+
endTry: endTryToken
|
|
1255
|
+
});
|
|
1114
1256
|
return statement;
|
|
1115
1257
|
}
|
|
1116
1258
|
throwStatement() {
|
|
@@ -1122,7 +1264,7 @@ class Parser {
|
|
|
1122
1264
|
else {
|
|
1123
1265
|
expression = this.expression();
|
|
1124
1266
|
}
|
|
1125
|
-
return new Statement_1.ThrowStatement(throwToken, expression);
|
|
1267
|
+
return new Statement_1.ThrowStatement({ throw: throwToken, expression: expression });
|
|
1126
1268
|
}
|
|
1127
1269
|
dimStatement() {
|
|
1128
1270
|
const dim = this.advance();
|
|
@@ -1153,7 +1295,13 @@ class Parser {
|
|
|
1153
1295
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.missingExpressionsInDimStatement()), { range: this.peek().range }));
|
|
1154
1296
|
}
|
|
1155
1297
|
let rightSquareBracket = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.missingRightSquareBracketAfterDimIdentifier(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1156
|
-
return new Statement_1.DimStatement(
|
|
1298
|
+
return new Statement_1.DimStatement({
|
|
1299
|
+
dim: dim,
|
|
1300
|
+
name: identifier,
|
|
1301
|
+
openingSquare: leftSquareBracket,
|
|
1302
|
+
dimensions: expressions,
|
|
1303
|
+
closingSquare: rightSquareBracket
|
|
1304
|
+
});
|
|
1157
1305
|
}
|
|
1158
1306
|
ifStatement() {
|
|
1159
1307
|
// colon before `if` is usually not allowed, unless it's after `then`
|
|
@@ -1263,8 +1411,12 @@ class Parser {
|
|
|
1263
1411
|
if: ifToken,
|
|
1264
1412
|
then: thenToken,
|
|
1265
1413
|
endIf: endIfToken,
|
|
1266
|
-
else: elseToken
|
|
1267
|
-
|
|
1414
|
+
else: elseToken,
|
|
1415
|
+
condition: condition,
|
|
1416
|
+
thenBranch: thenBranch,
|
|
1417
|
+
elseBranch: elseBranch,
|
|
1418
|
+
isInline: isInlineIfThen
|
|
1419
|
+
});
|
|
1268
1420
|
}
|
|
1269
1421
|
//consume a `then` or `else` branch block of an `if` statement
|
|
1270
1422
|
blockConditionalBranch(ifToken) {
|
|
@@ -1335,7 +1487,7 @@ class Parser {
|
|
|
1335
1487
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unexpectedToken(colon.text)), { range: colon.range }));
|
|
1336
1488
|
}
|
|
1337
1489
|
}
|
|
1338
|
-
return new Statement_1.Block(statements, startingRange);
|
|
1490
|
+
return new Statement_1.Block({ statements: statements, startingRange: startingRange });
|
|
1339
1491
|
}
|
|
1340
1492
|
expressionStatement(expr) {
|
|
1341
1493
|
let expressionStart = this.peek();
|
|
@@ -1349,15 +1501,15 @@ class Parser {
|
|
|
1349
1501
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.incrementDecrementOperatorsAreNotAllowedAsResultOfFunctionCall()), { range: expressionStart.range }));
|
|
1350
1502
|
throw this.lastDiagnosticAsError();
|
|
1351
1503
|
}
|
|
1352
|
-
const result = new Statement_1.IncrementStatement(expr, operator);
|
|
1504
|
+
const result = new Statement_1.IncrementStatement({ value: expr, operator: operator });
|
|
1353
1505
|
return result;
|
|
1354
1506
|
}
|
|
1355
1507
|
if ((0, reflection_1.isCallExpression)(expr) || (0, reflection_1.isCallfuncExpression)(expr)) {
|
|
1356
|
-
return new Statement_1.ExpressionStatement(expr);
|
|
1508
|
+
return new Statement_1.ExpressionStatement({ expression: expr });
|
|
1357
1509
|
}
|
|
1358
1510
|
//at this point, it's probably an error. However, we recover a little more gracefully by creating an inclosing ExpressionStatement
|
|
1359
1511
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()), { range: expressionStart.range }));
|
|
1360
|
-
return new Statement_1.ExpressionStatement(expr);
|
|
1512
|
+
return new Statement_1.ExpressionStatement({ expression: expr });
|
|
1361
1513
|
}
|
|
1362
1514
|
setStatement() {
|
|
1363
1515
|
/**
|
|
@@ -1373,14 +1525,25 @@ class Parser {
|
|
|
1373
1525
|
let right = this.expression();
|
|
1374
1526
|
// Create a dotted or indexed "set" based on the left-hand side's type
|
|
1375
1527
|
if ((0, reflection_1.isIndexedGetExpression)(left)) {
|
|
1376
|
-
return new Statement_1.IndexedSetStatement(
|
|
1377
|
-
|
|
1378
|
-
:
|
|
1528
|
+
return new Statement_1.IndexedSetStatement({
|
|
1529
|
+
obj: left.obj,
|
|
1530
|
+
indexes: left.indexes,
|
|
1531
|
+
value: operator.kind === TokenKind_1.TokenKind.Equal
|
|
1532
|
+
? right
|
|
1533
|
+
: new Expression_1.BinaryExpression({ left: left, operator: operator, right: right }),
|
|
1534
|
+
openingSquare: left.tokens.openingSquare,
|
|
1535
|
+
closingSquare: left.tokens.closingSquare
|
|
1536
|
+
});
|
|
1379
1537
|
}
|
|
1380
1538
|
else if ((0, reflection_1.isDottedGetExpression)(left)) {
|
|
1381
|
-
return new Statement_1.DottedSetStatement(
|
|
1382
|
-
|
|
1383
|
-
:
|
|
1539
|
+
return new Statement_1.DottedSetStatement({
|
|
1540
|
+
obj: left.obj,
|
|
1541
|
+
name: left.tokens.name,
|
|
1542
|
+
value: operator.kind === TokenKind_1.TokenKind.Equal
|
|
1543
|
+
? right
|
|
1544
|
+
: new Expression_1.BinaryExpression({ left: left, operator: operator, right: right }),
|
|
1545
|
+
dot: left.tokens.dot
|
|
1546
|
+
});
|
|
1384
1547
|
}
|
|
1385
1548
|
}
|
|
1386
1549
|
return this.expressionStatement(expr);
|
|
@@ -1413,27 +1576,27 @@ class Parser {
|
|
|
1413
1576
|
if ((0, Token_1.isToken)(last)) {
|
|
1414
1577
|
// TODO: error, expected value
|
|
1415
1578
|
}
|
|
1416
|
-
return new Statement_1.PrintStatement({ print: printKeyword
|
|
1579
|
+
return new Statement_1.PrintStatement({ print: printKeyword, expressions: values });
|
|
1417
1580
|
}
|
|
1418
1581
|
/**
|
|
1419
1582
|
* Parses a return statement with an optional return value.
|
|
1420
1583
|
* @returns an AST representation of a return statement.
|
|
1421
1584
|
*/
|
|
1422
1585
|
returnStatement() {
|
|
1423
|
-
let
|
|
1586
|
+
let options = { return: this.previous() };
|
|
1424
1587
|
if (this.checkEndOfStatement()) {
|
|
1425
|
-
return new Statement_1.ReturnStatement(
|
|
1588
|
+
return new Statement_1.ReturnStatement(options);
|
|
1426
1589
|
}
|
|
1427
1590
|
let toReturn = this.check(TokenKind_1.TokenKind.Else) ? undefined : this.expression();
|
|
1428
|
-
return new Statement_1.ReturnStatement(
|
|
1591
|
+
return new Statement_1.ReturnStatement(Object.assign(Object.assign({}, options), { value: toReturn }));
|
|
1429
1592
|
}
|
|
1430
1593
|
/**
|
|
1431
1594
|
* Parses a `label` statement
|
|
1432
1595
|
* @returns an AST representation of an `label` statement.
|
|
1433
1596
|
*/
|
|
1434
1597
|
labelStatement() {
|
|
1435
|
-
let
|
|
1436
|
-
|
|
1598
|
+
let options = {
|
|
1599
|
+
name: this.advance(),
|
|
1437
1600
|
colon: this.advance()
|
|
1438
1601
|
};
|
|
1439
1602
|
//label must be alone on its line, this is probably not a label
|
|
@@ -1442,7 +1605,7 @@ class Parser {
|
|
|
1442
1605
|
this.current -= 2;
|
|
1443
1606
|
throw new CancelStatementError();
|
|
1444
1607
|
}
|
|
1445
|
-
return new Statement_1.LabelStatement(
|
|
1608
|
+
return new Statement_1.LabelStatement(options);
|
|
1446
1609
|
}
|
|
1447
1610
|
/**
|
|
1448
1611
|
* Parses a `continue` statement
|
|
@@ -1469,16 +1632,16 @@ class Parser {
|
|
|
1469
1632
|
* @returns an AST representation of an `end` statement.
|
|
1470
1633
|
*/
|
|
1471
1634
|
endStatement() {
|
|
1472
|
-
let
|
|
1473
|
-
return new Statement_1.EndStatement(
|
|
1635
|
+
let options = { end: this.advance() };
|
|
1636
|
+
return new Statement_1.EndStatement(options);
|
|
1474
1637
|
}
|
|
1475
1638
|
/**
|
|
1476
1639
|
* Parses a `stop` statement
|
|
1477
1640
|
* @returns an AST representation of a `stop` statement
|
|
1478
1641
|
*/
|
|
1479
1642
|
stopStatement() {
|
|
1480
|
-
let
|
|
1481
|
-
return new Statement_1.StopStatement(
|
|
1643
|
+
let options = { stop: this.advance() };
|
|
1644
|
+
return new Statement_1.StopStatement(options);
|
|
1482
1645
|
}
|
|
1483
1646
|
/**
|
|
1484
1647
|
* Parses a block, looking for a specific terminating TokenKind to denote completion.
|
|
@@ -1530,7 +1693,7 @@ class Parser {
|
|
|
1530
1693
|
}
|
|
1531
1694
|
}
|
|
1532
1695
|
this.exitAnnotationBlock(parentAnnotations);
|
|
1533
|
-
return new Statement_1.Block(statements, startingToken.range);
|
|
1696
|
+
return new Statement_1.Block({ statements: statements, startingRange: startingToken.range });
|
|
1534
1697
|
}
|
|
1535
1698
|
/**
|
|
1536
1699
|
* Attach pending annotations to the provided statement,
|
|
@@ -1569,7 +1732,7 @@ class Parser {
|
|
|
1569
1732
|
// myVal = foo() as dynamic as string
|
|
1570
1733
|
[asToken, typeExpression] = this.consumeAsTokenAndTypeExpression();
|
|
1571
1734
|
if (asToken && typeExpression) {
|
|
1572
|
-
expression = new Expression_1.TypeCastExpression(expression, asToken, typeExpression);
|
|
1735
|
+
expression = new Expression_1.TypeCastExpression({ obj: expression, as: asToken, typeExpression: typeExpression });
|
|
1573
1736
|
}
|
|
1574
1737
|
}
|
|
1575
1738
|
else {
|
|
@@ -1606,7 +1769,7 @@ class Parser {
|
|
|
1606
1769
|
while (this.matchAny(TokenKind_1.TokenKind.And, TokenKind_1.TokenKind.Or)) {
|
|
1607
1770
|
let operator = this.previous();
|
|
1608
1771
|
let right = this.relational();
|
|
1609
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1772
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1610
1773
|
}
|
|
1611
1774
|
return expr;
|
|
1612
1775
|
}
|
|
@@ -1615,7 +1778,7 @@ class Parser {
|
|
|
1615
1778
|
while (this.matchAny(TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.LessGreater, TokenKind_1.TokenKind.Greater, TokenKind_1.TokenKind.GreaterEqual, TokenKind_1.TokenKind.Less, TokenKind_1.TokenKind.LessEqual)) {
|
|
1616
1779
|
let operator = this.previous();
|
|
1617
1780
|
let right = this.additive();
|
|
1618
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1781
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1619
1782
|
}
|
|
1620
1783
|
return expr;
|
|
1621
1784
|
}
|
|
@@ -1625,7 +1788,7 @@ class Parser {
|
|
|
1625
1788
|
while (this.matchAny(TokenKind_1.TokenKind.Plus, TokenKind_1.TokenKind.Minus)) {
|
|
1626
1789
|
let operator = this.previous();
|
|
1627
1790
|
let right = this.multiplicative();
|
|
1628
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1791
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1629
1792
|
}
|
|
1630
1793
|
return expr;
|
|
1631
1794
|
}
|
|
@@ -1634,7 +1797,7 @@ class Parser {
|
|
|
1634
1797
|
while (this.matchAny(TokenKind_1.TokenKind.Forwardslash, TokenKind_1.TokenKind.Backslash, TokenKind_1.TokenKind.Star, TokenKind_1.TokenKind.Mod, TokenKind_1.TokenKind.LeftShift, TokenKind_1.TokenKind.RightShift)) {
|
|
1635
1798
|
let operator = this.previous();
|
|
1636
1799
|
let right = this.exponential();
|
|
1637
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1800
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1638
1801
|
}
|
|
1639
1802
|
return expr;
|
|
1640
1803
|
}
|
|
@@ -1643,7 +1806,7 @@ class Parser {
|
|
|
1643
1806
|
while (this.match(TokenKind_1.TokenKind.Caret)) {
|
|
1644
1807
|
let operator = this.previous();
|
|
1645
1808
|
let right = this.prefixUnary();
|
|
1646
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1809
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1647
1810
|
}
|
|
1648
1811
|
return expr;
|
|
1649
1812
|
}
|
|
@@ -1653,7 +1816,7 @@ class Parser {
|
|
|
1653
1816
|
this.current++; //advance
|
|
1654
1817
|
let operator = this.previous();
|
|
1655
1818
|
let right = this.relational();
|
|
1656
|
-
return new Expression_1.UnaryExpression(operator, right);
|
|
1819
|
+
return new Expression_1.UnaryExpression({ operator: operator, right: right });
|
|
1657
1820
|
}
|
|
1658
1821
|
else if (nextKind === TokenKind_1.TokenKind.Minus || nextKind === TokenKind_1.TokenKind.Plus) {
|
|
1659
1822
|
this.current++; //advance
|
|
@@ -1661,25 +1824,38 @@ class Parser {
|
|
|
1661
1824
|
let right = nextKind === TokenKind_1.TokenKind.Not
|
|
1662
1825
|
? this.boolean()
|
|
1663
1826
|
: this.prefixUnary();
|
|
1664
|
-
return new Expression_1.UnaryExpression(operator, right);
|
|
1827
|
+
return new Expression_1.UnaryExpression({ operator: operator, right: right });
|
|
1665
1828
|
}
|
|
1666
1829
|
return this.call();
|
|
1667
1830
|
}
|
|
1668
1831
|
indexedGet(expr) {
|
|
1669
1832
|
let openingSquare = this.previous();
|
|
1670
1833
|
let questionDotToken = this.getMatchingTokenAtOffset(-2, TokenKind_1.TokenKind.QuestionDot);
|
|
1671
|
-
let
|
|
1672
|
-
|
|
1834
|
+
let indexes = [];
|
|
1835
|
+
//consume leading newlines
|
|
1673
1836
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1674
1837
|
try {
|
|
1675
|
-
|
|
1838
|
+
indexes.push(this.expression());
|
|
1839
|
+
//consume additional indexes separated by commas
|
|
1840
|
+
while (this.check(TokenKind_1.TokenKind.Comma)) {
|
|
1841
|
+
//discard the comma
|
|
1842
|
+
this.advance();
|
|
1843
|
+
indexes.push(this.expression());
|
|
1844
|
+
}
|
|
1676
1845
|
}
|
|
1677
1846
|
catch (error) {
|
|
1678
1847
|
this.rethrowNonDiagnosticError(error);
|
|
1679
1848
|
}
|
|
1849
|
+
//consume trailing newlines
|
|
1680
1850
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1681
|
-
closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightSquareBraceAfterArrayOrObjectIndex(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1682
|
-
return new Expression_1.IndexedGetExpression(
|
|
1851
|
+
const closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightSquareBraceAfterArrayOrObjectIndex(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1852
|
+
return new Expression_1.IndexedGetExpression({
|
|
1853
|
+
obj: expr,
|
|
1854
|
+
indexes: indexes,
|
|
1855
|
+
openingSquare: openingSquare,
|
|
1856
|
+
closingSquare: closingSquare,
|
|
1857
|
+
questionDot: questionDotToken
|
|
1858
|
+
});
|
|
1683
1859
|
}
|
|
1684
1860
|
newExpression() {
|
|
1685
1861
|
var _a;
|
|
@@ -1692,12 +1868,12 @@ class Parser {
|
|
|
1692
1868
|
// wrap the name in an expression
|
|
1693
1869
|
const endOfStatementRange = util_1.util.createRangeFromPositions(newToken.range.end, (_a = this.peek()) === null || _a === void 0 ? void 0 : _a.range.end);
|
|
1694
1870
|
const exprStmt = nameExpr !== null && nameExpr !== void 0 ? nameExpr : (0, creators_1.createStringLiteral)('', endOfStatementRange);
|
|
1695
|
-
return new Statement_1.ExpressionStatement(exprStmt);
|
|
1871
|
+
return new Statement_1.ExpressionStatement({ expression: exprStmt });
|
|
1696
1872
|
}
|
|
1697
1873
|
let call = this.finishCall(leftParen, nameExpr);
|
|
1698
1874
|
//pop the call from the callExpressions list because this is technically something else
|
|
1699
1875
|
this.callExpressions.pop();
|
|
1700
|
-
let result = new Expression_1.NewExpression(newToken, call);
|
|
1876
|
+
let result = new Expression_1.NewExpression({ new: newToken, call: call });
|
|
1701
1877
|
return result;
|
|
1702
1878
|
}
|
|
1703
1879
|
/**
|
|
@@ -1711,7 +1887,14 @@ class Parser {
|
|
|
1711
1887
|
methodName.kind = TokenKind_1.TokenKind.Identifier;
|
|
1712
1888
|
let openParen = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedOpenParenToFollowCallfuncIdentifier(), TokenKind_1.TokenKind.LeftParen);
|
|
1713
1889
|
let call = this.finishCall(openParen, callee, false);
|
|
1714
|
-
return new Expression_1.CallfuncExpression(
|
|
1890
|
+
return new Expression_1.CallfuncExpression({
|
|
1891
|
+
callee: callee,
|
|
1892
|
+
operator: operator,
|
|
1893
|
+
methodName: methodName,
|
|
1894
|
+
openingParen: openParen,
|
|
1895
|
+
args: call.args,
|
|
1896
|
+
closingParen: call.tokens.closingParen
|
|
1897
|
+
});
|
|
1715
1898
|
}
|
|
1716
1899
|
call() {
|
|
1717
1900
|
if (this.check(TokenKind_1.TokenKind.New) && this.checkAnyNext(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers)) {
|
|
@@ -1740,7 +1923,7 @@ class Parser {
|
|
|
1740
1923
|
}
|
|
1741
1924
|
// force it into an identifier so the AST makes some sense
|
|
1742
1925
|
name.kind = TokenKind_1.TokenKind.Identifier;
|
|
1743
|
-
expr = new Expression_1.DottedGetExpression(expr, name, dot);
|
|
1926
|
+
expr = new Expression_1.DottedGetExpression({ obj: expr, name: name, dot: dot });
|
|
1744
1927
|
}
|
|
1745
1928
|
}
|
|
1746
1929
|
else if (this.checkAny(TokenKind_1.TokenKind.At, TokenKind_1.TokenKind.QuestionAt)) {
|
|
@@ -1751,7 +1934,7 @@ class Parser {
|
|
|
1751
1934
|
if (!name) {
|
|
1752
1935
|
break;
|
|
1753
1936
|
}
|
|
1754
|
-
expr = new Expression_1.XmlAttributeGetExpression(expr, name, dot);
|
|
1937
|
+
expr = new Expression_1.XmlAttributeGetExpression({ obj: expr, name: name, at: dot });
|
|
1755
1938
|
//only allow a single `@` expression
|
|
1756
1939
|
break;
|
|
1757
1940
|
}
|
|
@@ -1783,7 +1966,12 @@ class Parser {
|
|
|
1783
1966
|
}
|
|
1784
1967
|
while (this.match(TokenKind_1.TokenKind.Newline)) { }
|
|
1785
1968
|
const closingParen = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(), TokenKind_1.TokenKind.RightParen);
|
|
1786
|
-
let expression = new Expression_1.CallExpression(
|
|
1969
|
+
let expression = new Expression_1.CallExpression({
|
|
1970
|
+
callee: callee,
|
|
1971
|
+
openingParen: openingParen,
|
|
1972
|
+
args: args,
|
|
1973
|
+
closingParen: closingParen
|
|
1974
|
+
});
|
|
1787
1975
|
if (addToCallExpressionList) {
|
|
1788
1976
|
this.callExpressions.push(expression);
|
|
1789
1977
|
}
|
|
@@ -1802,14 +1990,14 @@ class Parser {
|
|
|
1802
1990
|
let operator = this.previous();
|
|
1803
1991
|
let right = this.getTypeExpressionPart(changedTokens);
|
|
1804
1992
|
if (right) {
|
|
1805
|
-
expr = new Expression_1.BinaryExpression(expr, operator, right);
|
|
1993
|
+
expr = new Expression_1.BinaryExpression({ left: expr, operator: operator, right: right });
|
|
1806
1994
|
}
|
|
1807
1995
|
else {
|
|
1808
1996
|
break;
|
|
1809
1997
|
}
|
|
1810
1998
|
}
|
|
1811
1999
|
if (expr) {
|
|
1812
|
-
return new Expression_1.TypeExpression(expr);
|
|
2000
|
+
return new Expression_1.TypeExpression({ expression: expr });
|
|
1813
2001
|
}
|
|
1814
2002
|
}
|
|
1815
2003
|
catch (error) {
|
|
@@ -1831,7 +2019,7 @@ class Parser {
|
|
|
1831
2019
|
let expr;
|
|
1832
2020
|
if (this.checkAny(...TokenKind_1.DeclarableTypes)) {
|
|
1833
2021
|
// if this is just a type, just use directly
|
|
1834
|
-
expr = new Expression_1.VariableExpression(this.advance());
|
|
2022
|
+
expr = new Expression_1.VariableExpression({ name: this.advance() });
|
|
1835
2023
|
}
|
|
1836
2024
|
else {
|
|
1837
2025
|
if (this.checkAny(...TokenKind_1.AllowedTypeIdentifiers)) {
|
|
@@ -1856,7 +2044,7 @@ class Parser {
|
|
|
1856
2044
|
const leftBracket = this.advance();
|
|
1857
2045
|
if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
|
|
1858
2046
|
const rightBracket = this.advance();
|
|
1859
|
-
expr = new Expression_1.TypedArrayExpression(expr, leftBracket, rightBracket);
|
|
2047
|
+
expr = new Expression_1.TypedArrayExpression({ innerType: expr, leftBracket: leftBracket, rightBracket: rightBracket });
|
|
1860
2048
|
}
|
|
1861
2049
|
}
|
|
1862
2050
|
}
|
|
@@ -1865,10 +2053,10 @@ class Parser {
|
|
|
1865
2053
|
primary() {
|
|
1866
2054
|
switch (true) {
|
|
1867
2055
|
case this.matchAny(TokenKind_1.TokenKind.False, TokenKind_1.TokenKind.True, TokenKind_1.TokenKind.Invalid, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.LongIntegerLiteral, TokenKind_1.TokenKind.FloatLiteral, TokenKind_1.TokenKind.DoubleLiteral, TokenKind_1.TokenKind.StringLiteral):
|
|
1868
|
-
return new Expression_1.LiteralExpression(this.previous());
|
|
2056
|
+
return new Expression_1.LiteralExpression({ value: this.previous() });
|
|
1869
2057
|
//capture source literals (LINE_NUM if brightscript, or a bunch of them if brighterscript)
|
|
1870
2058
|
case this.matchAny(TokenKind_1.TokenKind.LineNumLiteral, ...(this.options.mode === ParseMode.BrightScript ? [] : TokenKind_1.BrighterScriptSourceLiterals)):
|
|
1871
|
-
return new Expression_1.SourceLiteralExpression(this.previous());
|
|
2059
|
+
return new Expression_1.SourceLiteralExpression({ value: this.previous() });
|
|
1872
2060
|
//template string
|
|
1873
2061
|
case this.check(TokenKind_1.TokenKind.BackTick):
|
|
1874
2062
|
return this.templateString(false);
|
|
@@ -1876,12 +2064,12 @@ class Parser {
|
|
|
1876
2064
|
case this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedLocalIdentifiers) && this.checkNext(TokenKind_1.TokenKind.BackTick):
|
|
1877
2065
|
return this.templateString(true);
|
|
1878
2066
|
case this.matchAny(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers):
|
|
1879
|
-
return new Expression_1.VariableExpression(this.previous());
|
|
2067
|
+
return new Expression_1.VariableExpression({ name: this.previous() });
|
|
1880
2068
|
case this.match(TokenKind_1.TokenKind.LeftParen):
|
|
1881
2069
|
let left = this.previous();
|
|
1882
2070
|
let expr = this.expression();
|
|
1883
2071
|
let right = this.consume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftParenAfterExpression(), TokenKind_1.TokenKind.RightParen);
|
|
1884
|
-
return new Expression_1.GroupingExpression({
|
|
2072
|
+
return new Expression_1.GroupingExpression({ leftParen: left, rightParen: right, expression: expr });
|
|
1885
2073
|
case this.matchAny(TokenKind_1.TokenKind.LeftSquareBracket):
|
|
1886
2074
|
return this.arrayLiteral();
|
|
1887
2075
|
case this.match(TokenKind_1.TokenKind.LeftCurlyBrace):
|
|
@@ -1890,13 +2078,13 @@ class Parser {
|
|
|
1890
2078
|
let token = Object.assign(this.previous(), {
|
|
1891
2079
|
kind: TokenKind_1.TokenKind.Identifier
|
|
1892
2080
|
});
|
|
1893
|
-
return new Expression_1.VariableExpression(token);
|
|
2081
|
+
return new Expression_1.VariableExpression({ name: token });
|
|
1894
2082
|
case this.checkAny(TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Sub):
|
|
1895
2083
|
return this.anonymousFunction();
|
|
1896
2084
|
case this.check(TokenKind_1.TokenKind.RegexLiteral):
|
|
1897
2085
|
return this.regexLiteralExpression();
|
|
1898
2086
|
case this.check(TokenKind_1.TokenKind.Comment):
|
|
1899
|
-
return new Statement_1.CommentStatement([this.advance()]);
|
|
2087
|
+
return new Statement_1.CommentStatement({ comments: [this.advance()] });
|
|
1900
2088
|
default:
|
|
1901
2089
|
//if we found an expected terminator, don't throw a diagnostic...just return undefined
|
|
1902
2090
|
if (this.checkAny(...this.peekGlobalTerminators())) {
|
|
@@ -1914,7 +2102,7 @@ class Parser {
|
|
|
1914
2102
|
let openingSquare = this.previous();
|
|
1915
2103
|
//add any comment found right after the opening square
|
|
1916
2104
|
if (this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1917
|
-
elements.push(new Statement_1.CommentStatement([this.advance()]));
|
|
2105
|
+
elements.push(new Statement_1.CommentStatement({ comments: [this.advance()] }));
|
|
1918
2106
|
}
|
|
1919
2107
|
while (this.match(TokenKind_1.TokenKind.Newline)) {
|
|
1920
2108
|
}
|
|
@@ -1925,7 +2113,7 @@ class Parser {
|
|
|
1925
2113
|
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Comment)) {
|
|
1926
2114
|
if (this.checkPrevious(TokenKind_1.TokenKind.Comment) || this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1927
2115
|
let comment = this.check(TokenKind_1.TokenKind.Comment) ? this.advance() : this.previous();
|
|
1928
|
-
elements.push(new Statement_1.CommentStatement([comment]));
|
|
2116
|
+
elements.push(new Statement_1.CommentStatement({ comments: [comment] }));
|
|
1929
2117
|
}
|
|
1930
2118
|
while (this.match(TokenKind_1.TokenKind.Newline)) {
|
|
1931
2119
|
}
|
|
@@ -1944,7 +2132,7 @@ class Parser {
|
|
|
1944
2132
|
closingSquare = this.previous();
|
|
1945
2133
|
}
|
|
1946
2134
|
//this.consume("Expected newline or ':' after array literal", TokenKind.Newline, TokenKind.Colon, TokenKind.Eof);
|
|
1947
|
-
return new Expression_1.ArrayLiteralExpression(elements, openingSquare, closingSquare);
|
|
2135
|
+
return new Expression_1.ArrayLiteralExpression({ elements: elements, open: openingSquare, close: closingSquare });
|
|
1948
2136
|
}
|
|
1949
2137
|
aaLiteral() {
|
|
1950
2138
|
let openingBrace = this.previous();
|
|
@@ -1976,23 +2164,27 @@ class Parser {
|
|
|
1976
2164
|
try {
|
|
1977
2165
|
if (this.check(TokenKind_1.TokenKind.Comment)) {
|
|
1978
2166
|
lastAAMember = null;
|
|
1979
|
-
members.push(new Statement_1.CommentStatement([this.advance()]));
|
|
2167
|
+
members.push(new Statement_1.CommentStatement({ comments: [this.advance()] }));
|
|
1980
2168
|
}
|
|
1981
2169
|
else {
|
|
1982
2170
|
let k = key();
|
|
1983
2171
|
let expr = this.expression();
|
|
1984
|
-
lastAAMember = new Expression_1.AAMemberExpression(
|
|
2172
|
+
lastAAMember = new Expression_1.AAMemberExpression({
|
|
2173
|
+
key: k.keyToken,
|
|
2174
|
+
colon: k.colonToken,
|
|
2175
|
+
value: expr
|
|
2176
|
+
});
|
|
1985
2177
|
members.push(lastAAMember);
|
|
1986
2178
|
}
|
|
1987
2179
|
while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Colon, TokenKind_1.TokenKind.Comment)) {
|
|
1988
2180
|
// collect comma at end of expression
|
|
1989
2181
|
if (lastAAMember && this.checkPrevious(TokenKind_1.TokenKind.Comma)) {
|
|
1990
|
-
lastAAMember.
|
|
2182
|
+
lastAAMember.tokens.comma = this.previous();
|
|
1991
2183
|
}
|
|
1992
2184
|
//check for comment at the end of the current line
|
|
1993
2185
|
if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
|
|
1994
2186
|
let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
|
|
1995
|
-
members.push(new Statement_1.CommentStatement([token]));
|
|
2187
|
+
members.push(new Statement_1.CommentStatement({ comments: [token] }));
|
|
1996
2188
|
}
|
|
1997
2189
|
else {
|
|
1998
2190
|
this.consumeStatementSeparators(true);
|
|
@@ -2000,7 +2192,7 @@ class Parser {
|
|
|
2000
2192
|
if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
|
|
2001
2193
|
let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
|
|
2002
2194
|
lastAAMember = null;
|
|
2003
|
-
members.push(new Statement_1.CommentStatement([token]));
|
|
2195
|
+
members.push(new Statement_1.CommentStatement({ comments: [token] }));
|
|
2004
2196
|
continue;
|
|
2005
2197
|
}
|
|
2006
2198
|
if (this.check(TokenKind_1.TokenKind.RightCurlyBrace)) {
|
|
@@ -2008,7 +2200,11 @@ class Parser {
|
|
|
2008
2200
|
}
|
|
2009
2201
|
let k = key();
|
|
2010
2202
|
let expr = this.expression();
|
|
2011
|
-
lastAAMember = new Expression_1.AAMemberExpression(
|
|
2203
|
+
lastAAMember = new Expression_1.AAMemberExpression({
|
|
2204
|
+
key: k.keyToken,
|
|
2205
|
+
colon: k.colonToken,
|
|
2206
|
+
value: expr
|
|
2207
|
+
});
|
|
2012
2208
|
members.push(lastAAMember);
|
|
2013
2209
|
}
|
|
2014
2210
|
}
|
|
@@ -2021,7 +2217,7 @@ class Parser {
|
|
|
2021
2217
|
else {
|
|
2022
2218
|
closingBrace = this.previous();
|
|
2023
2219
|
}
|
|
2024
|
-
const aaExpr = new Expression_1.AALiteralExpression(members, openingBrace, closingBrace);
|
|
2220
|
+
const aaExpr = new Expression_1.AALiteralExpression({ elements: members, open: openingBrace, close: closingBrace });
|
|
2025
2221
|
return aaExpr;
|
|
2026
2222
|
}
|
|
2027
2223
|
/**
|
|
@@ -2130,6 +2326,11 @@ class Parser {
|
|
|
2130
2326
|
var _a;
|
|
2131
2327
|
return ((_a = this.previous()) === null || _a === void 0 ? void 0 : _a.kind) === tokenKind;
|
|
2132
2328
|
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Check that the next token kind is the expected kind
|
|
2331
|
+
* @param tokenKind the expected next kind
|
|
2332
|
+
* @returns true if the next tokenKind is the expected value
|
|
2333
|
+
*/
|
|
2133
2334
|
check(tokenKind) {
|
|
2134
2335
|
const nextKind = this.peek().kind;
|
|
2135
2336
|
if (nextKind === TokenKind_1.TokenKind.Eof) {
|