@mojir/lits 2.0.14 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +1131 -1858
- package/dist/cli/reference/api.d.ts +8 -8
- package/dist/cli/src/analyze/index.d.ts +0 -2
- package/dist/cli/src/builtin/index.d.ts +6 -11
- package/dist/cli/src/builtin/specialExpressions/and.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/declared.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/or.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/{when.d.ts → switch.d.ts} +2 -2
- package/dist/cli/src/builtin/specialExpressions/try.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/{if-not.d.ts → unless.d.ts} +2 -2
- package/dist/cli/src/evaluator/ContextStack.d.ts +2 -0
- package/dist/cli/src/identifier.d.ts +2 -2
- package/dist/cli/src/parser/AlgebraicParser.d.ts +12 -2
- package/dist/cli/src/tokenizer/algebraic/algebraicReservedNames.d.ts +94 -7
- package/dist/cli/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
- package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +8 -7
- package/dist/cli/src/tokenizer/polish/polishTokenizers.d.ts +1 -1
- package/dist/cli/src/tokenizer/polish/polishTokens.d.ts +1 -1
- package/dist/cli/src/tokenizer/utils.d.ts +1 -1
- package/dist/cli/src/typeGuards/index.d.ts +1 -0
- package/dist/index.esm.js +1132 -1861
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1132 -1861
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1132 -1861
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +8 -8
- package/dist/src/analyze/index.d.ts +0 -2
- package/dist/src/builtin/index.d.ts +6 -11
- package/dist/src/builtin/specialExpressions/and.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/declared.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/or.d.ts +1 -1
- package/dist/{cli/src/builtin/specialExpressions/time.d.ts → src/builtin/specialExpressions/switch.d.ts} +2 -2
- package/dist/src/builtin/specialExpressions/try.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/{if-not.d.ts → unless.d.ts} +2 -2
- package/dist/src/evaluator/ContextStack.d.ts +2 -0
- package/dist/src/identifier.d.ts +2 -2
- package/dist/src/parser/AlgebraicParser.d.ts +12 -2
- package/dist/src/tokenizer/algebraic/algebraicReservedNames.d.ts +94 -7
- package/dist/src/tokenizer/algebraic/algebraicTokenizers.d.ts +1 -1
- package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +8 -7
- package/dist/src/tokenizer/polish/polishTokenizers.d.ts +1 -1
- package/dist/src/tokenizer/polish/polishTokens.d.ts +1 -1
- package/dist/src/tokenizer/utils.d.ts +1 -1
- package/dist/src/typeGuards/index.d.ts +1 -0
- package/dist/testFramework.esm.js +772 -1325
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +772 -1325
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
- package/dist/cli/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
- package/dist/cli/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateTimeOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/index.d.ts +0 -18
- package/dist/cli/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
- package/dist/cli/src/builtin/specialExpressions/if-let.d.ts +0 -7
- package/dist/cli/src/builtin/specialExpressions/when-first.d.ts +0 -7
- package/dist/cli/src/builtin/specialExpressions/when-let.d.ts +0 -7
- package/dist/cli/src/builtin/specialExpressions/when-not.d.ts +0 -6
- package/dist/src/analyze/calculateOutcomes/calculateAndOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateCommentOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateCondOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateDeclaredOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateDefOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateDefsOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateDoOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateFunctionOutcomes.d.ts +0 -5
- package/dist/src/analyze/calculateOutcomes/calculateIfLetOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateIfNotOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateIfOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateLetOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateLoopOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateLoopsOutcomes.d.ts +0 -4
- package/dist/src/analyze/calculateOutcomes/calculateOrOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateQqOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateRecurOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateThrowOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateTimeOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateTryOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateWhenFirstOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateWhenLetOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateWhenNotOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateWhenOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/index.d.ts +0 -18
- package/dist/src/analyze/calculateOutcomes/specialExpressionCalculators.d.ts +0 -55
- package/dist/src/builtin/specialExpressions/if-let.d.ts +0 -7
- package/dist/src/builtin/specialExpressions/time.d.ts +0 -6
- package/dist/src/builtin/specialExpressions/when-first.d.ts +0 -7
- package/dist/src/builtin/specialExpressions/when-let.d.ts +0 -7
- package/dist/src/builtin/specialExpressions/when-not.d.ts +0 -6
- package/dist/src/builtin/specialExpressions/when.d.ts +0 -6
package/dist/testFramework.js
CHANGED
|
@@ -238,6 +238,12 @@ function isFunctionType(type) {
|
|
|
238
238
|
return typeof type === 'number' && functionTypeName.has(type);
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
function getSourceCodeInfo(anyValue, sourceCodeInfo) {
|
|
242
|
+
var _a;
|
|
243
|
+
// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access
|
|
244
|
+
return (_a = anyValue === null || anyValue === void 0 ? void 0 : anyValue.sourceCodeInfo) !== null && _a !== void 0 ? _a : sourceCodeInfo;
|
|
245
|
+
}
|
|
246
|
+
|
|
241
247
|
function isTokenDebugData(tokenDebugData) {
|
|
242
248
|
return (typeof tokenDebugData === 'object'
|
|
243
249
|
&& tokenDebugData !== null
|
|
@@ -256,8 +262,12 @@ function addTokenDebugData(token, debugData) {
|
|
|
256
262
|
}
|
|
257
263
|
token.push(debugData);
|
|
258
264
|
}
|
|
259
|
-
function throwUnexpectedToken(expected, actual) {
|
|
260
|
-
|
|
265
|
+
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
266
|
+
if (actual === undefined) {
|
|
267
|
+
throw new LitsError("Unexpected end of input, expected ".concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), undefined);
|
|
268
|
+
}
|
|
269
|
+
var actualOutput = "".concat(actual[0]).concat(actual[1] ? " '".concat(actual[1], "'") : '');
|
|
270
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), getSourceCodeInfo(actual));
|
|
261
271
|
}
|
|
262
272
|
|
|
263
273
|
var commonSimpleTokenTypes = [
|
|
@@ -279,7 +289,7 @@ function isLParenToken(token) {
|
|
|
279
289
|
}
|
|
280
290
|
function assertLParenToken(token) {
|
|
281
291
|
if (!isLParenToken(token)) {
|
|
282
|
-
throwUnexpectedToken('LParen', token);
|
|
292
|
+
throwUnexpectedToken('LParen', undefined, token);
|
|
283
293
|
}
|
|
284
294
|
}
|
|
285
295
|
function asLParenToken(token) {
|
|
@@ -291,7 +301,7 @@ function isRParenToken(token) {
|
|
|
291
301
|
}
|
|
292
302
|
function assertRParenToken(token) {
|
|
293
303
|
if (!isRParenToken(token)) {
|
|
294
|
-
throwUnexpectedToken('RParen', token);
|
|
304
|
+
throwUnexpectedToken('RParen', undefined, token);
|
|
295
305
|
}
|
|
296
306
|
}
|
|
297
307
|
function isLBracketToken(token) {
|
|
@@ -299,7 +309,7 @@ function isLBracketToken(token) {
|
|
|
299
309
|
}
|
|
300
310
|
function assertLBracketToken(token) {
|
|
301
311
|
if (!isLBracketToken(token)) {
|
|
302
|
-
throwUnexpectedToken('LBracket', token);
|
|
312
|
+
throwUnexpectedToken('LBracket', undefined, token);
|
|
303
313
|
}
|
|
304
314
|
}
|
|
305
315
|
function asLBracketToken(token) {
|
|
@@ -311,7 +321,7 @@ function isRBracketToken(token) {
|
|
|
311
321
|
}
|
|
312
322
|
function assertRBracketToken(token) {
|
|
313
323
|
if (!isRBracketToken(token)) {
|
|
314
|
-
throwUnexpectedToken('RBracket', token);
|
|
324
|
+
throwUnexpectedToken('RBracket', undefined, token);
|
|
315
325
|
}
|
|
316
326
|
}
|
|
317
327
|
function isLBraceToken(token) {
|
|
@@ -319,7 +329,7 @@ function isLBraceToken(token) {
|
|
|
319
329
|
}
|
|
320
330
|
function assertLBraceToken(token) {
|
|
321
331
|
if (!isLBraceToken(token)) {
|
|
322
|
-
throwUnexpectedToken('LBrace', token);
|
|
332
|
+
throwUnexpectedToken('LBrace', undefined, token);
|
|
323
333
|
}
|
|
324
334
|
}
|
|
325
335
|
function asLBraceToken(token) {
|
|
@@ -331,7 +341,7 @@ function isRBraceToken(token) {
|
|
|
331
341
|
}
|
|
332
342
|
function assertRBraceToken(token) {
|
|
333
343
|
if (!isRBraceToken(token)) {
|
|
334
|
-
throwUnexpectedToken('RBrace', token);
|
|
344
|
+
throwUnexpectedToken('RBrace', undefined, token);
|
|
335
345
|
}
|
|
336
346
|
}
|
|
337
347
|
function isStringToken(token) {
|
|
@@ -339,7 +349,7 @@ function isStringToken(token) {
|
|
|
339
349
|
}
|
|
340
350
|
function assertStringToken(token) {
|
|
341
351
|
if (!isStringToken(token)) {
|
|
342
|
-
throwUnexpectedToken('String', token);
|
|
352
|
+
throwUnexpectedToken('String', undefined, token);
|
|
343
353
|
}
|
|
344
354
|
}
|
|
345
355
|
function asStringToken(token) {
|
|
@@ -357,7 +367,7 @@ function isEndNotationToken(token) {
|
|
|
357
367
|
}
|
|
358
368
|
function assertEndNotationToken(token) {
|
|
359
369
|
if (!isEndNotationToken(token)) {
|
|
360
|
-
throwUnexpectedToken('EndNotation', token);
|
|
370
|
+
throwUnexpectedToken('EndNotation', undefined, token);
|
|
361
371
|
}
|
|
362
372
|
}
|
|
363
373
|
|
|
@@ -415,24 +425,18 @@ var otherSymbolicOperators = [
|
|
|
415
425
|
var symbolicOperators = __spreadArray(__spreadArray(__spreadArray([], __read(symbolicUnaryOperators), false), __read(symbolicBinaryOperators), false), __read(otherSymbolicOperators), false);
|
|
416
426
|
var nonFunctionOperators = [
|
|
417
427
|
'??',
|
|
418
|
-
'
|
|
428
|
+
'&&',
|
|
419
429
|
'comment',
|
|
420
430
|
'cond',
|
|
421
|
-
'
|
|
431
|
+
'defined?',
|
|
422
432
|
'if',
|
|
423
|
-
'
|
|
424
|
-
'
|
|
425
|
-
'when',
|
|
426
|
-
'when-not',
|
|
433
|
+
'unless',
|
|
434
|
+
'||',
|
|
427
435
|
'do',
|
|
428
|
-
'time!',
|
|
429
436
|
'throw',
|
|
430
437
|
'let',
|
|
431
438
|
'def',
|
|
432
439
|
'defs',
|
|
433
|
-
'if-let',
|
|
434
|
-
'when-let',
|
|
435
|
-
'when-first',
|
|
436
440
|
'fn',
|
|
437
441
|
'defn',
|
|
438
442
|
'defns',
|
|
@@ -458,23 +462,40 @@ var symbolicOperatorSet = new Set(symbolicOperators);
|
|
|
458
462
|
function isSymbolicOperator(operator) {
|
|
459
463
|
return symbolicOperatorSet.has(operator);
|
|
460
464
|
}
|
|
461
|
-
function isA_SymbolToken(token) {
|
|
462
|
-
|
|
465
|
+
function isA_SymbolToken(token, symbolName) {
|
|
466
|
+
if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Symbol') {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
if (symbolName && token[1] !== symbolName) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
return true;
|
|
463
473
|
}
|
|
464
|
-
function assertA_SymbolToken(token) {
|
|
465
|
-
if (!isA_SymbolToken(token)) {
|
|
466
|
-
throwUnexpectedToken('A_Symbol', token);
|
|
474
|
+
function assertA_SymbolToken(token, symbolName) {
|
|
475
|
+
if (!isA_SymbolToken(token, symbolName)) {
|
|
476
|
+
throwUnexpectedToken('A_Symbol', undefined, token);
|
|
467
477
|
}
|
|
468
478
|
}
|
|
469
|
-
function asA_SymbolToken(token) {
|
|
470
|
-
assertA_SymbolToken(token);
|
|
479
|
+
function asA_SymbolToken(token, symbolName) {
|
|
480
|
+
assertA_SymbolToken(token, symbolName);
|
|
471
481
|
return token;
|
|
472
482
|
}
|
|
473
483
|
function isA_BinaryOperatorToken(token) {
|
|
474
484
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Operator' && isSymbolicBinaryOperator(token[1]);
|
|
475
485
|
}
|
|
476
|
-
function isA_ReservedSymbolToken(token) {
|
|
477
|
-
|
|
486
|
+
function isA_ReservedSymbolToken(token, symbolName) {
|
|
487
|
+
if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_ReservedSymbol') {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
if (symbolName && token[1] !== symbolName) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
function assertA_ReservedSymbolToken(token, symbolName) {
|
|
496
|
+
if (!isA_ReservedSymbolToken(token, symbolName)) {
|
|
497
|
+
throwUnexpectedToken('A_ReservedSymbol', symbolName, token);
|
|
498
|
+
}
|
|
478
499
|
}
|
|
479
500
|
function isA_CommentToken(token) {
|
|
480
501
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_SingleLineComment';
|
|
@@ -493,10 +514,9 @@ function isA_OperatorToken(token, operatorName) {
|
|
|
493
514
|
}
|
|
494
515
|
function assertA_OperatorToken(token, operatorName) {
|
|
495
516
|
if (!isA_OperatorToken(token, operatorName)) {
|
|
496
|
-
|
|
517
|
+
{
|
|
497
518
|
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), undefined);
|
|
498
519
|
}
|
|
499
|
-
throwUnexpectedToken('A_Operator', token);
|
|
500
520
|
}
|
|
501
521
|
}
|
|
502
522
|
function isA_WhitespaceToken(token) {
|
|
@@ -509,7 +529,7 @@ function isA_BasePrefixedNumberToken(token) {
|
|
|
509
529
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_BasePrefixedNumber';
|
|
510
530
|
}
|
|
511
531
|
|
|
512
|
-
var modifierNames = ['&', '&let', '&when', '&while'];
|
|
532
|
+
var modifierNames = ['&rest', '&let', '&when', '&while'];
|
|
513
533
|
var polishOnlySimpleTokenTypes = [
|
|
514
534
|
'P_FnShorthand',
|
|
515
535
|
];
|
|
@@ -532,7 +552,7 @@ function isP_StringShorthandToken(token) {
|
|
|
532
552
|
}
|
|
533
553
|
function assertP_StringShorthandToken(token) {
|
|
534
554
|
if (!isP_StringShorthandToken(token)) {
|
|
535
|
-
throwUnexpectedToken('P_StringShorthand', token);
|
|
555
|
+
throwUnexpectedToken('P_StringShorthand', undefined, token);
|
|
536
556
|
}
|
|
537
557
|
}
|
|
538
558
|
function asP_StringShorthandToken(token) {
|
|
@@ -544,7 +564,7 @@ function isP_SymbolToken(token) {
|
|
|
544
564
|
}
|
|
545
565
|
function assertP_SymbolToken(token) {
|
|
546
566
|
if (!isP_SymbolToken(token)) {
|
|
547
|
-
throwUnexpectedToken('P_Symbol', token);
|
|
567
|
+
throwUnexpectedToken('P_Symbol', undefined, token);
|
|
548
568
|
}
|
|
549
569
|
}
|
|
550
570
|
function asP_SymbolToken(token) {
|
|
@@ -562,7 +582,7 @@ function isP_RegexpShorthandToken(token) {
|
|
|
562
582
|
}
|
|
563
583
|
function assertP_RegexpShorthandToken(token) {
|
|
564
584
|
if (!isP_RegexpShorthandToken(token)) {
|
|
565
|
-
throwUnexpectedToken('P_RegexpShorthand', token);
|
|
585
|
+
throwUnexpectedToken('P_RegexpShorthand', undefined, token);
|
|
566
586
|
}
|
|
567
587
|
}
|
|
568
588
|
function asP_RegexpShorthandToken(token) {
|
|
@@ -577,7 +597,7 @@ function isP_CollectionAccessorToken(token) {
|
|
|
577
597
|
}
|
|
578
598
|
function assertP_CollectionAccessorToken(token) {
|
|
579
599
|
if (!isP_CollectionAccessorToken(token)) {
|
|
580
|
-
throwUnexpectedToken('P_CollectionAccessor', token);
|
|
600
|
+
throwUnexpectedToken('P_CollectionAccessor', undefined, token);
|
|
581
601
|
}
|
|
582
602
|
}
|
|
583
603
|
function asP_CollectionAccessorToken(token) {
|
|
@@ -589,7 +609,7 @@ function isP_CommentToken(token) {
|
|
|
589
609
|
}
|
|
590
610
|
function assertP_CommentToken(token) {
|
|
591
611
|
if (!isP_CommentToken(token)) {
|
|
592
|
-
throwUnexpectedToken('P_Comment', token);
|
|
612
|
+
throwUnexpectedToken('P_Comment', undefined, token);
|
|
593
613
|
}
|
|
594
614
|
}
|
|
595
615
|
function asP_CommentToken(token) {
|
|
@@ -604,7 +624,7 @@ function isP_NumberToken(token) {
|
|
|
604
624
|
}
|
|
605
625
|
function assertP_NumberToken(token) {
|
|
606
626
|
if (!isP_NumberToken(token)) {
|
|
607
|
-
throwUnexpectedToken('P_Number', token);
|
|
627
|
+
throwUnexpectedToken('P_Number', undefined, token);
|
|
608
628
|
}
|
|
609
629
|
}
|
|
610
630
|
|
|
@@ -672,12 +692,6 @@ function valueToString(value) {
|
|
|
672
692
|
return JSON.stringify(value);
|
|
673
693
|
}
|
|
674
694
|
|
|
675
|
-
function getSourceCodeInfo(anyValue, sourceCodeInfo) {
|
|
676
|
-
var _a;
|
|
677
|
-
// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access
|
|
678
|
-
return (_a = anyValue === null || anyValue === void 0 ? void 0 : anyValue.sourceCodeInfo) !== null && _a !== void 0 ? _a : sourceCodeInfo;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
695
|
function getRangeString(options) {
|
|
682
696
|
var hasUpperAndLowerBound = (typeof options.gt === 'number' || typeof options.gte === 'number')
|
|
683
697
|
&& (typeof options.lt === 'number' || typeof options.lte === 'number');
|
|
@@ -810,7 +824,7 @@ function isExpressionNode(value) {
|
|
|
810
824
|
}
|
|
811
825
|
|
|
812
826
|
var specialExpressionCommentRemovers = {
|
|
813
|
-
'
|
|
827
|
+
'&&': function (node, removeOptions) {
|
|
814
828
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
815
829
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
816
830
|
},
|
|
@@ -822,7 +836,11 @@ var specialExpressionCommentRemovers = {
|
|
|
822
836
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
823
837
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
824
838
|
},
|
|
825
|
-
'
|
|
839
|
+
'switch': function (node, removeOptions) {
|
|
840
|
+
removeOptions.removeCommenNodesFromArray(node.p);
|
|
841
|
+
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
842
|
+
},
|
|
843
|
+
'defined?': function (node, removeOptions) {
|
|
826
844
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
827
845
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
828
846
|
},
|
|
@@ -843,12 +861,11 @@ var specialExpressionCommentRemovers = {
|
|
|
843
861
|
'doseq': function (_node, _removeOptions) { },
|
|
844
862
|
'fn': function (_node, _removeOptions) { },
|
|
845
863
|
'for': function (_node, _removeOptions) { },
|
|
846
|
-
'if-let': function (_node, _removeOptions) { },
|
|
847
864
|
'if': function (node, removeOptions) {
|
|
848
865
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
849
866
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
850
867
|
},
|
|
851
|
-
'
|
|
868
|
+
'unless': function (node, removeOptions) {
|
|
852
869
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
853
870
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
854
871
|
},
|
|
@@ -860,7 +877,7 @@ var specialExpressionCommentRemovers = {
|
|
|
860
877
|
});
|
|
861
878
|
},
|
|
862
879
|
'loop': function (_node, _removeOptions) { },
|
|
863
|
-
'
|
|
880
|
+
'||': function (node, removeOptions) {
|
|
864
881
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
865
882
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
866
883
|
},
|
|
@@ -872,19 +889,11 @@ var specialExpressionCommentRemovers = {
|
|
|
872
889
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
873
890
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
874
891
|
},
|
|
875
|
-
'time!': function (node, removeOptions) {
|
|
876
|
-
removeOptions.removeCommenNodesFromArray(node.p);
|
|
877
|
-
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
878
|
-
},
|
|
879
892
|
'throw': function (node, removeOptions) {
|
|
880
893
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
881
894
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
882
895
|
},
|
|
883
896
|
'try': function (_node, _removeOptions) { },
|
|
884
|
-
'when-first': function (_node, _removeOptions) { },
|
|
885
|
-
'when-let': function (_node, _removeOptions) { },
|
|
886
|
-
'when': function (_node, _removeOptions) { },
|
|
887
|
-
'when-not': function (_node, _removeOptions) { },
|
|
888
897
|
};
|
|
889
898
|
function removeCommentNodesFromSpecialExpression(node, removeOptions) {
|
|
890
899
|
var uncommenter = specialExpressionCommentRemovers[node.n];
|
|
@@ -926,6 +935,13 @@ function assertEvenNumberOfParams(node) {
|
|
|
926
935
|
throw new LitsError("Wrong number of arguments, expected an even number, got ".concat(valueToString(length), "."), (_a = getTokenDebugData(node.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
927
936
|
}
|
|
928
937
|
}
|
|
938
|
+
function assertOddNumberOfParams(node) {
|
|
939
|
+
var _a;
|
|
940
|
+
var length = withoutCommentNodes(node.p).length;
|
|
941
|
+
if (length % 2 !== 1) {
|
|
942
|
+
throw new LitsError("Wrong number of arguments, expected an odd number, got ".concat(valueToString(length), "."), (_a = getTokenDebugData(node.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
929
945
|
function assertNumberOfParams(count, node) {
|
|
930
946
|
var _a, _b;
|
|
931
947
|
assertCount({
|
|
@@ -970,7 +986,7 @@ function assertCount(_a) {
|
|
|
970
986
|
}
|
|
971
987
|
|
|
972
988
|
var bitwiseNormalExpression = {
|
|
973
|
-
'
|
|
989
|
+
'<<': {
|
|
974
990
|
evaluate: function (_a, sourceCodeInfo) {
|
|
975
991
|
var _b = __read(_a, 2), num = _b[0], count = _b[1];
|
|
976
992
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -979,7 +995,7 @@ var bitwiseNormalExpression = {
|
|
|
979
995
|
},
|
|
980
996
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
981
997
|
},
|
|
982
|
-
'
|
|
998
|
+
'>>': {
|
|
983
999
|
evaluate: function (_a, sourceCodeInfo) {
|
|
984
1000
|
var _b = __read(_a, 2), num = _b[0], count = _b[1];
|
|
985
1001
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -988,7 +1004,7 @@ var bitwiseNormalExpression = {
|
|
|
988
1004
|
},
|
|
989
1005
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
990
1006
|
},
|
|
991
|
-
'
|
|
1007
|
+
'>>>': {
|
|
992
1008
|
evaluate: function (_a, sourceCodeInfo) {
|
|
993
1009
|
var _b = __read(_a, 2), num = _b[0], count = _b[1];
|
|
994
1010
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -997,7 +1013,7 @@ var bitwiseNormalExpression = {
|
|
|
997
1013
|
},
|
|
998
1014
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
999
1015
|
},
|
|
1000
|
-
'
|
|
1016
|
+
'~': {
|
|
1001
1017
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1002
1018
|
var _b = __read(_a, 1), num = _b[0];
|
|
1003
1019
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -1005,7 +1021,7 @@ var bitwiseNormalExpression = {
|
|
|
1005
1021
|
},
|
|
1006
1022
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
1007
1023
|
},
|
|
1008
|
-
'
|
|
1024
|
+
'&': {
|
|
1009
1025
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1010
1026
|
var _b = __read(_a), first = _b[0], rest = _b.slice(1);
|
|
1011
1027
|
assertNumber(first, sourceCodeInfo, { integer: true });
|
|
@@ -1016,7 +1032,7 @@ var bitwiseNormalExpression = {
|
|
|
1016
1032
|
},
|
|
1017
1033
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
1018
1034
|
},
|
|
1019
|
-
'
|
|
1035
|
+
'&!': {
|
|
1020
1036
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1021
1037
|
var _b = __read(_a), first = _b[0], rest = _b.slice(1);
|
|
1022
1038
|
assertNumber(first, sourceCodeInfo, { integer: true });
|
|
@@ -1027,7 +1043,7 @@ var bitwiseNormalExpression = {
|
|
|
1027
1043
|
},
|
|
1028
1044
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
1029
1045
|
},
|
|
1030
|
-
'
|
|
1046
|
+
'|': {
|
|
1031
1047
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1032
1048
|
var _b = __read(_a), first = _b[0], rest = _b.slice(1);
|
|
1033
1049
|
assertNumber(first, sourceCodeInfo, { integer: true });
|
|
@@ -1038,7 +1054,7 @@ var bitwiseNormalExpression = {
|
|
|
1038
1054
|
},
|
|
1039
1055
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
1040
1056
|
},
|
|
1041
|
-
'
|
|
1057
|
+
'^': {
|
|
1042
1058
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1043
1059
|
var _b = __read(_a), first = _b[0], rest = _b.slice(1);
|
|
1044
1060
|
assertNumber(first, sourceCodeInfo, { integer: true });
|
|
@@ -1049,7 +1065,7 @@ var bitwiseNormalExpression = {
|
|
|
1049
1065
|
},
|
|
1050
1066
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
1051
1067
|
},
|
|
1052
|
-
'
|
|
1068
|
+
'bit_flip': {
|
|
1053
1069
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1054
1070
|
var _b = __read(_a, 2), num = _b[0], index = _b[1];
|
|
1055
1071
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -1059,7 +1075,7 @@ var bitwiseNormalExpression = {
|
|
|
1059
1075
|
},
|
|
1060
1076
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1061
1077
|
},
|
|
1062
|
-
'
|
|
1078
|
+
'bit_set': {
|
|
1063
1079
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1064
1080
|
var _b = __read(_a, 2), num = _b[0], index = _b[1];
|
|
1065
1081
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -1069,7 +1085,7 @@ var bitwiseNormalExpression = {
|
|
|
1069
1085
|
},
|
|
1070
1086
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1071
1087
|
},
|
|
1072
|
-
'
|
|
1088
|
+
'bit_clear': {
|
|
1073
1089
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1074
1090
|
var _b = __read(_a, 2), num = _b[0], index = _b[1];
|
|
1075
1091
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -1079,7 +1095,7 @@ var bitwiseNormalExpression = {
|
|
|
1079
1095
|
},
|
|
1080
1096
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1081
1097
|
},
|
|
1082
|
-
'
|
|
1098
|
+
'bit_test': {
|
|
1083
1099
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1084
1100
|
var _b = __read(_a, 2), num = _b[0], index = _b[1];
|
|
1085
1101
|
assertNumber(num, sourceCodeInfo, { integer: true });
|
|
@@ -2780,7 +2796,7 @@ var mathNormalExpression = {
|
|
|
2780
2796
|
},
|
|
2781
2797
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2782
2798
|
},
|
|
2783
|
-
'
|
|
2799
|
+
'%': {
|
|
2784
2800
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2785
2801
|
var _b = __read(_a, 2), dividend = _b[0], divisor = _b[1];
|
|
2786
2802
|
assertNumber(dividend, sourceCodeInfo);
|
|
@@ -2806,7 +2822,7 @@ var mathNormalExpression = {
|
|
|
2806
2822
|
},
|
|
2807
2823
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2808
2824
|
},
|
|
2809
|
-
'
|
|
2825
|
+
'**': {
|
|
2810
2826
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2811
2827
|
var _b = __read(_a, 2), first = _b[0], second = _b[1];
|
|
2812
2828
|
assertNumber(first, sourceCodeInfo);
|
|
@@ -3083,10 +3099,6 @@ var mathNormalExpression = {
|
|
|
3083
3099
|
},
|
|
3084
3100
|
};
|
|
3085
3101
|
|
|
3086
|
-
var version = "2.0.14";
|
|
3087
|
-
|
|
3088
|
-
var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
3089
|
-
var xyRegexp = /[xy]/g;
|
|
3090
3102
|
var miscNormalExpression = {
|
|
3091
3103
|
'!=': {
|
|
3092
3104
|
evaluate: function (params) {
|
|
@@ -3100,7 +3112,7 @@ var miscNormalExpression = {
|
|
|
3100
3112
|
},
|
|
3101
3113
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
3102
3114
|
},
|
|
3103
|
-
'
|
|
3115
|
+
'==': {
|
|
3104
3116
|
evaluate: function (_a) {
|
|
3105
3117
|
var e_1, _b;
|
|
3106
3118
|
var _c = __read(_a), first = _c[0], rest = _c.slice(1);
|
|
@@ -3225,20 +3237,14 @@ var miscNormalExpression = {
|
|
|
3225
3237
|
},
|
|
3226
3238
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
3227
3239
|
},
|
|
3228
|
-
'
|
|
3240
|
+
'!': {
|
|
3229
3241
|
evaluate: function (_a) {
|
|
3230
3242
|
var _b = __read(_a, 1), first = _b[0];
|
|
3231
3243
|
return !first;
|
|
3232
3244
|
},
|
|
3233
3245
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3234
3246
|
},
|
|
3235
|
-
'
|
|
3236
|
-
evaluate: function () {
|
|
3237
|
-
return Date.now();
|
|
3238
|
-
},
|
|
3239
|
-
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
3240
|
-
},
|
|
3241
|
-
'inst-ms->iso-date-time': {
|
|
3247
|
+
'epoch>iso_date': {
|
|
3242
3248
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3243
3249
|
var _b = __read(_a, 1), ms = _b[0];
|
|
3244
3250
|
assertNumber(ms, sourceCodeInfo);
|
|
@@ -3246,7 +3252,7 @@ var miscNormalExpression = {
|
|
|
3246
3252
|
},
|
|
3247
3253
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3248
3254
|
},
|
|
3249
|
-
'
|
|
3255
|
+
'iso_date>epoch': {
|
|
3250
3256
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3251
3257
|
var _b = __read(_a, 1), dateTime = _b[0];
|
|
3252
3258
|
assertString(dateTime, sourceCodeInfo);
|
|
@@ -3279,23 +3285,7 @@ var miscNormalExpression = {
|
|
|
3279
3285
|
},
|
|
3280
3286
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
3281
3287
|
},
|
|
3282
|
-
'
|
|
3283
|
-
evaluate: function () {
|
|
3284
|
-
return uuidTemplate.replace(xyRegexp, function (character) {
|
|
3285
|
-
var randomNbr = Math.floor(Math.random() * 16);
|
|
3286
|
-
var newValue = character === 'x' ? randomNbr : (randomNbr & 0x3) | 0x8;
|
|
3287
|
-
return newValue.toString(16);
|
|
3288
|
-
});
|
|
3289
|
-
},
|
|
3290
|
-
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
3291
|
-
},
|
|
3292
|
-
'lits-version!': {
|
|
3293
|
-
evaluate: function () {
|
|
3294
|
-
return version;
|
|
3295
|
-
},
|
|
3296
|
-
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
3297
|
-
},
|
|
3298
|
-
'json-parse': {
|
|
3288
|
+
'json_parse': {
|
|
3299
3289
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3300
3290
|
var _b = __read(_a, 1), first = _b[0];
|
|
3301
3291
|
assertString(first, sourceCodeInfo);
|
|
@@ -3304,7 +3294,7 @@ var miscNormalExpression = {
|
|
|
3304
3294
|
},
|
|
3305
3295
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3306
3296
|
},
|
|
3307
|
-
'
|
|
3297
|
+
'json_stringify': {
|
|
3308
3298
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3309
3299
|
var _b = __read(_a, 2), first = _b[0], second = _b[1];
|
|
3310
3300
|
assertAny(first, sourceCodeInfo);
|
|
@@ -3517,7 +3507,7 @@ var assertNormalExpression = {
|
|
|
3517
3507
|
};
|
|
3518
3508
|
|
|
3519
3509
|
var objectNormalExpression = {
|
|
3520
|
-
|
|
3510
|
+
object: {
|
|
3521
3511
|
evaluate: function (params, sourceCodeInfo) {
|
|
3522
3512
|
var result = {};
|
|
3523
3513
|
for (var i = 0; i < params.length; i += 2) {
|
|
@@ -3530,7 +3520,7 @@ var objectNormalExpression = {
|
|
|
3530
3520
|
},
|
|
3531
3521
|
validate: function (node) { return assertEvenNumberOfParams(node); },
|
|
3532
3522
|
},
|
|
3533
|
-
|
|
3523
|
+
keys: {
|
|
3534
3524
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3535
3525
|
var _b = __read(_a, 1), obj = _b[0];
|
|
3536
3526
|
assertObj(obj, sourceCodeInfo);
|
|
@@ -3538,7 +3528,7 @@ var objectNormalExpression = {
|
|
|
3538
3528
|
},
|
|
3539
3529
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3540
3530
|
},
|
|
3541
|
-
|
|
3531
|
+
vals: {
|
|
3542
3532
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3543
3533
|
var _b = __read(_a, 1), obj = _b[0];
|
|
3544
3534
|
assertObj(obj, sourceCodeInfo);
|
|
@@ -3546,7 +3536,7 @@ var objectNormalExpression = {
|
|
|
3546
3536
|
},
|
|
3547
3537
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3548
3538
|
},
|
|
3549
|
-
|
|
3539
|
+
entries: {
|
|
3550
3540
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3551
3541
|
var _b = __read(_a, 1), obj = _b[0];
|
|
3552
3542
|
assertObj(obj, sourceCodeInfo);
|
|
@@ -3554,7 +3544,7 @@ var objectNormalExpression = {
|
|
|
3554
3544
|
},
|
|
3555
3545
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3556
3546
|
},
|
|
3557
|
-
|
|
3547
|
+
find: {
|
|
3558
3548
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3559
3549
|
var _b = __read(_a, 2), obj = _b[0], key = _b[1];
|
|
3560
3550
|
assertObj(obj, sourceCodeInfo);
|
|
@@ -3565,7 +3555,7 @@ var objectNormalExpression = {
|
|
|
3565
3555
|
},
|
|
3566
3556
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
3567
3557
|
},
|
|
3568
|
-
|
|
3558
|
+
dissoc: {
|
|
3569
3559
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3570
3560
|
var _b = __read(_a, 2), obj = _b[0], key = _b[1];
|
|
3571
3561
|
assertObj(obj, sourceCodeInfo);
|
|
@@ -3576,7 +3566,7 @@ var objectNormalExpression = {
|
|
|
3576
3566
|
},
|
|
3577
3567
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
3578
3568
|
},
|
|
3579
|
-
|
|
3569
|
+
merge: {
|
|
3580
3570
|
evaluate: function (params, sourceCodeInfo) {
|
|
3581
3571
|
if (params.length === 0)
|
|
3582
3572
|
return null;
|
|
@@ -3589,7 +3579,7 @@ var objectNormalExpression = {
|
|
|
3589
3579
|
},
|
|
3590
3580
|
validate: function (node) { return assertNumberOfParams({ min: 0 }, node); },
|
|
3591
3581
|
},
|
|
3592
|
-
|
|
3582
|
+
merge_with: {
|
|
3593
3583
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
3594
3584
|
var executeFunction = _a.executeFunction;
|
|
3595
3585
|
var first = params[0];
|
|
@@ -3612,7 +3602,7 @@ var objectNormalExpression = {
|
|
|
3612
3602
|
},
|
|
3613
3603
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
3614
3604
|
},
|
|
3615
|
-
|
|
3605
|
+
zipmap: {
|
|
3616
3606
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3617
3607
|
var _b = __read(_a, 2), keys = _b[0], values = _b[1];
|
|
3618
3608
|
assertStringArray(keys, sourceCodeInfo);
|
|
@@ -3627,7 +3617,7 @@ var objectNormalExpression = {
|
|
|
3627
3617
|
},
|
|
3628
3618
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
3629
3619
|
},
|
|
3630
|
-
|
|
3620
|
+
select_keys: {
|
|
3631
3621
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3632
3622
|
var _b = __read(_a, 2), obj = _b[0], keys = _b[1];
|
|
3633
3623
|
assertStringArray(keys, sourceCodeInfo);
|
|
@@ -3893,7 +3883,7 @@ var stringNormalExpression = {
|
|
|
3893
3883
|
},
|
|
3894
3884
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3895
3885
|
},
|
|
3896
|
-
'
|
|
3886
|
+
'string_repeat': {
|
|
3897
3887
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3898
3888
|
var _b = __read(_a, 2), str = _b[0], count = _b[1];
|
|
3899
3889
|
assertString(str, sourceCodeInfo);
|
|
@@ -3927,27 +3917,7 @@ var stringNormalExpression = {
|
|
|
3927
3917
|
},
|
|
3928
3918
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3929
3919
|
},
|
|
3930
|
-
'
|
|
3931
|
-
evaluate: function (params, sourceCodeInfo) {
|
|
3932
|
-
var _a = __read(params, 2), num = _a[0], base = _a[1];
|
|
3933
|
-
assertNumber(num, sourceCodeInfo, { finite: true });
|
|
3934
|
-
if (params.length === 1) {
|
|
3935
|
-
return "".concat(num);
|
|
3936
|
-
}
|
|
3937
|
-
else {
|
|
3938
|
-
assertNumber(base, sourceCodeInfo, { finite: true });
|
|
3939
|
-
if (base !== 2 && base !== 8 && base !== 10 && base !== 16) {
|
|
3940
|
-
throw new LitsError("Expected \"number-to-string\" base argument to be 2, 8, 10 or 16, got: ".concat(base), sourceCodeInfo);
|
|
3941
|
-
}
|
|
3942
|
-
if (base === 10)
|
|
3943
|
-
return "".concat(num);
|
|
3944
|
-
assertNumber(num, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
3945
|
-
return Number(num).toString(base);
|
|
3946
|
-
}
|
|
3947
|
-
},
|
|
3948
|
-
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3949
|
-
},
|
|
3950
|
-
'from-char-code': {
|
|
3920
|
+
'from_char_code': {
|
|
3951
3921
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3952
3922
|
var _b = __read(_a, 1), num = _b[0];
|
|
3953
3923
|
assertNumber(num, sourceCodeInfo, { finite: true });
|
|
@@ -3961,7 +3931,7 @@ var stringNormalExpression = {
|
|
|
3961
3931
|
},
|
|
3962
3932
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3963
3933
|
},
|
|
3964
|
-
'
|
|
3934
|
+
'to_char_code': {
|
|
3965
3935
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3966
3936
|
var _b = __read(_a, 1), str = _b[0];
|
|
3967
3937
|
assertString(str, sourceCodeInfo, { nonEmpty: true });
|
|
@@ -3969,7 +3939,7 @@ var stringNormalExpression = {
|
|
|
3969
3939
|
},
|
|
3970
3940
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3971
3941
|
},
|
|
3972
|
-
'
|
|
3942
|
+
'lower_case': {
|
|
3973
3943
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3974
3944
|
var _b = __read(_a, 1), str = _b[0];
|
|
3975
3945
|
assertString(str, sourceCodeInfo);
|
|
@@ -3977,7 +3947,7 @@ var stringNormalExpression = {
|
|
|
3977
3947
|
},
|
|
3978
3948
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3979
3949
|
},
|
|
3980
|
-
'
|
|
3950
|
+
'upper_case': {
|
|
3981
3951
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3982
3952
|
var _b = __read(_a, 1), str = _b[0];
|
|
3983
3953
|
assertString(str, sourceCodeInfo);
|
|
@@ -3993,7 +3963,7 @@ var stringNormalExpression = {
|
|
|
3993
3963
|
},
|
|
3994
3964
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3995
3965
|
},
|
|
3996
|
-
'
|
|
3966
|
+
'trim_left': {
|
|
3997
3967
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3998
3968
|
var _b = __read(_a, 1), str = _b[0];
|
|
3999
3969
|
assertString(str, sourceCodeInfo);
|
|
@@ -4001,7 +3971,7 @@ var stringNormalExpression = {
|
|
|
4001
3971
|
},
|
|
4002
3972
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4003
3973
|
},
|
|
4004
|
-
'
|
|
3974
|
+
'trim_right': {
|
|
4005
3975
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4006
3976
|
var _b = __read(_a, 1), str = _b[0];
|
|
4007
3977
|
assertString(str, sourceCodeInfo);
|
|
@@ -4009,6 +3979,30 @@ var stringNormalExpression = {
|
|
|
4009
3979
|
},
|
|
4010
3980
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4011
3981
|
},
|
|
3982
|
+
'++': {
|
|
3983
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
3984
|
+
if (params.length === 0) {
|
|
3985
|
+
return '';
|
|
3986
|
+
}
|
|
3987
|
+
var first = params[0];
|
|
3988
|
+
if (first !== null) {
|
|
3989
|
+
assertStringOrNumber(first, sourceCodeInfo);
|
|
3990
|
+
}
|
|
3991
|
+
if (params.length === 1) {
|
|
3992
|
+
return first === null ? '' : "".concat(first);
|
|
3993
|
+
}
|
|
3994
|
+
return params.slice(1).reduce(function (acc, str) {
|
|
3995
|
+
if (str !== null) {
|
|
3996
|
+
assertStringOrNumber(str, sourceCodeInfo);
|
|
3997
|
+
}
|
|
3998
|
+
if (str === null) {
|
|
3999
|
+
return acc;
|
|
4000
|
+
}
|
|
4001
|
+
return "".concat(acc).concat(str);
|
|
4002
|
+
}, first === null ? '' : "".concat(first));
|
|
4003
|
+
},
|
|
4004
|
+
validate: function () { return undefined; },
|
|
4005
|
+
},
|
|
4012
4006
|
'join': {
|
|
4013
4007
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4014
4008
|
var _b = __read(_a, 2), stringList = _b[0], delimiter = _b[1];
|
|
@@ -4033,7 +4027,7 @@ var stringNormalExpression = {
|
|
|
4033
4027
|
},
|
|
4034
4028
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
4035
4029
|
},
|
|
4036
|
-
'
|
|
4030
|
+
'pad_left': {
|
|
4037
4031
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4038
4032
|
var _b = __read(_a, 3), str = _b[0], length = _b[1], padString = _b[2];
|
|
4039
4033
|
assertString(str, sourceCodeInfo);
|
|
@@ -4044,7 +4038,7 @@ var stringNormalExpression = {
|
|
|
4044
4038
|
},
|
|
4045
4039
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
4046
4040
|
},
|
|
4047
|
-
'
|
|
4041
|
+
'pad_right': {
|
|
4048
4042
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4049
4043
|
var _b = __read(_a, 3), str = _b[0], length = _b[1], padString = _b[2];
|
|
4050
4044
|
assertString(str, sourceCodeInfo);
|
|
@@ -4086,7 +4080,7 @@ var stringNormalExpression = {
|
|
|
4086
4080
|
},
|
|
4087
4081
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 10 }, node); },
|
|
4088
4082
|
},
|
|
4089
|
-
'
|
|
4083
|
+
'encode_base64': {
|
|
4090
4084
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4091
4085
|
var _b = __read(_a, 1), value = _b[0];
|
|
4092
4086
|
assertString(value, sourceCodeInfo);
|
|
@@ -4097,7 +4091,7 @@ var stringNormalExpression = {
|
|
|
4097
4091
|
},
|
|
4098
4092
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4099
4093
|
},
|
|
4100
|
-
'
|
|
4094
|
+
'decode_base64': {
|
|
4101
4095
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4102
4096
|
var _b = __read(_a, 1), value = _b[0];
|
|
4103
4097
|
assertString(value, sourceCodeInfo);
|
|
@@ -4115,7 +4109,7 @@ var stringNormalExpression = {
|
|
|
4115
4109
|
},
|
|
4116
4110
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4117
4111
|
},
|
|
4118
|
-
'
|
|
4112
|
+
'encode_uri_component': {
|
|
4119
4113
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4120
4114
|
var _b = __read(_a, 1), value = _b[0];
|
|
4121
4115
|
assertString(value, sourceCodeInfo);
|
|
@@ -4123,7 +4117,7 @@ var stringNormalExpression = {
|
|
|
4123
4117
|
},
|
|
4124
4118
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4125
4119
|
},
|
|
4126
|
-
'
|
|
4120
|
+
'decode_uri_component': {
|
|
4127
4121
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4128
4122
|
var _b = __read(_a, 1), value = _b[0];
|
|
4129
4123
|
assertString(value, sourceCodeInfo);
|
|
@@ -4292,7 +4286,7 @@ var andSpecialExpression = {
|
|
|
4292
4286
|
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4293
4287
|
var node = {
|
|
4294
4288
|
t: AstNodeType.SpecialExpression,
|
|
4295
|
-
n: '
|
|
4289
|
+
n: '&&',
|
|
4296
4290
|
p: params,
|
|
4297
4291
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
4298
4292
|
};
|
|
@@ -4377,8 +4371,39 @@ var condSpecialExpression = {
|
|
|
4377
4371
|
},
|
|
4378
4372
|
};
|
|
4379
4373
|
|
|
4374
|
+
var switchSpecialExpression = {
|
|
4375
|
+
polishParse: getCommonPolishSpecialExpressionParser('switch'),
|
|
4376
|
+
validateParameterCount: function (node) { return assertOddNumberOfParams(node); },
|
|
4377
|
+
evaluate: function (node, contextStack, _a) {
|
|
4378
|
+
var e_1, _b;
|
|
4379
|
+
var evaluateAstNode = _a.evaluateAstNode;
|
|
4380
|
+
var switchValue = evaluateAstNode(node.p[0], contextStack);
|
|
4381
|
+
try {
|
|
4382
|
+
for (var _c = __values(arrayToPairs(node.p.slice(1))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4383
|
+
var _e = __read(_d.value, 2), test = _e[0], form = _e[1];
|
|
4384
|
+
var value = evaluateAstNode(test, contextStack);
|
|
4385
|
+
if (value === switchValue) {
|
|
4386
|
+
return evaluateAstNode(form, contextStack);
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4391
|
+
finally {
|
|
4392
|
+
try {
|
|
4393
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
4394
|
+
}
|
|
4395
|
+
finally { if (e_1) throw e_1.error; }
|
|
4396
|
+
}
|
|
4397
|
+
return null;
|
|
4398
|
+
},
|
|
4399
|
+
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4400
|
+
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4401
|
+
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
4402
|
+
},
|
|
4403
|
+
};
|
|
4404
|
+
|
|
4380
4405
|
var declaredSpecialExpression = {
|
|
4381
|
-
polishParse: getCommonPolishSpecialExpressionParser('
|
|
4406
|
+
polishParse: getCommonPolishSpecialExpressionParser('defined?'),
|
|
4382
4407
|
validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
|
|
4383
4408
|
evaluate: function (node, contextStack) {
|
|
4384
4409
|
var lookUpResult = contextStack.lookUp(node.p[0]);
|
|
@@ -4433,9 +4458,7 @@ var defSpecialExpression = {
|
|
|
4433
4458
|
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4434
4459
|
var name = node.p[0].v;
|
|
4435
4460
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4436
|
-
contextStack.
|
|
4437
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4438
|
-
};
|
|
4461
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4439
4462
|
return null;
|
|
4440
4463
|
},
|
|
4441
4464
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4446,7 +4469,7 @@ var defSpecialExpression = {
|
|
|
4446
4469
|
var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
|
|
4447
4470
|
var name = asSymbolNode(node.p[0]).v;
|
|
4448
4471
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4449
|
-
contextStack.
|
|
4472
|
+
contextStack.exportValue(name, true);
|
|
4450
4473
|
return result;
|
|
4451
4474
|
},
|
|
4452
4475
|
};
|
|
@@ -4472,9 +4495,7 @@ var defsSpecialExpression = {
|
|
|
4472
4495
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4473
4496
|
assertString(name, sourceCodeInfo);
|
|
4474
4497
|
assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
4475
|
-
contextStack.
|
|
4476
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4477
|
-
};
|
|
4498
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4478
4499
|
return null;
|
|
4479
4500
|
},
|
|
4480
4501
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4486,7 +4507,7 @@ var defsSpecialExpression = {
|
|
|
4486
4507
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4487
4508
|
assertString(name, sourceCodeInfo);
|
|
4488
4509
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4489
|
-
contextStack.
|
|
4510
|
+
contextStack.exportValue(name, true);
|
|
4490
4511
|
return result;
|
|
4491
4512
|
},
|
|
4492
4513
|
};
|
|
@@ -4517,7 +4538,7 @@ var doSpecialExpression = {
|
|
|
4517
4538
|
},
|
|
4518
4539
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4519
4540
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4520
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
4541
|
+
return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
|
|
4521
4542
|
},
|
|
4522
4543
|
};
|
|
4523
4544
|
|
|
@@ -4546,11 +4567,6 @@ function joinAnalyzeResults() {
|
|
|
4546
4567
|
function addAnalyzeResults(target, source) {
|
|
4547
4568
|
source.forEach(function (symbol) { return target.add(symbol); });
|
|
4548
4569
|
}
|
|
4549
|
-
function combinate(arrays) {
|
|
4550
|
-
return arrays.reduce(function (acc, curr) {
|
|
4551
|
-
return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
|
|
4552
|
-
}, [[]]);
|
|
4553
|
-
}
|
|
4554
4570
|
|
|
4555
4571
|
var defnSpecialExpression = {
|
|
4556
4572
|
polishParse: function (tokenStream, parseState, firstToken, parsers) {
|
|
@@ -4585,13 +4601,13 @@ var defnSpecialExpression = {
|
|
|
4585
4601
|
_b.n = name,
|
|
4586
4602
|
_b.o = evaluatedFunctionOverloades,
|
|
4587
4603
|
_b);
|
|
4588
|
-
contextStack.
|
|
4604
|
+
contextStack.exportValue(name, litsFunction);
|
|
4589
4605
|
return null;
|
|
4590
4606
|
},
|
|
4591
4607
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4592
4608
|
var _b;
|
|
4593
4609
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4594
|
-
contextStack.
|
|
4610
|
+
contextStack.exportValue(node.f.v, true);
|
|
4595
4611
|
var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
|
|
4596
4612
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4597
4613
|
},
|
|
@@ -4627,7 +4643,7 @@ var defnsSpecialExpression = {
|
|
|
4627
4643
|
_b.n = name,
|
|
4628
4644
|
_b.o = evaluatedFunctionOverloades,
|
|
4629
4645
|
_b);
|
|
4630
|
-
contextStack.
|
|
4646
|
+
contextStack.exportValue(name, litsFunction);
|
|
4631
4647
|
return null;
|
|
4632
4648
|
},
|
|
4633
4649
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4638,7 +4654,7 @@ var defnsSpecialExpression = {
|
|
|
4638
4654
|
var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
|
|
4639
4655
|
assertString(name, sourceCodeInfo);
|
|
4640
4656
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4641
|
-
contextStack.
|
|
4657
|
+
contextStack.exportValue(name, true);
|
|
4642
4658
|
var newContext = (_b = {}, _b[name] = { value: true }, _b);
|
|
4643
4659
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4644
4660
|
},
|
|
@@ -4848,7 +4864,7 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
|
|
|
4848
4864
|
tkn = asToken(tokenStream.tokens[parseState.position]);
|
|
4849
4865
|
if (node.t === AstNodeType.Modifier) {
|
|
4850
4866
|
switch (node.v) {
|
|
4851
|
-
case '&':
|
|
4867
|
+
case '&rest':
|
|
4852
4868
|
if (state === 'rest')
|
|
4853
4869
|
throw new LitsError('& can only appear once', (_a = getTokenDebugData(tkn)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
4854
4870
|
state = 'rest';
|
|
@@ -4911,56 +4927,8 @@ var ifSpecialExpression = {
|
|
|
4911
4927
|
},
|
|
4912
4928
|
};
|
|
4913
4929
|
|
|
4914
|
-
var
|
|
4915
|
-
polishParse:
|
|
4916
|
-
var _b, _c;
|
|
4917
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
4918
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
4919
|
-
if (bindings.length !== 1) {
|
|
4920
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
4921
|
-
}
|
|
4922
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
4923
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4924
|
-
var node = {
|
|
4925
|
-
t: AstNodeType.SpecialExpression,
|
|
4926
|
-
n: 'if-let',
|
|
4927
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
4928
|
-
p: params,
|
|
4929
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
4930
|
-
};
|
|
4931
|
-
return node;
|
|
4932
|
-
},
|
|
4933
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
4934
|
-
evaluate: function (node, contextStack, _a) {
|
|
4935
|
-
var _b;
|
|
4936
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
4937
|
-
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4938
|
-
var locals = {};
|
|
4939
|
-
var bindingValue = evaluateAstNode(node.b.v, contextStack);
|
|
4940
|
-
if (bindingValue) {
|
|
4941
|
-
locals[node.b.n] = { value: bindingValue };
|
|
4942
|
-
var newContextStack = contextStack.create(locals);
|
|
4943
|
-
var thenForm = asAstNode(node.p[0], sourceCodeInfo);
|
|
4944
|
-
return evaluateAstNode(thenForm, newContextStack);
|
|
4945
|
-
}
|
|
4946
|
-
if (node.p.length === 2) {
|
|
4947
|
-
var elseForm = asAstNode(node.p[1], sourceCodeInfo);
|
|
4948
|
-
return evaluateAstNode(elseForm, contextStack);
|
|
4949
|
-
}
|
|
4950
|
-
return null;
|
|
4951
|
-
},
|
|
4952
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4953
|
-
var _b;
|
|
4954
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4955
|
-
var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
|
|
4956
|
-
var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
|
|
4957
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
4958
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
4959
|
-
},
|
|
4960
|
-
};
|
|
4961
|
-
|
|
4962
|
-
var ifNotSpecialExpression = {
|
|
4963
|
-
polishParse: getCommonPolishSpecialExpressionParser('if-not'),
|
|
4930
|
+
var unlessSpecialExpression = {
|
|
4931
|
+
polishParse: getCommonPolishSpecialExpressionParser('unless'),
|
|
4964
4932
|
validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
4965
4933
|
evaluate: function (node, contextStack, _a) {
|
|
4966
4934
|
var _b;
|
|
@@ -4985,55 +4953,39 @@ var ifNotSpecialExpression = {
|
|
|
4985
4953
|
|
|
4986
4954
|
var letSpecialExpression = {
|
|
4987
4955
|
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
4988
|
-
var parseBindings = _a.parseBindings
|
|
4956
|
+
var parseBindings = _a.parseBindings;
|
|
4989
4957
|
var bindings = parseBindings(tokenStream, parseState);
|
|
4990
|
-
|
|
4958
|
+
// const params = parseTokensUntilClosingBracket(tokenStream, parseState)
|
|
4991
4959
|
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4992
4960
|
var node = {
|
|
4993
4961
|
t: AstNodeType.SpecialExpression,
|
|
4994
4962
|
n: 'let',
|
|
4995
|
-
p:
|
|
4963
|
+
p: [],
|
|
4996
4964
|
bs: bindings,
|
|
4997
4965
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
4998
4966
|
};
|
|
4999
4967
|
return node;
|
|
5000
4968
|
},
|
|
5001
|
-
validateParameterCount: function () { return
|
|
4969
|
+
validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
|
|
5002
4970
|
evaluate: function (node, contextStack, _a) {
|
|
5003
|
-
var e_1, _b
|
|
4971
|
+
var e_1, _b;
|
|
5004
4972
|
var evaluateAstNode = _a.evaluateAstNode;
|
|
5005
|
-
var locals = {};
|
|
5006
|
-
var newContextStack = contextStack.create(locals);
|
|
5007
4973
|
try {
|
|
5008
|
-
for (var
|
|
5009
|
-
var binding =
|
|
4974
|
+
for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4975
|
+
var binding = _d.value;
|
|
5010
4976
|
var bindingValueNode = binding.v;
|
|
5011
|
-
var bindingValue = evaluateAstNode(bindingValueNode,
|
|
5012
|
-
|
|
4977
|
+
var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
|
|
4978
|
+
contextStack.addValue(binding.n, bindingValue);
|
|
5013
4979
|
}
|
|
5014
4980
|
}
|
|
5015
4981
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5016
4982
|
finally {
|
|
5017
4983
|
try {
|
|
5018
|
-
if (
|
|
4984
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5019
4985
|
}
|
|
5020
4986
|
finally { if (e_1) throw e_1.error; }
|
|
5021
4987
|
}
|
|
5022
|
-
|
|
5023
|
-
try {
|
|
5024
|
-
for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
5025
|
-
var astNode = _g.value;
|
|
5026
|
-
result = evaluateAstNode(astNode, newContextStack);
|
|
5027
|
-
}
|
|
5028
|
-
}
|
|
5029
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5030
|
-
finally {
|
|
5031
|
-
try {
|
|
5032
|
-
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
5033
|
-
}
|
|
5034
|
-
finally { if (e_2) throw e_2.error; }
|
|
5035
|
-
}
|
|
5036
|
-
return result;
|
|
4988
|
+
return null;
|
|
5037
4989
|
},
|
|
5038
4990
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5039
4991
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
@@ -5043,11 +4995,10 @@ var letSpecialExpression = {
|
|
|
5043
4995
|
context[name] = { value: true };
|
|
5044
4996
|
return context;
|
|
5045
4997
|
}, {});
|
|
5046
|
-
var bindingContext = {};
|
|
5047
4998
|
var bindingResults = node.bs.map(function (bindingNode) {
|
|
5048
4999
|
var valueNode = bindingNode.v;
|
|
5049
|
-
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack
|
|
5050
|
-
|
|
5000
|
+
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
|
|
5001
|
+
contextStack.addValue(bindingNode.n, { value: true });
|
|
5051
5002
|
return bindingsResult;
|
|
5052
5003
|
});
|
|
5053
5004
|
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
@@ -5170,7 +5121,7 @@ function parseLoopBinding(tokenStream, parseState, _a) {
|
|
|
5170
5121
|
loopBinding.we = parseToken(tokenStream, parseState);
|
|
5171
5122
|
loopBinding.m.push('&while');
|
|
5172
5123
|
break;
|
|
5173
|
-
case '&':
|
|
5124
|
+
case '&rest':
|
|
5174
5125
|
throw new LitsError("Illegal modifier: ".concat(modifier), (_e = getTokenDebugData(tkn)) === null || _e === void 0 ? void 0 : _e.sourceCodeInfo);
|
|
5175
5126
|
default:
|
|
5176
5127
|
throw new LitsError("Illegal modifier: ".concat(modifier), (_f = getTokenDebugData(tkn)) === null || _f === void 0 ? void 0 : _f.sourceCodeInfo);
|
|
@@ -5370,7 +5321,7 @@ var doseqSpecialExpression = {
|
|
|
5370
5321
|
};
|
|
5371
5322
|
|
|
5372
5323
|
var orSpecialExpression = {
|
|
5373
|
-
polishParse: getCommonPolishSpecialExpressionParser('
|
|
5324
|
+
polishParse: getCommonPolishSpecialExpressionParser('||'),
|
|
5374
5325
|
validateParameterCount: function () { return undefined; },
|
|
5375
5326
|
evaluate: function (node, contextStack, _a) {
|
|
5376
5327
|
var e_1, _b;
|
|
@@ -5462,25 +5413,6 @@ var throwSpecialExpression = {
|
|
|
5462
5413
|
},
|
|
5463
5414
|
};
|
|
5464
5415
|
|
|
5465
|
-
var timeSpecialExpression = {
|
|
5466
|
-
polishParse: getCommonPolishSpecialExpressionParser('time!'),
|
|
5467
|
-
validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
|
|
5468
|
-
evaluate: function (node, contextStack, _a) {
|
|
5469
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5470
|
-
var param = node.p[0];
|
|
5471
|
-
var startTime = Date.now();
|
|
5472
|
-
var result = evaluateAstNode(param, contextStack);
|
|
5473
|
-
var totalTime = Date.now() - startTime;
|
|
5474
|
-
// eslint-disable-next-line no-console
|
|
5475
|
-
console.log("Elapsed time: ".concat(totalTime, " ms"));
|
|
5476
|
-
return result;
|
|
5477
|
-
},
|
|
5478
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5479
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5480
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5481
|
-
},
|
|
5482
|
-
};
|
|
5483
|
-
|
|
5484
5416
|
var trySpecialExpression = {
|
|
5485
5417
|
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5486
5418
|
var _b, _c, _d;
|
|
@@ -5517,9 +5449,10 @@ var trySpecialExpression = {
|
|
|
5517
5449
|
return evaluateAstNode(tryExpressions[0], contextStack);
|
|
5518
5450
|
}
|
|
5519
5451
|
catch (error) {
|
|
5520
|
-
var newContext =
|
|
5521
|
-
_b
|
|
5522
|
-
|
|
5452
|
+
var newContext = errorNode
|
|
5453
|
+
? (_b = {},
|
|
5454
|
+
_b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
|
|
5455
|
+
_b) : {};
|
|
5523
5456
|
return evaluateAstNode(catchExpression, contextStack.create(newContext));
|
|
5524
5457
|
}
|
|
5525
5458
|
},
|
|
@@ -5528,288 +5461,128 @@ var trySpecialExpression = {
|
|
|
5528
5461
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5529
5462
|
var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
|
|
5530
5463
|
var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
|
|
5531
|
-
var newContext =
|
|
5532
|
-
_b
|
|
5533
|
-
|
|
5464
|
+
var newContext = errorNode
|
|
5465
|
+
? (_b = {},
|
|
5466
|
+
_b[errorNode.v] = { value: true },
|
|
5467
|
+
_b) : {};
|
|
5534
5468
|
var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
|
|
5535
5469
|
return joinAnalyzeResults(tryResult, catchResult);
|
|
5536
5470
|
},
|
|
5537
5471
|
};
|
|
5538
5472
|
|
|
5539
|
-
var
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5473
|
+
var specialExpressions = {
|
|
5474
|
+
'&&': andSpecialExpression,
|
|
5475
|
+
'comment': commentSpecialExpression,
|
|
5476
|
+
'cond': condSpecialExpression,
|
|
5477
|
+
'switch': switchSpecialExpression,
|
|
5478
|
+
'def': defSpecialExpression,
|
|
5479
|
+
'defn': defnSpecialExpression,
|
|
5480
|
+
'defns': defnsSpecialExpression,
|
|
5481
|
+
'defs': defsSpecialExpression,
|
|
5482
|
+
'do': doSpecialExpression,
|
|
5483
|
+
'doseq': doseqSpecialExpression,
|
|
5484
|
+
'for': forSpecialExpression,
|
|
5485
|
+
'fn': fnSpecialExpression,
|
|
5486
|
+
'if': ifSpecialExpression,
|
|
5487
|
+
'unless': unlessSpecialExpression,
|
|
5488
|
+
'let': letSpecialExpression,
|
|
5489
|
+
'loop': loopSpecialExpression,
|
|
5490
|
+
'||': orSpecialExpression,
|
|
5491
|
+
'recur': recurSpecialExpression,
|
|
5492
|
+
'throw': throwSpecialExpression,
|
|
5493
|
+
'try': trySpecialExpression,
|
|
5494
|
+
'defined?': declaredSpecialExpression,
|
|
5495
|
+
'??': qqSpecialExpression,
|
|
5496
|
+
};
|
|
5497
|
+
Object.keys(specialExpressions).forEach(function (key) {
|
|
5498
|
+
/* v8 ignore next 2 */
|
|
5499
|
+
if (normalExpressions[key])
|
|
5500
|
+
throw new Error("Expression ".concat(key, " is defined as both a normal expression and a special expression"));
|
|
5501
|
+
});
|
|
5502
|
+
var builtin = {
|
|
5503
|
+
normalExpressions: normalExpressions,
|
|
5504
|
+
specialExpressions: specialExpressions,
|
|
5505
|
+
};
|
|
5506
|
+
var normalExpressionKeys = Object.keys(normalExpressions);
|
|
5507
|
+
var specialExpressionKeys = Object.keys(specialExpressions);
|
|
5508
|
+
|
|
5509
|
+
function isContextEntry(value) {
|
|
5510
|
+
return isUnknownRecord(value) && value.value !== undefined;
|
|
5511
|
+
}
|
|
5512
|
+
|
|
5513
|
+
var ContextStackImpl = /** @class */ (function () {
|
|
5514
|
+
function ContextStackImpl(_a) {
|
|
5515
|
+
var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
|
|
5516
|
+
this.globalContext = asNonUndefined(contexts[0]);
|
|
5517
|
+
this.contexts = contexts;
|
|
5518
|
+
this.values = hostValues;
|
|
5519
|
+
this.lazyValues = lazyHostValues;
|
|
5520
|
+
this.nativeJsFunctions = nativeJsFunctions;
|
|
5521
|
+
}
|
|
5522
|
+
ContextStackImpl.prototype.create = function (context, extraData) {
|
|
5523
|
+
var globalContext = this.globalContext;
|
|
5524
|
+
var contextStack = new ContextStackImpl({
|
|
5525
|
+
contexts: __spreadArray([context], __read(this.contexts), false),
|
|
5526
|
+
values: this.values,
|
|
5527
|
+
lazyValues: extraData ? __assign(__assign({}, this.lazyValues), extraData) : this.lazyValues,
|
|
5528
|
+
nativeJsFunctions: this.nativeJsFunctions,
|
|
5529
|
+
});
|
|
5530
|
+
contextStack.globalContext = globalContext;
|
|
5531
|
+
return contextStack;
|
|
5532
|
+
};
|
|
5533
|
+
ContextStackImpl.prototype.exportValue = function (name, value) {
|
|
5534
|
+
if (this.globalContext[name]) {
|
|
5535
|
+
throw new Error("Cannot redefine exported value \"".concat(name, "\""));
|
|
5536
|
+
}
|
|
5537
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5538
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5539
|
+
}
|
|
5540
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5541
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5542
|
+
}
|
|
5543
|
+
this.addValue(name, value);
|
|
5544
|
+
this.globalContext[name] = { value: value };
|
|
5545
|
+
};
|
|
5546
|
+
ContextStackImpl.prototype.addValue = function (name, value) {
|
|
5547
|
+
var currentContext = this.contexts[0];
|
|
5548
|
+
if (!currentContext) {
|
|
5549
|
+
throw new Error('No context to add value to');
|
|
5550
|
+
}
|
|
5551
|
+
if (currentContext[name]) {
|
|
5552
|
+
throw new Error("Cannot redefine value \"".concat(name, "\""));
|
|
5553
|
+
}
|
|
5554
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5555
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5556
|
+
}
|
|
5557
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5558
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5559
|
+
}
|
|
5560
|
+
currentContext[name] = { value: toAny(value) };
|
|
5561
|
+
};
|
|
5562
|
+
ContextStackImpl.prototype.clone = function () {
|
|
5563
|
+
// eslint-disable-next-line ts/no-unsafe-argument
|
|
5564
|
+
return new ContextStackImpl(JSON.parse(JSON.stringify({
|
|
5565
|
+
contexts: this.contexts,
|
|
5566
|
+
values: this.values,
|
|
5567
|
+
lazyValues: this.lazyValues,
|
|
5568
|
+
nativeJsFunctions: this.nativeJsFunctions,
|
|
5569
|
+
})));
|
|
5570
|
+
};
|
|
5571
|
+
ContextStackImpl.prototype.getValue = function (name) {
|
|
5572
|
+
var e_1, _a;
|
|
5573
|
+
var _b, _c, _d;
|
|
5551
5574
|
try {
|
|
5552
|
-
for (var
|
|
5553
|
-
var
|
|
5554
|
-
|
|
5575
|
+
for (var _e = __values(this.contexts), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5576
|
+
var context = _f.value;
|
|
5577
|
+
var contextEntry = context[name];
|
|
5578
|
+
if (contextEntry)
|
|
5579
|
+
return contextEntry.value;
|
|
5555
5580
|
}
|
|
5556
5581
|
}
|
|
5557
5582
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5558
5583
|
finally {
|
|
5559
5584
|
try {
|
|
5560
|
-
if (
|
|
5561
|
-
}
|
|
5562
|
-
finally { if (e_1) throw e_1.error; }
|
|
5563
|
-
}
|
|
5564
|
-
return result;
|
|
5565
|
-
},
|
|
5566
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5567
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5568
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5569
|
-
},
|
|
5570
|
-
};
|
|
5571
|
-
|
|
5572
|
-
var whenFirstSpecialExpression = {
|
|
5573
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5574
|
-
var _b, _c;
|
|
5575
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5576
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5577
|
-
if (bindings.length !== 1) {
|
|
5578
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5579
|
-
}
|
|
5580
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5581
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5582
|
-
var node = {
|
|
5583
|
-
t: AstNodeType.SpecialExpression,
|
|
5584
|
-
n: 'when-first',
|
|
5585
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5586
|
-
p: params,
|
|
5587
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5588
|
-
};
|
|
5589
|
-
return node;
|
|
5590
|
-
},
|
|
5591
|
-
validateParameterCount: function () { return undefined; },
|
|
5592
|
-
evaluate: function (node, contextStack, _a) {
|
|
5593
|
-
var e_1, _b;
|
|
5594
|
-
var _c;
|
|
5595
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5596
|
-
var locals = {};
|
|
5597
|
-
var binding = node.b;
|
|
5598
|
-
var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
|
|
5599
|
-
if (!isSeq(evaluatedBindingForm)) {
|
|
5600
|
-
throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5601
|
-
}
|
|
5602
|
-
if (evaluatedBindingForm.length === 0)
|
|
5603
|
-
return null;
|
|
5604
|
-
var bindingValue = toAny(evaluatedBindingForm[0]);
|
|
5605
|
-
locals[binding.n] = { value: bindingValue };
|
|
5606
|
-
var newContextStack = contextStack.create(locals);
|
|
5607
|
-
var result = null;
|
|
5608
|
-
try {
|
|
5609
|
-
for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
5610
|
-
var form = _e.value;
|
|
5611
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5612
|
-
}
|
|
5613
|
-
}
|
|
5614
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5615
|
-
finally {
|
|
5616
|
-
try {
|
|
5617
|
-
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
5618
|
-
}
|
|
5619
|
-
finally { if (e_1) throw e_1.error; }
|
|
5620
|
-
}
|
|
5621
|
-
return result;
|
|
5622
|
-
},
|
|
5623
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5624
|
-
var _b;
|
|
5625
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5626
|
-
var binding = node.b;
|
|
5627
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5628
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5629
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5630
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5631
|
-
},
|
|
5632
|
-
};
|
|
5633
|
-
|
|
5634
|
-
var whenLetSpecialExpression = {
|
|
5635
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5636
|
-
var _b, _c;
|
|
5637
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5638
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5639
|
-
if (bindings.length !== 1) {
|
|
5640
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5641
|
-
}
|
|
5642
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5643
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5644
|
-
var node = {
|
|
5645
|
-
t: AstNodeType.SpecialExpression,
|
|
5646
|
-
n: 'when-let',
|
|
5647
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5648
|
-
p: params,
|
|
5649
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5650
|
-
};
|
|
5651
|
-
return node;
|
|
5652
|
-
},
|
|
5653
|
-
validateParameterCount: function () { return undefined; },
|
|
5654
|
-
evaluate: function (node, contextStack, _a) {
|
|
5655
|
-
var e_1, _b;
|
|
5656
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5657
|
-
var binding = node.b;
|
|
5658
|
-
var locals = {};
|
|
5659
|
-
var bindingValue = evaluateAstNode(binding.v, contextStack);
|
|
5660
|
-
if (!bindingValue)
|
|
5661
|
-
return null;
|
|
5662
|
-
locals[binding.n] = { value: bindingValue };
|
|
5663
|
-
var newContextStack = contextStack.create(locals);
|
|
5664
|
-
var result = null;
|
|
5665
|
-
try {
|
|
5666
|
-
for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5667
|
-
var form = _d.value;
|
|
5668
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5669
|
-
}
|
|
5670
|
-
}
|
|
5671
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5672
|
-
finally {
|
|
5673
|
-
try {
|
|
5674
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5675
|
-
}
|
|
5676
|
-
finally { if (e_1) throw e_1.error; }
|
|
5677
|
-
}
|
|
5678
|
-
return result;
|
|
5679
|
-
},
|
|
5680
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5681
|
-
var _b;
|
|
5682
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5683
|
-
var binding = node.b;
|
|
5684
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5685
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5686
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5687
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5688
|
-
},
|
|
5689
|
-
};
|
|
5690
|
-
|
|
5691
|
-
var whenNotSpecialExpression = {
|
|
5692
|
-
polishParse: getCommonPolishSpecialExpressionParser('when-not'),
|
|
5693
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5694
|
-
evaluate: function (node, contextStack, _a) {
|
|
5695
|
-
var e_1, _b;
|
|
5696
|
-
var _c;
|
|
5697
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5698
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5699
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5700
|
-
if (evaluateAstNode(whenExpression, contextStack))
|
|
5701
|
-
return null;
|
|
5702
|
-
var result = null;
|
|
5703
|
-
try {
|
|
5704
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5705
|
-
var form = body_1_1.value;
|
|
5706
|
-
result = evaluateAstNode(form, contextStack);
|
|
5707
|
-
}
|
|
5708
|
-
}
|
|
5709
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5710
|
-
finally {
|
|
5711
|
-
try {
|
|
5712
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5713
|
-
}
|
|
5714
|
-
finally { if (e_1) throw e_1.error; }
|
|
5715
|
-
}
|
|
5716
|
-
return result;
|
|
5717
|
-
},
|
|
5718
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5719
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5720
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5721
|
-
},
|
|
5722
|
-
};
|
|
5723
|
-
|
|
5724
|
-
var specialExpressions = {
|
|
5725
|
-
'and': andSpecialExpression,
|
|
5726
|
-
'comment': commentSpecialExpression,
|
|
5727
|
-
'cond': condSpecialExpression,
|
|
5728
|
-
'def': defSpecialExpression,
|
|
5729
|
-
'defn': defnSpecialExpression,
|
|
5730
|
-
'defns': defnsSpecialExpression,
|
|
5731
|
-
'defs': defsSpecialExpression,
|
|
5732
|
-
'do': doSpecialExpression,
|
|
5733
|
-
'doseq': doseqSpecialExpression,
|
|
5734
|
-
'for': forSpecialExpression,
|
|
5735
|
-
'fn': fnSpecialExpression,
|
|
5736
|
-
'if': ifSpecialExpression,
|
|
5737
|
-
'if-let': ifLetSpecialExpression,
|
|
5738
|
-
'if-not': ifNotSpecialExpression,
|
|
5739
|
-
'let': letSpecialExpression,
|
|
5740
|
-
'loop': loopSpecialExpression,
|
|
5741
|
-
'or': orSpecialExpression,
|
|
5742
|
-
'recur': recurSpecialExpression,
|
|
5743
|
-
'throw': throwSpecialExpression,
|
|
5744
|
-
'time!': timeSpecialExpression,
|
|
5745
|
-
'try': trySpecialExpression,
|
|
5746
|
-
'when': whenSpecialExpression,
|
|
5747
|
-
'when-first': whenFirstSpecialExpression,
|
|
5748
|
-
'when-let': whenLetSpecialExpression,
|
|
5749
|
-
'when-not': whenNotSpecialExpression,
|
|
5750
|
-
'declared?': declaredSpecialExpression,
|
|
5751
|
-
'??': qqSpecialExpression,
|
|
5752
|
-
};
|
|
5753
|
-
Object.keys(specialExpressions).forEach(function (key) {
|
|
5754
|
-
/* v8 ignore next 2 */
|
|
5755
|
-
if (normalExpressions[key])
|
|
5756
|
-
throw new Error("Expression ".concat(key, " is defined as both a normal expression and a special expression"));
|
|
5757
|
-
});
|
|
5758
|
-
var builtin = {
|
|
5759
|
-
normalExpressions: normalExpressions,
|
|
5760
|
-
specialExpressions: specialExpressions,
|
|
5761
|
-
};
|
|
5762
|
-
var normalExpressionKeys = Object.keys(normalExpressions);
|
|
5763
|
-
var specialExpressionKeys = Object.keys(specialExpressions);
|
|
5764
|
-
|
|
5765
|
-
function isContextEntry(value) {
|
|
5766
|
-
return isUnknownRecord(value) && value.value !== undefined;
|
|
5767
|
-
}
|
|
5768
|
-
|
|
5769
|
-
var ContextStackImpl = /** @class */ (function () {
|
|
5770
|
-
function ContextStackImpl(_a) {
|
|
5771
|
-
var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
|
|
5772
|
-
this.contexts = contexts;
|
|
5773
|
-
this.globalContext = asNonUndefined(contexts[0]);
|
|
5774
|
-
this.values = hostValues;
|
|
5775
|
-
this.lazyValues = lazyHostValues;
|
|
5776
|
-
this.nativeJsFunctions = nativeJsFunctions;
|
|
5777
|
-
}
|
|
5778
|
-
ContextStackImpl.prototype.create = function (context, extraData) {
|
|
5779
|
-
var globalContext = this.globalContext;
|
|
5780
|
-
var contextStack = new ContextStackImpl({
|
|
5781
|
-
contexts: __spreadArray([context], __read(this.contexts), false),
|
|
5782
|
-
values: this.values,
|
|
5783
|
-
lazyValues: extraData ? __assign(__assign({}, this.lazyValues), extraData) : this.lazyValues,
|
|
5784
|
-
nativeJsFunctions: this.nativeJsFunctions,
|
|
5785
|
-
});
|
|
5786
|
-
contextStack.globalContext = globalContext;
|
|
5787
|
-
return contextStack;
|
|
5788
|
-
};
|
|
5789
|
-
ContextStackImpl.prototype.clone = function () {
|
|
5790
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
5791
|
-
return new ContextStackImpl(JSON.parse(JSON.stringify({
|
|
5792
|
-
contexts: this.contexts,
|
|
5793
|
-
values: this.values,
|
|
5794
|
-
lazyValues: this.lazyValues,
|
|
5795
|
-
nativeJsFunctions: this.nativeJsFunctions,
|
|
5796
|
-
})));
|
|
5797
|
-
};
|
|
5798
|
-
ContextStackImpl.prototype.getValue = function (name) {
|
|
5799
|
-
var e_1, _a;
|
|
5800
|
-
var _b, _c, _d;
|
|
5801
|
-
try {
|
|
5802
|
-
for (var _e = __values(this.contexts), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5803
|
-
var context = _f.value;
|
|
5804
|
-
var contextEntry = context[name];
|
|
5805
|
-
if (contextEntry)
|
|
5806
|
-
return contextEntry.value;
|
|
5807
|
-
}
|
|
5808
|
-
}
|
|
5809
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5810
|
-
finally {
|
|
5811
|
-
try {
|
|
5812
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
5585
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
5813
5586
|
}
|
|
5814
5587
|
finally { if (e_1) throw e_1.error; }
|
|
5815
5588
|
}
|
|
@@ -5915,7 +5688,7 @@ function createContextStack(params) {
|
|
|
5915
5688
|
return acc;
|
|
5916
5689
|
}, {}),
|
|
5917
5690
|
});
|
|
5918
|
-
return contextStack;
|
|
5691
|
+
return contextStack.create({});
|
|
5919
5692
|
}
|
|
5920
5693
|
|
|
5921
5694
|
var _a;
|
|
@@ -6227,7 +6000,14 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6227
6000
|
|
|
6228
6001
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6229
6002
|
var e_1, _a;
|
|
6230
|
-
var astNodes = Array.isArray(ast)
|
|
6003
|
+
var astNodes = Array.isArray(ast)
|
|
6004
|
+
? ast
|
|
6005
|
+
: [{
|
|
6006
|
+
t: AstNodeType.SpecialExpression,
|
|
6007
|
+
n: 'do',
|
|
6008
|
+
p: ast.b,
|
|
6009
|
+
token: undefined,
|
|
6010
|
+
}];
|
|
6231
6011
|
var unresolvedIdentifiers = new Set();
|
|
6232
6012
|
try {
|
|
6233
6013
|
for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
|
|
@@ -6299,538 +6079,9 @@ function findUnresolvedIdentifiersInAstNode(astNode, contextStack, builtin) {
|
|
|
6299
6079
|
}
|
|
6300
6080
|
}
|
|
6301
6081
|
|
|
6302
|
-
var calculateAndOutcomes = function (_a) {
|
|
6303
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6304
|
-
return combinateAstNodes(astNode.p)
|
|
6305
|
-
.map(function (p) { return ({
|
|
6306
|
-
n: 'and',
|
|
6307
|
-
t: AstNodeType.SpecialExpression,
|
|
6308
|
-
p: p,
|
|
6309
|
-
token: astNode.token,
|
|
6310
|
-
}); });
|
|
6311
|
-
};
|
|
6312
|
-
|
|
6313
|
-
var calculateCondOutcomes = function (_a) {
|
|
6314
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
|
|
6315
|
-
var testNodes = arrayToPairs(astNode.p).map(function (_a) {
|
|
6316
|
-
var _b = __read(_a, 1), t = _b[0];
|
|
6317
|
-
return t;
|
|
6318
|
-
});
|
|
6319
|
-
if (isAstComputable(testNodes)) {
|
|
6320
|
-
return combinate(arrayToPairs(astNode.p)
|
|
6321
|
-
// Create a list of ast nodes from the test and form of each condition
|
|
6322
|
-
.reduce(function (acc, _a) {
|
|
6323
|
-
var _b = __read(_a, 2), test = _b[0], form = _b[1];
|
|
6324
|
-
acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
|
|
6325
|
-
return acc;
|
|
6326
|
-
}, []))
|
|
6327
|
-
// Create a new CondNode for each combination of test and form outcomes
|
|
6328
|
-
.map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
|
|
6329
|
-
var _b = __read(_a, 2), t = _b[0], f = _b[1];
|
|
6330
|
-
return ({ t: t, f: f });
|
|
6331
|
-
}) })); });
|
|
6332
|
-
}
|
|
6333
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
|
|
6334
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6335
|
-
return calculatePossibleAstNodes(form);
|
|
6336
|
-
})), false), [
|
|
6337
|
-
nilNode,
|
|
6338
|
-
], false);
|
|
6339
|
-
};
|
|
6340
|
-
|
|
6341
|
-
var trueNode = { t: AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
|
|
6342
|
-
var falseNode = { t: AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
|
|
6343
|
-
var calculateDeclaredOutcomes = function (_a) {
|
|
6344
|
-
var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
|
|
6345
|
-
if (isAstComputable(astNode.p))
|
|
6346
|
-
return [trueNode];
|
|
6347
|
-
return [trueNode, falseNode];
|
|
6348
|
-
};
|
|
6349
|
-
|
|
6350
|
-
var calculateDefOutcomes = function (_a) {
|
|
6351
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6352
|
-
var nameNode = asSymbolNode(astNode.p[0]);
|
|
6353
|
-
var valueNode = astNode.p[1];
|
|
6354
|
-
addGlobalIdentifier(nameNode.v);
|
|
6355
|
-
return calculatePossibleAstNodes(valueNode)
|
|
6356
|
-
.map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
|
|
6357
|
-
};
|
|
6358
|
-
|
|
6359
|
-
var calculateDefsOutcomes = function (_a) {
|
|
6360
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6361
|
-
return combinateAstNodes(astNode.p)
|
|
6362
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6363
|
-
};
|
|
6364
|
-
|
|
6365
|
-
var calculateDoOutcomes = function (_a) {
|
|
6366
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6367
|
-
return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6368
|
-
};
|
|
6369
|
-
|
|
6370
|
-
function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
|
|
6371
|
-
return combinate(functionOverloads
|
|
6372
|
-
// For each overload, calculate the possible outcomes for each parameter
|
|
6373
|
-
.map(function (functionOverload) {
|
|
6374
|
-
var _a;
|
|
6375
|
-
return combinateAstNodes(functionOverload.b, [
|
|
6376
|
-
functionOverload.as.m,
|
|
6377
|
-
functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
|
|
6378
|
-
(_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
|
|
6379
|
-
].flat())
|
|
6380
|
-
// For each combination of parameter outcomes, create a new overload
|
|
6381
|
-
.map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
|
|
6382
|
-
}));
|
|
6383
|
-
}
|
|
6384
|
-
var calculateDefnOutcomes = function (_a) {
|
|
6385
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6386
|
-
addGlobalIdentifier(astNode.f.v);
|
|
6387
|
-
// astNode.o is an array of overloads
|
|
6388
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6389
|
-
};
|
|
6390
|
-
var calculateDefnsOutcomes = function (_a) {
|
|
6391
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
|
|
6392
|
-
// astNode.o is an array of overloads
|
|
6393
|
-
return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
|
|
6394
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
|
|
6395
|
-
});
|
|
6396
|
-
};
|
|
6397
|
-
var calculateFnOutcomes = function (_a) {
|
|
6398
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6399
|
-
// astNode.o is an array of overloads
|
|
6400
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6401
|
-
};
|
|
6402
|
-
|
|
6403
|
-
var calculateIfLetOutcomes = function (_a) {
|
|
6404
|
-
var _b;
|
|
6405
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6406
|
-
var bindingNode = astNode.b;
|
|
6407
|
-
var thenBranch = astNode.p[0];
|
|
6408
|
-
var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6409
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6410
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6411
|
-
}
|
|
6412
|
-
var newIdentifier = bindingNode.n;
|
|
6413
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6414
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6415
|
-
.flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6416
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
|
|
6417
|
-
};
|
|
6418
|
-
|
|
6419
|
-
var calculateIfNotOutcomes = function (_a) {
|
|
6420
|
-
var _b;
|
|
6421
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6422
|
-
var condition = astNode.p[0];
|
|
6423
|
-
var thenBranch = astNode.p[1];
|
|
6424
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6425
|
-
if (isAstComputable(condition)) {
|
|
6426
|
-
return combinateAstNodes(astNode.p)
|
|
6427
|
-
.map(function (p) { return ({
|
|
6428
|
-
n: 'if-not',
|
|
6429
|
-
t: astNode.t,
|
|
6430
|
-
p: p,
|
|
6431
|
-
token: astNode.token,
|
|
6432
|
-
}); });
|
|
6433
|
-
}
|
|
6434
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6435
|
-
};
|
|
6436
|
-
|
|
6437
|
-
var calculateIfOutcomes = function (_a) {
|
|
6438
|
-
var _b;
|
|
6439
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6440
|
-
var condition = astNode.p[0];
|
|
6441
|
-
var thenBranch = astNode.p[1];
|
|
6442
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6443
|
-
if (isAstComputable(condition)) {
|
|
6444
|
-
return combinateAstNodes(astNode.p)
|
|
6445
|
-
.map(function (p) { return ({
|
|
6446
|
-
n: 'if',
|
|
6447
|
-
t: astNode.t,
|
|
6448
|
-
p: p,
|
|
6449
|
-
token: astNode.token,
|
|
6450
|
-
}); });
|
|
6451
|
-
}
|
|
6452
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6453
|
-
};
|
|
6454
|
-
|
|
6455
|
-
var calculateLetOutcomes = function (_a) {
|
|
6456
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6457
|
-
try {
|
|
6458
|
-
// check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
|
|
6459
|
-
if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
|
|
6460
|
-
throw new Error('Could not calculate binding value');
|
|
6461
|
-
}
|
|
6462
|
-
catch (_b) {
|
|
6463
|
-
var doNodes = combinateAstNodes(astNode.p)
|
|
6464
|
-
.map(function (p) {
|
|
6465
|
-
return {
|
|
6466
|
-
n: 'do',
|
|
6467
|
-
t: AstNodeType.SpecialExpression,
|
|
6468
|
-
p: p,
|
|
6469
|
-
token: astNode.token,
|
|
6470
|
-
};
|
|
6471
|
-
});
|
|
6472
|
-
return doNodes;
|
|
6473
|
-
}
|
|
6474
|
-
var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
|
|
6475
|
-
var letNodes = combinate(astNode.bs.map(function (bindingNode) {
|
|
6476
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6477
|
-
.map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
|
|
6478
|
-
}))
|
|
6479
|
-
.flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
|
|
6480
|
-
.map(function (p) {
|
|
6481
|
-
return {
|
|
6482
|
-
n: 'let',
|
|
6483
|
-
bs: bindingNodes,
|
|
6484
|
-
t: AstNodeType.SpecialExpression,
|
|
6485
|
-
p: p,
|
|
6486
|
-
token: astNode.token,
|
|
6487
|
-
};
|
|
6488
|
-
}); });
|
|
6489
|
-
return letNodes;
|
|
6490
|
-
};
|
|
6491
|
-
|
|
6492
|
-
var calculateForOutcomes = function (_a) {
|
|
6493
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6494
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6495
|
-
throw new Error('Could not calculate for loop, not deterministic');
|
|
6496
|
-
return [astNode];
|
|
6497
|
-
};
|
|
6498
|
-
var calculateDoSeqOutcomes = function (_a) {
|
|
6499
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6500
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6501
|
-
throw new Error('Could not calculate doSeq node, not deterministic');
|
|
6502
|
-
return [astNode];
|
|
6503
|
-
};
|
|
6504
|
-
function isDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6505
|
-
var e_1, _a;
|
|
6506
|
-
try {
|
|
6507
|
-
for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6508
|
-
var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
|
|
6509
|
-
if (l && l.some(function (_a) {
|
|
6510
|
-
var v = _a.v;
|
|
6511
|
-
return !astIsDeterministic(calculatePossibleAstNodes, v);
|
|
6512
|
-
}))
|
|
6513
|
-
return false;
|
|
6514
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
|
|
6515
|
-
return false;
|
|
6516
|
-
if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
|
|
6517
|
-
return false;
|
|
6518
|
-
if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
|
|
6519
|
-
return false;
|
|
6520
|
-
}
|
|
6521
|
-
}
|
|
6522
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6523
|
-
finally {
|
|
6524
|
-
try {
|
|
6525
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6526
|
-
}
|
|
6527
|
-
finally { if (e_1) throw e_1.error; }
|
|
6528
|
-
}
|
|
6529
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
|
|
6530
|
-
return false;
|
|
6531
|
-
return true;
|
|
6532
|
-
}
|
|
6533
|
-
function astIsDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6534
|
-
return calculatePossibleAstNodes(astNode).length === 1;
|
|
6535
|
-
}
|
|
6536
|
-
|
|
6537
|
-
var calculateOrOutcomes = function (_a) {
|
|
6538
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6539
|
-
return combinateAstNodes(astNode.p)
|
|
6540
|
-
.map(function (p) { return ({
|
|
6541
|
-
n: 'or',
|
|
6542
|
-
t: AstNodeType.SpecialExpression,
|
|
6543
|
-
p: p,
|
|
6544
|
-
token: astNode.token,
|
|
6545
|
-
}); });
|
|
6546
|
-
};
|
|
6547
|
-
|
|
6548
|
-
var calculateQqOutcomes = function (_a) {
|
|
6549
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6550
|
-
if (!isAstComputable(astNode.p[0]))
|
|
6551
|
-
throw new Error('First argument of ?? not computable');
|
|
6552
|
-
return combinateAstNodes(astNode.p)
|
|
6553
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6554
|
-
};
|
|
6555
|
-
|
|
6556
|
-
var calculateThrowOutcomes = function (_a) {
|
|
6557
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6558
|
-
return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
|
|
6559
|
-
};
|
|
6560
|
-
|
|
6561
|
-
var calculateTimeOutcomes = function (_a) {
|
|
6562
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6563
|
-
return calculatePossibleAstNodes(astNode.p[0])
|
|
6564
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { n: 'do', p: [p] })); });
|
|
6565
|
-
};
|
|
6566
|
-
|
|
6567
|
-
var calculateTryOutcomes = function (_a) {
|
|
6568
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6569
|
-
var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
|
|
6570
|
-
if (node.n === 'throw') {
|
|
6571
|
-
acc.throws.push(node.p[0]);
|
|
6572
|
-
}
|
|
6573
|
-
else {
|
|
6574
|
-
acc.vals.push(node);
|
|
6575
|
-
}
|
|
6576
|
-
return acc;
|
|
6577
|
-
}, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
|
|
6578
|
-
var catches = throws.flatMap(function (throwNode) {
|
|
6579
|
-
var letNode = {
|
|
6580
|
-
t: AstNodeType.SpecialExpression,
|
|
6581
|
-
n: 'let',
|
|
6582
|
-
bs: [{
|
|
6583
|
-
t: AstNodeType.Binding,
|
|
6584
|
-
n: astNode.e.v,
|
|
6585
|
-
v: throwNode,
|
|
6586
|
-
token: undefined,
|
|
6587
|
-
p: [],
|
|
6588
|
-
}],
|
|
6589
|
-
p: [astNode.ce],
|
|
6590
|
-
token: undefined,
|
|
6591
|
-
};
|
|
6592
|
-
return calculatePossibleAstNodes(letNode);
|
|
6593
|
-
});
|
|
6594
|
-
return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
|
|
6595
|
-
};
|
|
6596
|
-
|
|
6597
|
-
var calculateWhenFirstOutcomes = function (_a) {
|
|
6598
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6599
|
-
var bindingNode = astNode.b;
|
|
6600
|
-
if (!isAstComputable(bindingNode.v))
|
|
6601
|
-
throw new Error('Could not calculate binding value');
|
|
6602
|
-
var newIdentifier = bindingNode.n;
|
|
6603
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6604
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6605
|
-
.flatMap(function (b) {
|
|
6606
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6607
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6608
|
-
});
|
|
6609
|
-
};
|
|
6610
|
-
|
|
6611
|
-
var calculateWhenLetOutcomes = function (_a) {
|
|
6612
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6613
|
-
var bindingNode = astNode.b;
|
|
6614
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6615
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
|
|
6616
|
-
.map(function (p) { return ({
|
|
6617
|
-
n: 'do',
|
|
6618
|
-
t: astNode.t,
|
|
6619
|
-
p: p,
|
|
6620
|
-
token: astNode.token,
|
|
6621
|
-
}); })), false), [
|
|
6622
|
-
nilNode,
|
|
6623
|
-
], false);
|
|
6624
|
-
}
|
|
6625
|
-
var newIdentifier = bindingNode.n;
|
|
6626
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6627
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6628
|
-
.flatMap(function (b) {
|
|
6629
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6630
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6631
|
-
});
|
|
6632
|
-
};
|
|
6633
|
-
|
|
6634
|
-
var calculateWhenNotOutcomes = function (_a) {
|
|
6635
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6636
|
-
var condition = astNode.p[0];
|
|
6637
|
-
if (isAstComputable(condition)) {
|
|
6638
|
-
return combinateAstNodes(astNode.p)
|
|
6639
|
-
.map(function (p) { return ({
|
|
6640
|
-
n: 'when-not',
|
|
6641
|
-
t: astNode.t,
|
|
6642
|
-
p: p,
|
|
6643
|
-
token: astNode.token,
|
|
6644
|
-
}); });
|
|
6645
|
-
}
|
|
6646
|
-
var body = astNode.p.slice(1);
|
|
6647
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6648
|
-
.map(function (p) { return ({
|
|
6649
|
-
n: 'do',
|
|
6650
|
-
t: astNode.t,
|
|
6651
|
-
p: p,
|
|
6652
|
-
token: astNode.token,
|
|
6653
|
-
}); })), false), [
|
|
6654
|
-
nilNode,
|
|
6655
|
-
], false);
|
|
6656
|
-
};
|
|
6657
|
-
|
|
6658
|
-
var calculateWhenOutcomes = function (_a) {
|
|
6659
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6660
|
-
var condition = astNode.p[0];
|
|
6661
|
-
if (isAstComputable(condition)) {
|
|
6662
|
-
return combinateAstNodes(astNode.p)
|
|
6663
|
-
.map(function (p) { return ({
|
|
6664
|
-
n: 'when',
|
|
6665
|
-
t: astNode.t,
|
|
6666
|
-
p: p,
|
|
6667
|
-
token: astNode.token,
|
|
6668
|
-
}); });
|
|
6669
|
-
}
|
|
6670
|
-
var body = astNode.p.slice(1);
|
|
6671
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6672
|
-
.map(function (p) { return ({
|
|
6673
|
-
n: 'do',
|
|
6674
|
-
t: astNode.t,
|
|
6675
|
-
p: p,
|
|
6676
|
-
token: astNode.token,
|
|
6677
|
-
}); })), false), [
|
|
6678
|
-
nilNode,
|
|
6679
|
-
], false);
|
|
6680
|
-
};
|
|
6681
|
-
|
|
6682
|
-
var calculateRecurOutcomes = function (_a) {
|
|
6683
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6684
|
-
return combinateAstNodes(astNode.p)
|
|
6685
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6686
|
-
};
|
|
6687
|
-
|
|
6688
|
-
var calculateCommentOutcomes = function (_a) {
|
|
6689
|
-
var nilNode = _a.nilNode;
|
|
6690
|
-
return [nilNode];
|
|
6691
|
-
};
|
|
6692
|
-
|
|
6693
|
-
var calculateLoopOutcomes = function (_a) {
|
|
6694
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6695
|
-
return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
|
|
6696
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6697
|
-
};
|
|
6698
|
-
|
|
6699
|
-
var specialExpressionCalculator = {
|
|
6700
|
-
'and': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6701
|
-
'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6702
|
-
'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6703
|
-
'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6704
|
-
'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6705
|
-
'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6706
|
-
'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6707
|
-
'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6708
|
-
'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6709
|
-
'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6710
|
-
'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6711
|
-
'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6712
|
-
'if-let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6713
|
-
'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6714
|
-
'if-not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6715
|
-
'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6716
|
-
'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6717
|
-
'or': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6718
|
-
'??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6719
|
-
'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6720
|
-
'time!': function (astNode, helperOptions) { return calculateTimeOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6721
|
-
'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6722
|
-
'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6723
|
-
'when-first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6724
|
-
'when-let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6725
|
-
'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6726
|
-
'when-not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6727
|
-
};
|
|
6728
|
-
|
|
6729
|
-
function isIdempotent(normalExpressionName) {
|
|
6730
|
-
return !normalExpressionName.endsWith('!')
|
|
6731
|
-
|| normalExpressionName === 'write!';
|
|
6732
|
-
}
|
|
6733
|
-
function calculateOutcomes(contextStack, astNodes) {
|
|
6734
|
-
// First, we try to calculate outcomes for the whole astNodes array.
|
|
6735
|
-
// If that fails, we try to calculate outcomes for the array without the first element.
|
|
6736
|
-
// If that fails, we try to calculate outcomes for the array without the first two elements.
|
|
6737
|
-
// And so on.
|
|
6738
|
-
// This makes it possible to calculate outcomes for e.g.
|
|
6739
|
-
// (write! x) x
|
|
6740
|
-
// Problems occur for e.g.
|
|
6741
|
-
// (def x 1) (write! x) x
|
|
6742
|
-
// This should output [1], but since (write! x) fails to calculate outcomes, we get null.
|
|
6743
|
-
// Ok, but not optimal
|
|
6744
|
-
// The contract is that when an array is returned, it must be correct.
|
|
6745
|
-
// But returning null (indicating that the calculation failed) is always a way out.
|
|
6746
|
-
for (var i = 0; i < astNodes.length; i++) {
|
|
6747
|
-
var usingAstNode = astNodes.slice(i);
|
|
6748
|
-
var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
|
|
6749
|
-
if (outcomes !== null)
|
|
6750
|
-
return outcomes;
|
|
6751
|
-
}
|
|
6752
|
-
return null;
|
|
6753
|
-
}
|
|
6754
|
-
function calculateOutcomesInner(contextStack, astNodes) {
|
|
6755
|
-
var e_1, _a;
|
|
6756
|
-
var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
|
|
6757
|
-
if (possibleAsts === null)
|
|
6758
|
-
return null;
|
|
6759
|
-
var outcomes = [];
|
|
6760
|
-
try {
|
|
6761
|
-
for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
|
|
6762
|
-
var possibleAst = possibleAsts_1_1.value;
|
|
6763
|
-
var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
|
|
6764
|
-
if (unresolvedIdentifiers.size !== 0)
|
|
6765
|
-
return null;
|
|
6766
|
-
var ast = {
|
|
6767
|
-
b: possibleAst,
|
|
6768
|
-
hasDebugData: true,
|
|
6769
|
-
};
|
|
6770
|
-
try {
|
|
6771
|
-
outcomes.push(evaluate(ast, contextStack.clone()));
|
|
6772
|
-
}
|
|
6773
|
-
catch (e) {
|
|
6774
|
-
outcomes.push(e);
|
|
6775
|
-
}
|
|
6776
|
-
}
|
|
6777
|
-
}
|
|
6778
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6779
|
-
finally {
|
|
6780
|
-
try {
|
|
6781
|
-
if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
|
|
6782
|
-
}
|
|
6783
|
-
finally { if (e_1) throw e_1.error; }
|
|
6784
|
-
}
|
|
6785
|
-
return outcomes;
|
|
6786
|
-
}
|
|
6787
|
-
function calculatePossibleAsts(contextStack, astNodes) {
|
|
6788
|
-
var possibleAsts;
|
|
6789
|
-
try {
|
|
6790
|
-
possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
|
|
6791
|
-
}
|
|
6792
|
-
catch (e) {
|
|
6793
|
-
return null;
|
|
6794
|
-
}
|
|
6795
|
-
return possibleAsts;
|
|
6796
|
-
}
|
|
6797
|
-
var nilNode = { t: AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
|
|
6798
|
-
function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
|
|
6799
|
-
var newContext = newIndentifiers
|
|
6800
|
-
? newIndentifiers.reduce(function (acc, identity) {
|
|
6801
|
-
acc[identity] = { value: null };
|
|
6802
|
-
return acc;
|
|
6803
|
-
}, {})
|
|
6804
|
-
: undefined;
|
|
6805
|
-
var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
|
|
6806
|
-
if (astNode.t === AstNodeType.NormalExpression) {
|
|
6807
|
-
if (astNode.n && !isIdempotent(astNode.n))
|
|
6808
|
-
throw new Error("NormalExpressionNode with name ".concat(astNode.n, " is not idempotent. Cannot calculate possible ASTs."));
|
|
6809
|
-
return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
|
|
6810
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6811
|
-
}
|
|
6812
|
-
else if (astNode.t === AstNodeType.SpecialExpression) {
|
|
6813
|
-
var helperOptions = {
|
|
6814
|
-
nilNode: nilNode,
|
|
6815
|
-
calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
|
|
6816
|
-
combinateAstNodes: function (nodes, identifiers) {
|
|
6817
|
-
return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
|
|
6818
|
-
},
|
|
6819
|
-
isAstComputable: function (node) {
|
|
6820
|
-
return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
|
|
6821
|
-
},
|
|
6822
|
-
addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
|
|
6823
|
-
};
|
|
6824
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6825
|
-
return specialExpressionCalculator[astNode.n](astNode, helperOptions);
|
|
6826
|
-
}
|
|
6827
|
-
return [astNode];
|
|
6828
|
-
}
|
|
6829
|
-
|
|
6830
6082
|
function analyze(ast, params) {
|
|
6831
6083
|
return {
|
|
6832
6084
|
unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
|
|
6833
|
-
outcomes: calculateOutcomes(createContextStack(params), ast.b),
|
|
6834
6085
|
};
|
|
6835
6086
|
}
|
|
6836
6087
|
|
|
@@ -7032,13 +6283,10 @@ function fromUnaryAlgebraicToAstNode(operator, operand) {
|
|
|
7032
6283
|
var operatorName = operator[1];
|
|
7033
6284
|
switch (operatorName) {
|
|
7034
6285
|
case '+':
|
|
7035
|
-
return createNamedNormalExpressionNode('+', [operand], token);
|
|
7036
6286
|
case '-':
|
|
7037
|
-
return createNamedNormalExpressionNode('-', [operand], token);
|
|
7038
6287
|
case '!':
|
|
7039
|
-
return createNamedNormalExpressionNode('not', [operand], token);
|
|
7040
6288
|
case '~':
|
|
7041
|
-
return createNamedNormalExpressionNode(
|
|
6289
|
+
return createNamedNormalExpressionNode(operatorName, [operand], token);
|
|
7042
6290
|
/* v8 ignore next 2 */
|
|
7043
6291
|
default:
|
|
7044
6292
|
throw new Error("Unknown operator: ".concat(operatorName));
|
|
@@ -7051,64 +6299,31 @@ function fromBinaryOperatorToAstNode(operator, left, right, token) {
|
|
|
7051
6299
|
case '.':
|
|
7052
6300
|
return createAccessorNode(left, fromSymbolToStringNode(asSymbolNode(right, (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo)), token);
|
|
7053
6301
|
case '**': // exponentiation
|
|
7054
|
-
return createNamedNormalExpressionNode('pow', [left, right], token);
|
|
7055
6302
|
case '*':
|
|
7056
|
-
return createNamedNormalExpressionNode('*', [left, right], token);
|
|
7057
6303
|
case '/':
|
|
7058
|
-
return createNamedNormalExpressionNode('/', [left, right], token);
|
|
7059
6304
|
case '%':
|
|
7060
|
-
return createNamedNormalExpressionNode('rem', [left, right], token);
|
|
7061
6305
|
case '+':
|
|
7062
|
-
return createNamedNormalExpressionNode('+', [left, right], token);
|
|
7063
6306
|
case '-':
|
|
7064
|
-
return createNamedNormalExpressionNode('-', [left, right], token);
|
|
7065
6307
|
case '<<':
|
|
7066
|
-
return createNamedNormalExpressionNode('bit-shift-left', [left, right], token);
|
|
7067
6308
|
case '>>':
|
|
7068
|
-
return createNamedNormalExpressionNode('bit-shift-right', [left, right], token);
|
|
7069
6309
|
case '>>>':
|
|
7070
|
-
|
|
7071
|
-
case '++': {
|
|
7072
|
-
var leftString = createNamedNormalExpressionNode('str', [left], token);
|
|
7073
|
-
var rightString = createNamedNormalExpressionNode('str', [right], token);
|
|
7074
|
-
return createNamedNormalExpressionNode('str', [leftString, rightString], token);
|
|
7075
|
-
}
|
|
6310
|
+
case '++':
|
|
7076
6311
|
case '<':
|
|
7077
|
-
return createNamedNormalExpressionNode('<', [left, right], token);
|
|
7078
6312
|
case '<=':
|
|
7079
|
-
return createNamedNormalExpressionNode('<=', [left, right], token);
|
|
7080
6313
|
case '>':
|
|
7081
|
-
return createNamedNormalExpressionNode('>', [left, right], token);
|
|
7082
6314
|
case '>=':
|
|
7083
|
-
return createNamedNormalExpressionNode('>=', [left, right], token);
|
|
7084
6315
|
case '==':
|
|
7085
|
-
return createNamedNormalExpressionNode('=', [left, right], token);
|
|
7086
6316
|
case '!=':
|
|
7087
|
-
return createNamedNormalExpressionNode('!=', [left, right], token);
|
|
7088
6317
|
case '&':
|
|
7089
|
-
return createNamedNormalExpressionNode('bit-and', [left, right], token);
|
|
7090
6318
|
case '^':
|
|
7091
|
-
return createNamedNormalExpressionNode('bit-xor', [left, right], token);
|
|
7092
6319
|
case '|':
|
|
7093
|
-
return createNamedNormalExpressionNode(
|
|
6320
|
+
return createNamedNormalExpressionNode(operatorName, [left, right], token);
|
|
7094
6321
|
case '&&':
|
|
7095
|
-
return {
|
|
7096
|
-
t: AstNodeType.SpecialExpression,
|
|
7097
|
-
n: 'and',
|
|
7098
|
-
p: [left, right],
|
|
7099
|
-
token: getTokenDebugData(token) && token,
|
|
7100
|
-
};
|
|
7101
6322
|
case '||':
|
|
7102
|
-
return {
|
|
7103
|
-
t: AstNodeType.SpecialExpression,
|
|
7104
|
-
n: 'or',
|
|
7105
|
-
p: [left, right],
|
|
7106
|
-
token: getTokenDebugData(token) && token,
|
|
7107
|
-
};
|
|
7108
6323
|
case '??':
|
|
7109
6324
|
return {
|
|
7110
6325
|
t: AstNodeType.SpecialExpression,
|
|
7111
|
-
n:
|
|
6326
|
+
n: operatorName,
|
|
7112
6327
|
p: [left, right],
|
|
7113
6328
|
token: getTokenDebugData(token) && token,
|
|
7114
6329
|
};
|
|
@@ -7148,19 +6363,43 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7148
6363
|
var _a;
|
|
7149
6364
|
if (precedence === void 0) { precedence = 0; }
|
|
7150
6365
|
var firstToken = this.peek();
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
6366
|
+
var left;
|
|
6367
|
+
if (isA_SymbolToken(firstToken)) {
|
|
6368
|
+
switch (firstToken[1]) {
|
|
6369
|
+
case 'def':
|
|
6370
|
+
return this.parseDef(firstToken);
|
|
6371
|
+
case 'defn':
|
|
6372
|
+
return this.parseDefn(firstToken);
|
|
6373
|
+
case 'let':
|
|
6374
|
+
return this.parseLet(firstToken);
|
|
6375
|
+
case 'if':
|
|
6376
|
+
case 'unless':
|
|
6377
|
+
left = this.parseIfOrUnless(firstToken);
|
|
6378
|
+
break;
|
|
6379
|
+
case 'cond':
|
|
6380
|
+
left = this.parseCond(firstToken);
|
|
6381
|
+
break;
|
|
6382
|
+
case 'switch':
|
|
6383
|
+
left = this.parseSwitch(firstToken);
|
|
6384
|
+
break;
|
|
6385
|
+
case 'for':
|
|
6386
|
+
case 'doseq':
|
|
6387
|
+
left = this.parseForOrDoseq(firstToken);
|
|
6388
|
+
break;
|
|
6389
|
+
case 'do':
|
|
6390
|
+
left = this.parseDo(firstToken);
|
|
6391
|
+
break;
|
|
6392
|
+
case 'loop':
|
|
6393
|
+
left = this.parseLoop(firstToken);
|
|
6394
|
+
break;
|
|
6395
|
+
case 'try':
|
|
6396
|
+
left = this.parseTry(firstToken);
|
|
6397
|
+
break;
|
|
6398
|
+
}
|
|
7156
6399
|
}
|
|
7157
|
-
|
|
6400
|
+
left || (left = this.parseOperand());
|
|
7158
6401
|
var operator = this.peek();
|
|
7159
|
-
while (!this.
|
|
7160
|
-
&& !isA_OperatorToken(operator, ',')
|
|
7161
|
-
&& !isA_OperatorToken(operator, ';')
|
|
7162
|
-
&& !isRBracketToken(operator)
|
|
7163
|
-
&& !isRParenToken(operator)) {
|
|
6402
|
+
while (!this.isAtExpressionEnd()) {
|
|
7164
6403
|
if (isA_BinaryOperatorToken(operator)) {
|
|
7165
6404
|
var name_1 = operator[1];
|
|
7166
6405
|
var newPrecedece = getPrecedence(name_1);
|
|
@@ -7391,9 +6630,6 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7391
6630
|
var _a, _b;
|
|
7392
6631
|
var isNamedFunction = symbol.t === AstNodeType.Symbol;
|
|
7393
6632
|
this.advance();
|
|
7394
|
-
if (isNamedFunction && symbol.v === 'for') {
|
|
7395
|
-
return this.parseFor(symbol);
|
|
7396
|
-
}
|
|
7397
6633
|
var params = [];
|
|
7398
6634
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
7399
6635
|
params.push(this.parseExpression());
|
|
@@ -7414,17 +6650,11 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7414
6650
|
var name_2 = symbol.v;
|
|
7415
6651
|
switch (name_2) {
|
|
7416
6652
|
case '??':
|
|
7417
|
-
case '
|
|
6653
|
+
case '&&':
|
|
7418
6654
|
case 'comment':
|
|
7419
|
-
case '
|
|
7420
|
-
case '
|
|
7421
|
-
case '
|
|
7422
|
-
case 'if-not':
|
|
7423
|
-
case 'or':
|
|
7424
|
-
case 'when':
|
|
7425
|
-
case 'when-not':
|
|
7426
|
-
case 'do':
|
|
7427
|
-
case 'time!':
|
|
6655
|
+
case 'defined?':
|
|
6656
|
+
case '||':
|
|
6657
|
+
case 'recur':
|
|
7428
6658
|
case 'throw': {
|
|
7429
6659
|
var node = {
|
|
7430
6660
|
t: AstNodeType.SpecialExpression,
|
|
@@ -7435,17 +6665,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7435
6665
|
builtin.specialExpressions[node.n].validateParameterCount(node);
|
|
7436
6666
|
return node;
|
|
7437
6667
|
}
|
|
7438
|
-
case 'let':
|
|
7439
|
-
return this.parseLet(symbol, params);
|
|
7440
6668
|
case 'defs':
|
|
7441
|
-
case 'if-let':
|
|
7442
|
-
case 'when-let':
|
|
7443
|
-
case 'when-first':
|
|
7444
6669
|
case 'fn':
|
|
7445
6670
|
case 'defns':
|
|
7446
6671
|
case 'try':
|
|
7447
|
-
case 'recur':
|
|
7448
|
-
case 'loop':
|
|
7449
6672
|
case 'doseq':
|
|
7450
6673
|
throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
|
|
7451
6674
|
default:
|
|
@@ -7582,93 +6805,200 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7582
6805
|
}
|
|
7583
6806
|
}
|
|
7584
6807
|
}
|
|
7585
|
-
var mandatoryArguments = [];
|
|
7586
|
-
for (var i = 1; i <= arity; i += 1) {
|
|
7587
|
-
if (i === 1 && percent1 === 'NAKED')
|
|
7588
|
-
mandatoryArguments.push('$');
|
|
7589
|
-
else
|
|
7590
|
-
mandatoryArguments.push("$".concat(i));
|
|
6808
|
+
var mandatoryArguments = [];
|
|
6809
|
+
for (var i = 1; i <= arity; i += 1) {
|
|
6810
|
+
if (i === 1 && percent1 === 'NAKED')
|
|
6811
|
+
mandatoryArguments.push('$');
|
|
6812
|
+
else
|
|
6813
|
+
mandatoryArguments.push("$".concat(i));
|
|
6814
|
+
}
|
|
6815
|
+
var args = {
|
|
6816
|
+
b: [],
|
|
6817
|
+
m: mandatoryArguments,
|
|
6818
|
+
};
|
|
6819
|
+
var node = {
|
|
6820
|
+
t: AstNodeType.SpecialExpression,
|
|
6821
|
+
n: 'fn',
|
|
6822
|
+
p: [],
|
|
6823
|
+
o: [
|
|
6824
|
+
{
|
|
6825
|
+
as: args,
|
|
6826
|
+
b: [exprNode],
|
|
6827
|
+
a: args.m.length,
|
|
6828
|
+
},
|
|
6829
|
+
],
|
|
6830
|
+
token: getTokenDebugData(firstToken) && firstToken,
|
|
6831
|
+
};
|
|
6832
|
+
return node;
|
|
6833
|
+
};
|
|
6834
|
+
AlgebraicParser.prototype.parseLet = function (token) {
|
|
6835
|
+
this.advance();
|
|
6836
|
+
var letSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6837
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6838
|
+
this.advance();
|
|
6839
|
+
var value = this.parseExpression();
|
|
6840
|
+
return {
|
|
6841
|
+
t: AstNodeType.SpecialExpression,
|
|
6842
|
+
n: 'let',
|
|
6843
|
+
p: [],
|
|
6844
|
+
token: getTokenDebugData(letSymbol.token) && letSymbol.token,
|
|
6845
|
+
bs: [{
|
|
6846
|
+
t: AstNodeType.Binding,
|
|
6847
|
+
n: letSymbol.v,
|
|
6848
|
+
v: value,
|
|
6849
|
+
p: [],
|
|
6850
|
+
token: getTokenDebugData(token) && token,
|
|
6851
|
+
}],
|
|
6852
|
+
};
|
|
6853
|
+
};
|
|
6854
|
+
AlgebraicParser.prototype.parseDo = function (token) {
|
|
6855
|
+
this.advance();
|
|
6856
|
+
var expressions = [];
|
|
6857
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6858
|
+
expressions.push(this.parseExpression());
|
|
6859
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6860
|
+
this.advance();
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6864
|
+
this.advance();
|
|
6865
|
+
return {
|
|
6866
|
+
t: AstNodeType.SpecialExpression,
|
|
6867
|
+
n: 'do',
|
|
6868
|
+
p: expressions,
|
|
6869
|
+
token: getTokenDebugData(token) && token,
|
|
6870
|
+
};
|
|
6871
|
+
};
|
|
6872
|
+
AlgebraicParser.prototype.parseLoop = function (token) {
|
|
6873
|
+
var _a;
|
|
6874
|
+
this.advance();
|
|
6875
|
+
assertLParenToken(this.peek());
|
|
6876
|
+
this.advance();
|
|
6877
|
+
var bindingNodes = [];
|
|
6878
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6879
|
+
var symbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6880
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6881
|
+
this.advance();
|
|
6882
|
+
var value = this.parseExpression();
|
|
6883
|
+
bindingNodes.push({
|
|
6884
|
+
t: AstNodeType.Binding,
|
|
6885
|
+
n: symbol.v,
|
|
6886
|
+
v: value,
|
|
6887
|
+
p: [],
|
|
6888
|
+
token: getTokenDebugData(symbol.token) && symbol.token,
|
|
6889
|
+
});
|
|
6890
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
6891
|
+
this.advance();
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
if (bindingNodes.length === 0) {
|
|
6895
|
+
throw new LitsError('Expected binding', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7591
6896
|
}
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
6897
|
+
assertRParenToken(this.peek());
|
|
6898
|
+
this.advance();
|
|
6899
|
+
var params = [];
|
|
6900
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6901
|
+
params.push(this.parseExpression());
|
|
6902
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6903
|
+
this.advance();
|
|
6904
|
+
}
|
|
6905
|
+
}
|
|
6906
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6907
|
+
this.advance();
|
|
6908
|
+
return {
|
|
7597
6909
|
t: AstNodeType.SpecialExpression,
|
|
7598
|
-
n: '
|
|
7599
|
-
p:
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
as: args,
|
|
7603
|
-
b: [exprNode],
|
|
7604
|
-
a: args.m.length,
|
|
7605
|
-
},
|
|
7606
|
-
],
|
|
7607
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
6910
|
+
n: 'loop',
|
|
6911
|
+
p: params,
|
|
6912
|
+
bs: bindingNodes,
|
|
6913
|
+
token: getTokenDebugData(token) && token,
|
|
7608
6914
|
};
|
|
7609
|
-
return node;
|
|
7610
6915
|
};
|
|
7611
|
-
AlgebraicParser.prototype.
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
6916
|
+
AlgebraicParser.prototype.parseTry = function (token) {
|
|
6917
|
+
this.advance();
|
|
6918
|
+
var tryExpressions = [];
|
|
6919
|
+
while (!this.isAtEnd() && !isA_SymbolToken(this.peek(), 'catch')) {
|
|
6920
|
+
tryExpressions.push(this.parseExpression());
|
|
6921
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6922
|
+
this.advance();
|
|
6923
|
+
}
|
|
6924
|
+
}
|
|
6925
|
+
var tryExpression = tryExpressions.length === 1
|
|
6926
|
+
? tryExpressions[0]
|
|
6927
|
+
: {
|
|
6928
|
+
t: AstNodeType.SpecialExpression,
|
|
6929
|
+
n: 'do',
|
|
6930
|
+
p: tryExpressions,
|
|
6931
|
+
token: getTokenDebugData(token) && token,
|
|
6932
|
+
};
|
|
6933
|
+
assertA_SymbolToken(this.peek(), 'catch');
|
|
6934
|
+
this.advance();
|
|
6935
|
+
var errorSymbol;
|
|
6936
|
+
if (isLParenToken(this.peek())) {
|
|
6937
|
+
this.advance();
|
|
6938
|
+
errorSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6939
|
+
assertRParenToken(this.peek());
|
|
6940
|
+
this.advance();
|
|
7615
6941
|
}
|
|
7616
|
-
var
|
|
7617
|
-
|
|
7618
|
-
|
|
6942
|
+
var catchExpressions = [];
|
|
6943
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6944
|
+
catchExpressions.push(this.parseExpression());
|
|
6945
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6946
|
+
this.advance();
|
|
6947
|
+
}
|
|
7619
6948
|
}
|
|
7620
|
-
|
|
7621
|
-
|
|
6949
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6950
|
+
this.advance();
|
|
6951
|
+
var catchExpression = catchExpressions.length === 1
|
|
6952
|
+
? catchExpressions[0]
|
|
6953
|
+
: {
|
|
6954
|
+
t: AstNodeType.SpecialExpression,
|
|
6955
|
+
n: 'do',
|
|
6956
|
+
p: catchExpressions,
|
|
6957
|
+
token: getTokenDebugData(token) && token,
|
|
6958
|
+
};
|
|
7622
6959
|
return {
|
|
7623
6960
|
t: AstNodeType.SpecialExpression,
|
|
7624
|
-
n: '
|
|
7625
|
-
p: [
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
var value = pair[1];
|
|
7630
|
-
return {
|
|
7631
|
-
t: AstNodeType.Binding,
|
|
7632
|
-
n: key.v,
|
|
7633
|
-
v: value,
|
|
7634
|
-
p: [],
|
|
7635
|
-
token: getTokenDebugData(key.token) && key.token,
|
|
7636
|
-
};
|
|
7637
|
-
}),
|
|
6961
|
+
n: 'try',
|
|
6962
|
+
p: [tryExpression],
|
|
6963
|
+
ce: catchExpression,
|
|
6964
|
+
e: errorSymbol,
|
|
6965
|
+
token: getTokenDebugData(token) && token,
|
|
7638
6966
|
};
|
|
7639
6967
|
};
|
|
7640
|
-
AlgebraicParser.prototype.
|
|
6968
|
+
AlgebraicParser.prototype.parseForOrDoseq = function (token) {
|
|
6969
|
+
var isDoseq = token[1] === 'doseq';
|
|
6970
|
+
this.advance();
|
|
6971
|
+
assertLParenToken(this.peek());
|
|
6972
|
+
this.advance();
|
|
7641
6973
|
var forLoopBindings = [
|
|
7642
6974
|
this.parseForLoopBinding(),
|
|
7643
6975
|
];
|
|
7644
|
-
|
|
7645
|
-
while (isA_SymbolToken(nextToken) && nextToken[1] === 'of') {
|
|
6976
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
7646
6977
|
forLoopBindings.push(this.parseForLoopBinding());
|
|
7647
|
-
|
|
6978
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
6979
|
+
this.advance();
|
|
6980
|
+
}
|
|
7648
6981
|
}
|
|
7649
|
-
var expression = this.parseExpression();
|
|
7650
6982
|
assertRParenToken(this.peek());
|
|
7651
6983
|
this.advance();
|
|
6984
|
+
var expression = this.parseExpression();
|
|
6985
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6986
|
+
this.advance();
|
|
7652
6987
|
return {
|
|
7653
6988
|
t: AstNodeType.SpecialExpression,
|
|
7654
|
-
n: 'for',
|
|
6989
|
+
n: isDoseq ? 'doseq' : 'for',
|
|
7655
6990
|
p: [expression],
|
|
7656
|
-
token: getTokenDebugData(
|
|
6991
|
+
token: getTokenDebugData(token) && token,
|
|
7657
6992
|
l: forLoopBindings,
|
|
7658
6993
|
};
|
|
7659
6994
|
};
|
|
7660
|
-
// export interface LoopBindingNode {
|
|
7661
|
-
// b: BindingNode // Binding
|
|
7662
|
-
// m: Array<'&let' | '&when' | '&while'> // Modifiers
|
|
7663
|
-
// l?: BindingNode[] // Let-Bindings
|
|
7664
|
-
// wn?: AstNode // When Node
|
|
7665
|
-
// we?: AstNode // While Node
|
|
7666
|
-
// }
|
|
7667
6995
|
AlgebraicParser.prototype.parseForLoopBinding = function () {
|
|
7668
6996
|
var _a;
|
|
7669
6997
|
var bindingNode = this.parseBinding();
|
|
7670
|
-
if (isA_OperatorToken(this.peek(), ',')) {
|
|
7671
|
-
this.
|
|
6998
|
+
if (isRParenToken(this.peek()) || isA_OperatorToken(this.peek(), ',')) {
|
|
6999
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
7000
|
+
this.advance();
|
|
7001
|
+
}
|
|
7672
7002
|
return {
|
|
7673
7003
|
b: bindingNode,
|
|
7674
7004
|
m: [],
|
|
@@ -7676,33 +7006,26 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7676
7006
|
}
|
|
7677
7007
|
var modifiers = [];
|
|
7678
7008
|
var token = this.peek();
|
|
7679
|
-
if (!isA_SymbolToken(token)
|
|
7009
|
+
if (!isA_SymbolToken(token, 'let')
|
|
7010
|
+
&& !isA_ReservedSymbolToken(token, 'when')
|
|
7011
|
+
&& !isA_ReservedSymbolToken(token, 'while')) {
|
|
7680
7012
|
throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7681
7013
|
}
|
|
7682
7014
|
var letBindings;
|
|
7683
7015
|
if (token[1] === 'let') {
|
|
7684
7016
|
modifiers.push('&let');
|
|
7685
7017
|
letBindings = [];
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
return {
|
|
7692
|
-
t: AstNodeType.Binding,
|
|
7693
|
-
n: key.v,
|
|
7694
|
-
v: value,
|
|
7695
|
-
p: [],
|
|
7696
|
-
token: getTokenDebugData(key.token) && key.token,
|
|
7697
|
-
};
|
|
7698
|
-
});
|
|
7018
|
+
while (isA_SymbolToken(token, 'let')) {
|
|
7019
|
+
var letNode = this.parseLet(token);
|
|
7020
|
+
letBindings.push(letNode.bs[0]);
|
|
7021
|
+
token = this.peek();
|
|
7022
|
+
}
|
|
7699
7023
|
}
|
|
7700
7024
|
token = this.peek();
|
|
7701
7025
|
var whenNode;
|
|
7702
7026
|
var whileNode;
|
|
7703
|
-
while (
|
|
7704
|
-
|
|
7705
|
-
|| (token[1] === 'while' && !modifiers.includes('&while')))) {
|
|
7027
|
+
while (isA_ReservedSymbolToken(token, 'when')
|
|
7028
|
+
|| isA_ReservedSymbolToken(token, 'while')) {
|
|
7706
7029
|
this.advance();
|
|
7707
7030
|
if (token[1] === 'when') {
|
|
7708
7031
|
modifiers.push('&when');
|
|
@@ -7714,8 +7037,9 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7714
7037
|
}
|
|
7715
7038
|
token = this.peek();
|
|
7716
7039
|
}
|
|
7717
|
-
|
|
7718
|
-
|
|
7040
|
+
if (isA_OperatorToken(token, ',')) {
|
|
7041
|
+
this.advance();
|
|
7042
|
+
}
|
|
7719
7043
|
return {
|
|
7720
7044
|
b: bindingNode,
|
|
7721
7045
|
m: modifiers,
|
|
@@ -7744,6 +7068,141 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7744
7068
|
};
|
|
7745
7069
|
return node;
|
|
7746
7070
|
};
|
|
7071
|
+
AlgebraicParser.prototype.parseIfOrUnless = function (token) {
|
|
7072
|
+
var isUnless = token[1] === 'unless';
|
|
7073
|
+
this.advance();
|
|
7074
|
+
var condition = this.parseExpression();
|
|
7075
|
+
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
7076
|
+
this.advance();
|
|
7077
|
+
var thenExpressions = [];
|
|
7078
|
+
while (!this.isAtEnd()
|
|
7079
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'else')
|
|
7080
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7081
|
+
thenExpressions.push(this.parseExpression());
|
|
7082
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
7083
|
+
this.advance();
|
|
7084
|
+
}
|
|
7085
|
+
}
|
|
7086
|
+
var thenExpression = thenExpressions.length === 1
|
|
7087
|
+
? thenExpressions[0]
|
|
7088
|
+
: {
|
|
7089
|
+
t: AstNodeType.SpecialExpression,
|
|
7090
|
+
n: 'do',
|
|
7091
|
+
p: thenExpressions,
|
|
7092
|
+
token: getTokenDebugData(token) && token,
|
|
7093
|
+
};
|
|
7094
|
+
var elseExpression;
|
|
7095
|
+
if (isA_ReservedSymbolToken(this.peek(), 'else')) {
|
|
7096
|
+
this.advance();
|
|
7097
|
+
var elseExpressions = [];
|
|
7098
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7099
|
+
elseExpressions.push(this.parseExpression());
|
|
7100
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
7101
|
+
this.advance();
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
elseExpression = elseExpressions.length === 1
|
|
7105
|
+
? elseExpressions[0]
|
|
7106
|
+
: {
|
|
7107
|
+
t: AstNodeType.SpecialExpression,
|
|
7108
|
+
n: 'do',
|
|
7109
|
+
p: elseExpressions,
|
|
7110
|
+
token: getTokenDebugData(token) && token,
|
|
7111
|
+
};
|
|
7112
|
+
}
|
|
7113
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
7114
|
+
this.advance();
|
|
7115
|
+
var params = [condition, thenExpression];
|
|
7116
|
+
if (elseExpression) {
|
|
7117
|
+
params.push(elseExpression);
|
|
7118
|
+
}
|
|
7119
|
+
return {
|
|
7120
|
+
t: AstNodeType.SpecialExpression,
|
|
7121
|
+
n: isUnless ? 'unless' : 'if',
|
|
7122
|
+
p: params,
|
|
7123
|
+
token: getTokenDebugData(token) && token,
|
|
7124
|
+
};
|
|
7125
|
+
};
|
|
7126
|
+
AlgebraicParser.prototype.parseCond = function (token) {
|
|
7127
|
+
this.advance();
|
|
7128
|
+
var params = [];
|
|
7129
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7130
|
+
assertA_ReservedSymbolToken(this.peek(), 'case');
|
|
7131
|
+
this.advance();
|
|
7132
|
+
params.push(this.parseExpression());
|
|
7133
|
+
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
7134
|
+
this.advance();
|
|
7135
|
+
var expressions = [];
|
|
7136
|
+
while (!this.isAtEnd()
|
|
7137
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'case')
|
|
7138
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7139
|
+
expressions.push(this.parseExpression());
|
|
7140
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
7141
|
+
this.advance();
|
|
7142
|
+
}
|
|
7143
|
+
}
|
|
7144
|
+
params.push(expressions.length === 1
|
|
7145
|
+
? expressions[0]
|
|
7146
|
+
: {
|
|
7147
|
+
t: AstNodeType.SpecialExpression,
|
|
7148
|
+
n: 'do',
|
|
7149
|
+
p: expressions,
|
|
7150
|
+
token: getTokenDebugData(token) && token,
|
|
7151
|
+
});
|
|
7152
|
+
if (isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7153
|
+
break;
|
|
7154
|
+
}
|
|
7155
|
+
assertA_ReservedSymbolToken(this.peek(), 'case');
|
|
7156
|
+
}
|
|
7157
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
7158
|
+
this.advance();
|
|
7159
|
+
return {
|
|
7160
|
+
t: AstNodeType.SpecialExpression,
|
|
7161
|
+
n: 'cond',
|
|
7162
|
+
p: params,
|
|
7163
|
+
token: getTokenDebugData(token) && token,
|
|
7164
|
+
};
|
|
7165
|
+
};
|
|
7166
|
+
AlgebraicParser.prototype.parseSwitch = function (token) {
|
|
7167
|
+
this.advance();
|
|
7168
|
+
var params = [this.parseExpression()];
|
|
7169
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7170
|
+
assertA_ReservedSymbolToken(this.peek(), 'case');
|
|
7171
|
+
this.advance();
|
|
7172
|
+
params.push(this.parseExpression());
|
|
7173
|
+
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
7174
|
+
this.advance();
|
|
7175
|
+
var expressions = [];
|
|
7176
|
+
while (!this.isAtEnd()
|
|
7177
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'case')
|
|
7178
|
+
&& !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7179
|
+
expressions.push(this.parseExpression());
|
|
7180
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
7181
|
+
this.advance();
|
|
7182
|
+
}
|
|
7183
|
+
}
|
|
7184
|
+
params.push(expressions.length === 1
|
|
7185
|
+
? expressions[0]
|
|
7186
|
+
: {
|
|
7187
|
+
t: AstNodeType.SpecialExpression,
|
|
7188
|
+
n: 'do',
|
|
7189
|
+
p: expressions,
|
|
7190
|
+
token: getTokenDebugData(token) && token,
|
|
7191
|
+
});
|
|
7192
|
+
if (isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7193
|
+
break;
|
|
7194
|
+
}
|
|
7195
|
+
assertA_ReservedSymbolToken(this.peek(), 'case');
|
|
7196
|
+
}
|
|
7197
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
7198
|
+
this.advance();
|
|
7199
|
+
return {
|
|
7200
|
+
t: AstNodeType.SpecialExpression,
|
|
7201
|
+
n: 'switch',
|
|
7202
|
+
p: params,
|
|
7203
|
+
token: getTokenDebugData(token) && token,
|
|
7204
|
+
};
|
|
7205
|
+
};
|
|
7747
7206
|
AlgebraicParser.prototype.parseDef = function (token) {
|
|
7748
7207
|
this.advance();
|
|
7749
7208
|
var symbol = parseSymbol(this.tokenStream, this.parseState);
|
|
@@ -7758,22 +7217,17 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7758
7217
|
};
|
|
7759
7218
|
};
|
|
7760
7219
|
AlgebraicParser.prototype.parseDefn = function (token) {
|
|
7761
|
-
var _a;
|
|
7762
7220
|
this.advance();
|
|
7763
7221
|
var symbol = parseSymbol(this.tokenStream, this.parseState);
|
|
7764
|
-
var
|
|
7765
|
-
assertLBraceToken(this.peek());
|
|
7766
|
-
this.advance();
|
|
7222
|
+
var _a = this.parseFunctionArguments(), functionArguments = _a.functionArguments, arity = _a.arity;
|
|
7767
7223
|
var body = [];
|
|
7768
|
-
while (!this.isAtEnd() && !
|
|
7224
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
7769
7225
|
body.push(this.parseExpression());
|
|
7770
7226
|
if (isA_OperatorToken(this.peek(), ';')) {
|
|
7771
7227
|
this.advance();
|
|
7772
7228
|
}
|
|
7773
7229
|
}
|
|
7774
|
-
|
|
7775
|
-
throw new LitsError('Expected closing brace', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7776
|
-
}
|
|
7230
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
7777
7231
|
this.advance();
|
|
7778
7232
|
return {
|
|
7779
7233
|
t: AstNodeType.SpecialExpression,
|
|
@@ -7791,12 +7245,25 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7791
7245
|
AlgebraicParser.prototype.isAtEnd = function () {
|
|
7792
7246
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
7793
7247
|
};
|
|
7248
|
+
AlgebraicParser.prototype.isAtExpressionEnd = function () {
|
|
7249
|
+
if (this.isAtEnd()) {
|
|
7250
|
+
return true;
|
|
7251
|
+
}
|
|
7252
|
+
var token = this.peek();
|
|
7253
|
+
if (isA_OperatorToken(token)) {
|
|
7254
|
+
return [';', ','].includes(token[1]);
|
|
7255
|
+
}
|
|
7256
|
+
if (isA_SymbolToken(token)) {
|
|
7257
|
+
return ['catch'].includes(token[1]);
|
|
7258
|
+
}
|
|
7259
|
+
if (isA_ReservedSymbolToken(token)) {
|
|
7260
|
+
return ['else', 'when', 'while', 'then', 'end', 'case'].includes(token[1]);
|
|
7261
|
+
}
|
|
7262
|
+
return false;
|
|
7263
|
+
};
|
|
7794
7264
|
AlgebraicParser.prototype.peek = function () {
|
|
7795
7265
|
return this.tokenStream.tokens[this.parseState.position];
|
|
7796
7266
|
};
|
|
7797
|
-
AlgebraicParser.prototype.peekAhead = function () {
|
|
7798
|
-
return this.tokenStream.tokens[this.parseState.position + 1];
|
|
7799
|
-
};
|
|
7800
7267
|
return AlgebraicParser;
|
|
7801
7268
|
}());
|
|
7802
7269
|
|
|
@@ -8169,7 +7636,7 @@ function parseToken(tokenStream, parseState) {
|
|
|
8169
7636
|
return parsePolishToken(tokenStream, parseState);
|
|
8170
7637
|
}
|
|
8171
7638
|
|
|
8172
|
-
var polishIdentifierCharacterClass = '[\\w
|
|
7639
|
+
var polishIdentifierCharacterClass = '[\\w@%^?=!$<>+*/:&\|~-]';
|
|
8173
7640
|
var algebraicIdentifierCharacterClass = '[\\w$:!?]';
|
|
8174
7641
|
var algebraicIdentifierFirstCharacterClass = '[a-zA-Z_$]';
|
|
8175
7642
|
|
|
@@ -8249,22 +7716,23 @@ var commonTokenizers = [
|
|
|
8249
7716
|
tokenizeString,
|
|
8250
7717
|
];
|
|
8251
7718
|
|
|
8252
|
-
var
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
'recur': { value: null, forbidden: true },
|
|
8264
|
-
'loop': { value: null, forbidden: true },
|
|
8265
|
-
'time!': { value: null, forbidden: true },
|
|
8266
|
-
'doseq': { value: null, forbidden: true },
|
|
7719
|
+
var validAlgebraicReservedNamesRecord = {
|
|
7720
|
+
true: { value: true, forbidden: false },
|
|
7721
|
+
false: { value: false, forbidden: false },
|
|
7722
|
+
nil: { value: null, forbidden: false },
|
|
7723
|
+
null: { value: null, forbidden: false },
|
|
7724
|
+
then: { value: null, forbidden: false },
|
|
7725
|
+
else: { value: null, forbidden: false },
|
|
7726
|
+
end: { value: null, forbidden: false },
|
|
7727
|
+
case: { value: null, forbidden: false },
|
|
7728
|
+
when: { value: null, forbidden: false },
|
|
7729
|
+
while: { value: null, forbidden: false },
|
|
8267
7730
|
};
|
|
7731
|
+
var forbiddenAlgebraicReservedNamesRecord = {
|
|
7732
|
+
fn: { value: null, forbidden: true },
|
|
7733
|
+
defns: { value: null, forbidden: true },
|
|
7734
|
+
};
|
|
7735
|
+
var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
|
|
8268
7736
|
|
|
8269
7737
|
var identifierRegExp = new RegExp(algebraicIdentifierCharacterClass);
|
|
8270
7738
|
var identifierFirstCharacterRegExp = new RegExp(algebraicIdentifierFirstCharacterClass);
|
|
@@ -8336,45 +7804,19 @@ var tokenizeA_BasePrefixedNumber = function (input, position) {
|
|
|
8336
7804
|
}
|
|
8337
7805
|
return [length, ['A_BasePrefixedNumber', input.substring(position, i)]];
|
|
8338
7806
|
};
|
|
8339
|
-
var tokenizeA_ReservedSymbolToken = function (input, position) {
|
|
8340
|
-
var e_1, _a;
|
|
8341
|
-
try {
|
|
8342
|
-
for (var _b = __values(Object.entries(algebraicReservedNamesRecord)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8343
|
-
var _d = __read(_c.value, 2), reservedName = _d[0], forbidden = _d[1].forbidden;
|
|
8344
|
-
var length_1 = reservedName.length;
|
|
8345
|
-
var nextChar = input[position + length_1];
|
|
8346
|
-
if (nextChar && identifierRegExp.test(nextChar))
|
|
8347
|
-
continue;
|
|
8348
|
-
var name_1 = input.substring(position, position + length_1);
|
|
8349
|
-
if (name_1 === reservedName) {
|
|
8350
|
-
if (forbidden)
|
|
8351
|
-
throw new LitsError("".concat(name_1, " is forbidden!"), undefined);
|
|
8352
|
-
return [length_1, ['A_ReservedSymbol', reservedName]];
|
|
8353
|
-
}
|
|
8354
|
-
}
|
|
8355
|
-
}
|
|
8356
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8357
|
-
finally {
|
|
8358
|
-
try {
|
|
8359
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8360
|
-
}
|
|
8361
|
-
finally { if (e_1) throw e_1.error; }
|
|
8362
|
-
}
|
|
8363
|
-
return NO_MATCH;
|
|
8364
|
-
};
|
|
8365
7807
|
var tokenizeA_Symbol = function (input, position) {
|
|
8366
7808
|
var value = input[position];
|
|
8367
7809
|
if (!value) {
|
|
8368
7810
|
return NO_MATCH;
|
|
8369
7811
|
}
|
|
8370
7812
|
if (value === '\'') {
|
|
8371
|
-
var
|
|
8372
|
-
var char = input[position +
|
|
7813
|
+
var length_1 = 1;
|
|
7814
|
+
var char = input[position + length_1];
|
|
8373
7815
|
var escaping = false;
|
|
8374
7816
|
while (char !== '\'' || escaping) {
|
|
8375
7817
|
if (char === undefined)
|
|
8376
7818
|
throw new LitsError("Unclosed string at position ".concat(position, "."), undefined);
|
|
8377
|
-
|
|
7819
|
+
length_1 += 1;
|
|
8378
7820
|
if (escaping) {
|
|
8379
7821
|
escaping = false;
|
|
8380
7822
|
value += char;
|
|
@@ -8385,10 +7827,10 @@ var tokenizeA_Symbol = function (input, position) {
|
|
|
8385
7827
|
}
|
|
8386
7828
|
value += char;
|
|
8387
7829
|
}
|
|
8388
|
-
char = input[position +
|
|
7830
|
+
char = input[position + length_1];
|
|
8389
7831
|
}
|
|
8390
7832
|
value += '\''; // closing quote
|
|
8391
|
-
return [
|
|
7833
|
+
return [length_1 + 1, ['A_Symbol', value]];
|
|
8392
7834
|
}
|
|
8393
7835
|
if (identifierFirstCharacterRegExp.test(value)) {
|
|
8394
7836
|
var initialPosition = position;
|
|
@@ -8403,6 +7845,22 @@ var tokenizeA_Symbol = function (input, position) {
|
|
|
8403
7845
|
}
|
|
8404
7846
|
return NO_MATCH;
|
|
8405
7847
|
};
|
|
7848
|
+
var tokenizeA_ReservedSymbolToken = function (input, position) {
|
|
7849
|
+
var symbolMeta = tokenizeA_Symbol(input, position);
|
|
7850
|
+
if (symbolMeta[0] === 0 || !symbolMeta[1]) {
|
|
7851
|
+
return NO_MATCH;
|
|
7852
|
+
}
|
|
7853
|
+
var symbolName = symbolMeta[1][1];
|
|
7854
|
+
symbolName = symbolName.startsWith('\'') ? symbolName.slice(1, symbolName.length - 1) : symbolName;
|
|
7855
|
+
var info = algebraicReservedNamesRecord[symbolName];
|
|
7856
|
+
if (!info) {
|
|
7857
|
+
return NO_MATCH;
|
|
7858
|
+
}
|
|
7859
|
+
if (info.forbidden) {
|
|
7860
|
+
throw new LitsError("".concat(symbolName, " is forbidden!"), undefined);
|
|
7861
|
+
}
|
|
7862
|
+
return [symbolMeta[0], ['A_ReservedSymbol', symbolName]];
|
|
7863
|
+
};
|
|
8406
7864
|
var tokenizeA_Operator = function (input, position) {
|
|
8407
7865
|
var _a;
|
|
8408
7866
|
var threeChars = input.slice(position, position + 3);
|
|
@@ -8421,30 +7879,30 @@ var tokenizeA_Operator = function (input, position) {
|
|
|
8421
7879
|
};
|
|
8422
7880
|
var tokenizeA_MultiLineComment = function (input, position) {
|
|
8423
7881
|
if (input[position] === '/' && input[position + 1] === '*') {
|
|
8424
|
-
var
|
|
7882
|
+
var length_2 = 2;
|
|
8425
7883
|
var value = '/*';
|
|
8426
|
-
while (input[position +
|
|
8427
|
-
value += input[position +
|
|
8428
|
-
|
|
7884
|
+
while (input[position + length_2] !== '*' && input[position + length_2 + 1] !== '/' && position + length_2 + 1 < input.length) {
|
|
7885
|
+
value += input[position + length_2];
|
|
7886
|
+
length_2 += 1;
|
|
8429
7887
|
}
|
|
8430
|
-
if (position +
|
|
7888
|
+
if (position + length_2 + 1 >= input.length) {
|
|
8431
7889
|
throw new LitsError('Comment not closed', undefined);
|
|
8432
7890
|
}
|
|
8433
7891
|
value += '*/';
|
|
8434
|
-
|
|
8435
|
-
return [
|
|
7892
|
+
length_2 += 2;
|
|
7893
|
+
return [length_2, ['A_MultiLineComment', value]];
|
|
8436
7894
|
}
|
|
8437
7895
|
return NO_MATCH;
|
|
8438
7896
|
};
|
|
8439
7897
|
var tokenizeA_SingleLineComment = function (input, position) {
|
|
8440
7898
|
if (input[position] === '/' && input[position + 1] === '/') {
|
|
8441
|
-
var
|
|
7899
|
+
var length_3 = 2;
|
|
8442
7900
|
var value = '//';
|
|
8443
|
-
while (input[position +
|
|
8444
|
-
value += input[position +
|
|
8445
|
-
|
|
7901
|
+
while (input[position + length_3] !== '\n' && position + length_3 < input.length) {
|
|
7902
|
+
value += input[position + length_3];
|
|
7903
|
+
length_3 += 1;
|
|
8446
7904
|
}
|
|
8447
|
-
return [
|
|
7905
|
+
return [length_3, ['A_SingleLineComment', value]];
|
|
8448
7906
|
}
|
|
8449
7907
|
return NO_MATCH;
|
|
8450
7908
|
};
|
|
@@ -8604,31 +8062,20 @@ var tokenizeP_FnShorthand = function (input, position) {
|
|
|
8604
8062
|
return [1, ['P_FnShorthand']];
|
|
8605
8063
|
};
|
|
8606
8064
|
var tokenizeP_ReservedSymbol = function (input, position) {
|
|
8607
|
-
var
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
var _d = __read(_c.value, 2), reservedName = _d[0], forbidden = _d[1].forbidden;
|
|
8611
|
-
var length_3 = reservedName.length;
|
|
8612
|
-
var nextChar = input[position + length_3];
|
|
8613
|
-
if (nextChar && P_symbolRegExp.test(nextChar)) {
|
|
8614
|
-
continue;
|
|
8615
|
-
}
|
|
8616
|
-
var symbol = input.substring(position, position + length_3);
|
|
8617
|
-
if (symbol === reservedName) {
|
|
8618
|
-
if (forbidden)
|
|
8619
|
-
throw new LitsError("".concat(symbol, " is forbidden!"), undefined);
|
|
8620
|
-
return [length_3, ['P_ReservedSymbol', reservedName]];
|
|
8621
|
-
}
|
|
8622
|
-
}
|
|
8065
|
+
var symbolMeta = tokenizeP_Symbol(input, position);
|
|
8066
|
+
if (symbolMeta[0] === 0 || !symbolMeta[1]) {
|
|
8067
|
+
return NO_MATCH;
|
|
8623
8068
|
}
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
finally { if (e_1) throw e_1.error; }
|
|
8069
|
+
var symbolName = symbolMeta[1][1];
|
|
8070
|
+
symbolName = symbolName.startsWith('\'') ? symbolName.slice(1, symbolName.length - 1) : symbolName;
|
|
8071
|
+
var info = polishReservedNamesRecord[symbolName];
|
|
8072
|
+
if (!info) {
|
|
8073
|
+
return NO_MATCH;
|
|
8630
8074
|
}
|
|
8631
|
-
|
|
8075
|
+
if (info.forbidden) {
|
|
8076
|
+
throw new LitsError("".concat(symbolName, " is forbidden!"), undefined);
|
|
8077
|
+
}
|
|
8078
|
+
return [symbolMeta[0], ['P_ReservedSymbol', symbolName]];
|
|
8632
8079
|
};
|
|
8633
8080
|
var tokenizeP_StringShorthand = function (input, position) {
|
|
8634
8081
|
if (input[position] !== ':')
|
|
@@ -8641,24 +8088,24 @@ var tokenizeP_StringShorthand = function (input, position) {
|
|
|
8641
8088
|
return [symbolDescription[0] + 1, ['P_StringShorthand', ":".concat(symbolToken[1])]];
|
|
8642
8089
|
};
|
|
8643
8090
|
var tokenizeP_Modifier = function (input, position) {
|
|
8644
|
-
var
|
|
8091
|
+
var e_1, _a;
|
|
8645
8092
|
try {
|
|
8646
8093
|
for (var modifierNames_1 = __values(modifierNames), modifierNames_1_1 = modifierNames_1.next(); !modifierNames_1_1.done; modifierNames_1_1 = modifierNames_1.next()) {
|
|
8647
8094
|
var modifierName = modifierNames_1_1.value;
|
|
8648
|
-
var
|
|
8649
|
-
var charAfterModifier = input[position +
|
|
8650
|
-
if (input.substring(position, position +
|
|
8095
|
+
var length_3 = modifierName.length;
|
|
8096
|
+
var charAfterModifier = input[position + length_3];
|
|
8097
|
+
if (input.substring(position, position + length_3) === modifierName && (!charAfterModifier || !P_symbolRegExp.test(charAfterModifier))) {
|
|
8651
8098
|
var value = modifierName;
|
|
8652
|
-
return [
|
|
8099
|
+
return [length_3, ['P_Modifier', value]];
|
|
8653
8100
|
}
|
|
8654
8101
|
}
|
|
8655
8102
|
}
|
|
8656
|
-
catch (
|
|
8103
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8657
8104
|
finally {
|
|
8658
8105
|
try {
|
|
8659
8106
|
if (modifierNames_1_1 && !modifierNames_1_1.done && (_a = modifierNames_1.return)) _a.call(modifierNames_1);
|
|
8660
8107
|
}
|
|
8661
|
-
finally { if (
|
|
8108
|
+
finally { if (e_1) throw e_1.error; }
|
|
8662
8109
|
}
|
|
8663
8110
|
return NO_MATCH;
|
|
8664
8111
|
};
|
|
@@ -8695,8 +8142,8 @@ var polishTokenizers = __spreadArray(__spreadArray([
|
|
|
8695
8142
|
tokenizeP_StringShorthand,
|
|
8696
8143
|
tokenizeP_Number,
|
|
8697
8144
|
tokenizeP_ReservedSymbol,
|
|
8698
|
-
tokenizeP_Symbol,
|
|
8699
8145
|
tokenizeP_Modifier,
|
|
8146
|
+
tokenizeP_Symbol,
|
|
8700
8147
|
tokenizeP_RegexpShorthand,
|
|
8701
8148
|
tokenizeP_FnShorthand,
|
|
8702
8149
|
tokenizeP_CollectionAccessor,
|