@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/index.esm.js
CHANGED
|
@@ -426,20 +426,15 @@ var nonFunctionOperators = [
|
|
|
426
426
|
'&&',
|
|
427
427
|
'comment',
|
|
428
428
|
'cond',
|
|
429
|
-
'
|
|
429
|
+
'defined?',
|
|
430
430
|
'if',
|
|
431
|
-
'
|
|
431
|
+
'unless',
|
|
432
432
|
'||',
|
|
433
|
-
'when',
|
|
434
|
-
'when_not',
|
|
435
433
|
'do',
|
|
436
434
|
'throw',
|
|
437
435
|
'let',
|
|
438
436
|
'def',
|
|
439
437
|
'defs',
|
|
440
|
-
'if_let',
|
|
441
|
-
'when_let',
|
|
442
|
-
'when_first',
|
|
443
438
|
'fn',
|
|
444
439
|
'defn',
|
|
445
440
|
'defns',
|
|
@@ -465,16 +460,22 @@ var symbolicOperatorSet = new Set(symbolicOperators);
|
|
|
465
460
|
function isSymbolicOperator(operator) {
|
|
466
461
|
return symbolicOperatorSet.has(operator);
|
|
467
462
|
}
|
|
468
|
-
function isA_SymbolToken(token) {
|
|
469
|
-
|
|
463
|
+
function isA_SymbolToken(token, symbolName) {
|
|
464
|
+
if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Symbol') {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
if (symbolName && token[1] !== symbolName) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
470
471
|
}
|
|
471
|
-
function assertA_SymbolToken(token) {
|
|
472
|
-
if (!isA_SymbolToken(token)) {
|
|
472
|
+
function assertA_SymbolToken(token, symbolName) {
|
|
473
|
+
if (!isA_SymbolToken(token, symbolName)) {
|
|
473
474
|
throwUnexpectedToken('A_Symbol', undefined, token);
|
|
474
475
|
}
|
|
475
476
|
}
|
|
476
|
-
function asA_SymbolToken(token) {
|
|
477
|
-
assertA_SymbolToken(token);
|
|
477
|
+
function asA_SymbolToken(token, symbolName) {
|
|
478
|
+
assertA_SymbolToken(token, symbolName);
|
|
478
479
|
return token;
|
|
479
480
|
}
|
|
480
481
|
function isA_BinaryOperatorToken(token) {
|
|
@@ -757,7 +758,7 @@ var specialExpressionCommentRemovers = {
|
|
|
757
758
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
758
759
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
759
760
|
},
|
|
760
|
-
'
|
|
761
|
+
'defined?': function (node, removeOptions) {
|
|
761
762
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
762
763
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
763
764
|
},
|
|
@@ -778,12 +779,11 @@ var specialExpressionCommentRemovers = {
|
|
|
778
779
|
'doseq': function (_node, _removeOptions) { },
|
|
779
780
|
'fn': function (_node, _removeOptions) { },
|
|
780
781
|
'for': function (_node, _removeOptions) { },
|
|
781
|
-
'if_let': function (_node, _removeOptions) { },
|
|
782
782
|
'if': function (node, removeOptions) {
|
|
783
783
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
784
784
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
785
785
|
},
|
|
786
|
-
'
|
|
786
|
+
'unless': function (node, removeOptions) {
|
|
787
787
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
788
788
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
789
789
|
},
|
|
@@ -812,10 +812,6 @@ var specialExpressionCommentRemovers = {
|
|
|
812
812
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
813
813
|
},
|
|
814
814
|
'try': function (_node, _removeOptions) { },
|
|
815
|
-
'when_first': function (_node, _removeOptions) { },
|
|
816
|
-
'when_let': function (_node, _removeOptions) { },
|
|
817
|
-
'when': function (_node, _removeOptions) { },
|
|
818
|
-
'when_not': function (_node, _removeOptions) { },
|
|
819
815
|
};
|
|
820
816
|
function removeCommentNodesFromSpecialExpression(node, removeOptions) {
|
|
821
817
|
var uncommenter = specialExpressionCommentRemovers[node.n];
|
|
@@ -4442,7 +4438,7 @@ var switchSpecialExpression = {
|
|
|
4442
4438
|
};
|
|
4443
4439
|
|
|
4444
4440
|
var declaredSpecialExpression = {
|
|
4445
|
-
polishParse: getCommonPolishSpecialExpressionParser('
|
|
4441
|
+
polishParse: getCommonPolishSpecialExpressionParser('defined?'),
|
|
4446
4442
|
validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
|
|
4447
4443
|
evaluate: function (node, contextStack) {
|
|
4448
4444
|
var lookUpResult = contextStack.lookUp(node.p[0]);
|
|
@@ -4498,9 +4494,7 @@ var defSpecialExpression = {
|
|
|
4498
4494
|
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4499
4495
|
var name = node.p[0].v;
|
|
4500
4496
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4501
|
-
contextStack.
|
|
4502
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4503
|
-
};
|
|
4497
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4504
4498
|
return null;
|
|
4505
4499
|
},
|
|
4506
4500
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4511,7 +4505,7 @@ var defSpecialExpression = {
|
|
|
4511
4505
|
var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
|
|
4512
4506
|
var name = asSymbolNode(node.p[0]).v;
|
|
4513
4507
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4514
|
-
contextStack.
|
|
4508
|
+
contextStack.exportValue(name, true);
|
|
4515
4509
|
return result;
|
|
4516
4510
|
},
|
|
4517
4511
|
};
|
|
@@ -4537,9 +4531,7 @@ var defsSpecialExpression = {
|
|
|
4537
4531
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4538
4532
|
assertString(name, sourceCodeInfo);
|
|
4539
4533
|
assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
4540
|
-
contextStack.
|
|
4541
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4542
|
-
};
|
|
4534
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4543
4535
|
return null;
|
|
4544
4536
|
},
|
|
4545
4537
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4551,7 +4543,7 @@ var defsSpecialExpression = {
|
|
|
4551
4543
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4552
4544
|
assertString(name, sourceCodeInfo);
|
|
4553
4545
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4554
|
-
contextStack.
|
|
4546
|
+
contextStack.exportValue(name, true);
|
|
4555
4547
|
return result;
|
|
4556
4548
|
},
|
|
4557
4549
|
};
|
|
@@ -4582,7 +4574,7 @@ var doSpecialExpression = {
|
|
|
4582
4574
|
},
|
|
4583
4575
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4584
4576
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4585
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
4577
|
+
return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
|
|
4586
4578
|
},
|
|
4587
4579
|
};
|
|
4588
4580
|
|
|
@@ -4611,11 +4603,6 @@ function joinAnalyzeResults() {
|
|
|
4611
4603
|
function addAnalyzeResults(target, source) {
|
|
4612
4604
|
source.forEach(function (symbol) { return target.add(symbol); });
|
|
4613
4605
|
}
|
|
4614
|
-
function combinate(arrays) {
|
|
4615
|
-
return arrays.reduce(function (acc, curr) {
|
|
4616
|
-
return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
|
|
4617
|
-
}, [[]]);
|
|
4618
|
-
}
|
|
4619
4606
|
|
|
4620
4607
|
var defnSpecialExpression = {
|
|
4621
4608
|
polishParse: function (tokenStream, parseState, firstToken, parsers) {
|
|
@@ -4650,13 +4637,13 @@ var defnSpecialExpression = {
|
|
|
4650
4637
|
_b.n = name,
|
|
4651
4638
|
_b.o = evaluatedFunctionOverloades,
|
|
4652
4639
|
_b);
|
|
4653
|
-
contextStack.
|
|
4640
|
+
contextStack.exportValue(name, litsFunction);
|
|
4654
4641
|
return null;
|
|
4655
4642
|
},
|
|
4656
4643
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4657
4644
|
var _b;
|
|
4658
4645
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4659
|
-
contextStack.
|
|
4646
|
+
contextStack.exportValue(node.f.v, true);
|
|
4660
4647
|
var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
|
|
4661
4648
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4662
4649
|
},
|
|
@@ -4692,7 +4679,7 @@ var defnsSpecialExpression = {
|
|
|
4692
4679
|
_b.n = name,
|
|
4693
4680
|
_b.o = evaluatedFunctionOverloades,
|
|
4694
4681
|
_b);
|
|
4695
|
-
contextStack.
|
|
4682
|
+
contextStack.exportValue(name, litsFunction);
|
|
4696
4683
|
return null;
|
|
4697
4684
|
},
|
|
4698
4685
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4703,7 +4690,7 @@ var defnsSpecialExpression = {
|
|
|
4703
4690
|
var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
|
|
4704
4691
|
assertString(name, sourceCodeInfo);
|
|
4705
4692
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4706
|
-
contextStack.
|
|
4693
|
+
contextStack.exportValue(name, true);
|
|
4707
4694
|
var newContext = (_b = {}, _b[name] = { value: true }, _b);
|
|
4708
4695
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4709
4696
|
},
|
|
@@ -4976,56 +4963,8 @@ var ifSpecialExpression = {
|
|
|
4976
4963
|
},
|
|
4977
4964
|
};
|
|
4978
4965
|
|
|
4979
|
-
var
|
|
4980
|
-
polishParse:
|
|
4981
|
-
var _b, _c;
|
|
4982
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
4983
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
4984
|
-
if (bindings.length !== 1) {
|
|
4985
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
4986
|
-
}
|
|
4987
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
4988
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4989
|
-
var node = {
|
|
4990
|
-
t: AstNodeType.SpecialExpression,
|
|
4991
|
-
n: 'if_let',
|
|
4992
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
4993
|
-
p: params,
|
|
4994
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
4995
|
-
};
|
|
4996
|
-
return node;
|
|
4997
|
-
},
|
|
4998
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
4999
|
-
evaluate: function (node, contextStack, _a) {
|
|
5000
|
-
var _b;
|
|
5001
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5002
|
-
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
5003
|
-
var locals = {};
|
|
5004
|
-
var bindingValue = evaluateAstNode(node.b.v, contextStack);
|
|
5005
|
-
if (bindingValue) {
|
|
5006
|
-
locals[node.b.n] = { value: bindingValue };
|
|
5007
|
-
var newContextStack = contextStack.create(locals);
|
|
5008
|
-
var thenForm = asAstNode(node.p[0], sourceCodeInfo);
|
|
5009
|
-
return evaluateAstNode(thenForm, newContextStack);
|
|
5010
|
-
}
|
|
5011
|
-
if (node.p.length === 2) {
|
|
5012
|
-
var elseForm = asAstNode(node.p[1], sourceCodeInfo);
|
|
5013
|
-
return evaluateAstNode(elseForm, contextStack);
|
|
5014
|
-
}
|
|
5015
|
-
return null;
|
|
5016
|
-
},
|
|
5017
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5018
|
-
var _b;
|
|
5019
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5020
|
-
var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
|
|
5021
|
-
var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
|
|
5022
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5023
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5024
|
-
},
|
|
5025
|
-
};
|
|
5026
|
-
|
|
5027
|
-
var ifNotSpecialExpression = {
|
|
5028
|
-
polishParse: getCommonPolishSpecialExpressionParser('if_not'),
|
|
4966
|
+
var unlessSpecialExpression = {
|
|
4967
|
+
polishParse: getCommonPolishSpecialExpressionParser('unless'),
|
|
5029
4968
|
validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
5030
4969
|
evaluate: function (node, contextStack, _a) {
|
|
5031
4970
|
var _b;
|
|
@@ -5050,55 +4989,39 @@ var ifNotSpecialExpression = {
|
|
|
5050
4989
|
|
|
5051
4990
|
var letSpecialExpression = {
|
|
5052
4991
|
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5053
|
-
var parseBindings = _a.parseBindings
|
|
4992
|
+
var parseBindings = _a.parseBindings;
|
|
5054
4993
|
var bindings = parseBindings(tokenStream, parseState);
|
|
5055
|
-
|
|
4994
|
+
// const params = parseTokensUntilClosingBracket(tokenStream, parseState)
|
|
5056
4995
|
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5057
4996
|
var node = {
|
|
5058
4997
|
t: AstNodeType.SpecialExpression,
|
|
5059
4998
|
n: 'let',
|
|
5060
|
-
p:
|
|
4999
|
+
p: [],
|
|
5061
5000
|
bs: bindings,
|
|
5062
5001
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
5063
5002
|
};
|
|
5064
5003
|
return node;
|
|
5065
5004
|
},
|
|
5066
|
-
validateParameterCount: function () { return
|
|
5005
|
+
validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
|
|
5067
5006
|
evaluate: function (node, contextStack, _a) {
|
|
5068
|
-
var e_1, _b
|
|
5007
|
+
var e_1, _b;
|
|
5069
5008
|
var evaluateAstNode = _a.evaluateAstNode;
|
|
5070
|
-
var locals = {};
|
|
5071
|
-
var newContextStack = contextStack.create(locals);
|
|
5072
5009
|
try {
|
|
5073
|
-
for (var
|
|
5074
|
-
var binding =
|
|
5010
|
+
for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5011
|
+
var binding = _d.value;
|
|
5075
5012
|
var bindingValueNode = binding.v;
|
|
5076
|
-
var bindingValue = evaluateAstNode(bindingValueNode,
|
|
5077
|
-
|
|
5013
|
+
var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
|
|
5014
|
+
contextStack.addValue(binding.n, bindingValue);
|
|
5078
5015
|
}
|
|
5079
5016
|
}
|
|
5080
5017
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5081
5018
|
finally {
|
|
5082
5019
|
try {
|
|
5083
|
-
if (
|
|
5020
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5084
5021
|
}
|
|
5085
5022
|
finally { if (e_1) throw e_1.error; }
|
|
5086
5023
|
}
|
|
5087
|
-
|
|
5088
|
-
try {
|
|
5089
|
-
for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
5090
|
-
var astNode = _g.value;
|
|
5091
|
-
result = evaluateAstNode(astNode, newContextStack);
|
|
5092
|
-
}
|
|
5093
|
-
}
|
|
5094
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5095
|
-
finally {
|
|
5096
|
-
try {
|
|
5097
|
-
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
5098
|
-
}
|
|
5099
|
-
finally { if (e_2) throw e_2.error; }
|
|
5100
|
-
}
|
|
5101
|
-
return result;
|
|
5024
|
+
return null;
|
|
5102
5025
|
},
|
|
5103
5026
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5104
5027
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
@@ -5108,11 +5031,10 @@ var letSpecialExpression = {
|
|
|
5108
5031
|
context[name] = { value: true };
|
|
5109
5032
|
return context;
|
|
5110
5033
|
}, {});
|
|
5111
|
-
var bindingContext = {};
|
|
5112
5034
|
var bindingResults = node.bs.map(function (bindingNode) {
|
|
5113
5035
|
var valueNode = bindingNode.v;
|
|
5114
|
-
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack
|
|
5115
|
-
|
|
5036
|
+
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
|
|
5037
|
+
contextStack.addValue(bindingNode.n, { value: true });
|
|
5116
5038
|
return bindingsResult;
|
|
5117
5039
|
});
|
|
5118
5040
|
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
@@ -5563,9 +5485,10 @@ var trySpecialExpression = {
|
|
|
5563
5485
|
return evaluateAstNode(tryExpressions[0], contextStack);
|
|
5564
5486
|
}
|
|
5565
5487
|
catch (error) {
|
|
5566
|
-
var newContext =
|
|
5567
|
-
_b
|
|
5568
|
-
|
|
5488
|
+
var newContext = errorNode
|
|
5489
|
+
? (_b = {},
|
|
5490
|
+
_b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
|
|
5491
|
+
_b) : {};
|
|
5569
5492
|
return evaluateAstNode(catchExpression, contextStack.create(newContext));
|
|
5570
5493
|
}
|
|
5571
5494
|
},
|
|
@@ -5574,199 +5497,15 @@ var trySpecialExpression = {
|
|
|
5574
5497
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5575
5498
|
var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
|
|
5576
5499
|
var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
|
|
5577
|
-
var newContext =
|
|
5578
|
-
_b
|
|
5579
|
-
|
|
5500
|
+
var newContext = errorNode
|
|
5501
|
+
? (_b = {},
|
|
5502
|
+
_b[errorNode.v] = { value: true },
|
|
5503
|
+
_b) : {};
|
|
5580
5504
|
var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
|
|
5581
5505
|
return joinAnalyzeResults(tryResult, catchResult);
|
|
5582
5506
|
},
|
|
5583
5507
|
};
|
|
5584
5508
|
|
|
5585
|
-
var whenSpecialExpression = {
|
|
5586
|
-
polishParse: getCommonPolishSpecialExpressionParser('when'),
|
|
5587
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5588
|
-
evaluate: function (node, contextStack, _a) {
|
|
5589
|
-
var e_1, _b;
|
|
5590
|
-
var _c;
|
|
5591
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5592
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5593
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5594
|
-
if (!evaluateAstNode(whenExpression, contextStack))
|
|
5595
|
-
return null;
|
|
5596
|
-
var result = null;
|
|
5597
|
-
try {
|
|
5598
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5599
|
-
var form = body_1_1.value;
|
|
5600
|
-
result = evaluateAstNode(form, contextStack);
|
|
5601
|
-
}
|
|
5602
|
-
}
|
|
5603
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5604
|
-
finally {
|
|
5605
|
-
try {
|
|
5606
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5607
|
-
}
|
|
5608
|
-
finally { if (e_1) throw e_1.error; }
|
|
5609
|
-
}
|
|
5610
|
-
return result;
|
|
5611
|
-
},
|
|
5612
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5613
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5614
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5615
|
-
},
|
|
5616
|
-
};
|
|
5617
|
-
|
|
5618
|
-
var whenFirstSpecialExpression = {
|
|
5619
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5620
|
-
var _b, _c;
|
|
5621
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5622
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5623
|
-
if (bindings.length !== 1) {
|
|
5624
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5625
|
-
}
|
|
5626
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5627
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5628
|
-
var node = {
|
|
5629
|
-
t: AstNodeType.SpecialExpression,
|
|
5630
|
-
n: 'when_first',
|
|
5631
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5632
|
-
p: params,
|
|
5633
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5634
|
-
};
|
|
5635
|
-
return node;
|
|
5636
|
-
},
|
|
5637
|
-
validateParameterCount: function () { return undefined; },
|
|
5638
|
-
evaluate: function (node, contextStack, _a) {
|
|
5639
|
-
var e_1, _b;
|
|
5640
|
-
var _c;
|
|
5641
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5642
|
-
var locals = {};
|
|
5643
|
-
var binding = node.b;
|
|
5644
|
-
var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
|
|
5645
|
-
if (!isSeq(evaluatedBindingForm)) {
|
|
5646
|
-
throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5647
|
-
}
|
|
5648
|
-
if (evaluatedBindingForm.length === 0)
|
|
5649
|
-
return null;
|
|
5650
|
-
var bindingValue = toAny(evaluatedBindingForm[0]);
|
|
5651
|
-
locals[binding.n] = { value: bindingValue };
|
|
5652
|
-
var newContextStack = contextStack.create(locals);
|
|
5653
|
-
var result = null;
|
|
5654
|
-
try {
|
|
5655
|
-
for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
5656
|
-
var form = _e.value;
|
|
5657
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5658
|
-
}
|
|
5659
|
-
}
|
|
5660
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5661
|
-
finally {
|
|
5662
|
-
try {
|
|
5663
|
-
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
5664
|
-
}
|
|
5665
|
-
finally { if (e_1) throw e_1.error; }
|
|
5666
|
-
}
|
|
5667
|
-
return result;
|
|
5668
|
-
},
|
|
5669
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5670
|
-
var _b;
|
|
5671
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5672
|
-
var binding = node.b;
|
|
5673
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5674
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5675
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5676
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5677
|
-
},
|
|
5678
|
-
};
|
|
5679
|
-
|
|
5680
|
-
var whenLetSpecialExpression = {
|
|
5681
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5682
|
-
var _b, _c;
|
|
5683
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5684
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5685
|
-
if (bindings.length !== 1) {
|
|
5686
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5687
|
-
}
|
|
5688
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5689
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5690
|
-
var node = {
|
|
5691
|
-
t: AstNodeType.SpecialExpression,
|
|
5692
|
-
n: 'when_let',
|
|
5693
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5694
|
-
p: params,
|
|
5695
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5696
|
-
};
|
|
5697
|
-
return node;
|
|
5698
|
-
},
|
|
5699
|
-
validateParameterCount: function () { return undefined; },
|
|
5700
|
-
evaluate: function (node, contextStack, _a) {
|
|
5701
|
-
var e_1, _b;
|
|
5702
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5703
|
-
var binding = node.b;
|
|
5704
|
-
var locals = {};
|
|
5705
|
-
var bindingValue = evaluateAstNode(binding.v, contextStack);
|
|
5706
|
-
if (!bindingValue)
|
|
5707
|
-
return null;
|
|
5708
|
-
locals[binding.n] = { value: bindingValue };
|
|
5709
|
-
var newContextStack = contextStack.create(locals);
|
|
5710
|
-
var result = null;
|
|
5711
|
-
try {
|
|
5712
|
-
for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5713
|
-
var form = _d.value;
|
|
5714
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5715
|
-
}
|
|
5716
|
-
}
|
|
5717
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5718
|
-
finally {
|
|
5719
|
-
try {
|
|
5720
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5721
|
-
}
|
|
5722
|
-
finally { if (e_1) throw e_1.error; }
|
|
5723
|
-
}
|
|
5724
|
-
return result;
|
|
5725
|
-
},
|
|
5726
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5727
|
-
var _b;
|
|
5728
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5729
|
-
var binding = node.b;
|
|
5730
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5731
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5732
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5733
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5734
|
-
},
|
|
5735
|
-
};
|
|
5736
|
-
|
|
5737
|
-
var whenNotSpecialExpression = {
|
|
5738
|
-
polishParse: getCommonPolishSpecialExpressionParser('when_not'),
|
|
5739
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5740
|
-
evaluate: function (node, contextStack, _a) {
|
|
5741
|
-
var e_1, _b;
|
|
5742
|
-
var _c;
|
|
5743
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5744
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5745
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5746
|
-
if (evaluateAstNode(whenExpression, contextStack))
|
|
5747
|
-
return null;
|
|
5748
|
-
var result = null;
|
|
5749
|
-
try {
|
|
5750
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5751
|
-
var form = body_1_1.value;
|
|
5752
|
-
result = evaluateAstNode(form, contextStack);
|
|
5753
|
-
}
|
|
5754
|
-
}
|
|
5755
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5756
|
-
finally {
|
|
5757
|
-
try {
|
|
5758
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5759
|
-
}
|
|
5760
|
-
finally { if (e_1) throw e_1.error; }
|
|
5761
|
-
}
|
|
5762
|
-
return result;
|
|
5763
|
-
},
|
|
5764
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5765
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5766
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5767
|
-
},
|
|
5768
|
-
};
|
|
5769
|
-
|
|
5770
5509
|
var specialExpressions = {
|
|
5771
5510
|
'&&': andSpecialExpression,
|
|
5772
5511
|
'comment': commentSpecialExpression,
|
|
@@ -5781,19 +5520,14 @@ var specialExpressions = {
|
|
|
5781
5520
|
'for': forSpecialExpression,
|
|
5782
5521
|
'fn': fnSpecialExpression,
|
|
5783
5522
|
'if': ifSpecialExpression,
|
|
5784
|
-
'
|
|
5785
|
-
'if_not': ifNotSpecialExpression,
|
|
5523
|
+
'unless': unlessSpecialExpression,
|
|
5786
5524
|
'let': letSpecialExpression,
|
|
5787
5525
|
'loop': loopSpecialExpression,
|
|
5788
5526
|
'||': orSpecialExpression,
|
|
5789
5527
|
'recur': recurSpecialExpression,
|
|
5790
5528
|
'throw': throwSpecialExpression,
|
|
5791
5529
|
'try': trySpecialExpression,
|
|
5792
|
-
'
|
|
5793
|
-
'when_first': whenFirstSpecialExpression,
|
|
5794
|
-
'when_let': whenLetSpecialExpression,
|
|
5795
|
-
'when_not': whenNotSpecialExpression,
|
|
5796
|
-
'declared?': declaredSpecialExpression,
|
|
5530
|
+
'defined?': declaredSpecialExpression,
|
|
5797
5531
|
'??': qqSpecialExpression,
|
|
5798
5532
|
};
|
|
5799
5533
|
Object.keys(specialExpressions).forEach(function (key) {
|
|
@@ -5815,8 +5549,8 @@ function isContextEntry(value) {
|
|
|
5815
5549
|
var ContextStackImpl = /** @class */ (function () {
|
|
5816
5550
|
function ContextStackImpl(_a) {
|
|
5817
5551
|
var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
|
|
5818
|
-
this.contexts = contexts;
|
|
5819
5552
|
this.globalContext = asNonUndefined(contexts[0]);
|
|
5553
|
+
this.contexts = contexts;
|
|
5820
5554
|
this.values = hostValues;
|
|
5821
5555
|
this.lazyValues = lazyHostValues;
|
|
5822
5556
|
this.nativeJsFunctions = nativeJsFunctions;
|
|
@@ -5832,6 +5566,35 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5832
5566
|
contextStack.globalContext = globalContext;
|
|
5833
5567
|
return contextStack;
|
|
5834
5568
|
};
|
|
5569
|
+
ContextStackImpl.prototype.exportValue = function (name, value) {
|
|
5570
|
+
if (this.globalContext[name]) {
|
|
5571
|
+
throw new Error("Cannot redefine exported value \"".concat(name, "\""));
|
|
5572
|
+
}
|
|
5573
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5574
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5575
|
+
}
|
|
5576
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5577
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5578
|
+
}
|
|
5579
|
+
this.addValue(name, value);
|
|
5580
|
+
this.globalContext[name] = { value: value };
|
|
5581
|
+
};
|
|
5582
|
+
ContextStackImpl.prototype.addValue = function (name, value) {
|
|
5583
|
+
var currentContext = this.contexts[0];
|
|
5584
|
+
if (!currentContext) {
|
|
5585
|
+
throw new Error('No context to add value to');
|
|
5586
|
+
}
|
|
5587
|
+
if (currentContext[name]) {
|
|
5588
|
+
throw new Error("Cannot redefine value \"".concat(name, "\""));
|
|
5589
|
+
}
|
|
5590
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5591
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5592
|
+
}
|
|
5593
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5594
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5595
|
+
}
|
|
5596
|
+
currentContext[name] = { value: toAny(value) };
|
|
5597
|
+
};
|
|
5835
5598
|
ContextStackImpl.prototype.clone = function () {
|
|
5836
5599
|
// eslint-disable-next-line ts/no-unsafe-argument
|
|
5837
5600
|
return new ContextStackImpl(JSON.parse(JSON.stringify({
|
|
@@ -5961,7 +5724,7 @@ function createContextStack(params) {
|
|
|
5961
5724
|
return acc;
|
|
5962
5725
|
}, {}),
|
|
5963
5726
|
});
|
|
5964
|
-
return contextStack;
|
|
5727
|
+
return contextStack.create({});
|
|
5965
5728
|
}
|
|
5966
5729
|
|
|
5967
5730
|
var _a$1;
|
|
@@ -6273,7 +6036,14 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6273
6036
|
|
|
6274
6037
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6275
6038
|
var e_1, _a;
|
|
6276
|
-
var astNodes = Array.isArray(ast)
|
|
6039
|
+
var astNodes = Array.isArray(ast)
|
|
6040
|
+
? ast
|
|
6041
|
+
: [{
|
|
6042
|
+
t: AstNodeType.SpecialExpression,
|
|
6043
|
+
n: 'do',
|
|
6044
|
+
p: ast.b,
|
|
6045
|
+
token: undefined,
|
|
6046
|
+
}];
|
|
6277
6047
|
var unresolvedIdentifiers = new Set();
|
|
6278
6048
|
try {
|
|
6279
6049
|
for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
|
|
@@ -6334,548 +6104,20 @@ function findUnresolvedIdentifiersInAstNode(astNode, contextStack, builtin) {
|
|
|
6334
6104
|
}
|
|
6335
6105
|
case AstNodeType.SpecialExpression: {
|
|
6336
6106
|
var specialExpression = asNonUndefined(builtin.specialExpressions[astNode.n], (_b = getTokenDebugData(astNode.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
6337
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6338
|
-
var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
|
|
6339
|
-
findUnresolvedIdentifiers: findUnresolvedIdentifiers,
|
|
6340
|
-
builtin: builtin,
|
|
6341
|
-
evaluateAstNode: evaluateAstNode,
|
|
6342
|
-
});
|
|
6343
|
-
return unresolvedIdentifiers;
|
|
6344
|
-
}
|
|
6345
|
-
}
|
|
6346
|
-
}
|
|
6347
|
-
|
|
6348
|
-
var calculateAndOutcomes = function (_a) {
|
|
6349
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6350
|
-
return combinateAstNodes(astNode.p)
|
|
6351
|
-
.map(function (p) { return ({
|
|
6352
|
-
n: '&&',
|
|
6353
|
-
t: AstNodeType.SpecialExpression,
|
|
6354
|
-
p: p,
|
|
6355
|
-
token: astNode.token,
|
|
6356
|
-
}); });
|
|
6357
|
-
};
|
|
6358
|
-
|
|
6359
|
-
var calculateCondOutcomes = function (_a) {
|
|
6360
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
|
|
6361
|
-
var testNodes = arrayToPairs(astNode.p).map(function (_a) {
|
|
6362
|
-
var _b = __read(_a, 1), t = _b[0];
|
|
6363
|
-
return t;
|
|
6364
|
-
});
|
|
6365
|
-
if (isAstComputable(testNodes)) {
|
|
6366
|
-
return combinate(arrayToPairs(astNode.p)
|
|
6367
|
-
// Create a list of ast nodes from the test and form of each condition
|
|
6368
|
-
.reduce(function (acc, _a) {
|
|
6369
|
-
var _b = __read(_a, 2), test = _b[0], form = _b[1];
|
|
6370
|
-
acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
|
|
6371
|
-
return acc;
|
|
6372
|
-
}, []))
|
|
6373
|
-
// Create a new CondNode for each combination of test and form outcomes
|
|
6374
|
-
.map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
|
|
6375
|
-
var _b = __read(_a, 2), t = _b[0], f = _b[1];
|
|
6376
|
-
return ({ t: t, f: f });
|
|
6377
|
-
}) })); });
|
|
6378
|
-
}
|
|
6379
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
|
|
6380
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6381
|
-
return calculatePossibleAstNodes(form);
|
|
6382
|
-
})), false), [
|
|
6383
|
-
nilNode,
|
|
6384
|
-
], false);
|
|
6385
|
-
};
|
|
6386
|
-
|
|
6387
|
-
var trueNode = { t: AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
|
|
6388
|
-
var falseNode = { t: AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
|
|
6389
|
-
var calculateDeclaredOutcomes = function (_a) {
|
|
6390
|
-
var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
|
|
6391
|
-
if (isAstComputable(astNode.p))
|
|
6392
|
-
return [trueNode];
|
|
6393
|
-
return [trueNode, falseNode];
|
|
6394
|
-
};
|
|
6395
|
-
|
|
6396
|
-
var calculateDefOutcomes = function (_a) {
|
|
6397
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6398
|
-
var nameNode = asSymbolNode(astNode.p[0]);
|
|
6399
|
-
var valueNode = astNode.p[1];
|
|
6400
|
-
addGlobalIdentifier(nameNode.v);
|
|
6401
|
-
return calculatePossibleAstNodes(valueNode)
|
|
6402
|
-
.map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
|
|
6403
|
-
};
|
|
6404
|
-
|
|
6405
|
-
var calculateDefsOutcomes = function (_a) {
|
|
6406
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6407
|
-
return combinateAstNodes(astNode.p)
|
|
6408
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6409
|
-
};
|
|
6410
|
-
|
|
6411
|
-
var calculateDoOutcomes = function (_a) {
|
|
6412
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6413
|
-
return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6414
|
-
};
|
|
6415
|
-
|
|
6416
|
-
function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
|
|
6417
|
-
return combinate(functionOverloads
|
|
6418
|
-
// For each overload, calculate the possible outcomes for each parameter
|
|
6419
|
-
.map(function (functionOverload) {
|
|
6420
|
-
var _a;
|
|
6421
|
-
return combinateAstNodes(functionOverload.b, [
|
|
6422
|
-
functionOverload.as.m,
|
|
6423
|
-
functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
|
|
6424
|
-
(_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
|
|
6425
|
-
].flat())
|
|
6426
|
-
// For each combination of parameter outcomes, create a new overload
|
|
6427
|
-
.map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
|
|
6428
|
-
}));
|
|
6429
|
-
}
|
|
6430
|
-
var calculateDefnOutcomes = function (_a) {
|
|
6431
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6432
|
-
addGlobalIdentifier(astNode.f.v);
|
|
6433
|
-
// astNode.o is an array of overloads
|
|
6434
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6435
|
-
};
|
|
6436
|
-
var calculateDefnsOutcomes = function (_a) {
|
|
6437
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
|
|
6438
|
-
// astNode.o is an array of overloads
|
|
6439
|
-
return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
|
|
6440
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
|
|
6441
|
-
});
|
|
6442
|
-
};
|
|
6443
|
-
var calculateFnOutcomes = function (_a) {
|
|
6444
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6445
|
-
// astNode.o is an array of overloads
|
|
6446
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6447
|
-
};
|
|
6448
|
-
|
|
6449
|
-
var calculateIfLetOutcomes = function (_a) {
|
|
6450
|
-
var _b;
|
|
6451
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6452
|
-
var bindingNode = astNode.b;
|
|
6453
|
-
var thenBranch = astNode.p[0];
|
|
6454
|
-
var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6455
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6456
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6457
|
-
}
|
|
6458
|
-
var newIdentifier = bindingNode.n;
|
|
6459
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6460
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6461
|
-
.flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6462
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
|
|
6463
|
-
};
|
|
6464
|
-
|
|
6465
|
-
var calculateIfNotOutcomes = function (_a) {
|
|
6466
|
-
var _b;
|
|
6467
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6468
|
-
var condition = astNode.p[0];
|
|
6469
|
-
var thenBranch = astNode.p[1];
|
|
6470
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6471
|
-
if (isAstComputable(condition)) {
|
|
6472
|
-
return combinateAstNodes(astNode.p)
|
|
6473
|
-
.map(function (p) { return ({
|
|
6474
|
-
n: 'if_not',
|
|
6475
|
-
t: astNode.t,
|
|
6476
|
-
p: p,
|
|
6477
|
-
token: astNode.token,
|
|
6478
|
-
}); });
|
|
6479
|
-
}
|
|
6480
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6481
|
-
};
|
|
6482
|
-
|
|
6483
|
-
var calculateIfOutcomes = function (_a) {
|
|
6484
|
-
var _b;
|
|
6485
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6486
|
-
var condition = astNode.p[0];
|
|
6487
|
-
var thenBranch = astNode.p[1];
|
|
6488
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6489
|
-
if (isAstComputable(condition)) {
|
|
6490
|
-
return combinateAstNodes(astNode.p)
|
|
6491
|
-
.map(function (p) { return ({
|
|
6492
|
-
n: 'if',
|
|
6493
|
-
t: astNode.t,
|
|
6494
|
-
p: p,
|
|
6495
|
-
token: astNode.token,
|
|
6496
|
-
}); });
|
|
6497
|
-
}
|
|
6498
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6499
|
-
};
|
|
6500
|
-
|
|
6501
|
-
var calculateLetOutcomes = function (_a) {
|
|
6502
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6503
|
-
try {
|
|
6504
|
-
// check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
|
|
6505
|
-
if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
|
|
6506
|
-
throw new Error('Could not calculate binding value');
|
|
6507
|
-
}
|
|
6508
|
-
catch (_b) {
|
|
6509
|
-
var doNodes = combinateAstNodes(astNode.p)
|
|
6510
|
-
.map(function (p) {
|
|
6511
|
-
return {
|
|
6512
|
-
n: 'do',
|
|
6513
|
-
t: AstNodeType.SpecialExpression,
|
|
6514
|
-
p: p,
|
|
6515
|
-
token: astNode.token,
|
|
6516
|
-
};
|
|
6517
|
-
});
|
|
6518
|
-
return doNodes;
|
|
6519
|
-
}
|
|
6520
|
-
var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
|
|
6521
|
-
var letNodes = combinate(astNode.bs.map(function (bindingNode) {
|
|
6522
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6523
|
-
.map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
|
|
6524
|
-
}))
|
|
6525
|
-
.flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
|
|
6526
|
-
.map(function (p) {
|
|
6527
|
-
return {
|
|
6528
|
-
n: 'let',
|
|
6529
|
-
bs: bindingNodes,
|
|
6530
|
-
t: AstNodeType.SpecialExpression,
|
|
6531
|
-
p: p,
|
|
6532
|
-
token: astNode.token,
|
|
6533
|
-
};
|
|
6534
|
-
}); });
|
|
6535
|
-
return letNodes;
|
|
6536
|
-
};
|
|
6537
|
-
|
|
6538
|
-
var calculateForOutcomes = function (_a) {
|
|
6539
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6540
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6541
|
-
throw new Error('Could not calculate for loop, not deterministic');
|
|
6542
|
-
return [astNode];
|
|
6543
|
-
};
|
|
6544
|
-
var calculateDoSeqOutcomes = function (_a) {
|
|
6545
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6546
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6547
|
-
throw new Error('Could not calculate doSeq node, not deterministic');
|
|
6548
|
-
return [astNode];
|
|
6549
|
-
};
|
|
6550
|
-
function isDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6551
|
-
var e_1, _a;
|
|
6552
|
-
try {
|
|
6553
|
-
for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6554
|
-
var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
|
|
6555
|
-
if (l && l.some(function (_a) {
|
|
6556
|
-
var v = _a.v;
|
|
6557
|
-
return !astIsDeterministic(calculatePossibleAstNodes, v);
|
|
6558
|
-
}))
|
|
6559
|
-
return false;
|
|
6560
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
|
|
6561
|
-
return false;
|
|
6562
|
-
if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
|
|
6563
|
-
return false;
|
|
6564
|
-
if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
|
|
6565
|
-
return false;
|
|
6566
|
-
}
|
|
6567
|
-
}
|
|
6568
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6569
|
-
finally {
|
|
6570
|
-
try {
|
|
6571
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6572
|
-
}
|
|
6573
|
-
finally { if (e_1) throw e_1.error; }
|
|
6574
|
-
}
|
|
6575
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
|
|
6576
|
-
return false;
|
|
6577
|
-
return true;
|
|
6578
|
-
}
|
|
6579
|
-
function astIsDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6580
|
-
return calculatePossibleAstNodes(astNode).length === 1;
|
|
6581
|
-
}
|
|
6582
|
-
|
|
6583
|
-
var calculateOrOutcomes = function (_a) {
|
|
6584
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6585
|
-
return combinateAstNodes(astNode.p)
|
|
6586
|
-
.map(function (p) { return ({
|
|
6587
|
-
n: '||',
|
|
6588
|
-
t: AstNodeType.SpecialExpression,
|
|
6589
|
-
p: p,
|
|
6590
|
-
token: astNode.token,
|
|
6591
|
-
}); });
|
|
6592
|
-
};
|
|
6593
|
-
|
|
6594
|
-
var calculateQqOutcomes = function (_a) {
|
|
6595
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6596
|
-
if (!isAstComputable(astNode.p[0]))
|
|
6597
|
-
throw new Error('First argument of ?? not computable');
|
|
6598
|
-
return combinateAstNodes(astNode.p)
|
|
6599
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6600
|
-
};
|
|
6601
|
-
|
|
6602
|
-
var calculateThrowOutcomes = function (_a) {
|
|
6603
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6604
|
-
return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
|
|
6605
|
-
};
|
|
6606
|
-
|
|
6607
|
-
var calculateTryOutcomes = function (_a) {
|
|
6608
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6609
|
-
var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
|
|
6610
|
-
if (node.n === 'throw') {
|
|
6611
|
-
acc.throws.push(node.p[0]);
|
|
6612
|
-
}
|
|
6613
|
-
else {
|
|
6614
|
-
acc.vals.push(node);
|
|
6615
|
-
}
|
|
6616
|
-
return acc;
|
|
6617
|
-
}, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
|
|
6618
|
-
var catches = throws.flatMap(function (throwNode) {
|
|
6619
|
-
var letNode = {
|
|
6620
|
-
t: AstNodeType.SpecialExpression,
|
|
6621
|
-
n: 'let',
|
|
6622
|
-
bs: [{
|
|
6623
|
-
t: AstNodeType.Binding,
|
|
6624
|
-
n: astNode.e.v,
|
|
6625
|
-
v: throwNode,
|
|
6626
|
-
token: undefined,
|
|
6627
|
-
p: [],
|
|
6628
|
-
}],
|
|
6629
|
-
p: [astNode.ce],
|
|
6630
|
-
token: undefined,
|
|
6631
|
-
};
|
|
6632
|
-
return calculatePossibleAstNodes(letNode);
|
|
6633
|
-
});
|
|
6634
|
-
return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
|
|
6635
|
-
};
|
|
6636
|
-
|
|
6637
|
-
var calculateWhenFirstOutcomes = function (_a) {
|
|
6638
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6639
|
-
var bindingNode = astNode.b;
|
|
6640
|
-
if (!isAstComputable(bindingNode.v))
|
|
6641
|
-
throw new Error('Could not calculate binding value');
|
|
6642
|
-
var newIdentifier = bindingNode.n;
|
|
6643
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6644
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6645
|
-
.flatMap(function (b) {
|
|
6646
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6647
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6648
|
-
});
|
|
6649
|
-
};
|
|
6650
|
-
|
|
6651
|
-
var calculateWhenLetOutcomes = function (_a) {
|
|
6652
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6653
|
-
var bindingNode = astNode.b;
|
|
6654
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6655
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
|
|
6656
|
-
.map(function (p) { return ({
|
|
6657
|
-
n: 'do',
|
|
6658
|
-
t: astNode.t,
|
|
6659
|
-
p: p,
|
|
6660
|
-
token: astNode.token,
|
|
6661
|
-
}); })), false), [
|
|
6662
|
-
nilNode,
|
|
6663
|
-
], false);
|
|
6664
|
-
}
|
|
6665
|
-
var newIdentifier = bindingNode.n;
|
|
6666
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6667
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6668
|
-
.flatMap(function (b) {
|
|
6669
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6670
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6671
|
-
});
|
|
6672
|
-
};
|
|
6673
|
-
|
|
6674
|
-
var calculateWhenNotOutcomes = function (_a) {
|
|
6675
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6676
|
-
var condition = astNode.p[0];
|
|
6677
|
-
if (isAstComputable(condition)) {
|
|
6678
|
-
return combinateAstNodes(astNode.p)
|
|
6679
|
-
.map(function (p) { return ({
|
|
6680
|
-
n: 'when_not',
|
|
6681
|
-
t: astNode.t,
|
|
6682
|
-
p: p,
|
|
6683
|
-
token: astNode.token,
|
|
6684
|
-
}); });
|
|
6685
|
-
}
|
|
6686
|
-
var body = astNode.p.slice(1);
|
|
6687
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6688
|
-
.map(function (p) { return ({
|
|
6689
|
-
n: 'do',
|
|
6690
|
-
t: astNode.t,
|
|
6691
|
-
p: p,
|
|
6692
|
-
token: astNode.token,
|
|
6693
|
-
}); })), false), [
|
|
6694
|
-
nilNode,
|
|
6695
|
-
], false);
|
|
6696
|
-
};
|
|
6697
|
-
|
|
6698
|
-
var calculateWhenOutcomes = function (_a) {
|
|
6699
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6700
|
-
var condition = astNode.p[0];
|
|
6701
|
-
if (isAstComputable(condition)) {
|
|
6702
|
-
return combinateAstNodes(astNode.p)
|
|
6703
|
-
.map(function (p) { return ({
|
|
6704
|
-
n: 'when',
|
|
6705
|
-
t: astNode.t,
|
|
6706
|
-
p: p,
|
|
6707
|
-
token: astNode.token,
|
|
6708
|
-
}); });
|
|
6709
|
-
}
|
|
6710
|
-
var body = astNode.p.slice(1);
|
|
6711
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6712
|
-
.map(function (p) { return ({
|
|
6713
|
-
n: 'do',
|
|
6714
|
-
t: astNode.t,
|
|
6715
|
-
p: p,
|
|
6716
|
-
token: astNode.token,
|
|
6717
|
-
}); })), false), [
|
|
6718
|
-
nilNode,
|
|
6719
|
-
], false);
|
|
6720
|
-
};
|
|
6721
|
-
|
|
6722
|
-
var calculateRecurOutcomes = function (_a) {
|
|
6723
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6724
|
-
return combinateAstNodes(astNode.p)
|
|
6725
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6726
|
-
};
|
|
6727
|
-
|
|
6728
|
-
var calculateCommentOutcomes = function (_a) {
|
|
6729
|
-
var nilNode = _a.nilNode;
|
|
6730
|
-
return [nilNode];
|
|
6731
|
-
};
|
|
6732
|
-
|
|
6733
|
-
var calculateLoopOutcomes = function (_a) {
|
|
6734
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6735
|
-
return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
|
|
6736
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6737
|
-
};
|
|
6738
|
-
|
|
6739
|
-
var calculateSwitchOutcomes = function (_a) {
|
|
6740
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6741
|
-
// TODO be smarter about this
|
|
6742
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p.slice(1)).flatMap(function (_a) {
|
|
6743
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6744
|
-
return calculatePossibleAstNodes(form);
|
|
6745
|
-
})), false), [
|
|
6746
|
-
nilNode,
|
|
6747
|
-
], false);
|
|
6748
|
-
};
|
|
6749
|
-
|
|
6750
|
-
var specialExpressionCalculator = {
|
|
6751
|
-
'&&': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6752
|
-
'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6753
|
-
'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6754
|
-
'switch': function (astNode, helperOptions) { return calculateSwitchOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6755
|
-
'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6756
|
-
'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6757
|
-
'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6758
|
-
'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6759
|
-
'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6760
|
-
'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6761
|
-
'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6762
|
-
'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6763
|
-
'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6764
|
-
'if_let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6765
|
-
'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6766
|
-
'if_not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6767
|
-
'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6768
|
-
'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6769
|
-
'||': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6770
|
-
'??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6771
|
-
'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6772
|
-
'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6773
|
-
'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6774
|
-
'when_first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6775
|
-
'when_let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6776
|
-
'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6777
|
-
'when_not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6778
|
-
};
|
|
6779
|
-
|
|
6780
|
-
function calculateOutcomes(contextStack, astNodes) {
|
|
6781
|
-
// First, we try to calculate outcomes for the whole astNodes array.
|
|
6782
|
-
// If that fails, we try to calculate outcomes for the array without the first element.
|
|
6783
|
-
// If that fails, we try to calculate outcomes for the array without the first two elements.
|
|
6784
|
-
// And so on.
|
|
6785
|
-
// This makes it possible to calculate outcomes for e.g.
|
|
6786
|
-
// (write! x) x
|
|
6787
|
-
// Problems occur for e.g.
|
|
6788
|
-
// (def x 1) (write! x) x
|
|
6789
|
-
// This should output [1], but since (write! x) fails to calculate outcomes, we get null.
|
|
6790
|
-
// Ok, but not optimal
|
|
6791
|
-
// The contract is that when an array is returned, it must be correct.
|
|
6792
|
-
// But returning null (indicating that the calculation failed) is always a way out.
|
|
6793
|
-
for (var i = 0; i < astNodes.length; i++) {
|
|
6794
|
-
var usingAstNode = astNodes.slice(i);
|
|
6795
|
-
var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
|
|
6796
|
-
if (outcomes !== null)
|
|
6797
|
-
return outcomes;
|
|
6798
|
-
}
|
|
6799
|
-
return null;
|
|
6800
|
-
}
|
|
6801
|
-
function calculateOutcomesInner(contextStack, astNodes) {
|
|
6802
|
-
var e_1, _a;
|
|
6803
|
-
var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
|
|
6804
|
-
if (possibleAsts === null)
|
|
6805
|
-
return null;
|
|
6806
|
-
var outcomes = [];
|
|
6807
|
-
try {
|
|
6808
|
-
for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
|
|
6809
|
-
var possibleAst = possibleAsts_1_1.value;
|
|
6810
|
-
var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
|
|
6811
|
-
if (unresolvedIdentifiers.size !== 0)
|
|
6812
|
-
return null;
|
|
6813
|
-
var ast = {
|
|
6814
|
-
b: possibleAst,
|
|
6815
|
-
hasDebugData: true,
|
|
6816
|
-
};
|
|
6817
|
-
try {
|
|
6818
|
-
outcomes.push(evaluate(ast, contextStack.clone()));
|
|
6819
|
-
}
|
|
6820
|
-
catch (e) {
|
|
6821
|
-
outcomes.push(e);
|
|
6822
|
-
}
|
|
6823
|
-
}
|
|
6824
|
-
}
|
|
6825
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6826
|
-
finally {
|
|
6827
|
-
try {
|
|
6828
|
-
if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
|
|
6107
|
+
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6108
|
+
var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
|
|
6109
|
+
findUnresolvedIdentifiers: findUnresolvedIdentifiers,
|
|
6110
|
+
builtin: builtin,
|
|
6111
|
+
evaluateAstNode: evaluateAstNode,
|
|
6112
|
+
});
|
|
6113
|
+
return unresolvedIdentifiers;
|
|
6829
6114
|
}
|
|
6830
|
-
finally { if (e_1) throw e_1.error; }
|
|
6831
|
-
}
|
|
6832
|
-
return outcomes;
|
|
6833
|
-
}
|
|
6834
|
-
function calculatePossibleAsts(contextStack, astNodes) {
|
|
6835
|
-
var possibleAsts;
|
|
6836
|
-
try {
|
|
6837
|
-
possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
|
|
6838
|
-
}
|
|
6839
|
-
catch (e) {
|
|
6840
|
-
return null;
|
|
6841
|
-
}
|
|
6842
|
-
return possibleAsts;
|
|
6843
|
-
}
|
|
6844
|
-
var nilNode = { t: AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
|
|
6845
|
-
function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
|
|
6846
|
-
var newContext = newIndentifiers
|
|
6847
|
-
? newIndentifiers.reduce(function (acc, identity) {
|
|
6848
|
-
acc[identity] = { value: null };
|
|
6849
|
-
return acc;
|
|
6850
|
-
}, {})
|
|
6851
|
-
: undefined;
|
|
6852
|
-
var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
|
|
6853
|
-
if (astNode.t === AstNodeType.NormalExpression) {
|
|
6854
|
-
return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
|
|
6855
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6856
|
-
}
|
|
6857
|
-
else if (astNode.t === AstNodeType.SpecialExpression) {
|
|
6858
|
-
var helperOptions = {
|
|
6859
|
-
nilNode: nilNode,
|
|
6860
|
-
calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
|
|
6861
|
-
combinateAstNodes: function (nodes, identifiers) {
|
|
6862
|
-
return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
|
|
6863
|
-
},
|
|
6864
|
-
isAstComputable: function (node) {
|
|
6865
|
-
return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
|
|
6866
|
-
},
|
|
6867
|
-
addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
|
|
6868
|
-
};
|
|
6869
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6870
|
-
return specialExpressionCalculator[astNode.n](astNode, helperOptions);
|
|
6871
6115
|
}
|
|
6872
|
-
return [astNode];
|
|
6873
6116
|
}
|
|
6874
6117
|
|
|
6875
6118
|
function analyze(ast, params) {
|
|
6876
6119
|
return {
|
|
6877
6120
|
unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
|
|
6878
|
-
outcomes: calculateOutcomes(createContextStack(params), ast.b),
|
|
6879
6121
|
};
|
|
6880
6122
|
}
|
|
6881
6123
|
|
|
@@ -7157,38 +6399,43 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7157
6399
|
var _a;
|
|
7158
6400
|
if (precedence === void 0) { precedence = 0; }
|
|
7159
6401
|
var firstToken = this.peek();
|
|
7160
|
-
if (isA_SymbolToken(firstToken) && firstToken[1] === 'def') {
|
|
7161
|
-
return this.parseDef(firstToken);
|
|
7162
|
-
}
|
|
7163
|
-
else if (isA_SymbolToken(firstToken) && firstToken[1] === 'defn') {
|
|
7164
|
-
return this.parseDefn(firstToken);
|
|
7165
|
-
}
|
|
7166
6402
|
var left;
|
|
7167
|
-
if (isA_SymbolToken(firstToken)
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
6403
|
+
if (isA_SymbolToken(firstToken)) {
|
|
6404
|
+
switch (firstToken[1]) {
|
|
6405
|
+
case 'def':
|
|
6406
|
+
return this.parseDef(firstToken);
|
|
6407
|
+
case 'defn':
|
|
6408
|
+
return this.parseDefn(firstToken);
|
|
6409
|
+
case 'let':
|
|
6410
|
+
return this.parseLet(firstToken);
|
|
6411
|
+
case 'if':
|
|
6412
|
+
case 'unless':
|
|
6413
|
+
left = this.parseIfOrUnless(firstToken);
|
|
6414
|
+
break;
|
|
6415
|
+
case 'cond':
|
|
6416
|
+
left = this.parseCond(firstToken);
|
|
6417
|
+
break;
|
|
6418
|
+
case 'switch':
|
|
6419
|
+
left = this.parseSwitch(firstToken);
|
|
6420
|
+
break;
|
|
6421
|
+
case 'for':
|
|
6422
|
+
case 'doseq':
|
|
6423
|
+
left = this.parseForOrDoseq(firstToken);
|
|
6424
|
+
break;
|
|
6425
|
+
case 'do':
|
|
6426
|
+
left = this.parseDo(firstToken);
|
|
6427
|
+
break;
|
|
6428
|
+
case 'loop':
|
|
6429
|
+
left = this.parseLoop(firstToken);
|
|
6430
|
+
break;
|
|
6431
|
+
case 'try':
|
|
6432
|
+
left = this.parseTry(firstToken);
|
|
6433
|
+
break;
|
|
6434
|
+
}
|
|
7181
6435
|
}
|
|
6436
|
+
left || (left = this.parseOperand());
|
|
7182
6437
|
var operator = this.peek();
|
|
7183
|
-
while (!this.
|
|
7184
|
-
&& !isA_OperatorToken(operator, ',')
|
|
7185
|
-
&& !isA_OperatorToken(operator, ';')
|
|
7186
|
-
&& !isRBracketToken(operator)
|
|
7187
|
-
&& !isA_ReservedSymbolToken(operator, 'else')
|
|
7188
|
-
&& !isA_ReservedSymbolToken(operator, 'then')
|
|
7189
|
-
&& !isA_ReservedSymbolToken(operator, 'end')
|
|
7190
|
-
&& !isA_ReservedSymbolToken(operator, 'case')
|
|
7191
|
-
&& !isRParenToken(operator)) {
|
|
6438
|
+
while (!this.isAtExpressionEnd()) {
|
|
7192
6439
|
if (isA_BinaryOperatorToken(operator)) {
|
|
7193
6440
|
var name_1 = operator[1];
|
|
7194
6441
|
var newPrecedece = getPrecedence(name_1);
|
|
@@ -7441,12 +6688,9 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7441
6688
|
case '??':
|
|
7442
6689
|
case '&&':
|
|
7443
6690
|
case 'comment':
|
|
7444
|
-
case '
|
|
7445
|
-
case 'if_not':
|
|
6691
|
+
case 'defined?':
|
|
7446
6692
|
case '||':
|
|
7447
|
-
case '
|
|
7448
|
-
case 'when_not':
|
|
7449
|
-
case 'do':
|
|
6693
|
+
case 'recur':
|
|
7450
6694
|
case 'throw': {
|
|
7451
6695
|
var node = {
|
|
7452
6696
|
t: AstNodeType.SpecialExpression,
|
|
@@ -7457,17 +6701,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7457
6701
|
builtin.specialExpressions[node.n].validateParameterCount(node);
|
|
7458
6702
|
return node;
|
|
7459
6703
|
}
|
|
7460
|
-
case 'let':
|
|
7461
|
-
return this.parseLet(symbol, params);
|
|
7462
6704
|
case 'defs':
|
|
7463
|
-
case 'if_let':
|
|
7464
|
-
case 'when_let':
|
|
7465
|
-
case 'when_first':
|
|
7466
6705
|
case 'fn':
|
|
7467
6706
|
case 'defns':
|
|
7468
6707
|
case 'try':
|
|
7469
|
-
case 'recur':
|
|
7470
|
-
case 'loop':
|
|
7471
6708
|
case 'doseq':
|
|
7472
6709
|
throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
|
|
7473
6710
|
default:
|
|
@@ -7630,36 +6867,142 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7630
6867
|
};
|
|
7631
6868
|
return node;
|
|
7632
6869
|
};
|
|
7633
|
-
AlgebraicParser.prototype.parseLet = function (
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
var
|
|
7639
|
-
if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
|
|
7640
|
-
throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7641
|
-
}
|
|
7642
|
-
var letBindings = arrayToPairs(letObject.p);
|
|
7643
|
-
var expression = params[1];
|
|
6870
|
+
AlgebraicParser.prototype.parseLet = function (token) {
|
|
6871
|
+
this.advance();
|
|
6872
|
+
var letSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6873
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6874
|
+
this.advance();
|
|
6875
|
+
var value = this.parseExpression();
|
|
7644
6876
|
return {
|
|
7645
6877
|
t: AstNodeType.SpecialExpression,
|
|
7646
6878
|
n: 'let',
|
|
7647
|
-
p: [
|
|
6879
|
+
p: [],
|
|
7648
6880
|
token: getTokenDebugData(letSymbol.token) && letSymbol.token,
|
|
7649
|
-
bs:
|
|
7650
|
-
var key = pair[0];
|
|
7651
|
-
var value = pair[1];
|
|
7652
|
-
return {
|
|
6881
|
+
bs: [{
|
|
7653
6882
|
t: AstNodeType.Binding,
|
|
7654
|
-
n:
|
|
6883
|
+
n: letSymbol.v,
|
|
7655
6884
|
v: value,
|
|
7656
6885
|
p: [],
|
|
7657
|
-
token: getTokenDebugData(
|
|
7658
|
-
}
|
|
7659
|
-
|
|
6886
|
+
token: getTokenDebugData(token) && token,
|
|
6887
|
+
}],
|
|
6888
|
+
};
|
|
6889
|
+
};
|
|
6890
|
+
AlgebraicParser.prototype.parseDo = function (token) {
|
|
6891
|
+
this.advance();
|
|
6892
|
+
var expressions = [];
|
|
6893
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6894
|
+
expressions.push(this.parseExpression());
|
|
6895
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6896
|
+
this.advance();
|
|
6897
|
+
}
|
|
6898
|
+
}
|
|
6899
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6900
|
+
this.advance();
|
|
6901
|
+
return {
|
|
6902
|
+
t: AstNodeType.SpecialExpression,
|
|
6903
|
+
n: 'do',
|
|
6904
|
+
p: expressions,
|
|
6905
|
+
token: getTokenDebugData(token) && token,
|
|
6906
|
+
};
|
|
6907
|
+
};
|
|
6908
|
+
AlgebraicParser.prototype.parseLoop = function (token) {
|
|
6909
|
+
var _a;
|
|
6910
|
+
this.advance();
|
|
6911
|
+
assertLParenToken(this.peek());
|
|
6912
|
+
this.advance();
|
|
6913
|
+
var bindingNodes = [];
|
|
6914
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6915
|
+
var symbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6916
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6917
|
+
this.advance();
|
|
6918
|
+
var value = this.parseExpression();
|
|
6919
|
+
bindingNodes.push({
|
|
6920
|
+
t: AstNodeType.Binding,
|
|
6921
|
+
n: symbol.v,
|
|
6922
|
+
v: value,
|
|
6923
|
+
p: [],
|
|
6924
|
+
token: getTokenDebugData(symbol.token) && symbol.token,
|
|
6925
|
+
});
|
|
6926
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
6927
|
+
this.advance();
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
if (bindingNodes.length === 0) {
|
|
6931
|
+
throw new LitsError('Expected binding', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
6932
|
+
}
|
|
6933
|
+
assertRParenToken(this.peek());
|
|
6934
|
+
this.advance();
|
|
6935
|
+
var params = [];
|
|
6936
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6937
|
+
params.push(this.parseExpression());
|
|
6938
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6939
|
+
this.advance();
|
|
6940
|
+
}
|
|
6941
|
+
}
|
|
6942
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6943
|
+
this.advance();
|
|
6944
|
+
return {
|
|
6945
|
+
t: AstNodeType.SpecialExpression,
|
|
6946
|
+
n: 'loop',
|
|
6947
|
+
p: params,
|
|
6948
|
+
bs: bindingNodes,
|
|
6949
|
+
token: getTokenDebugData(token) && token,
|
|
6950
|
+
};
|
|
6951
|
+
};
|
|
6952
|
+
AlgebraicParser.prototype.parseTry = function (token) {
|
|
6953
|
+
this.advance();
|
|
6954
|
+
var tryExpressions = [];
|
|
6955
|
+
while (!this.isAtEnd() && !isA_SymbolToken(this.peek(), 'catch')) {
|
|
6956
|
+
tryExpressions.push(this.parseExpression());
|
|
6957
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6958
|
+
this.advance();
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
var tryExpression = tryExpressions.length === 1
|
|
6962
|
+
? tryExpressions[0]
|
|
6963
|
+
: {
|
|
6964
|
+
t: AstNodeType.SpecialExpression,
|
|
6965
|
+
n: 'do',
|
|
6966
|
+
p: tryExpressions,
|
|
6967
|
+
token: getTokenDebugData(token) && token,
|
|
6968
|
+
};
|
|
6969
|
+
assertA_SymbolToken(this.peek(), 'catch');
|
|
6970
|
+
this.advance();
|
|
6971
|
+
var errorSymbol;
|
|
6972
|
+
if (isLParenToken(this.peek())) {
|
|
6973
|
+
this.advance();
|
|
6974
|
+
errorSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6975
|
+
assertRParenToken(this.peek());
|
|
6976
|
+
this.advance();
|
|
6977
|
+
}
|
|
6978
|
+
var catchExpressions = [];
|
|
6979
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6980
|
+
catchExpressions.push(this.parseExpression());
|
|
6981
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6982
|
+
this.advance();
|
|
6983
|
+
}
|
|
6984
|
+
}
|
|
6985
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6986
|
+
this.advance();
|
|
6987
|
+
var catchExpression = catchExpressions.length === 1
|
|
6988
|
+
? catchExpressions[0]
|
|
6989
|
+
: {
|
|
6990
|
+
t: AstNodeType.SpecialExpression,
|
|
6991
|
+
n: 'do',
|
|
6992
|
+
p: catchExpressions,
|
|
6993
|
+
token: getTokenDebugData(token) && token,
|
|
6994
|
+
};
|
|
6995
|
+
return {
|
|
6996
|
+
t: AstNodeType.SpecialExpression,
|
|
6997
|
+
n: 'try',
|
|
6998
|
+
p: [tryExpression],
|
|
6999
|
+
ce: catchExpression,
|
|
7000
|
+
e: errorSymbol,
|
|
7001
|
+
token: getTokenDebugData(token) && token,
|
|
7660
7002
|
};
|
|
7661
7003
|
};
|
|
7662
|
-
AlgebraicParser.prototype.
|
|
7004
|
+
AlgebraicParser.prototype.parseForOrDoseq = function (token) {
|
|
7005
|
+
var isDoseq = token[1] === 'doseq';
|
|
7663
7006
|
this.advance();
|
|
7664
7007
|
assertLParenToken(this.peek());
|
|
7665
7008
|
this.advance();
|
|
@@ -7679,7 +7022,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7679
7022
|
this.advance();
|
|
7680
7023
|
return {
|
|
7681
7024
|
t: AstNodeType.SpecialExpression,
|
|
7682
|
-
n: 'for',
|
|
7025
|
+
n: isDoseq ? 'doseq' : 'for',
|
|
7683
7026
|
p: [expression],
|
|
7684
7027
|
token: getTokenDebugData(token) && token,
|
|
7685
7028
|
l: forLoopBindings,
|
|
@@ -7699,33 +7042,26 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7699
7042
|
}
|
|
7700
7043
|
var modifiers = [];
|
|
7701
7044
|
var token = this.peek();
|
|
7702
|
-
if (!isA_SymbolToken(token)
|
|
7045
|
+
if (!isA_SymbolToken(token, 'let')
|
|
7046
|
+
&& !isA_ReservedSymbolToken(token, 'when')
|
|
7047
|
+
&& !isA_ReservedSymbolToken(token, 'while')) {
|
|
7703
7048
|
throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7704
7049
|
}
|
|
7705
7050
|
var letBindings;
|
|
7706
7051
|
if (token[1] === 'let') {
|
|
7707
7052
|
modifiers.push('&let');
|
|
7708
7053
|
letBindings = [];
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
return {
|
|
7715
|
-
t: AstNodeType.Binding,
|
|
7716
|
-
n: key.v,
|
|
7717
|
-
v: value,
|
|
7718
|
-
p: [],
|
|
7719
|
-
token: getTokenDebugData(key.token) && key.token,
|
|
7720
|
-
};
|
|
7721
|
-
});
|
|
7054
|
+
while (isA_SymbolToken(token, 'let')) {
|
|
7055
|
+
var letNode = this.parseLet(token);
|
|
7056
|
+
letBindings.push(letNode.bs[0]);
|
|
7057
|
+
token = this.peek();
|
|
7058
|
+
}
|
|
7722
7059
|
}
|
|
7723
7060
|
token = this.peek();
|
|
7724
7061
|
var whenNode;
|
|
7725
7062
|
var whileNode;
|
|
7726
|
-
while (
|
|
7727
|
-
|
|
7728
|
-
|| (token[1] === 'while' && !modifiers.includes('&while')))) {
|
|
7063
|
+
while (isA_ReservedSymbolToken(token, 'when')
|
|
7064
|
+
|| isA_ReservedSymbolToken(token, 'while')) {
|
|
7729
7065
|
this.advance();
|
|
7730
7066
|
if (token[1] === 'when') {
|
|
7731
7067
|
modifiers.push('&when');
|
|
@@ -7768,7 +7104,8 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7768
7104
|
};
|
|
7769
7105
|
return node;
|
|
7770
7106
|
};
|
|
7771
|
-
AlgebraicParser.prototype.
|
|
7107
|
+
AlgebraicParser.prototype.parseIfOrUnless = function (token) {
|
|
7108
|
+
var isUnless = token[1] === 'unless';
|
|
7772
7109
|
this.advance();
|
|
7773
7110
|
var condition = this.parseExpression();
|
|
7774
7111
|
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
@@ -7817,7 +7154,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7817
7154
|
}
|
|
7818
7155
|
return {
|
|
7819
7156
|
t: AstNodeType.SpecialExpression,
|
|
7820
|
-
n: 'if',
|
|
7157
|
+
n: isUnless ? 'unless' : 'if',
|
|
7821
7158
|
p: params,
|
|
7822
7159
|
token: getTokenDebugData(token) && token,
|
|
7823
7160
|
};
|
|
@@ -7944,6 +7281,22 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7944
7281
|
AlgebraicParser.prototype.isAtEnd = function () {
|
|
7945
7282
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
7946
7283
|
};
|
|
7284
|
+
AlgebraicParser.prototype.isAtExpressionEnd = function () {
|
|
7285
|
+
if (this.isAtEnd()) {
|
|
7286
|
+
return true;
|
|
7287
|
+
}
|
|
7288
|
+
var token = this.peek();
|
|
7289
|
+
if (isA_OperatorToken(token)) {
|
|
7290
|
+
return [';', ','].includes(token[1]);
|
|
7291
|
+
}
|
|
7292
|
+
if (isA_SymbolToken(token)) {
|
|
7293
|
+
return ['catch'].includes(token[1]);
|
|
7294
|
+
}
|
|
7295
|
+
if (isA_ReservedSymbolToken(token)) {
|
|
7296
|
+
return ['else', 'when', 'while', 'then', 'end', 'case'].includes(token[1]);
|
|
7297
|
+
}
|
|
7298
|
+
return false;
|
|
7299
|
+
};
|
|
7947
7300
|
AlgebraicParser.prototype.peek = function () {
|
|
7948
7301
|
return this.tokenStream.tokens[this.parseState.position];
|
|
7949
7302
|
};
|
|
@@ -8409,17 +7762,12 @@ var validAlgebraicReservedNamesRecord = {
|
|
|
8409
7762
|
else: { value: null, forbidden: false },
|
|
8410
7763
|
end: { value: null, forbidden: false },
|
|
8411
7764
|
case: { value: null, forbidden: false },
|
|
7765
|
+
when: { value: null, forbidden: false },
|
|
7766
|
+
while: { value: null, forbidden: false },
|
|
8412
7767
|
};
|
|
8413
7768
|
var forbiddenAlgebraicReservedNamesRecord = {
|
|
8414
|
-
if_let: { value: null, forbidden: true },
|
|
8415
|
-
when_let: { value: null, forbidden: true },
|
|
8416
|
-
when_first: { value: null, forbidden: true },
|
|
8417
7769
|
fn: { value: null, forbidden: true },
|
|
8418
7770
|
defns: { value: null, forbidden: true },
|
|
8419
|
-
try: { value: null, forbidden: true },
|
|
8420
|
-
recur: { value: null, forbidden: true },
|
|
8421
|
-
loop: { value: null, forbidden: true },
|
|
8422
|
-
doseq: { value: null, forbidden: true },
|
|
8423
7771
|
};
|
|
8424
7772
|
var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
|
|
8425
7773
|
|
|
@@ -10118,7 +9466,7 @@ var arrayReference = {
|
|
|
10118
9466
|
description: 'Takes a nested array $x and flattens it.',
|
|
10119
9467
|
examples: [
|
|
10120
9468
|
'(flatten [1 2 [3 4] 5])',
|
|
10121
|
-
"\n(let [foo :bar]\n
|
|
9469
|
+
"\n(let [foo :bar])\n(flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6])",
|
|
10122
9470
|
'(flatten 12)',
|
|
10123
9471
|
],
|
|
10124
9472
|
},
|
|
@@ -13965,97 +13313,12 @@ var specialExpressionsReference = {
|
|
|
13965
13313
|
type: '*binding',
|
|
13966
13314
|
rest: true,
|
|
13967
13315
|
},
|
|
13968
|
-
expressions: {
|
|
13969
|
-
type: '*expression',
|
|
13970
|
-
rest: true,
|
|
13971
|
-
},
|
|
13972
|
-
},
|
|
13973
|
-
variants: [
|
|
13974
|
-
{ argumentNames: ['bindings', 'expressions'] },
|
|
13975
|
-
],
|
|
13976
|
-
description: "\nBinds local variables. The variables lives only within $expressions.\nIt returns evaluation of the last expression in $expressions.",
|
|
13977
|
-
examples: ["\n (let [a (+ 1 2 3 4) \n b (* 1 2 3 4)]\n (write! a b))"],
|
|
13978
|
-
},
|
|
13979
|
-
'if_let': {
|
|
13980
|
-
title: 'if_let',
|
|
13981
|
-
category: 'Special expression',
|
|
13982
|
-
linkName: 'if_let',
|
|
13983
|
-
returns: {
|
|
13984
|
-
type: 'any',
|
|
13985
|
-
},
|
|
13986
|
-
args: {
|
|
13987
|
-
'binding': {
|
|
13988
|
-
type: '*binding',
|
|
13989
|
-
},
|
|
13990
|
-
'then-expr': {
|
|
13991
|
-
type: '*expression',
|
|
13992
|
-
},
|
|
13993
|
-
'else-expr': {
|
|
13994
|
-
type: '*expression',
|
|
13995
|
-
},
|
|
13996
|
-
},
|
|
13997
|
-
variants: [
|
|
13998
|
-
{ argumentNames: ['binding', 'then-expr'] },
|
|
13999
|
-
{ argumentNames: ['binding', 'then-expr', 'else-expr'] },
|
|
14000
|
-
],
|
|
14001
|
-
description: "\nBinds one local variable. If it evaluates to a truthy value\n$then-expr is executed with the variable accessable.\nIf the bound variable evaluates to false, the $else-expr is evaluated\n(without variable accessable).",
|
|
14002
|
-
examples: [
|
|
14003
|
-
"\n(if_let [a (> (count \"Albert\") 4)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
|
|
14004
|
-
"\n(if_let [a (> (count \"Albert\") 10)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
|
|
14005
|
-
],
|
|
14006
|
-
},
|
|
14007
|
-
'when_let': {
|
|
14008
|
-
title: 'when_let',
|
|
14009
|
-
category: 'Special expression',
|
|
14010
|
-
linkName: 'when_let',
|
|
14011
|
-
returns: {
|
|
14012
|
-
type: 'any',
|
|
14013
|
-
},
|
|
14014
|
-
args: {
|
|
14015
|
-
binding: {
|
|
14016
|
-
type: '*binding',
|
|
14017
|
-
},
|
|
14018
|
-
expressions: {
|
|
14019
|
-
type: '*expression',
|
|
14020
|
-
rest: true,
|
|
14021
|
-
},
|
|
14022
|
-
},
|
|
14023
|
-
variants: [
|
|
14024
|
-
{ argumentNames: ['binding', 'expressions'] },
|
|
14025
|
-
],
|
|
14026
|
-
description: "\nBinds one local variable. If it evaluates to a truthy value\n$expressions is executed with the variable accessable.\nIf the bound variable evaluates to a falsy value, `nil` is returned.",
|
|
14027
|
-
examples: [
|
|
14028
|
-
"\n(when_let [a (> (count \"Albert\") 4)]\n (write! a))",
|
|
14029
|
-
],
|
|
14030
|
-
},
|
|
14031
|
-
'when_first': {
|
|
14032
|
-
title: 'when_first',
|
|
14033
|
-
category: 'Special expression',
|
|
14034
|
-
linkName: 'when_first',
|
|
14035
|
-
returns: {
|
|
14036
|
-
type: 'any',
|
|
14037
|
-
},
|
|
14038
|
-
args: {
|
|
14039
|
-
binding: {
|
|
14040
|
-
type: '*binding',
|
|
14041
|
-
rest: true,
|
|
14042
|
-
},
|
|
14043
|
-
expressions: {
|
|
14044
|
-
type: '*expression',
|
|
14045
|
-
rest: true,
|
|
14046
|
-
},
|
|
14047
13316
|
},
|
|
14048
13317
|
variants: [
|
|
14049
|
-
{ argumentNames: ['
|
|
14050
|
-
],
|
|
14051
|
-
description: 'When the binding value in $binding is a non empty sequence, the first element of that sequence (instead of the sequence itself) is bound to the variable.',
|
|
14052
|
-
examples: [
|
|
14053
|
-
"\n(when_first [x [1 2 3]]\n (write! x)\n x)",
|
|
14054
|
-
"\n(when_first [x \"Albert\"]\n (write! x)\n x)",
|
|
14055
|
-
"\n(when_first [x [0]]\n (write! x)\n x)",
|
|
14056
|
-
"\n(when_first [x [nil]]\n (write! x)\n x)",
|
|
14057
|
-
"\n(when_first [x []]\n (write! x)\n x)",
|
|
13318
|
+
{ argumentNames: ['bindings'] },
|
|
14058
13319
|
],
|
|
13320
|
+
description: "\nBinds local variables.",
|
|
13321
|
+
examples: ["\n(let [a (+ 1 2 3 4) \n b (* 1 2 3 4)])\n(write! a b)"],
|
|
14059
13322
|
},
|
|
14060
13323
|
'fn': {
|
|
14061
13324
|
title: 'fn',
|
|
@@ -14219,10 +13482,11 @@ var specialExpressionsReference = {
|
|
|
14219
13482
|
'(if false (write! "TRUE"))',
|
|
14220
13483
|
],
|
|
14221
13484
|
},
|
|
14222
|
-
'
|
|
14223
|
-
title: '
|
|
13485
|
+
'unless': {
|
|
13486
|
+
title: 'unless',
|
|
14224
13487
|
category: 'Special expression',
|
|
14225
|
-
linkName: '
|
|
13488
|
+
linkName: 'unless',
|
|
13489
|
+
clojureDocs: 'if-not',
|
|
14226
13490
|
returns: {
|
|
14227
13491
|
type: 'any',
|
|
14228
13492
|
},
|
|
@@ -14243,10 +13507,10 @@ var specialExpressionsReference = {
|
|
|
14243
13507
|
],
|
|
14244
13508
|
description: 'Either $then-expr or $else-expr branch is taken. $then-expr is selected when $test is falsy. If $test is truthy $else-expr is executed, if no $else-expr exists, `nil` is returned.',
|
|
14245
13509
|
examples: [
|
|
14246
|
-
'(
|
|
14247
|
-
'(
|
|
14248
|
-
'(
|
|
14249
|
-
'(
|
|
13510
|
+
'(unless true (write! "TRUE") (write! "FALSE"))',
|
|
13511
|
+
'(unless false (write! "TRUE") (write! "FALSE"))',
|
|
13512
|
+
'(unless true (write! "TRUE"))',
|
|
13513
|
+
'(unless false (write! "TRUE"))',
|
|
14250
13514
|
],
|
|
14251
13515
|
},
|
|
14252
13516
|
'cond': {
|
|
@@ -14296,60 +13560,6 @@ var specialExpressionsReference = {
|
|
|
14296
13560
|
"\n(switch 3\n 1 (write! \"FALSE\")\n 2 (write! \"nil\"))",
|
|
14297
13561
|
],
|
|
14298
13562
|
},
|
|
14299
|
-
'when': {
|
|
14300
|
-
title: 'when',
|
|
14301
|
-
category: 'Special expression',
|
|
14302
|
-
linkName: 'when',
|
|
14303
|
-
returns: {
|
|
14304
|
-
type: 'any',
|
|
14305
|
-
},
|
|
14306
|
-
args: {
|
|
14307
|
-
test: {
|
|
14308
|
-
type: '*expression',
|
|
14309
|
-
},
|
|
14310
|
-
expressions: {
|
|
14311
|
-
type: '*expression',
|
|
14312
|
-
rest: true,
|
|
14313
|
-
},
|
|
14314
|
-
},
|
|
14315
|
-
variants: [
|
|
14316
|
-
{ argumentNames: ['test', 'expressions'] },
|
|
14317
|
-
],
|
|
14318
|
-
description: "If $test yields a thruthy value, the expressions are evaluated\nand the value returned by the last expression is returned.\nOtherwise, if $test yields a falsy value, the expressions are not evaluated,\nand `nil` is returned. If no $expressions are provided, `nil` is returned.",
|
|
14319
|
-
examples: [
|
|
14320
|
-
"(when true\n (write! \"Hi\")\n (write! \"There\"))",
|
|
14321
|
-
"(when false\n (write! \"Hi\")\n (write! \"There\"))",
|
|
14322
|
-
'(when true)',
|
|
14323
|
-
'(when false)',
|
|
14324
|
-
],
|
|
14325
|
-
},
|
|
14326
|
-
'when_not': {
|
|
14327
|
-
title: 'when_not',
|
|
14328
|
-
category: 'Special expression',
|
|
14329
|
-
linkName: 'when_not',
|
|
14330
|
-
returns: {
|
|
14331
|
-
type: 'any',
|
|
14332
|
-
},
|
|
14333
|
-
args: {
|
|
14334
|
-
test: {
|
|
14335
|
-
type: '*expression',
|
|
14336
|
-
},
|
|
14337
|
-
expressions: {
|
|
14338
|
-
type: '*expression',
|
|
14339
|
-
rest: true,
|
|
14340
|
-
},
|
|
14341
|
-
},
|
|
14342
|
-
variants: [
|
|
14343
|
-
{ argumentNames: ['test', 'expressions'] },
|
|
14344
|
-
],
|
|
14345
|
-
description: "If $test yields a falsy value, the expressions are evaluated\nand the value returned by the last `expression` is returned.\nOtherwise, if $test yields a truthy value, the $expressions are not evaluated,\nand `nil` is returned. If no `expression` is provided, `nil` is returned.",
|
|
14346
|
-
examples: [
|
|
14347
|
-
'(when_not true (write! "Hi") (write! "There"))',
|
|
14348
|
-
'(when_not false (write! "Hi") (write! "There"))',
|
|
14349
|
-
'(when_not true)',
|
|
14350
|
-
'(when_not false)',
|
|
14351
|
-
],
|
|
14352
|
-
},
|
|
14353
13563
|
'comment': {
|
|
14354
13564
|
title: 'comment',
|
|
14355
13565
|
category: 'Special expression',
|
|
@@ -14409,9 +13619,9 @@ var specialExpressionsReference = {
|
|
|
14409
13619
|
],
|
|
14410
13620
|
description: 'Recursevly calls enclosing function or loop with its evaluated $expressions.',
|
|
14411
13621
|
examples: [
|
|
14412
|
-
"\n(defn foo [n]\n (write! n)\n (
|
|
14413
|
-
"\n(\n (fn [n]\n (write! n)\n (
|
|
14414
|
-
"\n(\n loop [n 3]\n (write! n)\n (
|
|
13622
|
+
"\n(defn foo [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
|
|
13623
|
+
"\n(\n (fn [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n 3)",
|
|
13624
|
+
"\n(\n loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
|
|
14415
13625
|
],
|
|
14416
13626
|
},
|
|
14417
13627
|
'loop': {
|
|
@@ -14436,7 +13646,7 @@ var specialExpressionsReference = {
|
|
|
14436
13646
|
],
|
|
14437
13647
|
description: 'Executes $expressions with initial $bindings. The $bindings will be replaced with the recur parameters for subsequent recursions.',
|
|
14438
13648
|
examples: [
|
|
14439
|
-
"\n(loop [n 3]\n (write! n)\n (
|
|
13649
|
+
"\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
|
|
14440
13650
|
"\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))\n n))",
|
|
14441
13651
|
],
|
|
14442
13652
|
},
|
|
@@ -14495,10 +13705,10 @@ var specialExpressionsReference = {
|
|
|
14495
13705
|
"\n(for\n [x [1 2 3] y [1 2 3] z [1 2 3]\n &while (<= x y)]\n \n [x y z])",
|
|
14496
13706
|
],
|
|
14497
13707
|
},
|
|
14498
|
-
'
|
|
14499
|
-
title: '
|
|
13708
|
+
'defined?': {
|
|
13709
|
+
title: 'defined?',
|
|
14500
13710
|
category: 'Special expression',
|
|
14501
|
-
linkName: '
|
|
13711
|
+
linkName: 'defined-question',
|
|
14502
13712
|
returns: {
|
|
14503
13713
|
type: 'boolean',
|
|
14504
13714
|
},
|
|
@@ -14512,11 +13722,11 @@ var specialExpressionsReference = {
|
|
|
14512
13722
|
],
|
|
14513
13723
|
description: 'Returns `true` if $n is a declared variable or a builtin function, otherwise `false`.',
|
|
14514
13724
|
examples: [
|
|
14515
|
-
'(
|
|
14516
|
-
"\n(def foo :foo)\n(
|
|
14517
|
-
'(
|
|
14518
|
-
"\n(def foo nil)\n(
|
|
14519
|
-
'(
|
|
13725
|
+
'(defined? foo)',
|
|
13726
|
+
"\n(def foo :foo)\n(defined? foo)",
|
|
13727
|
+
'(defined? +)',
|
|
13728
|
+
"\n(def foo nil)\n(defined? foo)",
|
|
13729
|
+
'(defined? if)',
|
|
14520
13730
|
],
|
|
14521
13731
|
},
|
|
14522
13732
|
'??': {
|
|
@@ -15795,27 +15005,22 @@ var api = {
|
|
|
15795
15005
|
'def',
|
|
15796
15006
|
'defs',
|
|
15797
15007
|
'let',
|
|
15798
|
-
'if_let',
|
|
15799
|
-
'when_let',
|
|
15800
|
-
'when_first',
|
|
15801
15008
|
'fn',
|
|
15802
15009
|
'defn',
|
|
15803
15010
|
'defns',
|
|
15804
15011
|
'try',
|
|
15805
15012
|
'throw',
|
|
15806
15013
|
'if',
|
|
15807
|
-
'
|
|
15014
|
+
'unless',
|
|
15808
15015
|
'cond',
|
|
15809
15016
|
'switch',
|
|
15810
|
-
'when',
|
|
15811
|
-
'when_not',
|
|
15812
15017
|
'comment',
|
|
15813
15018
|
'do',
|
|
15814
15019
|
'recur',
|
|
15815
15020
|
'loop',
|
|
15816
15021
|
'doseq',
|
|
15817
15022
|
'for',
|
|
15818
|
-
'
|
|
15023
|
+
'defined?',
|
|
15819
15024
|
'??',
|
|
15820
15025
|
],
|
|
15821
15026
|
string: [
|