@mojir/lits 2.0.15 → 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 +318 -1113
- package/dist/cli/reference/api.d.ts +2 -2
- package/dist/cli/src/analyze/index.d.ts +0 -2
- package/dist/cli/src/builtin/index.d.ts +3 -8
- package/dist/cli/src/builtin/specialExpressions/declared.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/try.d.ts +1 -1
- package/dist/{src/builtin/specialExpressions/if_not.d.ts → cli/src/builtin/specialExpressions/unless.d.ts} +2 -2
- package/dist/cli/src/evaluator/ContextStack.d.ts +2 -0
- package/dist/cli/src/parser/AlgebraicParser.d.ts +7 -2
- package/dist/cli/src/tokenizer/algebraic/algebraicReservedNames.d.ts +14 -26
- package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +3 -3
- package/dist/index.esm.js +318 -1113
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +318 -1113
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +318 -1113
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +2 -2
- package/dist/src/analyze/index.d.ts +0 -2
- package/dist/src/builtin/index.d.ts +3 -8
- package/dist/src/builtin/specialExpressions/declared.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/try.d.ts +1 -1
- package/dist/{cli/src/builtin/specialExpressions/if_not.d.ts → src/builtin/specialExpressions/unless.d.ts} +2 -2
- package/dist/src/evaluator/ContextStack.d.ts +2 -0
- package/dist/src/parser/AlgebraicParser.d.ts +7 -2
- package/dist/src/tokenizer/algebraic/algebraicReservedNames.d.ts +14 -26
- package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +3 -3
- package/dist/testFramework.esm.js +285 -937
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +285 -937
- 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/calculateSwitchOutcomes.d.ts +0 -3
- package/dist/cli/src/analyze/calculateOutcomes/calculateThrowOutcomes.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.d.ts +0 -6
- 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/calculateSwitchOutcomes.d.ts +0 -3
- package/dist/src/analyze/calculateOutcomes/calculateThrowOutcomes.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/when.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/testFramework.js
CHANGED
|
@@ -428,20 +428,15 @@ var nonFunctionOperators = [
|
|
|
428
428
|
'&&',
|
|
429
429
|
'comment',
|
|
430
430
|
'cond',
|
|
431
|
-
'
|
|
431
|
+
'defined?',
|
|
432
432
|
'if',
|
|
433
|
-
'
|
|
433
|
+
'unless',
|
|
434
434
|
'||',
|
|
435
|
-
'when',
|
|
436
|
-
'when_not',
|
|
437
435
|
'do',
|
|
438
436
|
'throw',
|
|
439
437
|
'let',
|
|
440
438
|
'def',
|
|
441
439
|
'defs',
|
|
442
|
-
'if_let',
|
|
443
|
-
'when_let',
|
|
444
|
-
'when_first',
|
|
445
440
|
'fn',
|
|
446
441
|
'defn',
|
|
447
442
|
'defns',
|
|
@@ -467,16 +462,22 @@ var symbolicOperatorSet = new Set(symbolicOperators);
|
|
|
467
462
|
function isSymbolicOperator(operator) {
|
|
468
463
|
return symbolicOperatorSet.has(operator);
|
|
469
464
|
}
|
|
470
|
-
function isA_SymbolToken(token) {
|
|
471
|
-
|
|
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;
|
|
472
473
|
}
|
|
473
|
-
function assertA_SymbolToken(token) {
|
|
474
|
-
if (!isA_SymbolToken(token)) {
|
|
474
|
+
function assertA_SymbolToken(token, symbolName) {
|
|
475
|
+
if (!isA_SymbolToken(token, symbolName)) {
|
|
475
476
|
throwUnexpectedToken('A_Symbol', undefined, token);
|
|
476
477
|
}
|
|
477
478
|
}
|
|
478
|
-
function asA_SymbolToken(token) {
|
|
479
|
-
assertA_SymbolToken(token);
|
|
479
|
+
function asA_SymbolToken(token, symbolName) {
|
|
480
|
+
assertA_SymbolToken(token, symbolName);
|
|
480
481
|
return token;
|
|
481
482
|
}
|
|
482
483
|
function isA_BinaryOperatorToken(token) {
|
|
@@ -839,7 +840,7 @@ var specialExpressionCommentRemovers = {
|
|
|
839
840
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
840
841
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
841
842
|
},
|
|
842
|
-
'
|
|
843
|
+
'defined?': function (node, removeOptions) {
|
|
843
844
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
844
845
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
845
846
|
},
|
|
@@ -860,12 +861,11 @@ var specialExpressionCommentRemovers = {
|
|
|
860
861
|
'doseq': function (_node, _removeOptions) { },
|
|
861
862
|
'fn': function (_node, _removeOptions) { },
|
|
862
863
|
'for': function (_node, _removeOptions) { },
|
|
863
|
-
'if_let': function (_node, _removeOptions) { },
|
|
864
864
|
'if': function (node, removeOptions) {
|
|
865
865
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
866
866
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
867
867
|
},
|
|
868
|
-
'
|
|
868
|
+
'unless': function (node, removeOptions) {
|
|
869
869
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
870
870
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
871
871
|
},
|
|
@@ -894,10 +894,6 @@ var specialExpressionCommentRemovers = {
|
|
|
894
894
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
895
895
|
},
|
|
896
896
|
'try': function (_node, _removeOptions) { },
|
|
897
|
-
'when_first': function (_node, _removeOptions) { },
|
|
898
|
-
'when_let': function (_node, _removeOptions) { },
|
|
899
|
-
'when': function (_node, _removeOptions) { },
|
|
900
|
-
'when_not': function (_node, _removeOptions) { },
|
|
901
897
|
};
|
|
902
898
|
function removeCommentNodesFromSpecialExpression(node, removeOptions) {
|
|
903
899
|
var uncommenter = specialExpressionCommentRemovers[node.n];
|
|
@@ -4407,7 +4403,7 @@ var switchSpecialExpression = {
|
|
|
4407
4403
|
};
|
|
4408
4404
|
|
|
4409
4405
|
var declaredSpecialExpression = {
|
|
4410
|
-
polishParse: getCommonPolishSpecialExpressionParser('
|
|
4406
|
+
polishParse: getCommonPolishSpecialExpressionParser('defined?'),
|
|
4411
4407
|
validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
|
|
4412
4408
|
evaluate: function (node, contextStack) {
|
|
4413
4409
|
var lookUpResult = contextStack.lookUp(node.p[0]);
|
|
@@ -4462,9 +4458,7 @@ var defSpecialExpression = {
|
|
|
4462
4458
|
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4463
4459
|
var name = node.p[0].v;
|
|
4464
4460
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4465
|
-
contextStack.
|
|
4466
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4467
|
-
};
|
|
4461
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4468
4462
|
return null;
|
|
4469
4463
|
},
|
|
4470
4464
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4475,7 +4469,7 @@ var defSpecialExpression = {
|
|
|
4475
4469
|
var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
|
|
4476
4470
|
var name = asSymbolNode(node.p[0]).v;
|
|
4477
4471
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4478
|
-
contextStack.
|
|
4472
|
+
contextStack.exportValue(name, true);
|
|
4479
4473
|
return result;
|
|
4480
4474
|
},
|
|
4481
4475
|
};
|
|
@@ -4501,9 +4495,7 @@ var defsSpecialExpression = {
|
|
|
4501
4495
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4502
4496
|
assertString(name, sourceCodeInfo);
|
|
4503
4497
|
assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
4504
|
-
contextStack.
|
|
4505
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4506
|
-
};
|
|
4498
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4507
4499
|
return null;
|
|
4508
4500
|
},
|
|
4509
4501
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4515,7 +4507,7 @@ var defsSpecialExpression = {
|
|
|
4515
4507
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4516
4508
|
assertString(name, sourceCodeInfo);
|
|
4517
4509
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4518
|
-
contextStack.
|
|
4510
|
+
contextStack.exportValue(name, true);
|
|
4519
4511
|
return result;
|
|
4520
4512
|
},
|
|
4521
4513
|
};
|
|
@@ -4546,7 +4538,7 @@ var doSpecialExpression = {
|
|
|
4546
4538
|
},
|
|
4547
4539
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4548
4540
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4549
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
4541
|
+
return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
|
|
4550
4542
|
},
|
|
4551
4543
|
};
|
|
4552
4544
|
|
|
@@ -4575,11 +4567,6 @@ function joinAnalyzeResults() {
|
|
|
4575
4567
|
function addAnalyzeResults(target, source) {
|
|
4576
4568
|
source.forEach(function (symbol) { return target.add(symbol); });
|
|
4577
4569
|
}
|
|
4578
|
-
function combinate(arrays) {
|
|
4579
|
-
return arrays.reduce(function (acc, curr) {
|
|
4580
|
-
return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
|
|
4581
|
-
}, [[]]);
|
|
4582
|
-
}
|
|
4583
4570
|
|
|
4584
4571
|
var defnSpecialExpression = {
|
|
4585
4572
|
polishParse: function (tokenStream, parseState, firstToken, parsers) {
|
|
@@ -4614,13 +4601,13 @@ var defnSpecialExpression = {
|
|
|
4614
4601
|
_b.n = name,
|
|
4615
4602
|
_b.o = evaluatedFunctionOverloades,
|
|
4616
4603
|
_b);
|
|
4617
|
-
contextStack.
|
|
4604
|
+
contextStack.exportValue(name, litsFunction);
|
|
4618
4605
|
return null;
|
|
4619
4606
|
},
|
|
4620
4607
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4621
4608
|
var _b;
|
|
4622
4609
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4623
|
-
contextStack.
|
|
4610
|
+
contextStack.exportValue(node.f.v, true);
|
|
4624
4611
|
var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
|
|
4625
4612
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4626
4613
|
},
|
|
@@ -4656,7 +4643,7 @@ var defnsSpecialExpression = {
|
|
|
4656
4643
|
_b.n = name,
|
|
4657
4644
|
_b.o = evaluatedFunctionOverloades,
|
|
4658
4645
|
_b);
|
|
4659
|
-
contextStack.
|
|
4646
|
+
contextStack.exportValue(name, litsFunction);
|
|
4660
4647
|
return null;
|
|
4661
4648
|
},
|
|
4662
4649
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4667,7 +4654,7 @@ var defnsSpecialExpression = {
|
|
|
4667
4654
|
var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
|
|
4668
4655
|
assertString(name, sourceCodeInfo);
|
|
4669
4656
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4670
|
-
contextStack.
|
|
4657
|
+
contextStack.exportValue(name, true);
|
|
4671
4658
|
var newContext = (_b = {}, _b[name] = { value: true }, _b);
|
|
4672
4659
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4673
4660
|
},
|
|
@@ -4940,56 +4927,8 @@ var ifSpecialExpression = {
|
|
|
4940
4927
|
},
|
|
4941
4928
|
};
|
|
4942
4929
|
|
|
4943
|
-
var
|
|
4944
|
-
polishParse:
|
|
4945
|
-
var _b, _c;
|
|
4946
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
4947
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
4948
|
-
if (bindings.length !== 1) {
|
|
4949
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
4950
|
-
}
|
|
4951
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
4952
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4953
|
-
var node = {
|
|
4954
|
-
t: AstNodeType.SpecialExpression,
|
|
4955
|
-
n: 'if_let',
|
|
4956
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
4957
|
-
p: params,
|
|
4958
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
4959
|
-
};
|
|
4960
|
-
return node;
|
|
4961
|
-
},
|
|
4962
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
4963
|
-
evaluate: function (node, contextStack, _a) {
|
|
4964
|
-
var _b;
|
|
4965
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
4966
|
-
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4967
|
-
var locals = {};
|
|
4968
|
-
var bindingValue = evaluateAstNode(node.b.v, contextStack);
|
|
4969
|
-
if (bindingValue) {
|
|
4970
|
-
locals[node.b.n] = { value: bindingValue };
|
|
4971
|
-
var newContextStack = contextStack.create(locals);
|
|
4972
|
-
var thenForm = asAstNode(node.p[0], sourceCodeInfo);
|
|
4973
|
-
return evaluateAstNode(thenForm, newContextStack);
|
|
4974
|
-
}
|
|
4975
|
-
if (node.p.length === 2) {
|
|
4976
|
-
var elseForm = asAstNode(node.p[1], sourceCodeInfo);
|
|
4977
|
-
return evaluateAstNode(elseForm, contextStack);
|
|
4978
|
-
}
|
|
4979
|
-
return null;
|
|
4980
|
-
},
|
|
4981
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4982
|
-
var _b;
|
|
4983
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4984
|
-
var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
|
|
4985
|
-
var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
|
|
4986
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
4987
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
4988
|
-
},
|
|
4989
|
-
};
|
|
4990
|
-
|
|
4991
|
-
var ifNotSpecialExpression = {
|
|
4992
|
-
polishParse: getCommonPolishSpecialExpressionParser('if_not'),
|
|
4930
|
+
var unlessSpecialExpression = {
|
|
4931
|
+
polishParse: getCommonPolishSpecialExpressionParser('unless'),
|
|
4993
4932
|
validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
4994
4933
|
evaluate: function (node, contextStack, _a) {
|
|
4995
4934
|
var _b;
|
|
@@ -5014,55 +4953,39 @@ var ifNotSpecialExpression = {
|
|
|
5014
4953
|
|
|
5015
4954
|
var letSpecialExpression = {
|
|
5016
4955
|
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5017
|
-
var parseBindings = _a.parseBindings
|
|
4956
|
+
var parseBindings = _a.parseBindings;
|
|
5018
4957
|
var bindings = parseBindings(tokenStream, parseState);
|
|
5019
|
-
|
|
4958
|
+
// const params = parseTokensUntilClosingBracket(tokenStream, parseState)
|
|
5020
4959
|
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5021
4960
|
var node = {
|
|
5022
4961
|
t: AstNodeType.SpecialExpression,
|
|
5023
4962
|
n: 'let',
|
|
5024
|
-
p:
|
|
4963
|
+
p: [],
|
|
5025
4964
|
bs: bindings,
|
|
5026
4965
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
5027
4966
|
};
|
|
5028
4967
|
return node;
|
|
5029
4968
|
},
|
|
5030
|
-
validateParameterCount: function () { return
|
|
4969
|
+
validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
|
|
5031
4970
|
evaluate: function (node, contextStack, _a) {
|
|
5032
|
-
var e_1, _b
|
|
4971
|
+
var e_1, _b;
|
|
5033
4972
|
var evaluateAstNode = _a.evaluateAstNode;
|
|
5034
|
-
var locals = {};
|
|
5035
|
-
var newContextStack = contextStack.create(locals);
|
|
5036
4973
|
try {
|
|
5037
|
-
for (var
|
|
5038
|
-
var binding =
|
|
4974
|
+
for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4975
|
+
var binding = _d.value;
|
|
5039
4976
|
var bindingValueNode = binding.v;
|
|
5040
|
-
var bindingValue = evaluateAstNode(bindingValueNode,
|
|
5041
|
-
|
|
4977
|
+
var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
|
|
4978
|
+
contextStack.addValue(binding.n, bindingValue);
|
|
5042
4979
|
}
|
|
5043
4980
|
}
|
|
5044
4981
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5045
4982
|
finally {
|
|
5046
4983
|
try {
|
|
5047
|
-
if (
|
|
4984
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5048
4985
|
}
|
|
5049
4986
|
finally { if (e_1) throw e_1.error; }
|
|
5050
4987
|
}
|
|
5051
|
-
|
|
5052
|
-
try {
|
|
5053
|
-
for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
5054
|
-
var astNode = _g.value;
|
|
5055
|
-
result = evaluateAstNode(astNode, newContextStack);
|
|
5056
|
-
}
|
|
5057
|
-
}
|
|
5058
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5059
|
-
finally {
|
|
5060
|
-
try {
|
|
5061
|
-
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
5062
|
-
}
|
|
5063
|
-
finally { if (e_2) throw e_2.error; }
|
|
5064
|
-
}
|
|
5065
|
-
return result;
|
|
4988
|
+
return null;
|
|
5066
4989
|
},
|
|
5067
4990
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5068
4991
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
@@ -5072,11 +4995,10 @@ var letSpecialExpression = {
|
|
|
5072
4995
|
context[name] = { value: true };
|
|
5073
4996
|
return context;
|
|
5074
4997
|
}, {});
|
|
5075
|
-
var bindingContext = {};
|
|
5076
4998
|
var bindingResults = node.bs.map(function (bindingNode) {
|
|
5077
4999
|
var valueNode = bindingNode.v;
|
|
5078
|
-
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack
|
|
5079
|
-
|
|
5000
|
+
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
|
|
5001
|
+
contextStack.addValue(bindingNode.n, { value: true });
|
|
5080
5002
|
return bindingsResult;
|
|
5081
5003
|
});
|
|
5082
5004
|
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
@@ -5527,9 +5449,10 @@ var trySpecialExpression = {
|
|
|
5527
5449
|
return evaluateAstNode(tryExpressions[0], contextStack);
|
|
5528
5450
|
}
|
|
5529
5451
|
catch (error) {
|
|
5530
|
-
var newContext =
|
|
5531
|
-
_b
|
|
5532
|
-
|
|
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) : {};
|
|
5533
5456
|
return evaluateAstNode(catchExpression, contextStack.create(newContext));
|
|
5534
5457
|
}
|
|
5535
5458
|
},
|
|
@@ -5538,199 +5461,15 @@ var trySpecialExpression = {
|
|
|
5538
5461
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5539
5462
|
var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
|
|
5540
5463
|
var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
|
|
5541
|
-
var newContext =
|
|
5542
|
-
_b
|
|
5543
|
-
|
|
5464
|
+
var newContext = errorNode
|
|
5465
|
+
? (_b = {},
|
|
5466
|
+
_b[errorNode.v] = { value: true },
|
|
5467
|
+
_b) : {};
|
|
5544
5468
|
var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
|
|
5545
5469
|
return joinAnalyzeResults(tryResult, catchResult);
|
|
5546
5470
|
},
|
|
5547
5471
|
};
|
|
5548
5472
|
|
|
5549
|
-
var whenSpecialExpression = {
|
|
5550
|
-
polishParse: getCommonPolishSpecialExpressionParser('when'),
|
|
5551
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5552
|
-
evaluate: function (node, contextStack, _a) {
|
|
5553
|
-
var e_1, _b;
|
|
5554
|
-
var _c;
|
|
5555
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5556
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5557
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5558
|
-
if (!evaluateAstNode(whenExpression, contextStack))
|
|
5559
|
-
return null;
|
|
5560
|
-
var result = null;
|
|
5561
|
-
try {
|
|
5562
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5563
|
-
var form = body_1_1.value;
|
|
5564
|
-
result = evaluateAstNode(form, contextStack);
|
|
5565
|
-
}
|
|
5566
|
-
}
|
|
5567
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5568
|
-
finally {
|
|
5569
|
-
try {
|
|
5570
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5571
|
-
}
|
|
5572
|
-
finally { if (e_1) throw e_1.error; }
|
|
5573
|
-
}
|
|
5574
|
-
return result;
|
|
5575
|
-
},
|
|
5576
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5577
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5578
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5579
|
-
},
|
|
5580
|
-
};
|
|
5581
|
-
|
|
5582
|
-
var whenFirstSpecialExpression = {
|
|
5583
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5584
|
-
var _b, _c;
|
|
5585
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5586
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5587
|
-
if (bindings.length !== 1) {
|
|
5588
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5589
|
-
}
|
|
5590
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5591
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5592
|
-
var node = {
|
|
5593
|
-
t: AstNodeType.SpecialExpression,
|
|
5594
|
-
n: 'when_first',
|
|
5595
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5596
|
-
p: params,
|
|
5597
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5598
|
-
};
|
|
5599
|
-
return node;
|
|
5600
|
-
},
|
|
5601
|
-
validateParameterCount: function () { return undefined; },
|
|
5602
|
-
evaluate: function (node, contextStack, _a) {
|
|
5603
|
-
var e_1, _b;
|
|
5604
|
-
var _c;
|
|
5605
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5606
|
-
var locals = {};
|
|
5607
|
-
var binding = node.b;
|
|
5608
|
-
var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
|
|
5609
|
-
if (!isSeq(evaluatedBindingForm)) {
|
|
5610
|
-
throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5611
|
-
}
|
|
5612
|
-
if (evaluatedBindingForm.length === 0)
|
|
5613
|
-
return null;
|
|
5614
|
-
var bindingValue = toAny(evaluatedBindingForm[0]);
|
|
5615
|
-
locals[binding.n] = { value: bindingValue };
|
|
5616
|
-
var newContextStack = contextStack.create(locals);
|
|
5617
|
-
var result = null;
|
|
5618
|
-
try {
|
|
5619
|
-
for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
5620
|
-
var form = _e.value;
|
|
5621
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5622
|
-
}
|
|
5623
|
-
}
|
|
5624
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5625
|
-
finally {
|
|
5626
|
-
try {
|
|
5627
|
-
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
5628
|
-
}
|
|
5629
|
-
finally { if (e_1) throw e_1.error; }
|
|
5630
|
-
}
|
|
5631
|
-
return result;
|
|
5632
|
-
},
|
|
5633
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5634
|
-
var _b;
|
|
5635
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5636
|
-
var binding = node.b;
|
|
5637
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5638
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5639
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5640
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5641
|
-
},
|
|
5642
|
-
};
|
|
5643
|
-
|
|
5644
|
-
var whenLetSpecialExpression = {
|
|
5645
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5646
|
-
var _b, _c;
|
|
5647
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5648
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5649
|
-
if (bindings.length !== 1) {
|
|
5650
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5651
|
-
}
|
|
5652
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5653
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5654
|
-
var node = {
|
|
5655
|
-
t: AstNodeType.SpecialExpression,
|
|
5656
|
-
n: 'when_let',
|
|
5657
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5658
|
-
p: params,
|
|
5659
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5660
|
-
};
|
|
5661
|
-
return node;
|
|
5662
|
-
},
|
|
5663
|
-
validateParameterCount: function () { return undefined; },
|
|
5664
|
-
evaluate: function (node, contextStack, _a) {
|
|
5665
|
-
var e_1, _b;
|
|
5666
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5667
|
-
var binding = node.b;
|
|
5668
|
-
var locals = {};
|
|
5669
|
-
var bindingValue = evaluateAstNode(binding.v, contextStack);
|
|
5670
|
-
if (!bindingValue)
|
|
5671
|
-
return null;
|
|
5672
|
-
locals[binding.n] = { value: bindingValue };
|
|
5673
|
-
var newContextStack = contextStack.create(locals);
|
|
5674
|
-
var result = null;
|
|
5675
|
-
try {
|
|
5676
|
-
for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5677
|
-
var form = _d.value;
|
|
5678
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5679
|
-
}
|
|
5680
|
-
}
|
|
5681
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5682
|
-
finally {
|
|
5683
|
-
try {
|
|
5684
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5685
|
-
}
|
|
5686
|
-
finally { if (e_1) throw e_1.error; }
|
|
5687
|
-
}
|
|
5688
|
-
return result;
|
|
5689
|
-
},
|
|
5690
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5691
|
-
var _b;
|
|
5692
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5693
|
-
var binding = node.b;
|
|
5694
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5695
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5696
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5697
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5698
|
-
},
|
|
5699
|
-
};
|
|
5700
|
-
|
|
5701
|
-
var whenNotSpecialExpression = {
|
|
5702
|
-
polishParse: getCommonPolishSpecialExpressionParser('when_not'),
|
|
5703
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5704
|
-
evaluate: function (node, contextStack, _a) {
|
|
5705
|
-
var e_1, _b;
|
|
5706
|
-
var _c;
|
|
5707
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5708
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5709
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5710
|
-
if (evaluateAstNode(whenExpression, contextStack))
|
|
5711
|
-
return null;
|
|
5712
|
-
var result = null;
|
|
5713
|
-
try {
|
|
5714
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5715
|
-
var form = body_1_1.value;
|
|
5716
|
-
result = evaluateAstNode(form, contextStack);
|
|
5717
|
-
}
|
|
5718
|
-
}
|
|
5719
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5720
|
-
finally {
|
|
5721
|
-
try {
|
|
5722
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5723
|
-
}
|
|
5724
|
-
finally { if (e_1) throw e_1.error; }
|
|
5725
|
-
}
|
|
5726
|
-
return result;
|
|
5727
|
-
},
|
|
5728
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5729
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5730
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5731
|
-
},
|
|
5732
|
-
};
|
|
5733
|
-
|
|
5734
5473
|
var specialExpressions = {
|
|
5735
5474
|
'&&': andSpecialExpression,
|
|
5736
5475
|
'comment': commentSpecialExpression,
|
|
@@ -5745,19 +5484,14 @@ var specialExpressions = {
|
|
|
5745
5484
|
'for': forSpecialExpression,
|
|
5746
5485
|
'fn': fnSpecialExpression,
|
|
5747
5486
|
'if': ifSpecialExpression,
|
|
5748
|
-
'
|
|
5749
|
-
'if_not': ifNotSpecialExpression,
|
|
5487
|
+
'unless': unlessSpecialExpression,
|
|
5750
5488
|
'let': letSpecialExpression,
|
|
5751
5489
|
'loop': loopSpecialExpression,
|
|
5752
5490
|
'||': orSpecialExpression,
|
|
5753
5491
|
'recur': recurSpecialExpression,
|
|
5754
5492
|
'throw': throwSpecialExpression,
|
|
5755
5493
|
'try': trySpecialExpression,
|
|
5756
|
-
'
|
|
5757
|
-
'when_first': whenFirstSpecialExpression,
|
|
5758
|
-
'when_let': whenLetSpecialExpression,
|
|
5759
|
-
'when_not': whenNotSpecialExpression,
|
|
5760
|
-
'declared?': declaredSpecialExpression,
|
|
5494
|
+
'defined?': declaredSpecialExpression,
|
|
5761
5495
|
'??': qqSpecialExpression,
|
|
5762
5496
|
};
|
|
5763
5497
|
Object.keys(specialExpressions).forEach(function (key) {
|
|
@@ -5779,8 +5513,8 @@ function isContextEntry(value) {
|
|
|
5779
5513
|
var ContextStackImpl = /** @class */ (function () {
|
|
5780
5514
|
function ContextStackImpl(_a) {
|
|
5781
5515
|
var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
|
|
5782
|
-
this.contexts = contexts;
|
|
5783
5516
|
this.globalContext = asNonUndefined(contexts[0]);
|
|
5517
|
+
this.contexts = contexts;
|
|
5784
5518
|
this.values = hostValues;
|
|
5785
5519
|
this.lazyValues = lazyHostValues;
|
|
5786
5520
|
this.nativeJsFunctions = nativeJsFunctions;
|
|
@@ -5796,6 +5530,35 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5796
5530
|
contextStack.globalContext = globalContext;
|
|
5797
5531
|
return contextStack;
|
|
5798
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
|
+
};
|
|
5799
5562
|
ContextStackImpl.prototype.clone = function () {
|
|
5800
5563
|
// eslint-disable-next-line ts/no-unsafe-argument
|
|
5801
5564
|
return new ContextStackImpl(JSON.parse(JSON.stringify({
|
|
@@ -5925,7 +5688,7 @@ function createContextStack(params) {
|
|
|
5925
5688
|
return acc;
|
|
5926
5689
|
}, {}),
|
|
5927
5690
|
});
|
|
5928
|
-
return contextStack;
|
|
5691
|
+
return contextStack.create({});
|
|
5929
5692
|
}
|
|
5930
5693
|
|
|
5931
5694
|
var _a;
|
|
@@ -6237,7 +6000,14 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6237
6000
|
|
|
6238
6001
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6239
6002
|
var e_1, _a;
|
|
6240
|
-
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
|
+
}];
|
|
6241
6011
|
var unresolvedIdentifiers = new Set();
|
|
6242
6012
|
try {
|
|
6243
6013
|
for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
|
|
@@ -6309,537 +6079,9 @@ function findUnresolvedIdentifiersInAstNode(astNode, contextStack, builtin) {
|
|
|
6309
6079
|
}
|
|
6310
6080
|
}
|
|
6311
6081
|
|
|
6312
|
-
var calculateAndOutcomes = function (_a) {
|
|
6313
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6314
|
-
return combinateAstNodes(astNode.p)
|
|
6315
|
-
.map(function (p) { return ({
|
|
6316
|
-
n: '&&',
|
|
6317
|
-
t: AstNodeType.SpecialExpression,
|
|
6318
|
-
p: p,
|
|
6319
|
-
token: astNode.token,
|
|
6320
|
-
}); });
|
|
6321
|
-
};
|
|
6322
|
-
|
|
6323
|
-
var calculateCondOutcomes = function (_a) {
|
|
6324
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
|
|
6325
|
-
var testNodes = arrayToPairs(astNode.p).map(function (_a) {
|
|
6326
|
-
var _b = __read(_a, 1), t = _b[0];
|
|
6327
|
-
return t;
|
|
6328
|
-
});
|
|
6329
|
-
if (isAstComputable(testNodes)) {
|
|
6330
|
-
return combinate(arrayToPairs(astNode.p)
|
|
6331
|
-
// Create a list of ast nodes from the test and form of each condition
|
|
6332
|
-
.reduce(function (acc, _a) {
|
|
6333
|
-
var _b = __read(_a, 2), test = _b[0], form = _b[1];
|
|
6334
|
-
acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
|
|
6335
|
-
return acc;
|
|
6336
|
-
}, []))
|
|
6337
|
-
// Create a new CondNode for each combination of test and form outcomes
|
|
6338
|
-
.map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
|
|
6339
|
-
var _b = __read(_a, 2), t = _b[0], f = _b[1];
|
|
6340
|
-
return ({ t: t, f: f });
|
|
6341
|
-
}) })); });
|
|
6342
|
-
}
|
|
6343
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
|
|
6344
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6345
|
-
return calculatePossibleAstNodes(form);
|
|
6346
|
-
})), false), [
|
|
6347
|
-
nilNode,
|
|
6348
|
-
], false);
|
|
6349
|
-
};
|
|
6350
|
-
|
|
6351
|
-
var trueNode = { t: AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
|
|
6352
|
-
var falseNode = { t: AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
|
|
6353
|
-
var calculateDeclaredOutcomes = function (_a) {
|
|
6354
|
-
var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
|
|
6355
|
-
if (isAstComputable(astNode.p))
|
|
6356
|
-
return [trueNode];
|
|
6357
|
-
return [trueNode, falseNode];
|
|
6358
|
-
};
|
|
6359
|
-
|
|
6360
|
-
var calculateDefOutcomes = function (_a) {
|
|
6361
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6362
|
-
var nameNode = asSymbolNode(astNode.p[0]);
|
|
6363
|
-
var valueNode = astNode.p[1];
|
|
6364
|
-
addGlobalIdentifier(nameNode.v);
|
|
6365
|
-
return calculatePossibleAstNodes(valueNode)
|
|
6366
|
-
.map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
|
|
6367
|
-
};
|
|
6368
|
-
|
|
6369
|
-
var calculateDefsOutcomes = function (_a) {
|
|
6370
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6371
|
-
return combinateAstNodes(astNode.p)
|
|
6372
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6373
|
-
};
|
|
6374
|
-
|
|
6375
|
-
var calculateDoOutcomes = function (_a) {
|
|
6376
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6377
|
-
return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6378
|
-
};
|
|
6379
|
-
|
|
6380
|
-
function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
|
|
6381
|
-
return combinate(functionOverloads
|
|
6382
|
-
// For each overload, calculate the possible outcomes for each parameter
|
|
6383
|
-
.map(function (functionOverload) {
|
|
6384
|
-
var _a;
|
|
6385
|
-
return combinateAstNodes(functionOverload.b, [
|
|
6386
|
-
functionOverload.as.m,
|
|
6387
|
-
functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
|
|
6388
|
-
(_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
|
|
6389
|
-
].flat())
|
|
6390
|
-
// For each combination of parameter outcomes, create a new overload
|
|
6391
|
-
.map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
|
|
6392
|
-
}));
|
|
6393
|
-
}
|
|
6394
|
-
var calculateDefnOutcomes = function (_a) {
|
|
6395
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6396
|
-
addGlobalIdentifier(astNode.f.v);
|
|
6397
|
-
// astNode.o is an array of overloads
|
|
6398
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6399
|
-
};
|
|
6400
|
-
var calculateDefnsOutcomes = function (_a) {
|
|
6401
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
|
|
6402
|
-
// astNode.o is an array of overloads
|
|
6403
|
-
return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
|
|
6404
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
|
|
6405
|
-
});
|
|
6406
|
-
};
|
|
6407
|
-
var calculateFnOutcomes = function (_a) {
|
|
6408
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6409
|
-
// astNode.o is an array of overloads
|
|
6410
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6411
|
-
};
|
|
6412
|
-
|
|
6413
|
-
var calculateIfLetOutcomes = function (_a) {
|
|
6414
|
-
var _b;
|
|
6415
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6416
|
-
var bindingNode = astNode.b;
|
|
6417
|
-
var thenBranch = astNode.p[0];
|
|
6418
|
-
var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6419
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6420
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6421
|
-
}
|
|
6422
|
-
var newIdentifier = bindingNode.n;
|
|
6423
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6424
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6425
|
-
.flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6426
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
|
|
6427
|
-
};
|
|
6428
|
-
|
|
6429
|
-
var calculateIfNotOutcomes = function (_a) {
|
|
6430
|
-
var _b;
|
|
6431
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6432
|
-
var condition = astNode.p[0];
|
|
6433
|
-
var thenBranch = astNode.p[1];
|
|
6434
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6435
|
-
if (isAstComputable(condition)) {
|
|
6436
|
-
return combinateAstNodes(astNode.p)
|
|
6437
|
-
.map(function (p) { return ({
|
|
6438
|
-
n: 'if_not',
|
|
6439
|
-
t: astNode.t,
|
|
6440
|
-
p: p,
|
|
6441
|
-
token: astNode.token,
|
|
6442
|
-
}); });
|
|
6443
|
-
}
|
|
6444
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6445
|
-
};
|
|
6446
|
-
|
|
6447
|
-
var calculateIfOutcomes = function (_a) {
|
|
6448
|
-
var _b;
|
|
6449
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6450
|
-
var condition = astNode.p[0];
|
|
6451
|
-
var thenBranch = astNode.p[1];
|
|
6452
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6453
|
-
if (isAstComputable(condition)) {
|
|
6454
|
-
return combinateAstNodes(astNode.p)
|
|
6455
|
-
.map(function (p) { return ({
|
|
6456
|
-
n: 'if',
|
|
6457
|
-
t: astNode.t,
|
|
6458
|
-
p: p,
|
|
6459
|
-
token: astNode.token,
|
|
6460
|
-
}); });
|
|
6461
|
-
}
|
|
6462
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6463
|
-
};
|
|
6464
|
-
|
|
6465
|
-
var calculateLetOutcomes = function (_a) {
|
|
6466
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6467
|
-
try {
|
|
6468
|
-
// check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
|
|
6469
|
-
if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
|
|
6470
|
-
throw new Error('Could not calculate binding value');
|
|
6471
|
-
}
|
|
6472
|
-
catch (_b) {
|
|
6473
|
-
var doNodes = combinateAstNodes(astNode.p)
|
|
6474
|
-
.map(function (p) {
|
|
6475
|
-
return {
|
|
6476
|
-
n: 'do',
|
|
6477
|
-
t: AstNodeType.SpecialExpression,
|
|
6478
|
-
p: p,
|
|
6479
|
-
token: astNode.token,
|
|
6480
|
-
};
|
|
6481
|
-
});
|
|
6482
|
-
return doNodes;
|
|
6483
|
-
}
|
|
6484
|
-
var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
|
|
6485
|
-
var letNodes = combinate(astNode.bs.map(function (bindingNode) {
|
|
6486
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6487
|
-
.map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
|
|
6488
|
-
}))
|
|
6489
|
-
.flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
|
|
6490
|
-
.map(function (p) {
|
|
6491
|
-
return {
|
|
6492
|
-
n: 'let',
|
|
6493
|
-
bs: bindingNodes,
|
|
6494
|
-
t: AstNodeType.SpecialExpression,
|
|
6495
|
-
p: p,
|
|
6496
|
-
token: astNode.token,
|
|
6497
|
-
};
|
|
6498
|
-
}); });
|
|
6499
|
-
return letNodes;
|
|
6500
|
-
};
|
|
6501
|
-
|
|
6502
|
-
var calculateForOutcomes = function (_a) {
|
|
6503
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6504
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6505
|
-
throw new Error('Could not calculate for loop, not deterministic');
|
|
6506
|
-
return [astNode];
|
|
6507
|
-
};
|
|
6508
|
-
var calculateDoSeqOutcomes = function (_a) {
|
|
6509
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6510
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6511
|
-
throw new Error('Could not calculate doSeq node, not deterministic');
|
|
6512
|
-
return [astNode];
|
|
6513
|
-
};
|
|
6514
|
-
function isDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6515
|
-
var e_1, _a;
|
|
6516
|
-
try {
|
|
6517
|
-
for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6518
|
-
var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
|
|
6519
|
-
if (l && l.some(function (_a) {
|
|
6520
|
-
var v = _a.v;
|
|
6521
|
-
return !astIsDeterministic(calculatePossibleAstNodes, v);
|
|
6522
|
-
}))
|
|
6523
|
-
return false;
|
|
6524
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
|
|
6525
|
-
return false;
|
|
6526
|
-
if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
|
|
6527
|
-
return false;
|
|
6528
|
-
if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
|
|
6529
|
-
return false;
|
|
6530
|
-
}
|
|
6531
|
-
}
|
|
6532
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6533
|
-
finally {
|
|
6534
|
-
try {
|
|
6535
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6536
|
-
}
|
|
6537
|
-
finally { if (e_1) throw e_1.error; }
|
|
6538
|
-
}
|
|
6539
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
|
|
6540
|
-
return false;
|
|
6541
|
-
return true;
|
|
6542
|
-
}
|
|
6543
|
-
function astIsDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6544
|
-
return calculatePossibleAstNodes(astNode).length === 1;
|
|
6545
|
-
}
|
|
6546
|
-
|
|
6547
|
-
var calculateOrOutcomes = function (_a) {
|
|
6548
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6549
|
-
return combinateAstNodes(astNode.p)
|
|
6550
|
-
.map(function (p) { return ({
|
|
6551
|
-
n: '||',
|
|
6552
|
-
t: AstNodeType.SpecialExpression,
|
|
6553
|
-
p: p,
|
|
6554
|
-
token: astNode.token,
|
|
6555
|
-
}); });
|
|
6556
|
-
};
|
|
6557
|
-
|
|
6558
|
-
var calculateQqOutcomes = function (_a) {
|
|
6559
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6560
|
-
if (!isAstComputable(astNode.p[0]))
|
|
6561
|
-
throw new Error('First argument of ?? not computable');
|
|
6562
|
-
return combinateAstNodes(astNode.p)
|
|
6563
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6564
|
-
};
|
|
6565
|
-
|
|
6566
|
-
var calculateThrowOutcomes = function (_a) {
|
|
6567
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6568
|
-
return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
|
|
6569
|
-
};
|
|
6570
|
-
|
|
6571
|
-
var calculateTryOutcomes = function (_a) {
|
|
6572
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6573
|
-
var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
|
|
6574
|
-
if (node.n === 'throw') {
|
|
6575
|
-
acc.throws.push(node.p[0]);
|
|
6576
|
-
}
|
|
6577
|
-
else {
|
|
6578
|
-
acc.vals.push(node);
|
|
6579
|
-
}
|
|
6580
|
-
return acc;
|
|
6581
|
-
}, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
|
|
6582
|
-
var catches = throws.flatMap(function (throwNode) {
|
|
6583
|
-
var letNode = {
|
|
6584
|
-
t: AstNodeType.SpecialExpression,
|
|
6585
|
-
n: 'let',
|
|
6586
|
-
bs: [{
|
|
6587
|
-
t: AstNodeType.Binding,
|
|
6588
|
-
n: astNode.e.v,
|
|
6589
|
-
v: throwNode,
|
|
6590
|
-
token: undefined,
|
|
6591
|
-
p: [],
|
|
6592
|
-
}],
|
|
6593
|
-
p: [astNode.ce],
|
|
6594
|
-
token: undefined,
|
|
6595
|
-
};
|
|
6596
|
-
return calculatePossibleAstNodes(letNode);
|
|
6597
|
-
});
|
|
6598
|
-
return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
|
|
6599
|
-
};
|
|
6600
|
-
|
|
6601
|
-
var calculateWhenFirstOutcomes = function (_a) {
|
|
6602
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6603
|
-
var bindingNode = astNode.b;
|
|
6604
|
-
if (!isAstComputable(bindingNode.v))
|
|
6605
|
-
throw new Error('Could not calculate binding value');
|
|
6606
|
-
var newIdentifier = bindingNode.n;
|
|
6607
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6608
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6609
|
-
.flatMap(function (b) {
|
|
6610
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6611
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6612
|
-
});
|
|
6613
|
-
};
|
|
6614
|
-
|
|
6615
|
-
var calculateWhenLetOutcomes = function (_a) {
|
|
6616
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6617
|
-
var bindingNode = astNode.b;
|
|
6618
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6619
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
|
|
6620
|
-
.map(function (p) { return ({
|
|
6621
|
-
n: 'do',
|
|
6622
|
-
t: astNode.t,
|
|
6623
|
-
p: p,
|
|
6624
|
-
token: astNode.token,
|
|
6625
|
-
}); })), false), [
|
|
6626
|
-
nilNode,
|
|
6627
|
-
], false);
|
|
6628
|
-
}
|
|
6629
|
-
var newIdentifier = bindingNode.n;
|
|
6630
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6631
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6632
|
-
.flatMap(function (b) {
|
|
6633
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6634
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6635
|
-
});
|
|
6636
|
-
};
|
|
6637
|
-
|
|
6638
|
-
var calculateWhenNotOutcomes = function (_a) {
|
|
6639
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6640
|
-
var condition = astNode.p[0];
|
|
6641
|
-
if (isAstComputable(condition)) {
|
|
6642
|
-
return combinateAstNodes(astNode.p)
|
|
6643
|
-
.map(function (p) { return ({
|
|
6644
|
-
n: 'when_not',
|
|
6645
|
-
t: astNode.t,
|
|
6646
|
-
p: p,
|
|
6647
|
-
token: astNode.token,
|
|
6648
|
-
}); });
|
|
6649
|
-
}
|
|
6650
|
-
var body = astNode.p.slice(1);
|
|
6651
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6652
|
-
.map(function (p) { return ({
|
|
6653
|
-
n: 'do',
|
|
6654
|
-
t: astNode.t,
|
|
6655
|
-
p: p,
|
|
6656
|
-
token: astNode.token,
|
|
6657
|
-
}); })), false), [
|
|
6658
|
-
nilNode,
|
|
6659
|
-
], false);
|
|
6660
|
-
};
|
|
6661
|
-
|
|
6662
|
-
var calculateWhenOutcomes = function (_a) {
|
|
6663
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6664
|
-
var condition = astNode.p[0];
|
|
6665
|
-
if (isAstComputable(condition)) {
|
|
6666
|
-
return combinateAstNodes(astNode.p)
|
|
6667
|
-
.map(function (p) { return ({
|
|
6668
|
-
n: 'when',
|
|
6669
|
-
t: astNode.t,
|
|
6670
|
-
p: p,
|
|
6671
|
-
token: astNode.token,
|
|
6672
|
-
}); });
|
|
6673
|
-
}
|
|
6674
|
-
var body = astNode.p.slice(1);
|
|
6675
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6676
|
-
.map(function (p) { return ({
|
|
6677
|
-
n: 'do',
|
|
6678
|
-
t: astNode.t,
|
|
6679
|
-
p: p,
|
|
6680
|
-
token: astNode.token,
|
|
6681
|
-
}); })), false), [
|
|
6682
|
-
nilNode,
|
|
6683
|
-
], false);
|
|
6684
|
-
};
|
|
6685
|
-
|
|
6686
|
-
var calculateRecurOutcomes = function (_a) {
|
|
6687
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6688
|
-
return combinateAstNodes(astNode.p)
|
|
6689
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6690
|
-
};
|
|
6691
|
-
|
|
6692
|
-
var calculateCommentOutcomes = function (_a) {
|
|
6693
|
-
var nilNode = _a.nilNode;
|
|
6694
|
-
return [nilNode];
|
|
6695
|
-
};
|
|
6696
|
-
|
|
6697
|
-
var calculateLoopOutcomes = function (_a) {
|
|
6698
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6699
|
-
return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
|
|
6700
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6701
|
-
};
|
|
6702
|
-
|
|
6703
|
-
var calculateSwitchOutcomes = function (_a) {
|
|
6704
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6705
|
-
// TODO be smarter about this
|
|
6706
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p.slice(1)).flatMap(function (_a) {
|
|
6707
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6708
|
-
return calculatePossibleAstNodes(form);
|
|
6709
|
-
})), false), [
|
|
6710
|
-
nilNode,
|
|
6711
|
-
], false);
|
|
6712
|
-
};
|
|
6713
|
-
|
|
6714
|
-
var specialExpressionCalculator = {
|
|
6715
|
-
'&&': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6716
|
-
'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6717
|
-
'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6718
|
-
'switch': function (astNode, helperOptions) { return calculateSwitchOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6719
|
-
'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6720
|
-
'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6721
|
-
'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6722
|
-
'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6723
|
-
'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6724
|
-
'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6725
|
-
'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6726
|
-
'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6727
|
-
'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6728
|
-
'if_let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6729
|
-
'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6730
|
-
'if_not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6731
|
-
'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6732
|
-
'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6733
|
-
'||': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6734
|
-
'??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6735
|
-
'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6736
|
-
'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6737
|
-
'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6738
|
-
'when_first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6739
|
-
'when_let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6740
|
-
'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6741
|
-
'when_not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6742
|
-
};
|
|
6743
|
-
|
|
6744
|
-
function calculateOutcomes(contextStack, astNodes) {
|
|
6745
|
-
// First, we try to calculate outcomes for the whole astNodes array.
|
|
6746
|
-
// If that fails, we try to calculate outcomes for the array without the first element.
|
|
6747
|
-
// If that fails, we try to calculate outcomes for the array without the first two elements.
|
|
6748
|
-
// And so on.
|
|
6749
|
-
// This makes it possible to calculate outcomes for e.g.
|
|
6750
|
-
// (write! x) x
|
|
6751
|
-
// Problems occur for e.g.
|
|
6752
|
-
// (def x 1) (write! x) x
|
|
6753
|
-
// This should output [1], but since (write! x) fails to calculate outcomes, we get null.
|
|
6754
|
-
// Ok, but not optimal
|
|
6755
|
-
// The contract is that when an array is returned, it must be correct.
|
|
6756
|
-
// But returning null (indicating that the calculation failed) is always a way out.
|
|
6757
|
-
for (var i = 0; i < astNodes.length; i++) {
|
|
6758
|
-
var usingAstNode = astNodes.slice(i);
|
|
6759
|
-
var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
|
|
6760
|
-
if (outcomes !== null)
|
|
6761
|
-
return outcomes;
|
|
6762
|
-
}
|
|
6763
|
-
return null;
|
|
6764
|
-
}
|
|
6765
|
-
function calculateOutcomesInner(contextStack, astNodes) {
|
|
6766
|
-
var e_1, _a;
|
|
6767
|
-
var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
|
|
6768
|
-
if (possibleAsts === null)
|
|
6769
|
-
return null;
|
|
6770
|
-
var outcomes = [];
|
|
6771
|
-
try {
|
|
6772
|
-
for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
|
|
6773
|
-
var possibleAst = possibleAsts_1_1.value;
|
|
6774
|
-
var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
|
|
6775
|
-
if (unresolvedIdentifiers.size !== 0)
|
|
6776
|
-
return null;
|
|
6777
|
-
var ast = {
|
|
6778
|
-
b: possibleAst,
|
|
6779
|
-
hasDebugData: true,
|
|
6780
|
-
};
|
|
6781
|
-
try {
|
|
6782
|
-
outcomes.push(evaluate(ast, contextStack.clone()));
|
|
6783
|
-
}
|
|
6784
|
-
catch (e) {
|
|
6785
|
-
outcomes.push(e);
|
|
6786
|
-
}
|
|
6787
|
-
}
|
|
6788
|
-
}
|
|
6789
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6790
|
-
finally {
|
|
6791
|
-
try {
|
|
6792
|
-
if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
|
|
6793
|
-
}
|
|
6794
|
-
finally { if (e_1) throw e_1.error; }
|
|
6795
|
-
}
|
|
6796
|
-
return outcomes;
|
|
6797
|
-
}
|
|
6798
|
-
function calculatePossibleAsts(contextStack, astNodes) {
|
|
6799
|
-
var possibleAsts;
|
|
6800
|
-
try {
|
|
6801
|
-
possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
|
|
6802
|
-
}
|
|
6803
|
-
catch (e) {
|
|
6804
|
-
return null;
|
|
6805
|
-
}
|
|
6806
|
-
return possibleAsts;
|
|
6807
|
-
}
|
|
6808
|
-
var nilNode = { t: AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
|
|
6809
|
-
function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
|
|
6810
|
-
var newContext = newIndentifiers
|
|
6811
|
-
? newIndentifiers.reduce(function (acc, identity) {
|
|
6812
|
-
acc[identity] = { value: null };
|
|
6813
|
-
return acc;
|
|
6814
|
-
}, {})
|
|
6815
|
-
: undefined;
|
|
6816
|
-
var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
|
|
6817
|
-
if (astNode.t === AstNodeType.NormalExpression) {
|
|
6818
|
-
return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
|
|
6819
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6820
|
-
}
|
|
6821
|
-
else if (astNode.t === AstNodeType.SpecialExpression) {
|
|
6822
|
-
var helperOptions = {
|
|
6823
|
-
nilNode: nilNode,
|
|
6824
|
-
calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
|
|
6825
|
-
combinateAstNodes: function (nodes, identifiers) {
|
|
6826
|
-
return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
|
|
6827
|
-
},
|
|
6828
|
-
isAstComputable: function (node) {
|
|
6829
|
-
return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
|
|
6830
|
-
},
|
|
6831
|
-
addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
|
|
6832
|
-
};
|
|
6833
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6834
|
-
return specialExpressionCalculator[astNode.n](astNode, helperOptions);
|
|
6835
|
-
}
|
|
6836
|
-
return [astNode];
|
|
6837
|
-
}
|
|
6838
|
-
|
|
6839
6082
|
function analyze(ast, params) {
|
|
6840
6083
|
return {
|
|
6841
6084
|
unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
|
|
6842
|
-
outcomes: calculateOutcomes(createContextStack(params), ast.b),
|
|
6843
6085
|
};
|
|
6844
6086
|
}
|
|
6845
6087
|
|
|
@@ -7121,38 +6363,43 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7121
6363
|
var _a;
|
|
7122
6364
|
if (precedence === void 0) { precedence = 0; }
|
|
7123
6365
|
var firstToken = this.peek();
|
|
7124
|
-
if (isA_SymbolToken(firstToken) && firstToken[1] === 'def') {
|
|
7125
|
-
return this.parseDef(firstToken);
|
|
7126
|
-
}
|
|
7127
|
-
else if (isA_SymbolToken(firstToken) && firstToken[1] === 'defn') {
|
|
7128
|
-
return this.parseDefn(firstToken);
|
|
7129
|
-
}
|
|
7130
6366
|
var left;
|
|
7131
|
-
if (isA_SymbolToken(firstToken)
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
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
|
+
}
|
|
7145
6399
|
}
|
|
6400
|
+
left || (left = this.parseOperand());
|
|
7146
6401
|
var operator = this.peek();
|
|
7147
|
-
while (!this.
|
|
7148
|
-
&& !isA_OperatorToken(operator, ',')
|
|
7149
|
-
&& !isA_OperatorToken(operator, ';')
|
|
7150
|
-
&& !isRBracketToken(operator)
|
|
7151
|
-
&& !isA_ReservedSymbolToken(operator, 'else')
|
|
7152
|
-
&& !isA_ReservedSymbolToken(operator, 'then')
|
|
7153
|
-
&& !isA_ReservedSymbolToken(operator, 'end')
|
|
7154
|
-
&& !isA_ReservedSymbolToken(operator, 'case')
|
|
7155
|
-
&& !isRParenToken(operator)) {
|
|
6402
|
+
while (!this.isAtExpressionEnd()) {
|
|
7156
6403
|
if (isA_BinaryOperatorToken(operator)) {
|
|
7157
6404
|
var name_1 = operator[1];
|
|
7158
6405
|
var newPrecedece = getPrecedence(name_1);
|
|
@@ -7405,12 +6652,9 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7405
6652
|
case '??':
|
|
7406
6653
|
case '&&':
|
|
7407
6654
|
case 'comment':
|
|
7408
|
-
case '
|
|
7409
|
-
case 'if_not':
|
|
6655
|
+
case 'defined?':
|
|
7410
6656
|
case '||':
|
|
7411
|
-
case '
|
|
7412
|
-
case 'when_not':
|
|
7413
|
-
case 'do':
|
|
6657
|
+
case 'recur':
|
|
7414
6658
|
case 'throw': {
|
|
7415
6659
|
var node = {
|
|
7416
6660
|
t: AstNodeType.SpecialExpression,
|
|
@@ -7421,17 +6665,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7421
6665
|
builtin.specialExpressions[node.n].validateParameterCount(node);
|
|
7422
6666
|
return node;
|
|
7423
6667
|
}
|
|
7424
|
-
case 'let':
|
|
7425
|
-
return this.parseLet(symbol, params);
|
|
7426
6668
|
case 'defs':
|
|
7427
|
-
case 'if_let':
|
|
7428
|
-
case 'when_let':
|
|
7429
|
-
case 'when_first':
|
|
7430
6669
|
case 'fn':
|
|
7431
6670
|
case 'defns':
|
|
7432
6671
|
case 'try':
|
|
7433
|
-
case 'recur':
|
|
7434
|
-
case 'loop':
|
|
7435
6672
|
case 'doseq':
|
|
7436
6673
|
throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
|
|
7437
6674
|
default:
|
|
@@ -7594,36 +6831,142 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7594
6831
|
};
|
|
7595
6832
|
return node;
|
|
7596
6833
|
};
|
|
7597
|
-
AlgebraicParser.prototype.parseLet = function (
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
var
|
|
7603
|
-
if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
|
|
7604
|
-
throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7605
|
-
}
|
|
7606
|
-
var letBindings = arrayToPairs(letObject.p);
|
|
7607
|
-
var expression = params[1];
|
|
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();
|
|
7608
6840
|
return {
|
|
7609
6841
|
t: AstNodeType.SpecialExpression,
|
|
7610
6842
|
n: 'let',
|
|
7611
|
-
p: [
|
|
6843
|
+
p: [],
|
|
7612
6844
|
token: getTokenDebugData(letSymbol.token) && letSymbol.token,
|
|
7613
|
-
bs:
|
|
7614
|
-
var key = pair[0];
|
|
7615
|
-
var value = pair[1];
|
|
7616
|
-
return {
|
|
6845
|
+
bs: [{
|
|
7617
6846
|
t: AstNodeType.Binding,
|
|
7618
|
-
n:
|
|
6847
|
+
n: letSymbol.v,
|
|
7619
6848
|
v: value,
|
|
7620
6849
|
p: [],
|
|
7621
|
-
token: getTokenDebugData(
|
|
7622
|
-
}
|
|
7623
|
-
|
|
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);
|
|
6896
|
+
}
|
|
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 {
|
|
6909
|
+
t: AstNodeType.SpecialExpression,
|
|
6910
|
+
n: 'loop',
|
|
6911
|
+
p: params,
|
|
6912
|
+
bs: bindingNodes,
|
|
6913
|
+
token: getTokenDebugData(token) && token,
|
|
6914
|
+
};
|
|
6915
|
+
};
|
|
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();
|
|
6941
|
+
}
|
|
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
|
+
}
|
|
6948
|
+
}
|
|
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
|
+
};
|
|
6959
|
+
return {
|
|
6960
|
+
t: AstNodeType.SpecialExpression,
|
|
6961
|
+
n: 'try',
|
|
6962
|
+
p: [tryExpression],
|
|
6963
|
+
ce: catchExpression,
|
|
6964
|
+
e: errorSymbol,
|
|
6965
|
+
token: getTokenDebugData(token) && token,
|
|
7624
6966
|
};
|
|
7625
6967
|
};
|
|
7626
|
-
AlgebraicParser.prototype.
|
|
6968
|
+
AlgebraicParser.prototype.parseForOrDoseq = function (token) {
|
|
6969
|
+
var isDoseq = token[1] === 'doseq';
|
|
7627
6970
|
this.advance();
|
|
7628
6971
|
assertLParenToken(this.peek());
|
|
7629
6972
|
this.advance();
|
|
@@ -7643,7 +6986,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7643
6986
|
this.advance();
|
|
7644
6987
|
return {
|
|
7645
6988
|
t: AstNodeType.SpecialExpression,
|
|
7646
|
-
n: 'for',
|
|
6989
|
+
n: isDoseq ? 'doseq' : 'for',
|
|
7647
6990
|
p: [expression],
|
|
7648
6991
|
token: getTokenDebugData(token) && token,
|
|
7649
6992
|
l: forLoopBindings,
|
|
@@ -7663,33 +7006,26 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7663
7006
|
}
|
|
7664
7007
|
var modifiers = [];
|
|
7665
7008
|
var token = this.peek();
|
|
7666
|
-
if (!isA_SymbolToken(token)
|
|
7009
|
+
if (!isA_SymbolToken(token, 'let')
|
|
7010
|
+
&& !isA_ReservedSymbolToken(token, 'when')
|
|
7011
|
+
&& !isA_ReservedSymbolToken(token, 'while')) {
|
|
7667
7012
|
throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7668
7013
|
}
|
|
7669
7014
|
var letBindings;
|
|
7670
7015
|
if (token[1] === 'let') {
|
|
7671
7016
|
modifiers.push('&let');
|
|
7672
7017
|
letBindings = [];
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7676
|
-
|
|
7677
|
-
|
|
7678
|
-
return {
|
|
7679
|
-
t: AstNodeType.Binding,
|
|
7680
|
-
n: key.v,
|
|
7681
|
-
v: value,
|
|
7682
|
-
p: [],
|
|
7683
|
-
token: getTokenDebugData(key.token) && key.token,
|
|
7684
|
-
};
|
|
7685
|
-
});
|
|
7018
|
+
while (isA_SymbolToken(token, 'let')) {
|
|
7019
|
+
var letNode = this.parseLet(token);
|
|
7020
|
+
letBindings.push(letNode.bs[0]);
|
|
7021
|
+
token = this.peek();
|
|
7022
|
+
}
|
|
7686
7023
|
}
|
|
7687
7024
|
token = this.peek();
|
|
7688
7025
|
var whenNode;
|
|
7689
7026
|
var whileNode;
|
|
7690
|
-
while (
|
|
7691
|
-
|
|
7692
|
-
|| (token[1] === 'while' && !modifiers.includes('&while')))) {
|
|
7027
|
+
while (isA_ReservedSymbolToken(token, 'when')
|
|
7028
|
+
|| isA_ReservedSymbolToken(token, 'while')) {
|
|
7693
7029
|
this.advance();
|
|
7694
7030
|
if (token[1] === 'when') {
|
|
7695
7031
|
modifiers.push('&when');
|
|
@@ -7732,7 +7068,8 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7732
7068
|
};
|
|
7733
7069
|
return node;
|
|
7734
7070
|
};
|
|
7735
|
-
AlgebraicParser.prototype.
|
|
7071
|
+
AlgebraicParser.prototype.parseIfOrUnless = function (token) {
|
|
7072
|
+
var isUnless = token[1] === 'unless';
|
|
7736
7073
|
this.advance();
|
|
7737
7074
|
var condition = this.parseExpression();
|
|
7738
7075
|
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
@@ -7781,7 +7118,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7781
7118
|
}
|
|
7782
7119
|
return {
|
|
7783
7120
|
t: AstNodeType.SpecialExpression,
|
|
7784
|
-
n: 'if',
|
|
7121
|
+
n: isUnless ? 'unless' : 'if',
|
|
7785
7122
|
p: params,
|
|
7786
7123
|
token: getTokenDebugData(token) && token,
|
|
7787
7124
|
};
|
|
@@ -7908,6 +7245,22 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7908
7245
|
AlgebraicParser.prototype.isAtEnd = function () {
|
|
7909
7246
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
7910
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
|
+
};
|
|
7911
7264
|
AlgebraicParser.prototype.peek = function () {
|
|
7912
7265
|
return this.tokenStream.tokens[this.parseState.position];
|
|
7913
7266
|
};
|
|
@@ -8372,17 +7725,12 @@ var validAlgebraicReservedNamesRecord = {
|
|
|
8372
7725
|
else: { value: null, forbidden: false },
|
|
8373
7726
|
end: { value: null, forbidden: false },
|
|
8374
7727
|
case: { value: null, forbidden: false },
|
|
7728
|
+
when: { value: null, forbidden: false },
|
|
7729
|
+
while: { value: null, forbidden: false },
|
|
8375
7730
|
};
|
|
8376
7731
|
var forbiddenAlgebraicReservedNamesRecord = {
|
|
8377
|
-
if_let: { value: null, forbidden: true },
|
|
8378
|
-
when_let: { value: null, forbidden: true },
|
|
8379
|
-
when_first: { value: null, forbidden: true },
|
|
8380
7732
|
fn: { value: null, forbidden: true },
|
|
8381
7733
|
defns: { value: null, forbidden: true },
|
|
8382
|
-
try: { value: null, forbidden: true },
|
|
8383
|
-
recur: { value: null, forbidden: true },
|
|
8384
|
-
loop: { value: null, forbidden: true },
|
|
8385
|
-
doseq: { value: null, forbidden: true },
|
|
8386
7734
|
};
|
|
8387
7735
|
var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
|
|
8388
7736
|
|