@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/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "2.0.
|
|
95
|
+
var version = "2.0.16";
|
|
96
96
|
|
|
97
97
|
var AstNodeType;
|
|
98
98
|
(function (AstNodeType) {
|
|
@@ -433,20 +433,15 @@ var nonFunctionOperators = [
|
|
|
433
433
|
'&&',
|
|
434
434
|
'comment',
|
|
435
435
|
'cond',
|
|
436
|
-
'
|
|
436
|
+
'defined?',
|
|
437
437
|
'if',
|
|
438
|
-
'
|
|
438
|
+
'unless',
|
|
439
439
|
'||',
|
|
440
|
-
'when',
|
|
441
|
-
'when_not',
|
|
442
440
|
'do',
|
|
443
441
|
'throw',
|
|
444
442
|
'let',
|
|
445
443
|
'def',
|
|
446
444
|
'defs',
|
|
447
|
-
'if_let',
|
|
448
|
-
'when_let',
|
|
449
|
-
'when_first',
|
|
450
445
|
'fn',
|
|
451
446
|
'defn',
|
|
452
447
|
'defns',
|
|
@@ -472,16 +467,22 @@ var symbolicOperatorSet = new Set(symbolicOperators);
|
|
|
472
467
|
function isSymbolicOperator(operator) {
|
|
473
468
|
return symbolicOperatorSet.has(operator);
|
|
474
469
|
}
|
|
475
|
-
function isA_SymbolToken(token) {
|
|
476
|
-
|
|
470
|
+
function isA_SymbolToken(token, symbolName) {
|
|
471
|
+
if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Symbol') {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
if (symbolName && token[1] !== symbolName) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
return true;
|
|
477
478
|
}
|
|
478
|
-
function assertA_SymbolToken(token) {
|
|
479
|
-
if (!isA_SymbolToken(token)) {
|
|
479
|
+
function assertA_SymbolToken(token, symbolName) {
|
|
480
|
+
if (!isA_SymbolToken(token, symbolName)) {
|
|
480
481
|
throwUnexpectedToken('A_Symbol', undefined, token);
|
|
481
482
|
}
|
|
482
483
|
}
|
|
483
|
-
function asA_SymbolToken(token) {
|
|
484
|
-
assertA_SymbolToken(token);
|
|
484
|
+
function asA_SymbolToken(token, symbolName) {
|
|
485
|
+
assertA_SymbolToken(token, symbolName);
|
|
485
486
|
return token;
|
|
486
487
|
}
|
|
487
488
|
function isA_BinaryOperatorToken(token) {
|
|
@@ -764,7 +765,7 @@ var specialExpressionCommentRemovers = {
|
|
|
764
765
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
765
766
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
766
767
|
},
|
|
767
|
-
'
|
|
768
|
+
'defined?': function (node, removeOptions) {
|
|
768
769
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
769
770
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
770
771
|
},
|
|
@@ -785,12 +786,11 @@ var specialExpressionCommentRemovers = {
|
|
|
785
786
|
'doseq': function (_node, _removeOptions) { },
|
|
786
787
|
'fn': function (_node, _removeOptions) { },
|
|
787
788
|
'for': function (_node, _removeOptions) { },
|
|
788
|
-
'if_let': function (_node, _removeOptions) { },
|
|
789
789
|
'if': function (node, removeOptions) {
|
|
790
790
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
791
791
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
792
792
|
},
|
|
793
|
-
'
|
|
793
|
+
'unless': function (node, removeOptions) {
|
|
794
794
|
removeOptions.removeCommenNodesFromArray(node.p);
|
|
795
795
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
796
796
|
},
|
|
@@ -819,10 +819,6 @@ var specialExpressionCommentRemovers = {
|
|
|
819
819
|
node.p.forEach(removeOptions.recursivelyRemoveCommentNodes);
|
|
820
820
|
},
|
|
821
821
|
'try': function (_node, _removeOptions) { },
|
|
822
|
-
'when_first': function (_node, _removeOptions) { },
|
|
823
|
-
'when_let': function (_node, _removeOptions) { },
|
|
824
|
-
'when': function (_node, _removeOptions) { },
|
|
825
|
-
'when_not': function (_node, _removeOptions) { },
|
|
826
822
|
};
|
|
827
823
|
function removeCommentNodesFromSpecialExpression(node, removeOptions) {
|
|
828
824
|
var uncommenter = specialExpressionCommentRemovers[node.n];
|
|
@@ -4412,7 +4408,7 @@ var switchSpecialExpression = {
|
|
|
4412
4408
|
};
|
|
4413
4409
|
|
|
4414
4410
|
var declaredSpecialExpression = {
|
|
4415
|
-
polishParse: getCommonPolishSpecialExpressionParser('
|
|
4411
|
+
polishParse: getCommonPolishSpecialExpressionParser('defined?'),
|
|
4416
4412
|
validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
|
|
4417
4413
|
evaluate: function (node, contextStack) {
|
|
4418
4414
|
var lookUpResult = contextStack.lookUp(node.p[0]);
|
|
@@ -4468,9 +4464,7 @@ var defSpecialExpression = {
|
|
|
4468
4464
|
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4469
4465
|
var name = node.p[0].v;
|
|
4470
4466
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4471
|
-
contextStack.
|
|
4472
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4473
|
-
};
|
|
4467
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4474
4468
|
return null;
|
|
4475
4469
|
},
|
|
4476
4470
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4481,7 +4475,7 @@ var defSpecialExpression = {
|
|
|
4481
4475
|
var result = findUnresolvedIdentifiers([subNode], contextStack, builtin);
|
|
4482
4476
|
var name = asSymbolNode(node.p[0]).v;
|
|
4483
4477
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4484
|
-
contextStack.
|
|
4478
|
+
contextStack.exportValue(name, true);
|
|
4485
4479
|
return result;
|
|
4486
4480
|
},
|
|
4487
4481
|
};
|
|
@@ -4507,9 +4501,7 @@ var defsSpecialExpression = {
|
|
|
4507
4501
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4508
4502
|
assertString(name, sourceCodeInfo);
|
|
4509
4503
|
assertNameNotDefined(name, contextStack, builtin, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
4510
|
-
contextStack.
|
|
4511
|
-
value: evaluateAstNode(node.p[1], contextStack),
|
|
4512
|
-
};
|
|
4504
|
+
contextStack.exportValue(name, evaluateAstNode(node.p[1], contextStack));
|
|
4513
4505
|
return null;
|
|
4514
4506
|
},
|
|
4515
4507
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4521,7 +4513,7 @@ var defsSpecialExpression = {
|
|
|
4521
4513
|
var name = evaluateAstNode(node.p[0], contextStack);
|
|
4522
4514
|
assertString(name, sourceCodeInfo);
|
|
4523
4515
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4524
|
-
contextStack.
|
|
4516
|
+
contextStack.exportValue(name, true);
|
|
4525
4517
|
return result;
|
|
4526
4518
|
},
|
|
4527
4519
|
};
|
|
@@ -4552,7 +4544,7 @@ var doSpecialExpression = {
|
|
|
4552
4544
|
},
|
|
4553
4545
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4554
4546
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4555
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
4547
|
+
return findUnresolvedIdentifiers(node.p, contextStack.create({}), builtin);
|
|
4556
4548
|
},
|
|
4557
4549
|
};
|
|
4558
4550
|
|
|
@@ -4581,11 +4573,6 @@ function joinAnalyzeResults() {
|
|
|
4581
4573
|
function addAnalyzeResults(target, source) {
|
|
4582
4574
|
source.forEach(function (symbol) { return target.add(symbol); });
|
|
4583
4575
|
}
|
|
4584
|
-
function combinate(arrays) {
|
|
4585
|
-
return arrays.reduce(function (acc, curr) {
|
|
4586
|
-
return acc.flatMap(function (a) { return curr.map(function (c) { return __spreadArray(__spreadArray([], __read(a), false), [c], false); }); });
|
|
4587
|
-
}, [[]]);
|
|
4588
|
-
}
|
|
4589
4576
|
|
|
4590
4577
|
var defnSpecialExpression = {
|
|
4591
4578
|
polishParse: function (tokenStream, parseState, firstToken, parsers) {
|
|
@@ -4620,13 +4607,13 @@ var defnSpecialExpression = {
|
|
|
4620
4607
|
_b.n = name,
|
|
4621
4608
|
_b.o = evaluatedFunctionOverloades,
|
|
4622
4609
|
_b);
|
|
4623
|
-
contextStack.
|
|
4610
|
+
contextStack.exportValue(name, litsFunction);
|
|
4624
4611
|
return null;
|
|
4625
4612
|
},
|
|
4626
4613
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4627
4614
|
var _b;
|
|
4628
4615
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4629
|
-
contextStack.
|
|
4616
|
+
contextStack.exportValue(node.f.v, true);
|
|
4630
4617
|
var newContext = (_b = {}, _b[node.f.v] = { value: true }, _b);
|
|
4631
4618
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4632
4619
|
},
|
|
@@ -4662,7 +4649,7 @@ var defnsSpecialExpression = {
|
|
|
4662
4649
|
_b.n = name,
|
|
4663
4650
|
_b.o = evaluatedFunctionOverloades,
|
|
4664
4651
|
_b);
|
|
4665
|
-
contextStack.
|
|
4652
|
+
contextStack.exportValue(name, litsFunction);
|
|
4666
4653
|
return null;
|
|
4667
4654
|
},
|
|
4668
4655
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
@@ -4673,7 +4660,7 @@ var defnsSpecialExpression = {
|
|
|
4673
4660
|
var name = evaluateAstNode(asAstNode(node.f, sourceCodeInfo), contextStack);
|
|
4674
4661
|
assertString(name, sourceCodeInfo);
|
|
4675
4662
|
assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo);
|
|
4676
|
-
contextStack.
|
|
4663
|
+
contextStack.exportValue(name, true);
|
|
4677
4664
|
var newContext = (_b = {}, _b[name] = { value: true }, _b);
|
|
4678
4665
|
return addOverloadsUnresolvedIdentifiers(node.o, contextStack, findUnresolvedIdentifiers, builtin, newContext);
|
|
4679
4666
|
},
|
|
@@ -4946,56 +4933,8 @@ var ifSpecialExpression = {
|
|
|
4946
4933
|
},
|
|
4947
4934
|
};
|
|
4948
4935
|
|
|
4949
|
-
var
|
|
4950
|
-
polishParse:
|
|
4951
|
-
var _b, _c;
|
|
4952
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
4953
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
4954
|
-
if (bindings.length !== 1) {
|
|
4955
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
4956
|
-
}
|
|
4957
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
4958
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
4959
|
-
var node = {
|
|
4960
|
-
t: AstNodeType.SpecialExpression,
|
|
4961
|
-
n: 'if_let',
|
|
4962
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
4963
|
-
p: params,
|
|
4964
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
4965
|
-
};
|
|
4966
|
-
return node;
|
|
4967
|
-
},
|
|
4968
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
4969
|
-
evaluate: function (node, contextStack, _a) {
|
|
4970
|
-
var _b;
|
|
4971
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
4972
|
-
var sourceCodeInfo = (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo;
|
|
4973
|
-
var locals = {};
|
|
4974
|
-
var bindingValue = evaluateAstNode(node.b.v, contextStack);
|
|
4975
|
-
if (bindingValue) {
|
|
4976
|
-
locals[node.b.n] = { value: bindingValue };
|
|
4977
|
-
var newContextStack = contextStack.create(locals);
|
|
4978
|
-
var thenForm = asAstNode(node.p[0], sourceCodeInfo);
|
|
4979
|
-
return evaluateAstNode(thenForm, newContextStack);
|
|
4980
|
-
}
|
|
4981
|
-
if (node.p.length === 2) {
|
|
4982
|
-
var elseForm = asAstNode(node.p[1], sourceCodeInfo);
|
|
4983
|
-
return evaluateAstNode(elseForm, contextStack);
|
|
4984
|
-
}
|
|
4985
|
-
return null;
|
|
4986
|
-
},
|
|
4987
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
4988
|
-
var _b;
|
|
4989
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
4990
|
-
var newContext = (_b = {}, _b[node.b.n] = { value: true }, _b);
|
|
4991
|
-
var bindingResult = findUnresolvedIdentifiers([node.b.v], contextStack, builtin);
|
|
4992
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
4993
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
4994
|
-
},
|
|
4995
|
-
};
|
|
4996
|
-
|
|
4997
|
-
var ifNotSpecialExpression = {
|
|
4998
|
-
polishParse: getCommonPolishSpecialExpressionParser('if_not'),
|
|
4936
|
+
var unlessSpecialExpression = {
|
|
4937
|
+
polishParse: getCommonPolishSpecialExpressionParser('unless'),
|
|
4999
4938
|
validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
5000
4939
|
evaluate: function (node, contextStack, _a) {
|
|
5001
4940
|
var _b;
|
|
@@ -5020,55 +4959,39 @@ var ifNotSpecialExpression = {
|
|
|
5020
4959
|
|
|
5021
4960
|
var letSpecialExpression = {
|
|
5022
4961
|
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5023
|
-
var parseBindings = _a.parseBindings
|
|
4962
|
+
var parseBindings = _a.parseBindings;
|
|
5024
4963
|
var bindings = parseBindings(tokenStream, parseState);
|
|
5025
|
-
|
|
4964
|
+
// const params = parseTokensUntilClosingBracket(tokenStream, parseState)
|
|
5026
4965
|
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5027
4966
|
var node = {
|
|
5028
4967
|
t: AstNodeType.SpecialExpression,
|
|
5029
4968
|
n: 'let',
|
|
5030
|
-
p:
|
|
4969
|
+
p: [],
|
|
5031
4970
|
bs: bindings,
|
|
5032
4971
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
5033
4972
|
};
|
|
5034
4973
|
return node;
|
|
5035
4974
|
},
|
|
5036
|
-
validateParameterCount: function () { return
|
|
4975
|
+
validateParameterCount: function (node) { return assertNumberOfParams(0, node); },
|
|
5037
4976
|
evaluate: function (node, contextStack, _a) {
|
|
5038
|
-
var e_1, _b
|
|
4977
|
+
var e_1, _b;
|
|
5039
4978
|
var evaluateAstNode = _a.evaluateAstNode;
|
|
5040
|
-
var locals = {};
|
|
5041
|
-
var newContextStack = contextStack.create(locals);
|
|
5042
4979
|
try {
|
|
5043
|
-
for (var
|
|
5044
|
-
var binding =
|
|
4980
|
+
for (var _c = __values(node.bs), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4981
|
+
var binding = _d.value;
|
|
5045
4982
|
var bindingValueNode = binding.v;
|
|
5046
|
-
var bindingValue = evaluateAstNode(bindingValueNode,
|
|
5047
|
-
|
|
4983
|
+
var bindingValue = evaluateAstNode(bindingValueNode, contextStack);
|
|
4984
|
+
contextStack.addValue(binding.n, bindingValue);
|
|
5048
4985
|
}
|
|
5049
4986
|
}
|
|
5050
4987
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5051
4988
|
finally {
|
|
5052
4989
|
try {
|
|
5053
|
-
if (
|
|
4990
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5054
4991
|
}
|
|
5055
4992
|
finally { if (e_1) throw e_1.error; }
|
|
5056
4993
|
}
|
|
5057
|
-
|
|
5058
|
-
try {
|
|
5059
|
-
for (var _f = __values(node.p), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
5060
|
-
var astNode = _g.value;
|
|
5061
|
-
result = evaluateAstNode(astNode, newContextStack);
|
|
5062
|
-
}
|
|
5063
|
-
}
|
|
5064
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5065
|
-
finally {
|
|
5066
|
-
try {
|
|
5067
|
-
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
5068
|
-
}
|
|
5069
|
-
finally { if (e_2) throw e_2.error; }
|
|
5070
|
-
}
|
|
5071
|
-
return result;
|
|
4994
|
+
return null;
|
|
5072
4995
|
},
|
|
5073
4996
|
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5074
4997
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
@@ -5078,11 +5001,10 @@ var letSpecialExpression = {
|
|
|
5078
5001
|
context[name] = { value: true };
|
|
5079
5002
|
return context;
|
|
5080
5003
|
}, {});
|
|
5081
|
-
var bindingContext = {};
|
|
5082
5004
|
var bindingResults = node.bs.map(function (bindingNode) {
|
|
5083
5005
|
var valueNode = bindingNode.v;
|
|
5084
|
-
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack
|
|
5085
|
-
|
|
5006
|
+
var bindingsResult = findUnresolvedIdentifiers([valueNode], contextStack, builtin);
|
|
5007
|
+
contextStack.addValue(bindingNode.n, { value: true });
|
|
5086
5008
|
return bindingsResult;
|
|
5087
5009
|
});
|
|
5088
5010
|
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
@@ -5533,9 +5455,10 @@ var trySpecialExpression = {
|
|
|
5533
5455
|
return evaluateAstNode(tryExpressions[0], contextStack);
|
|
5534
5456
|
}
|
|
5535
5457
|
catch (error) {
|
|
5536
|
-
var newContext =
|
|
5537
|
-
_b
|
|
5538
|
-
|
|
5458
|
+
var newContext = errorNode
|
|
5459
|
+
? (_b = {},
|
|
5460
|
+
_b[errorNode.v] = { value: asAny(error, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo) },
|
|
5461
|
+
_b) : {};
|
|
5539
5462
|
return evaluateAstNode(catchExpression, contextStack.create(newContext));
|
|
5540
5463
|
}
|
|
5541
5464
|
},
|
|
@@ -5544,199 +5467,15 @@ var trySpecialExpression = {
|
|
|
5544
5467
|
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5545
5468
|
var tryExpressions = node.p, catchExpression = node.ce, errorNode = node.e;
|
|
5546
5469
|
var tryResult = findUnresolvedIdentifiers(tryExpressions, contextStack, builtin);
|
|
5547
|
-
var newContext =
|
|
5548
|
-
_b
|
|
5549
|
-
|
|
5470
|
+
var newContext = errorNode
|
|
5471
|
+
? (_b = {},
|
|
5472
|
+
_b[errorNode.v] = { value: true },
|
|
5473
|
+
_b) : {};
|
|
5550
5474
|
var catchResult = findUnresolvedIdentifiers([catchExpression], contextStack.create(newContext), builtin);
|
|
5551
5475
|
return joinAnalyzeResults(tryResult, catchResult);
|
|
5552
5476
|
},
|
|
5553
5477
|
};
|
|
5554
5478
|
|
|
5555
|
-
var whenSpecialExpression = {
|
|
5556
|
-
polishParse: getCommonPolishSpecialExpressionParser('when'),
|
|
5557
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5558
|
-
evaluate: function (node, contextStack, _a) {
|
|
5559
|
-
var e_1, _b;
|
|
5560
|
-
var _c;
|
|
5561
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5562
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5563
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5564
|
-
if (!evaluateAstNode(whenExpression, contextStack))
|
|
5565
|
-
return null;
|
|
5566
|
-
var result = null;
|
|
5567
|
-
try {
|
|
5568
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5569
|
-
var form = body_1_1.value;
|
|
5570
|
-
result = evaluateAstNode(form, contextStack);
|
|
5571
|
-
}
|
|
5572
|
-
}
|
|
5573
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5574
|
-
finally {
|
|
5575
|
-
try {
|
|
5576
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5577
|
-
}
|
|
5578
|
-
finally { if (e_1) throw e_1.error; }
|
|
5579
|
-
}
|
|
5580
|
-
return result;
|
|
5581
|
-
},
|
|
5582
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5583
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5584
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5585
|
-
},
|
|
5586
|
-
};
|
|
5587
|
-
|
|
5588
|
-
var whenFirstSpecialExpression = {
|
|
5589
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5590
|
-
var _b, _c;
|
|
5591
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5592
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5593
|
-
if (bindings.length !== 1) {
|
|
5594
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5595
|
-
}
|
|
5596
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5597
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5598
|
-
var node = {
|
|
5599
|
-
t: AstNodeType.SpecialExpression,
|
|
5600
|
-
n: 'when_first',
|
|
5601
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5602
|
-
p: params,
|
|
5603
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5604
|
-
};
|
|
5605
|
-
return node;
|
|
5606
|
-
},
|
|
5607
|
-
validateParameterCount: function () { return undefined; },
|
|
5608
|
-
evaluate: function (node, contextStack, _a) {
|
|
5609
|
-
var e_1, _b;
|
|
5610
|
-
var _c;
|
|
5611
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5612
|
-
var locals = {};
|
|
5613
|
-
var binding = node.b;
|
|
5614
|
-
var evaluatedBindingForm = evaluateAstNode(binding.v, contextStack);
|
|
5615
|
-
if (!isSeq(evaluatedBindingForm)) {
|
|
5616
|
-
throw new LitsError("Expected undefined or a sequence, got ".concat(valueToString(evaluatedBindingForm)), (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5617
|
-
}
|
|
5618
|
-
if (evaluatedBindingForm.length === 0)
|
|
5619
|
-
return null;
|
|
5620
|
-
var bindingValue = toAny(evaluatedBindingForm[0]);
|
|
5621
|
-
locals[binding.n] = { value: bindingValue };
|
|
5622
|
-
var newContextStack = contextStack.create(locals);
|
|
5623
|
-
var result = null;
|
|
5624
|
-
try {
|
|
5625
|
-
for (var _d = __values(node.p), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
5626
|
-
var form = _e.value;
|
|
5627
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5628
|
-
}
|
|
5629
|
-
}
|
|
5630
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5631
|
-
finally {
|
|
5632
|
-
try {
|
|
5633
|
-
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
5634
|
-
}
|
|
5635
|
-
finally { if (e_1) throw e_1.error; }
|
|
5636
|
-
}
|
|
5637
|
-
return result;
|
|
5638
|
-
},
|
|
5639
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5640
|
-
var _b;
|
|
5641
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5642
|
-
var binding = node.b;
|
|
5643
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5644
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5645
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5646
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5647
|
-
},
|
|
5648
|
-
};
|
|
5649
|
-
|
|
5650
|
-
var whenLetSpecialExpression = {
|
|
5651
|
-
polishParse: function (tokenStream, parseState, firstToken, _a) {
|
|
5652
|
-
var _b, _c;
|
|
5653
|
-
var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
|
|
5654
|
-
var bindings = parseBindings(tokenStream, parseState);
|
|
5655
|
-
if (bindings.length !== 1) {
|
|
5656
|
-
throw new LitsError("Expected exactly one binding, got ".concat(valueToString(bindings.length)), (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
5657
|
-
}
|
|
5658
|
-
var params = parseTokensUntilClosingBracket(tokenStream, parseState);
|
|
5659
|
-
assertRParenToken(tokenStream.tokens[parseState.position++]);
|
|
5660
|
-
var node = {
|
|
5661
|
-
t: AstNodeType.SpecialExpression,
|
|
5662
|
-
n: 'when_let',
|
|
5663
|
-
b: asNonUndefined(bindings[0], (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo),
|
|
5664
|
-
p: params,
|
|
5665
|
-
token: getTokenDebugData(firstToken) && firstToken,
|
|
5666
|
-
};
|
|
5667
|
-
return node;
|
|
5668
|
-
},
|
|
5669
|
-
validateParameterCount: function () { return undefined; },
|
|
5670
|
-
evaluate: function (node, contextStack, _a) {
|
|
5671
|
-
var e_1, _b;
|
|
5672
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5673
|
-
var binding = node.b;
|
|
5674
|
-
var locals = {};
|
|
5675
|
-
var bindingValue = evaluateAstNode(binding.v, contextStack);
|
|
5676
|
-
if (!bindingValue)
|
|
5677
|
-
return null;
|
|
5678
|
-
locals[binding.n] = { value: bindingValue };
|
|
5679
|
-
var newContextStack = contextStack.create(locals);
|
|
5680
|
-
var result = null;
|
|
5681
|
-
try {
|
|
5682
|
-
for (var _c = __values(node.p), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5683
|
-
var form = _d.value;
|
|
5684
|
-
result = evaluateAstNode(form, newContextStack);
|
|
5685
|
-
}
|
|
5686
|
-
}
|
|
5687
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5688
|
-
finally {
|
|
5689
|
-
try {
|
|
5690
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5691
|
-
}
|
|
5692
|
-
finally { if (e_1) throw e_1.error; }
|
|
5693
|
-
}
|
|
5694
|
-
return result;
|
|
5695
|
-
},
|
|
5696
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5697
|
-
var _b;
|
|
5698
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5699
|
-
var binding = node.b;
|
|
5700
|
-
var newContext = (_b = {}, _b[binding.n] = { value: true }, _b);
|
|
5701
|
-
var bindingResult = findUnresolvedIdentifiers([binding.v], contextStack, builtin);
|
|
5702
|
-
var paramsResult = findUnresolvedIdentifiers(node.p, contextStack.create(newContext), builtin);
|
|
5703
|
-
return joinAnalyzeResults(bindingResult, paramsResult);
|
|
5704
|
-
},
|
|
5705
|
-
};
|
|
5706
|
-
|
|
5707
|
-
var whenNotSpecialExpression = {
|
|
5708
|
-
polishParse: getCommonPolishSpecialExpressionParser('when_not'),
|
|
5709
|
-
validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
5710
|
-
evaluate: function (node, contextStack, _a) {
|
|
5711
|
-
var e_1, _b;
|
|
5712
|
-
var _c;
|
|
5713
|
-
var evaluateAstNode = _a.evaluateAstNode;
|
|
5714
|
-
var _d = __read(node.p), whenExpression = _d[0], body = _d.slice(1);
|
|
5715
|
-
assertAstNode(whenExpression, (_c = getTokenDebugData(node.token)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
5716
|
-
if (evaluateAstNode(whenExpression, contextStack))
|
|
5717
|
-
return null;
|
|
5718
|
-
var result = null;
|
|
5719
|
-
try {
|
|
5720
|
-
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
5721
|
-
var form = body_1_1.value;
|
|
5722
|
-
result = evaluateAstNode(form, contextStack);
|
|
5723
|
-
}
|
|
5724
|
-
}
|
|
5725
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5726
|
-
finally {
|
|
5727
|
-
try {
|
|
5728
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
5729
|
-
}
|
|
5730
|
-
finally { if (e_1) throw e_1.error; }
|
|
5731
|
-
}
|
|
5732
|
-
return result;
|
|
5733
|
-
},
|
|
5734
|
-
findUnresolvedIdentifiers: function (node, contextStack, _a) {
|
|
5735
|
-
var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
|
|
5736
|
-
return findUnresolvedIdentifiers(node.p, contextStack, builtin);
|
|
5737
|
-
},
|
|
5738
|
-
};
|
|
5739
|
-
|
|
5740
5479
|
var specialExpressions = {
|
|
5741
5480
|
'&&': andSpecialExpression,
|
|
5742
5481
|
'comment': commentSpecialExpression,
|
|
@@ -5751,19 +5490,14 @@ var specialExpressions = {
|
|
|
5751
5490
|
'for': forSpecialExpression,
|
|
5752
5491
|
'fn': fnSpecialExpression,
|
|
5753
5492
|
'if': ifSpecialExpression,
|
|
5754
|
-
'
|
|
5755
|
-
'if_not': ifNotSpecialExpression,
|
|
5493
|
+
'unless': unlessSpecialExpression,
|
|
5756
5494
|
'let': letSpecialExpression,
|
|
5757
5495
|
'loop': loopSpecialExpression,
|
|
5758
5496
|
'||': orSpecialExpression,
|
|
5759
5497
|
'recur': recurSpecialExpression,
|
|
5760
5498
|
'throw': throwSpecialExpression,
|
|
5761
5499
|
'try': trySpecialExpression,
|
|
5762
|
-
'
|
|
5763
|
-
'when_first': whenFirstSpecialExpression,
|
|
5764
|
-
'when_let': whenLetSpecialExpression,
|
|
5765
|
-
'when_not': whenNotSpecialExpression,
|
|
5766
|
-
'declared?': declaredSpecialExpression,
|
|
5500
|
+
'defined?': declaredSpecialExpression,
|
|
5767
5501
|
'??': qqSpecialExpression,
|
|
5768
5502
|
};
|
|
5769
5503
|
Object.keys(specialExpressions).forEach(function (key) {
|
|
@@ -5785,8 +5519,8 @@ function isContextEntry(value) {
|
|
|
5785
5519
|
var ContextStackImpl = /** @class */ (function () {
|
|
5786
5520
|
function ContextStackImpl(_a) {
|
|
5787
5521
|
var contexts = _a.contexts, hostValues = _a.values, lazyHostValues = _a.lazyValues, nativeJsFunctions = _a.nativeJsFunctions;
|
|
5788
|
-
this.contexts = contexts;
|
|
5789
5522
|
this.globalContext = asNonUndefined(contexts[0]);
|
|
5523
|
+
this.contexts = contexts;
|
|
5790
5524
|
this.values = hostValues;
|
|
5791
5525
|
this.lazyValues = lazyHostValues;
|
|
5792
5526
|
this.nativeJsFunctions = nativeJsFunctions;
|
|
@@ -5802,6 +5536,35 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5802
5536
|
contextStack.globalContext = globalContext;
|
|
5803
5537
|
return contextStack;
|
|
5804
5538
|
};
|
|
5539
|
+
ContextStackImpl.prototype.exportValue = function (name, value) {
|
|
5540
|
+
if (this.globalContext[name]) {
|
|
5541
|
+
throw new Error("Cannot redefine exported value \"".concat(name, "\""));
|
|
5542
|
+
}
|
|
5543
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5544
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5545
|
+
}
|
|
5546
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5547
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5548
|
+
}
|
|
5549
|
+
this.addValue(name, value);
|
|
5550
|
+
this.globalContext[name] = { value: value };
|
|
5551
|
+
};
|
|
5552
|
+
ContextStackImpl.prototype.addValue = function (name, value) {
|
|
5553
|
+
var currentContext = this.contexts[0];
|
|
5554
|
+
if (!currentContext) {
|
|
5555
|
+
throw new Error('No context to add value to');
|
|
5556
|
+
}
|
|
5557
|
+
if (currentContext[name]) {
|
|
5558
|
+
throw new Error("Cannot redefine value \"".concat(name, "\""));
|
|
5559
|
+
}
|
|
5560
|
+
if (specialExpressionKeys.includes(name)) {
|
|
5561
|
+
throw new Error("Cannot shadow special expression \"".concat(name, "\""));
|
|
5562
|
+
}
|
|
5563
|
+
if (normalExpressionKeys.includes(name)) {
|
|
5564
|
+
throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
|
|
5565
|
+
}
|
|
5566
|
+
currentContext[name] = { value: toAny(value) };
|
|
5567
|
+
};
|
|
5805
5568
|
ContextStackImpl.prototype.clone = function () {
|
|
5806
5569
|
// eslint-disable-next-line ts/no-unsafe-argument
|
|
5807
5570
|
return new ContextStackImpl(JSON.parse(JSON.stringify({
|
|
@@ -5931,7 +5694,7 @@ function createContextStack(params) {
|
|
|
5931
5694
|
return acc;
|
|
5932
5695
|
}, {}),
|
|
5933
5696
|
});
|
|
5934
|
-
return contextStack;
|
|
5697
|
+
return contextStack.create({});
|
|
5935
5698
|
}
|
|
5936
5699
|
|
|
5937
5700
|
var _a$2;
|
|
@@ -6243,7 +6006,14 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6243
6006
|
|
|
6244
6007
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6245
6008
|
var e_1, _a;
|
|
6246
|
-
var astNodes = Array.isArray(ast)
|
|
6009
|
+
var astNodes = Array.isArray(ast)
|
|
6010
|
+
? ast
|
|
6011
|
+
: [{
|
|
6012
|
+
t: AstNodeType.SpecialExpression,
|
|
6013
|
+
n: 'do',
|
|
6014
|
+
p: ast.b,
|
|
6015
|
+
token: undefined,
|
|
6016
|
+
}];
|
|
6247
6017
|
var unresolvedIdentifiers = new Set();
|
|
6248
6018
|
try {
|
|
6249
6019
|
for (var astNodes_1 = __values(astNodes), astNodes_1_1 = astNodes_1.next(); !astNodes_1_1.done; astNodes_1_1 = astNodes_1.next()) {
|
|
@@ -6305,547 +6075,19 @@ function findUnresolvedIdentifiersInAstNode(astNode, contextStack, builtin) {
|
|
|
6305
6075
|
case AstNodeType.SpecialExpression: {
|
|
6306
6076
|
var specialExpression = asNonUndefined(builtin.specialExpressions[astNode.n], (_b = getTokenDebugData(astNode.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
6307
6077
|
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6308
|
-
var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
|
|
6309
|
-
findUnresolvedIdentifiers: findUnresolvedIdentifiers,
|
|
6310
|
-
builtin: builtin,
|
|
6311
|
-
evaluateAstNode: evaluateAstNode,
|
|
6312
|
-
});
|
|
6313
|
-
return unresolvedIdentifiers;
|
|
6314
|
-
}
|
|
6315
|
-
}
|
|
6316
|
-
}
|
|
6317
|
-
|
|
6318
|
-
var calculateAndOutcomes = function (_a) {
|
|
6319
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6320
|
-
return combinateAstNodes(astNode.p)
|
|
6321
|
-
.map(function (p) { return ({
|
|
6322
|
-
n: '&&',
|
|
6323
|
-
t: AstNodeType.SpecialExpression,
|
|
6324
|
-
p: p,
|
|
6325
|
-
token: astNode.token,
|
|
6326
|
-
}); });
|
|
6327
|
-
};
|
|
6328
|
-
|
|
6329
|
-
var calculateCondOutcomes = function (_a) {
|
|
6330
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, isAstComputable = _a.isAstComputable;
|
|
6331
|
-
var testNodes = arrayToPairs(astNode.p).map(function (_a) {
|
|
6332
|
-
var _b = __read(_a, 1), t = _b[0];
|
|
6333
|
-
return t;
|
|
6334
|
-
});
|
|
6335
|
-
if (isAstComputable(testNodes)) {
|
|
6336
|
-
return combinate(arrayToPairs(astNode.p)
|
|
6337
|
-
// Create a list of ast nodes from the test and form of each condition
|
|
6338
|
-
.reduce(function (acc, _a) {
|
|
6339
|
-
var _b = __read(_a, 2), test = _b[0], form = _b[1];
|
|
6340
|
-
acc.push(calculatePossibleAstNodes(test), calculatePossibleAstNodes(form));
|
|
6341
|
-
return acc;
|
|
6342
|
-
}, []))
|
|
6343
|
-
// Create a new CondNode for each combination of test and form outcomes
|
|
6344
|
-
.map(function (conditionAsts) { return (__assign(__assign({}, astNode), { c: arrayToPairs(conditionAsts).map(function (_a) {
|
|
6345
|
-
var _b = __read(_a, 2), t = _b[0], f = _b[1];
|
|
6346
|
-
return ({ t: t, f: f });
|
|
6347
|
-
}) })); });
|
|
6348
|
-
}
|
|
6349
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p).flatMap(function (_a) {
|
|
6350
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6351
|
-
return calculatePossibleAstNodes(form);
|
|
6352
|
-
})), false), [
|
|
6353
|
-
nilNode,
|
|
6354
|
-
], false);
|
|
6355
|
-
};
|
|
6356
|
-
|
|
6357
|
-
var trueNode = { t: AstNodeType.ReservedSymbol, v: 'true', token: undefined, p: [], n: undefined };
|
|
6358
|
-
var falseNode = { t: AstNodeType.ReservedSymbol, v: 'false', token: undefined, p: [], n: undefined };
|
|
6359
|
-
var calculateDeclaredOutcomes = function (_a) {
|
|
6360
|
-
var astNode = _a.astNode, isAstComputable = _a.isAstComputable;
|
|
6361
|
-
if (isAstComputable(astNode.p))
|
|
6362
|
-
return [trueNode];
|
|
6363
|
-
return [trueNode, falseNode];
|
|
6364
|
-
};
|
|
6365
|
-
|
|
6366
|
-
var calculateDefOutcomes = function (_a) {
|
|
6367
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6368
|
-
var nameNode = asSymbolNode(astNode.p[0]);
|
|
6369
|
-
var valueNode = astNode.p[1];
|
|
6370
|
-
addGlobalIdentifier(nameNode.v);
|
|
6371
|
-
return calculatePossibleAstNodes(valueNode)
|
|
6372
|
-
.map(function (node) { return (__assign(__assign({}, astNode), { p: [nameNode, node] })); });
|
|
6373
|
-
};
|
|
6374
|
-
|
|
6375
|
-
var calculateDefsOutcomes = function (_a) {
|
|
6376
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6377
|
-
return combinateAstNodes(astNode.p)
|
|
6378
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6379
|
-
};
|
|
6380
|
-
|
|
6381
|
-
var calculateDoOutcomes = function (_a) {
|
|
6382
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6383
|
-
return combinateAstNodes(astNode.p).map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6384
|
-
};
|
|
6385
|
-
|
|
6386
|
-
function calculateFunctionOverloadOutcomes(combinateAstNodes, functionOverloads) {
|
|
6387
|
-
return combinate(functionOverloads
|
|
6388
|
-
// For each overload, calculate the possible outcomes for each parameter
|
|
6389
|
-
.map(function (functionOverload) {
|
|
6390
|
-
var _a;
|
|
6391
|
-
return combinateAstNodes(functionOverload.b, [
|
|
6392
|
-
functionOverload.as.m,
|
|
6393
|
-
functionOverload.as.b.map(function (bindingNode) { return bindingNode.n; }),
|
|
6394
|
-
(_a = functionOverload.as.r) !== null && _a !== void 0 ? _a : [],
|
|
6395
|
-
].flat())
|
|
6396
|
-
// For each combination of parameter outcomes, create a new overload
|
|
6397
|
-
.map(function (body) { return (__assign(__assign({}, functionOverload), { b: body })); });
|
|
6398
|
-
}));
|
|
6399
|
-
}
|
|
6400
|
-
var calculateDefnOutcomes = function (_a) {
|
|
6401
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, addGlobalIdentifier = _a.addGlobalIdentifier;
|
|
6402
|
-
addGlobalIdentifier(astNode.f.v);
|
|
6403
|
-
// astNode.o is an array of overloads
|
|
6404
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6405
|
-
};
|
|
6406
|
-
var calculateDefnsOutcomes = function (_a) {
|
|
6407
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes;
|
|
6408
|
-
// astNode.o is an array of overloads
|
|
6409
|
-
return calculatePossibleAstNodes(astNode.f).flatMap(function (functionName) {
|
|
6410
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { f: functionName, o: functionOverloads })); });
|
|
6411
|
-
});
|
|
6412
|
-
};
|
|
6413
|
-
var calculateFnOutcomes = function (_a) {
|
|
6414
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6415
|
-
// astNode.o is an array of overloads
|
|
6416
|
-
return calculateFunctionOverloadOutcomes(combinateAstNodes, astNode.o).map(function (functionOverloads) { return (__assign(__assign({}, astNode), { o: functionOverloads })); });
|
|
6417
|
-
};
|
|
6418
|
-
|
|
6419
|
-
var calculateIfLetOutcomes = function (_a) {
|
|
6420
|
-
var _b;
|
|
6421
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6422
|
-
var bindingNode = astNode.b;
|
|
6423
|
-
var thenBranch = astNode.p[0];
|
|
6424
|
-
var elseBranch = (_b = astNode.p[1]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6425
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6426
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6427
|
-
}
|
|
6428
|
-
var newIdentifier = bindingNode.n;
|
|
6429
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6430
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6431
|
-
.flatMap(function (b) { return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6432
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); }); });
|
|
6433
|
-
};
|
|
6434
|
-
|
|
6435
|
-
var calculateIfNotOutcomes = function (_a) {
|
|
6436
|
-
var _b;
|
|
6437
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6438
|
-
var condition = astNode.p[0];
|
|
6439
|
-
var thenBranch = astNode.p[1];
|
|
6440
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6441
|
-
if (isAstComputable(condition)) {
|
|
6442
|
-
return combinateAstNodes(astNode.p)
|
|
6443
|
-
.map(function (p) { return ({
|
|
6444
|
-
n: 'if_not',
|
|
6445
|
-
t: astNode.t,
|
|
6446
|
-
p: p,
|
|
6447
|
-
token: astNode.token,
|
|
6448
|
-
}); });
|
|
6449
|
-
}
|
|
6450
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6451
|
-
};
|
|
6452
|
-
|
|
6453
|
-
var calculateIfOutcomes = function (_a) {
|
|
6454
|
-
var _b;
|
|
6455
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6456
|
-
var condition = astNode.p[0];
|
|
6457
|
-
var thenBranch = astNode.p[1];
|
|
6458
|
-
var elseBranch = (_b = astNode.p[2]) !== null && _b !== void 0 ? _b : nilNode;
|
|
6459
|
-
if (isAstComputable(condition)) {
|
|
6460
|
-
return combinateAstNodes(astNode.p)
|
|
6461
|
-
.map(function (p) { return ({
|
|
6462
|
-
n: 'if',
|
|
6463
|
-
t: astNode.t,
|
|
6464
|
-
p: p,
|
|
6465
|
-
token: astNode.token,
|
|
6466
|
-
}); });
|
|
6467
|
-
}
|
|
6468
|
-
return __spreadArray(__spreadArray([], __read(calculatePossibleAstNodes(thenBranch)), false), __read(calculatePossibleAstNodes(elseBranch)), false);
|
|
6469
|
-
};
|
|
6470
|
-
|
|
6471
|
-
var calculateLetOutcomes = function (_a) {
|
|
6472
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6473
|
-
try {
|
|
6474
|
-
// check bindings, if any binding value cannot be calculated, convert the whole let to a do-expression
|
|
6475
|
-
if (!isAstComputable(astNode.bs.map(function (b) { return calculatePossibleAstNodes(b.v); })))
|
|
6476
|
-
throw new Error('Could not calculate binding value');
|
|
6477
|
-
}
|
|
6478
|
-
catch (_b) {
|
|
6479
|
-
var doNodes = combinateAstNodes(astNode.p)
|
|
6480
|
-
.map(function (p) {
|
|
6481
|
-
return {
|
|
6482
|
-
n: 'do',
|
|
6483
|
-
t: AstNodeType.SpecialExpression,
|
|
6484
|
-
p: p,
|
|
6485
|
-
token: astNode.token,
|
|
6486
|
-
};
|
|
6487
|
-
});
|
|
6488
|
-
return doNodes;
|
|
6489
|
-
}
|
|
6490
|
-
var newIdentifiers = astNode.bs.map(function (bindingNode) { return bindingNode.n; });
|
|
6491
|
-
var letNodes = combinate(astNode.bs.map(function (bindingNode) {
|
|
6492
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6493
|
-
.map(function (bindingValues) { return (__assign(__assign({}, bindingNode), { v: bindingValues })); });
|
|
6494
|
-
}))
|
|
6495
|
-
.flatMap(function (bindingNodes) { return combinate(astNode.p.map(function (p) { return calculatePossibleAstNodes(p, newIdentifiers); }))
|
|
6496
|
-
.map(function (p) {
|
|
6497
|
-
return {
|
|
6498
|
-
n: 'let',
|
|
6499
|
-
bs: bindingNodes,
|
|
6500
|
-
t: AstNodeType.SpecialExpression,
|
|
6501
|
-
p: p,
|
|
6502
|
-
token: astNode.token,
|
|
6503
|
-
};
|
|
6504
|
-
}); });
|
|
6505
|
-
return letNodes;
|
|
6506
|
-
};
|
|
6507
|
-
|
|
6508
|
-
var calculateForOutcomes = function (_a) {
|
|
6509
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6510
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6511
|
-
throw new Error('Could not calculate for loop, not deterministic');
|
|
6512
|
-
return [astNode];
|
|
6513
|
-
};
|
|
6514
|
-
var calculateDoSeqOutcomes = function (_a) {
|
|
6515
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6516
|
-
if (!isDeterministic(calculatePossibleAstNodes, astNode))
|
|
6517
|
-
throw new Error('Could not calculate doSeq node, not deterministic');
|
|
6518
|
-
return [astNode];
|
|
6519
|
-
};
|
|
6520
|
-
function isDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6521
|
-
var e_1, _a;
|
|
6522
|
-
try {
|
|
6523
|
-
for (var _b = __values(astNode.l), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6524
|
-
var _d = _c.value, b = _d.b, l = _d.l, wn = _d.wn, we = _d.we;
|
|
6525
|
-
if (l && l.some(function (_a) {
|
|
6526
|
-
var v = _a.v;
|
|
6527
|
-
return !astIsDeterministic(calculatePossibleAstNodes, v);
|
|
6528
|
-
}))
|
|
6529
|
-
return false;
|
|
6530
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, b.v))
|
|
6531
|
-
return false;
|
|
6532
|
-
if (wn && !astIsDeterministic(calculatePossibleAstNodes, wn))
|
|
6533
|
-
return false;
|
|
6534
|
-
if (we && !astIsDeterministic(calculatePossibleAstNodes, we))
|
|
6535
|
-
return false;
|
|
6536
|
-
}
|
|
6537
|
-
}
|
|
6538
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6539
|
-
finally {
|
|
6540
|
-
try {
|
|
6541
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6542
|
-
}
|
|
6543
|
-
finally { if (e_1) throw e_1.error; }
|
|
6544
|
-
}
|
|
6545
|
-
if (!astIsDeterministic(calculatePossibleAstNodes, astNode.p[0]))
|
|
6546
|
-
return false;
|
|
6547
|
-
return true;
|
|
6548
|
-
}
|
|
6549
|
-
function astIsDeterministic(calculatePossibleAstNodes, astNode) {
|
|
6550
|
-
return calculatePossibleAstNodes(astNode).length === 1;
|
|
6551
|
-
}
|
|
6552
|
-
|
|
6553
|
-
var calculateOrOutcomes = function (_a) {
|
|
6554
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6555
|
-
return combinateAstNodes(astNode.p)
|
|
6556
|
-
.map(function (p) { return ({
|
|
6557
|
-
n: '||',
|
|
6558
|
-
t: AstNodeType.SpecialExpression,
|
|
6559
|
-
p: p,
|
|
6560
|
-
token: astNode.token,
|
|
6561
|
-
}); });
|
|
6562
|
-
};
|
|
6563
|
-
|
|
6564
|
-
var calculateQqOutcomes = function (_a) {
|
|
6565
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6566
|
-
if (!isAstComputable(astNode.p[0]))
|
|
6567
|
-
throw new Error('First argument of ?? not computable');
|
|
6568
|
-
return combinateAstNodes(astNode.p)
|
|
6569
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6570
|
-
};
|
|
6571
|
-
|
|
6572
|
-
var calculateThrowOutcomes = function (_a) {
|
|
6573
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6574
|
-
return calculatePossibleAstNodes(astNode.p[0]).map(function (m) { return (__assign(__assign({}, astNode), { p: [m] })); });
|
|
6575
|
-
};
|
|
6576
|
-
|
|
6577
|
-
var calculateTryOutcomes = function (_a) {
|
|
6578
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6579
|
-
var _b = calculatePossibleAstNodes(astNode.p[0]).reduce(function (acc, node) {
|
|
6580
|
-
if (node.n === 'throw') {
|
|
6581
|
-
acc.throws.push(node.p[0]);
|
|
6582
|
-
}
|
|
6583
|
-
else {
|
|
6584
|
-
acc.vals.push(node);
|
|
6585
|
-
}
|
|
6586
|
-
return acc;
|
|
6587
|
-
}, { vals: [], throws: [] }), vals = _b.vals, throws = _b.throws;
|
|
6588
|
-
var catches = throws.flatMap(function (throwNode) {
|
|
6589
|
-
var letNode = {
|
|
6590
|
-
t: AstNodeType.SpecialExpression,
|
|
6591
|
-
n: 'let',
|
|
6592
|
-
bs: [{
|
|
6593
|
-
t: AstNodeType.Binding,
|
|
6594
|
-
n: astNode.e.v,
|
|
6595
|
-
v: throwNode,
|
|
6596
|
-
token: undefined,
|
|
6597
|
-
p: [],
|
|
6598
|
-
}],
|
|
6599
|
-
p: [astNode.ce],
|
|
6600
|
-
token: undefined,
|
|
6601
|
-
};
|
|
6602
|
-
return calculatePossibleAstNodes(letNode);
|
|
6603
|
-
});
|
|
6604
|
-
return __spreadArray(__spreadArray([], __read(vals), false), __read(catches), false);
|
|
6605
|
-
};
|
|
6606
|
-
|
|
6607
|
-
var calculateWhenFirstOutcomes = function (_a) {
|
|
6608
|
-
var astNode = _a.astNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6609
|
-
var bindingNode = astNode.b;
|
|
6610
|
-
if (!isAstComputable(bindingNode.v))
|
|
6611
|
-
throw new Error('Could not calculate binding value');
|
|
6612
|
-
var newIdentifier = bindingNode.n;
|
|
6613
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6614
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6615
|
-
.flatMap(function (b) {
|
|
6616
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6617
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6618
|
-
});
|
|
6619
|
-
};
|
|
6620
|
-
|
|
6621
|
-
var calculateWhenLetOutcomes = function (_a) {
|
|
6622
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes, combinateAstNodes = _a.combinateAstNodes, isAstComputable = _a.isAstComputable;
|
|
6623
|
-
var bindingNode = astNode.b;
|
|
6624
|
-
if (!isAstComputable(bindingNode.v)) {
|
|
6625
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(astNode.p)
|
|
6626
|
-
.map(function (p) { return ({
|
|
6627
|
-
n: 'do',
|
|
6628
|
-
t: astNode.t,
|
|
6629
|
-
p: p,
|
|
6630
|
-
token: astNode.token,
|
|
6631
|
-
}); })), false), [
|
|
6632
|
-
nilNode,
|
|
6633
|
-
], false);
|
|
6634
|
-
}
|
|
6635
|
-
var newIdentifier = bindingNode.n;
|
|
6636
|
-
return calculatePossibleAstNodes(bindingNode.v)
|
|
6637
|
-
.map(function (bindingValue) { return (__assign(__assign({}, bindingNode), { v: bindingValue })); })
|
|
6638
|
-
.flatMap(function (b) {
|
|
6639
|
-
return combinateAstNodes(astNode.p, [newIdentifier])
|
|
6640
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { b: b, p: p })); });
|
|
6641
|
-
});
|
|
6642
|
-
};
|
|
6643
|
-
|
|
6644
|
-
var calculateWhenNotOutcomes = function (_a) {
|
|
6645
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6646
|
-
var condition = astNode.p[0];
|
|
6647
|
-
if (isAstComputable(condition)) {
|
|
6648
|
-
return combinateAstNodes(astNode.p)
|
|
6649
|
-
.map(function (p) { return ({
|
|
6650
|
-
n: 'when_not',
|
|
6651
|
-
t: astNode.t,
|
|
6652
|
-
p: p,
|
|
6653
|
-
token: astNode.token,
|
|
6654
|
-
}); });
|
|
6655
|
-
}
|
|
6656
|
-
var body = astNode.p.slice(1);
|
|
6657
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6658
|
-
.map(function (p) { return ({
|
|
6659
|
-
n: 'do',
|
|
6660
|
-
t: astNode.t,
|
|
6661
|
-
p: p,
|
|
6662
|
-
token: astNode.token,
|
|
6663
|
-
}); })), false), [
|
|
6664
|
-
nilNode,
|
|
6665
|
-
], false);
|
|
6666
|
-
};
|
|
6667
|
-
|
|
6668
|
-
var calculateWhenOutcomes = function (_a) {
|
|
6669
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes, nilNode = _a.nilNode, isAstComputable = _a.isAstComputable;
|
|
6670
|
-
var condition = astNode.p[0];
|
|
6671
|
-
if (isAstComputable(condition)) {
|
|
6672
|
-
return combinateAstNodes(astNode.p)
|
|
6673
|
-
.map(function (p) { return ({
|
|
6674
|
-
n: 'when',
|
|
6675
|
-
t: astNode.t,
|
|
6676
|
-
p: p,
|
|
6677
|
-
token: astNode.token,
|
|
6678
|
-
}); });
|
|
6679
|
-
}
|
|
6680
|
-
var body = astNode.p.slice(1);
|
|
6681
|
-
return __spreadArray(__spreadArray([], __read(combinateAstNodes(body)
|
|
6682
|
-
.map(function (p) { return ({
|
|
6683
|
-
n: 'do',
|
|
6684
|
-
t: astNode.t,
|
|
6685
|
-
p: p,
|
|
6686
|
-
token: astNode.token,
|
|
6687
|
-
}); })), false), [
|
|
6688
|
-
nilNode,
|
|
6689
|
-
], false);
|
|
6690
|
-
};
|
|
6691
|
-
|
|
6692
|
-
var calculateRecurOutcomes = function (_a) {
|
|
6693
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6694
|
-
return combinateAstNodes(astNode.p)
|
|
6695
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6696
|
-
};
|
|
6697
|
-
|
|
6698
|
-
var calculateCommentOutcomes = function (_a) {
|
|
6699
|
-
var nilNode = _a.nilNode;
|
|
6700
|
-
return [nilNode];
|
|
6701
|
-
};
|
|
6702
|
-
|
|
6703
|
-
var calculateLoopOutcomes = function (_a) {
|
|
6704
|
-
var astNode = _a.astNode, combinateAstNodes = _a.combinateAstNodes;
|
|
6705
|
-
return combinateAstNodes(astNode.p, astNode.bs.map(function (bindingNode) { return bindingNode.n; }))
|
|
6706
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6707
|
-
};
|
|
6708
|
-
|
|
6709
|
-
var calculateSwitchOutcomes = function (_a) {
|
|
6710
|
-
var astNode = _a.astNode, nilNode = _a.nilNode, calculatePossibleAstNodes = _a.calculatePossibleAstNodes;
|
|
6711
|
-
// TODO be smarter about this
|
|
6712
|
-
return __spreadArray(__spreadArray([], __read(arrayToPairs(astNode.p.slice(1)).flatMap(function (_a) {
|
|
6713
|
-
var _b = __read(_a, 2); _b[0]; var form = _b[1];
|
|
6714
|
-
return calculatePossibleAstNodes(form);
|
|
6715
|
-
})), false), [
|
|
6716
|
-
nilNode,
|
|
6717
|
-
], false);
|
|
6718
|
-
};
|
|
6719
|
-
|
|
6720
|
-
var specialExpressionCalculator = {
|
|
6721
|
-
'&&': function (astNode, helperOptions) { return calculateAndOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6722
|
-
'comment': function (astNode, helperOptions) { return calculateCommentOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6723
|
-
'cond': function (astNode, helperOptions) { return calculateCondOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6724
|
-
'switch': function (astNode, helperOptions) { return calculateSwitchOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6725
|
-
'declared?': function (astNode, helperOptions) { return calculateDeclaredOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6726
|
-
'defn': function (astNode, helperOptions) { return calculateDefnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6727
|
-
'def': function (astNode, helperOptions) { return calculateDefOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6728
|
-
'defns': function (astNode, helperOptions) { return calculateDefnsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6729
|
-
'defs': function (astNode, helperOptions) { return calculateDefsOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6730
|
-
'do': function (astNode, helperOptions) { return calculateDoOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6731
|
-
'doseq': function (astNode, helperOptions) { return calculateDoSeqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6732
|
-
'fn': function (astNode, helperOptions) { return calculateFnOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6733
|
-
'for': function (astNode, helperOptions) { return calculateForOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6734
|
-
'if_let': function (astNode, helperOptions) { return calculateIfLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6735
|
-
'if': function (astNode, helperOptions) { return calculateIfOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6736
|
-
'if_not': function (astNode, helperOptions) { return calculateIfNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6737
|
-
'let': function (astNode, helperOptions) { return calculateLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6738
|
-
'loop': function (astNode, helperOptions) { return calculateLoopOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6739
|
-
'||': function (astNode, helperOptions) { return calculateOrOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6740
|
-
'??': function (astNode, helperOptions) { return calculateQqOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6741
|
-
'recur': function (astNode, helperOptions) { return calculateRecurOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6742
|
-
'throw': function (astNode, helperOptions) { return calculateThrowOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6743
|
-
'try': function (astNode, helperOptions) { return calculateTryOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6744
|
-
'when_first': function (astNode, helperOptions) { return calculateWhenFirstOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6745
|
-
'when_let': function (astNode, helperOptions) { return calculateWhenLetOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6746
|
-
'when': function (astNode, helperOptions) { return calculateWhenOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6747
|
-
'when_not': function (astNode, helperOptions) { return calculateWhenNotOutcomes(__assign({ astNode: astNode }, helperOptions)); },
|
|
6748
|
-
};
|
|
6749
|
-
|
|
6750
|
-
function calculateOutcomes(contextStack, astNodes) {
|
|
6751
|
-
// First, we try to calculate outcomes for the whole astNodes array.
|
|
6752
|
-
// If that fails, we try to calculate outcomes for the array without the first element.
|
|
6753
|
-
// If that fails, we try to calculate outcomes for the array without the first two elements.
|
|
6754
|
-
// And so on.
|
|
6755
|
-
// This makes it possible to calculate outcomes for e.g.
|
|
6756
|
-
// (write! x) x
|
|
6757
|
-
// Problems occur for e.g.
|
|
6758
|
-
// (def x 1) (write! x) x
|
|
6759
|
-
// This should output [1], but since (write! x) fails to calculate outcomes, we get null.
|
|
6760
|
-
// Ok, but not optimal
|
|
6761
|
-
// The contract is that when an array is returned, it must be correct.
|
|
6762
|
-
// But returning null (indicating that the calculation failed) is always a way out.
|
|
6763
|
-
for (var i = 0; i < astNodes.length; i++) {
|
|
6764
|
-
var usingAstNode = astNodes.slice(i);
|
|
6765
|
-
var outcomes = calculateOutcomesInner(contextStack, usingAstNode);
|
|
6766
|
-
if (outcomes !== null)
|
|
6767
|
-
return outcomes;
|
|
6768
|
-
}
|
|
6769
|
-
return null;
|
|
6770
|
-
}
|
|
6771
|
-
function calculateOutcomesInner(contextStack, astNodes) {
|
|
6772
|
-
var e_1, _a;
|
|
6773
|
-
var possibleAsts = calculatePossibleAsts(contextStack.clone(), astNodes);
|
|
6774
|
-
if (possibleAsts === null)
|
|
6775
|
-
return null;
|
|
6776
|
-
var outcomes = [];
|
|
6777
|
-
try {
|
|
6778
|
-
for (var possibleAsts_1 = __values(possibleAsts), possibleAsts_1_1 = possibleAsts_1.next(); !possibleAsts_1_1.done; possibleAsts_1_1 = possibleAsts_1.next()) {
|
|
6779
|
-
var possibleAst = possibleAsts_1_1.value;
|
|
6780
|
-
var unresolvedIdentifiers = findUnresolvedIdentifiers(possibleAst, contextStack.clone(), builtin);
|
|
6781
|
-
if (unresolvedIdentifiers.size !== 0)
|
|
6782
|
-
return null;
|
|
6783
|
-
var ast = {
|
|
6784
|
-
b: possibleAst,
|
|
6785
|
-
hasDebugData: true,
|
|
6786
|
-
};
|
|
6787
|
-
try {
|
|
6788
|
-
outcomes.push(evaluate(ast, contextStack.clone()));
|
|
6789
|
-
}
|
|
6790
|
-
catch (e) {
|
|
6791
|
-
outcomes.push(e);
|
|
6792
|
-
}
|
|
6793
|
-
}
|
|
6794
|
-
}
|
|
6795
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6796
|
-
finally {
|
|
6797
|
-
try {
|
|
6798
|
-
if (possibleAsts_1_1 && !possibleAsts_1_1.done && (_a = possibleAsts_1.return)) _a.call(possibleAsts_1);
|
|
6078
|
+
var unresolvedIdentifiers = specialExpression.findUnresolvedIdentifiers(astNode, contextStack, {
|
|
6079
|
+
findUnresolvedIdentifiers: findUnresolvedIdentifiers,
|
|
6080
|
+
builtin: builtin,
|
|
6081
|
+
evaluateAstNode: evaluateAstNode,
|
|
6082
|
+
});
|
|
6083
|
+
return unresolvedIdentifiers;
|
|
6799
6084
|
}
|
|
6800
|
-
finally { if (e_1) throw e_1.error; }
|
|
6801
|
-
}
|
|
6802
|
-
return outcomes;
|
|
6803
|
-
}
|
|
6804
|
-
function calculatePossibleAsts(contextStack, astNodes) {
|
|
6805
|
-
var possibleAsts;
|
|
6806
|
-
try {
|
|
6807
|
-
possibleAsts = combinate(astNodes.map(function (astNode) { return calculatePossibleAstNodes(contextStack, astNode); }));
|
|
6808
|
-
}
|
|
6809
|
-
catch (e) {
|
|
6810
|
-
return null;
|
|
6811
|
-
}
|
|
6812
|
-
return possibleAsts;
|
|
6813
|
-
}
|
|
6814
|
-
var nilNode = { t: AstNodeType.ReservedSymbol, v: 'nil', token: undefined, p: [], n: undefined };
|
|
6815
|
-
function calculatePossibleAstNodes(contextStack, astNode, newIndentifiers) {
|
|
6816
|
-
var newContext = newIndentifiers
|
|
6817
|
-
? newIndentifiers.reduce(function (acc, identity) {
|
|
6818
|
-
acc[identity] = { value: null };
|
|
6819
|
-
return acc;
|
|
6820
|
-
}, {})
|
|
6821
|
-
: undefined;
|
|
6822
|
-
var newContextStack = newContext ? contextStack.create(newContext) : contextStack;
|
|
6823
|
-
if (astNode.t === AstNodeType.NormalExpression) {
|
|
6824
|
-
return combinate(astNode.p.map(function (n) { return calculatePossibleAstNodes(newContextStack, n); }))
|
|
6825
|
-
.map(function (p) { return (__assign(__assign({}, astNode), { p: p })); });
|
|
6826
|
-
}
|
|
6827
|
-
else if (astNode.t === AstNodeType.SpecialExpression) {
|
|
6828
|
-
var helperOptions = {
|
|
6829
|
-
nilNode: nilNode,
|
|
6830
|
-
calculatePossibleAstNodes: function (node, identifiers) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); },
|
|
6831
|
-
combinateAstNodes: function (nodes, identifiers) {
|
|
6832
|
-
return combinate(nodes.map(function (node) { return calculatePossibleAstNodes(newContextStack.clone(), node, identifiers); }));
|
|
6833
|
-
},
|
|
6834
|
-
isAstComputable: function (node) {
|
|
6835
|
-
return calculateOutcomesInner(newContextStack, Array.isArray(node) ? node.flat() : [node]) !== null;
|
|
6836
|
-
},
|
|
6837
|
-
addGlobalIdentifier: function (name) { return newContextStack.globalContext[name] = { value: null }; },
|
|
6838
|
-
};
|
|
6839
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
6840
|
-
return specialExpressionCalculator[astNode.n](astNode, helperOptions);
|
|
6841
6085
|
}
|
|
6842
|
-
return [astNode];
|
|
6843
6086
|
}
|
|
6844
6087
|
|
|
6845
6088
|
function analyze(ast, params) {
|
|
6846
6089
|
return {
|
|
6847
6090
|
unresolvedIdentifiers: findUnresolvedIdentifiers(ast, createContextStack(params), builtin),
|
|
6848
|
-
outcomes: calculateOutcomes(createContextStack(params), ast.b),
|
|
6849
6091
|
};
|
|
6850
6092
|
}
|
|
6851
6093
|
|
|
@@ -7127,38 +6369,43 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7127
6369
|
var _a;
|
|
7128
6370
|
if (precedence === void 0) { precedence = 0; }
|
|
7129
6371
|
var firstToken = this.peek();
|
|
7130
|
-
if (isA_SymbolToken(firstToken) && firstToken[1] === 'def') {
|
|
7131
|
-
return this.parseDef(firstToken);
|
|
7132
|
-
}
|
|
7133
|
-
else if (isA_SymbolToken(firstToken) && firstToken[1] === 'defn') {
|
|
7134
|
-
return this.parseDefn(firstToken);
|
|
7135
|
-
}
|
|
7136
6372
|
var left;
|
|
7137
|
-
if (isA_SymbolToken(firstToken)
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
6373
|
+
if (isA_SymbolToken(firstToken)) {
|
|
6374
|
+
switch (firstToken[1]) {
|
|
6375
|
+
case 'def':
|
|
6376
|
+
return this.parseDef(firstToken);
|
|
6377
|
+
case 'defn':
|
|
6378
|
+
return this.parseDefn(firstToken);
|
|
6379
|
+
case 'let':
|
|
6380
|
+
return this.parseLet(firstToken);
|
|
6381
|
+
case 'if':
|
|
6382
|
+
case 'unless':
|
|
6383
|
+
left = this.parseIfOrUnless(firstToken);
|
|
6384
|
+
break;
|
|
6385
|
+
case 'cond':
|
|
6386
|
+
left = this.parseCond(firstToken);
|
|
6387
|
+
break;
|
|
6388
|
+
case 'switch':
|
|
6389
|
+
left = this.parseSwitch(firstToken);
|
|
6390
|
+
break;
|
|
6391
|
+
case 'for':
|
|
6392
|
+
case 'doseq':
|
|
6393
|
+
left = this.parseForOrDoseq(firstToken);
|
|
6394
|
+
break;
|
|
6395
|
+
case 'do':
|
|
6396
|
+
left = this.parseDo(firstToken);
|
|
6397
|
+
break;
|
|
6398
|
+
case 'loop':
|
|
6399
|
+
left = this.parseLoop(firstToken);
|
|
6400
|
+
break;
|
|
6401
|
+
case 'try':
|
|
6402
|
+
left = this.parseTry(firstToken);
|
|
6403
|
+
break;
|
|
6404
|
+
}
|
|
7151
6405
|
}
|
|
6406
|
+
left || (left = this.parseOperand());
|
|
7152
6407
|
var operator = this.peek();
|
|
7153
|
-
while (!this.
|
|
7154
|
-
&& !isA_OperatorToken(operator, ',')
|
|
7155
|
-
&& !isA_OperatorToken(operator, ';')
|
|
7156
|
-
&& !isRBracketToken(operator)
|
|
7157
|
-
&& !isA_ReservedSymbolToken(operator, 'else')
|
|
7158
|
-
&& !isA_ReservedSymbolToken(operator, 'then')
|
|
7159
|
-
&& !isA_ReservedSymbolToken(operator, 'end')
|
|
7160
|
-
&& !isA_ReservedSymbolToken(operator, 'case')
|
|
7161
|
-
&& !isRParenToken(operator)) {
|
|
6408
|
+
while (!this.isAtExpressionEnd()) {
|
|
7162
6409
|
if (isA_BinaryOperatorToken(operator)) {
|
|
7163
6410
|
var name_1 = operator[1];
|
|
7164
6411
|
var newPrecedece = getPrecedence(name_1);
|
|
@@ -7411,12 +6658,9 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7411
6658
|
case '??':
|
|
7412
6659
|
case '&&':
|
|
7413
6660
|
case 'comment':
|
|
7414
|
-
case '
|
|
7415
|
-
case 'if_not':
|
|
6661
|
+
case 'defined?':
|
|
7416
6662
|
case '||':
|
|
7417
|
-
case '
|
|
7418
|
-
case 'when_not':
|
|
7419
|
-
case 'do':
|
|
6663
|
+
case 'recur':
|
|
7420
6664
|
case 'throw': {
|
|
7421
6665
|
var node = {
|
|
7422
6666
|
t: AstNodeType.SpecialExpression,
|
|
@@ -7427,17 +6671,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7427
6671
|
builtin.specialExpressions[node.n].validateParameterCount(node);
|
|
7428
6672
|
return node;
|
|
7429
6673
|
}
|
|
7430
|
-
case 'let':
|
|
7431
|
-
return this.parseLet(symbol, params);
|
|
7432
6674
|
case 'defs':
|
|
7433
|
-
case 'if_let':
|
|
7434
|
-
case 'when_let':
|
|
7435
|
-
case 'when_first':
|
|
7436
6675
|
case 'fn':
|
|
7437
6676
|
case 'defns':
|
|
7438
6677
|
case 'try':
|
|
7439
|
-
case 'recur':
|
|
7440
|
-
case 'loop':
|
|
7441
6678
|
case 'doseq':
|
|
7442
6679
|
throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
|
|
7443
6680
|
default:
|
|
@@ -7600,36 +6837,142 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7600
6837
|
};
|
|
7601
6838
|
return node;
|
|
7602
6839
|
};
|
|
7603
|
-
AlgebraicParser.prototype.parseLet = function (
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
var
|
|
7609
|
-
if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
|
|
7610
|
-
throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7611
|
-
}
|
|
7612
|
-
var letBindings = arrayToPairs(letObject.p);
|
|
7613
|
-
var expression = params[1];
|
|
6840
|
+
AlgebraicParser.prototype.parseLet = function (token) {
|
|
6841
|
+
this.advance();
|
|
6842
|
+
var letSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6843
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6844
|
+
this.advance();
|
|
6845
|
+
var value = this.parseExpression();
|
|
7614
6846
|
return {
|
|
7615
6847
|
t: AstNodeType.SpecialExpression,
|
|
7616
6848
|
n: 'let',
|
|
7617
|
-
p: [
|
|
6849
|
+
p: [],
|
|
7618
6850
|
token: getTokenDebugData(letSymbol.token) && letSymbol.token,
|
|
7619
|
-
bs:
|
|
7620
|
-
var key = pair[0];
|
|
7621
|
-
var value = pair[1];
|
|
7622
|
-
return {
|
|
6851
|
+
bs: [{
|
|
7623
6852
|
t: AstNodeType.Binding,
|
|
7624
|
-
n:
|
|
6853
|
+
n: letSymbol.v,
|
|
7625
6854
|
v: value,
|
|
7626
6855
|
p: [],
|
|
7627
|
-
token: getTokenDebugData(
|
|
7628
|
-
}
|
|
7629
|
-
|
|
6856
|
+
token: getTokenDebugData(token) && token,
|
|
6857
|
+
}],
|
|
6858
|
+
};
|
|
6859
|
+
};
|
|
6860
|
+
AlgebraicParser.prototype.parseDo = function (token) {
|
|
6861
|
+
this.advance();
|
|
6862
|
+
var expressions = [];
|
|
6863
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6864
|
+
expressions.push(this.parseExpression());
|
|
6865
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6866
|
+
this.advance();
|
|
6867
|
+
}
|
|
6868
|
+
}
|
|
6869
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6870
|
+
this.advance();
|
|
6871
|
+
return {
|
|
6872
|
+
t: AstNodeType.SpecialExpression,
|
|
6873
|
+
n: 'do',
|
|
6874
|
+
p: expressions,
|
|
6875
|
+
token: getTokenDebugData(token) && token,
|
|
6876
|
+
};
|
|
6877
|
+
};
|
|
6878
|
+
AlgebraicParser.prototype.parseLoop = function (token) {
|
|
6879
|
+
var _a;
|
|
6880
|
+
this.advance();
|
|
6881
|
+
assertLParenToken(this.peek());
|
|
6882
|
+
this.advance();
|
|
6883
|
+
var bindingNodes = [];
|
|
6884
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6885
|
+
var symbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6886
|
+
assertA_OperatorToken(this.peek(), '=');
|
|
6887
|
+
this.advance();
|
|
6888
|
+
var value = this.parseExpression();
|
|
6889
|
+
bindingNodes.push({
|
|
6890
|
+
t: AstNodeType.Binding,
|
|
6891
|
+
n: symbol.v,
|
|
6892
|
+
v: value,
|
|
6893
|
+
p: [],
|
|
6894
|
+
token: getTokenDebugData(symbol.token) && symbol.token,
|
|
6895
|
+
});
|
|
6896
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
6897
|
+
this.advance();
|
|
6898
|
+
}
|
|
6899
|
+
}
|
|
6900
|
+
if (bindingNodes.length === 0) {
|
|
6901
|
+
throw new LitsError('Expected binding', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
6902
|
+
}
|
|
6903
|
+
assertRParenToken(this.peek());
|
|
6904
|
+
this.advance();
|
|
6905
|
+
var params = [];
|
|
6906
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6907
|
+
params.push(this.parseExpression());
|
|
6908
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6909
|
+
this.advance();
|
|
6910
|
+
}
|
|
6911
|
+
}
|
|
6912
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6913
|
+
this.advance();
|
|
6914
|
+
return {
|
|
6915
|
+
t: AstNodeType.SpecialExpression,
|
|
6916
|
+
n: 'loop',
|
|
6917
|
+
p: params,
|
|
6918
|
+
bs: bindingNodes,
|
|
6919
|
+
token: getTokenDebugData(token) && token,
|
|
6920
|
+
};
|
|
6921
|
+
};
|
|
6922
|
+
AlgebraicParser.prototype.parseTry = function (token) {
|
|
6923
|
+
this.advance();
|
|
6924
|
+
var tryExpressions = [];
|
|
6925
|
+
while (!this.isAtEnd() && !isA_SymbolToken(this.peek(), 'catch')) {
|
|
6926
|
+
tryExpressions.push(this.parseExpression());
|
|
6927
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6928
|
+
this.advance();
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6931
|
+
var tryExpression = tryExpressions.length === 1
|
|
6932
|
+
? tryExpressions[0]
|
|
6933
|
+
: {
|
|
6934
|
+
t: AstNodeType.SpecialExpression,
|
|
6935
|
+
n: 'do',
|
|
6936
|
+
p: tryExpressions,
|
|
6937
|
+
token: getTokenDebugData(token) && token,
|
|
6938
|
+
};
|
|
6939
|
+
assertA_SymbolToken(this.peek(), 'catch');
|
|
6940
|
+
this.advance();
|
|
6941
|
+
var errorSymbol;
|
|
6942
|
+
if (isLParenToken(this.peek())) {
|
|
6943
|
+
this.advance();
|
|
6944
|
+
errorSymbol = parseSymbol(this.tokenStream, this.parseState);
|
|
6945
|
+
assertRParenToken(this.peek());
|
|
6946
|
+
this.advance();
|
|
6947
|
+
}
|
|
6948
|
+
var catchExpressions = [];
|
|
6949
|
+
while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
|
|
6950
|
+
catchExpressions.push(this.parseExpression());
|
|
6951
|
+
if (isA_OperatorToken(this.peek(), ';')) {
|
|
6952
|
+
this.advance();
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
assertA_ReservedSymbolToken(this.peek(), 'end');
|
|
6956
|
+
this.advance();
|
|
6957
|
+
var catchExpression = catchExpressions.length === 1
|
|
6958
|
+
? catchExpressions[0]
|
|
6959
|
+
: {
|
|
6960
|
+
t: AstNodeType.SpecialExpression,
|
|
6961
|
+
n: 'do',
|
|
6962
|
+
p: catchExpressions,
|
|
6963
|
+
token: getTokenDebugData(token) && token,
|
|
6964
|
+
};
|
|
6965
|
+
return {
|
|
6966
|
+
t: AstNodeType.SpecialExpression,
|
|
6967
|
+
n: 'try',
|
|
6968
|
+
p: [tryExpression],
|
|
6969
|
+
ce: catchExpression,
|
|
6970
|
+
e: errorSymbol,
|
|
6971
|
+
token: getTokenDebugData(token) && token,
|
|
7630
6972
|
};
|
|
7631
6973
|
};
|
|
7632
|
-
AlgebraicParser.prototype.
|
|
6974
|
+
AlgebraicParser.prototype.parseForOrDoseq = function (token) {
|
|
6975
|
+
var isDoseq = token[1] === 'doseq';
|
|
7633
6976
|
this.advance();
|
|
7634
6977
|
assertLParenToken(this.peek());
|
|
7635
6978
|
this.advance();
|
|
@@ -7649,7 +6992,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7649
6992
|
this.advance();
|
|
7650
6993
|
return {
|
|
7651
6994
|
t: AstNodeType.SpecialExpression,
|
|
7652
|
-
n: 'for',
|
|
6995
|
+
n: isDoseq ? 'doseq' : 'for',
|
|
7653
6996
|
p: [expression],
|
|
7654
6997
|
token: getTokenDebugData(token) && token,
|
|
7655
6998
|
l: forLoopBindings,
|
|
@@ -7669,33 +7012,26 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7669
7012
|
}
|
|
7670
7013
|
var modifiers = [];
|
|
7671
7014
|
var token = this.peek();
|
|
7672
|
-
if (!isA_SymbolToken(token)
|
|
7015
|
+
if (!isA_SymbolToken(token, 'let')
|
|
7016
|
+
&& !isA_ReservedSymbolToken(token, 'when')
|
|
7017
|
+
&& !isA_ReservedSymbolToken(token, 'while')) {
|
|
7673
7018
|
throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7674
7019
|
}
|
|
7675
7020
|
var letBindings;
|
|
7676
7021
|
if (token[1] === 'let') {
|
|
7677
7022
|
modifiers.push('&let');
|
|
7678
7023
|
letBindings = [];
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
return {
|
|
7685
|
-
t: AstNodeType.Binding,
|
|
7686
|
-
n: key.v,
|
|
7687
|
-
v: value,
|
|
7688
|
-
p: [],
|
|
7689
|
-
token: getTokenDebugData(key.token) && key.token,
|
|
7690
|
-
};
|
|
7691
|
-
});
|
|
7024
|
+
while (isA_SymbolToken(token, 'let')) {
|
|
7025
|
+
var letNode = this.parseLet(token);
|
|
7026
|
+
letBindings.push(letNode.bs[0]);
|
|
7027
|
+
token = this.peek();
|
|
7028
|
+
}
|
|
7692
7029
|
}
|
|
7693
7030
|
token = this.peek();
|
|
7694
7031
|
var whenNode;
|
|
7695
7032
|
var whileNode;
|
|
7696
|
-
while (
|
|
7697
|
-
|
|
7698
|
-
|| (token[1] === 'while' && !modifiers.includes('&while')))) {
|
|
7033
|
+
while (isA_ReservedSymbolToken(token, 'when')
|
|
7034
|
+
|| isA_ReservedSymbolToken(token, 'while')) {
|
|
7699
7035
|
this.advance();
|
|
7700
7036
|
if (token[1] === 'when') {
|
|
7701
7037
|
modifiers.push('&when');
|
|
@@ -7738,7 +7074,8 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7738
7074
|
};
|
|
7739
7075
|
return node;
|
|
7740
7076
|
};
|
|
7741
|
-
AlgebraicParser.prototype.
|
|
7077
|
+
AlgebraicParser.prototype.parseIfOrUnless = function (token) {
|
|
7078
|
+
var isUnless = token[1] === 'unless';
|
|
7742
7079
|
this.advance();
|
|
7743
7080
|
var condition = this.parseExpression();
|
|
7744
7081
|
assertA_ReservedSymbolToken(this.peek(), 'then');
|
|
@@ -7787,7 +7124,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7787
7124
|
}
|
|
7788
7125
|
return {
|
|
7789
7126
|
t: AstNodeType.SpecialExpression,
|
|
7790
|
-
n: 'if',
|
|
7127
|
+
n: isUnless ? 'unless' : 'if',
|
|
7791
7128
|
p: params,
|
|
7792
7129
|
token: getTokenDebugData(token) && token,
|
|
7793
7130
|
};
|
|
@@ -7914,6 +7251,22 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7914
7251
|
AlgebraicParser.prototype.isAtEnd = function () {
|
|
7915
7252
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
7916
7253
|
};
|
|
7254
|
+
AlgebraicParser.prototype.isAtExpressionEnd = function () {
|
|
7255
|
+
if (this.isAtEnd()) {
|
|
7256
|
+
return true;
|
|
7257
|
+
}
|
|
7258
|
+
var token = this.peek();
|
|
7259
|
+
if (isA_OperatorToken(token)) {
|
|
7260
|
+
return [';', ','].includes(token[1]);
|
|
7261
|
+
}
|
|
7262
|
+
if (isA_SymbolToken(token)) {
|
|
7263
|
+
return ['catch'].includes(token[1]);
|
|
7264
|
+
}
|
|
7265
|
+
if (isA_ReservedSymbolToken(token)) {
|
|
7266
|
+
return ['else', 'when', 'while', 'then', 'end', 'case'].includes(token[1]);
|
|
7267
|
+
}
|
|
7268
|
+
return false;
|
|
7269
|
+
};
|
|
7917
7270
|
AlgebraicParser.prototype.peek = function () {
|
|
7918
7271
|
return this.tokenStream.tokens[this.parseState.position];
|
|
7919
7272
|
};
|
|
@@ -8379,17 +7732,12 @@ var validAlgebraicReservedNamesRecord = {
|
|
|
8379
7732
|
else: { value: null, forbidden: false },
|
|
8380
7733
|
end: { value: null, forbidden: false },
|
|
8381
7734
|
case: { value: null, forbidden: false },
|
|
7735
|
+
when: { value: null, forbidden: false },
|
|
7736
|
+
while: { value: null, forbidden: false },
|
|
8382
7737
|
};
|
|
8383
7738
|
var forbiddenAlgebraicReservedNamesRecord = {
|
|
8384
|
-
if_let: { value: null, forbidden: true },
|
|
8385
|
-
when_let: { value: null, forbidden: true },
|
|
8386
|
-
when_first: { value: null, forbidden: true },
|
|
8387
7739
|
fn: { value: null, forbidden: true },
|
|
8388
7740
|
defns: { value: null, forbidden: true },
|
|
8389
|
-
try: { value: null, forbidden: true },
|
|
8390
|
-
recur: { value: null, forbidden: true },
|
|
8391
|
-
loop: { value: null, forbidden: true },
|
|
8392
|
-
doseq: { value: null, forbidden: true },
|
|
8393
7741
|
};
|
|
8394
7742
|
var algebraicReservedNamesRecord = __assign(__assign({}, validAlgebraicReservedNamesRecord), forbiddenAlgebraicReservedNamesRecord);
|
|
8395
7743
|
|
|
@@ -10088,7 +9436,7 @@ var arrayReference = {
|
|
|
10088
9436
|
description: 'Takes a nested array $x and flattens it.',
|
|
10089
9437
|
examples: [
|
|
10090
9438
|
'(flatten [1 2 [3 4] 5])',
|
|
10091
|
-
"\n(let [foo :bar]\n
|
|
9439
|
+
"\n(let [foo :bar])\n(flatten\n [1\n \" 2 A \"\n [foo [4 [:ABC]]] 6])",
|
|
10092
9440
|
'(flatten 12)',
|
|
10093
9441
|
],
|
|
10094
9442
|
},
|
|
@@ -13935,97 +13283,12 @@ var specialExpressionsReference = {
|
|
|
13935
13283
|
type: '*binding',
|
|
13936
13284
|
rest: true,
|
|
13937
13285
|
},
|
|
13938
|
-
expressions: {
|
|
13939
|
-
type: '*expression',
|
|
13940
|
-
rest: true,
|
|
13941
|
-
},
|
|
13942
|
-
},
|
|
13943
|
-
variants: [
|
|
13944
|
-
{ argumentNames: ['bindings', 'expressions'] },
|
|
13945
|
-
],
|
|
13946
|
-
description: "\nBinds local variables. The variables lives only within $expressions.\nIt returns evaluation of the last expression in $expressions.",
|
|
13947
|
-
examples: ["\n (let [a (+ 1 2 3 4) \n b (* 1 2 3 4)]\n (write! a b))"],
|
|
13948
|
-
},
|
|
13949
|
-
'if_let': {
|
|
13950
|
-
title: 'if_let',
|
|
13951
|
-
category: 'Special expression',
|
|
13952
|
-
linkName: 'if_let',
|
|
13953
|
-
returns: {
|
|
13954
|
-
type: 'any',
|
|
13955
|
-
},
|
|
13956
|
-
args: {
|
|
13957
|
-
'binding': {
|
|
13958
|
-
type: '*binding',
|
|
13959
|
-
},
|
|
13960
|
-
'then-expr': {
|
|
13961
|
-
type: '*expression',
|
|
13962
|
-
},
|
|
13963
|
-
'else-expr': {
|
|
13964
|
-
type: '*expression',
|
|
13965
|
-
},
|
|
13966
|
-
},
|
|
13967
|
-
variants: [
|
|
13968
|
-
{ argumentNames: ['binding', 'then-expr'] },
|
|
13969
|
-
{ argumentNames: ['binding', 'then-expr', 'else-expr'] },
|
|
13970
|
-
],
|
|
13971
|
-
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).",
|
|
13972
|
-
examples: [
|
|
13973
|
-
"\n(if_let [a (> (count \"Albert\") 4)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
|
|
13974
|
-
"\n(if_let [a (> (count \"Albert\") 10)]\n (write! (str a \", is big enough\"))\n (write! \"Sorry, not big enough.\"))",
|
|
13975
|
-
],
|
|
13976
|
-
},
|
|
13977
|
-
'when_let': {
|
|
13978
|
-
title: 'when_let',
|
|
13979
|
-
category: 'Special expression',
|
|
13980
|
-
linkName: 'when_let',
|
|
13981
|
-
returns: {
|
|
13982
|
-
type: 'any',
|
|
13983
|
-
},
|
|
13984
|
-
args: {
|
|
13985
|
-
binding: {
|
|
13986
|
-
type: '*binding',
|
|
13987
|
-
},
|
|
13988
|
-
expressions: {
|
|
13989
|
-
type: '*expression',
|
|
13990
|
-
rest: true,
|
|
13991
|
-
},
|
|
13992
|
-
},
|
|
13993
|
-
variants: [
|
|
13994
|
-
{ argumentNames: ['binding', 'expressions'] },
|
|
13995
|
-
],
|
|
13996
|
-
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.",
|
|
13997
|
-
examples: [
|
|
13998
|
-
"\n(when_let [a (> (count \"Albert\") 4)]\n (write! a))",
|
|
13999
|
-
],
|
|
14000
|
-
},
|
|
14001
|
-
'when_first': {
|
|
14002
|
-
title: 'when_first',
|
|
14003
|
-
category: 'Special expression',
|
|
14004
|
-
linkName: 'when_first',
|
|
14005
|
-
returns: {
|
|
14006
|
-
type: 'any',
|
|
14007
|
-
},
|
|
14008
|
-
args: {
|
|
14009
|
-
binding: {
|
|
14010
|
-
type: '*binding',
|
|
14011
|
-
rest: true,
|
|
14012
|
-
},
|
|
14013
|
-
expressions: {
|
|
14014
|
-
type: '*expression',
|
|
14015
|
-
rest: true,
|
|
14016
|
-
},
|
|
14017
13286
|
},
|
|
14018
13287
|
variants: [
|
|
14019
|
-
{ argumentNames: ['
|
|
14020
|
-
],
|
|
14021
|
-
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.',
|
|
14022
|
-
examples: [
|
|
14023
|
-
"\n(when_first [x [1 2 3]]\n (write! x)\n x)",
|
|
14024
|
-
"\n(when_first [x \"Albert\"]\n (write! x)\n x)",
|
|
14025
|
-
"\n(when_first [x [0]]\n (write! x)\n x)",
|
|
14026
|
-
"\n(when_first [x [nil]]\n (write! x)\n x)",
|
|
14027
|
-
"\n(when_first [x []]\n (write! x)\n x)",
|
|
13288
|
+
{ argumentNames: ['bindings'] },
|
|
14028
13289
|
],
|
|
13290
|
+
description: "\nBinds local variables.",
|
|
13291
|
+
examples: ["\n(let [a (+ 1 2 3 4) \n b (* 1 2 3 4)])\n(write! a b)"],
|
|
14029
13292
|
},
|
|
14030
13293
|
'fn': {
|
|
14031
13294
|
title: 'fn',
|
|
@@ -14189,10 +13452,11 @@ var specialExpressionsReference = {
|
|
|
14189
13452
|
'(if false (write! "TRUE"))',
|
|
14190
13453
|
],
|
|
14191
13454
|
},
|
|
14192
|
-
'
|
|
14193
|
-
title: '
|
|
13455
|
+
'unless': {
|
|
13456
|
+
title: 'unless',
|
|
14194
13457
|
category: 'Special expression',
|
|
14195
|
-
linkName: '
|
|
13458
|
+
linkName: 'unless',
|
|
13459
|
+
clojureDocs: 'if-not',
|
|
14196
13460
|
returns: {
|
|
14197
13461
|
type: 'any',
|
|
14198
13462
|
},
|
|
@@ -14213,10 +13477,10 @@ var specialExpressionsReference = {
|
|
|
14213
13477
|
],
|
|
14214
13478
|
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.',
|
|
14215
13479
|
examples: [
|
|
14216
|
-
'(
|
|
14217
|
-
'(
|
|
14218
|
-
'(
|
|
14219
|
-
'(
|
|
13480
|
+
'(unless true (write! "TRUE") (write! "FALSE"))',
|
|
13481
|
+
'(unless false (write! "TRUE") (write! "FALSE"))',
|
|
13482
|
+
'(unless true (write! "TRUE"))',
|
|
13483
|
+
'(unless false (write! "TRUE"))',
|
|
14220
13484
|
],
|
|
14221
13485
|
},
|
|
14222
13486
|
'cond': {
|
|
@@ -14266,60 +13530,6 @@ var specialExpressionsReference = {
|
|
|
14266
13530
|
"\n(switch 3\n 1 (write! \"FALSE\")\n 2 (write! \"nil\"))",
|
|
14267
13531
|
],
|
|
14268
13532
|
},
|
|
14269
|
-
'when': {
|
|
14270
|
-
title: 'when',
|
|
14271
|
-
category: 'Special expression',
|
|
14272
|
-
linkName: 'when',
|
|
14273
|
-
returns: {
|
|
14274
|
-
type: 'any',
|
|
14275
|
-
},
|
|
14276
|
-
args: {
|
|
14277
|
-
test: {
|
|
14278
|
-
type: '*expression',
|
|
14279
|
-
},
|
|
14280
|
-
expressions: {
|
|
14281
|
-
type: '*expression',
|
|
14282
|
-
rest: true,
|
|
14283
|
-
},
|
|
14284
|
-
},
|
|
14285
|
-
variants: [
|
|
14286
|
-
{ argumentNames: ['test', 'expressions'] },
|
|
14287
|
-
],
|
|
14288
|
-
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.",
|
|
14289
|
-
examples: [
|
|
14290
|
-
"(when true\n (write! \"Hi\")\n (write! \"There\"))",
|
|
14291
|
-
"(when false\n (write! \"Hi\")\n (write! \"There\"))",
|
|
14292
|
-
'(when true)',
|
|
14293
|
-
'(when false)',
|
|
14294
|
-
],
|
|
14295
|
-
},
|
|
14296
|
-
'when_not': {
|
|
14297
|
-
title: 'when_not',
|
|
14298
|
-
category: 'Special expression',
|
|
14299
|
-
linkName: 'when_not',
|
|
14300
|
-
returns: {
|
|
14301
|
-
type: 'any',
|
|
14302
|
-
},
|
|
14303
|
-
args: {
|
|
14304
|
-
test: {
|
|
14305
|
-
type: '*expression',
|
|
14306
|
-
},
|
|
14307
|
-
expressions: {
|
|
14308
|
-
type: '*expression',
|
|
14309
|
-
rest: true,
|
|
14310
|
-
},
|
|
14311
|
-
},
|
|
14312
|
-
variants: [
|
|
14313
|
-
{ argumentNames: ['test', 'expressions'] },
|
|
14314
|
-
],
|
|
14315
|
-
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.",
|
|
14316
|
-
examples: [
|
|
14317
|
-
'(when_not true (write! "Hi") (write! "There"))',
|
|
14318
|
-
'(when_not false (write! "Hi") (write! "There"))',
|
|
14319
|
-
'(when_not true)',
|
|
14320
|
-
'(when_not false)',
|
|
14321
|
-
],
|
|
14322
|
-
},
|
|
14323
13533
|
'comment': {
|
|
14324
13534
|
title: 'comment',
|
|
14325
13535
|
category: 'Special expression',
|
|
@@ -14379,9 +13589,9 @@ var specialExpressionsReference = {
|
|
|
14379
13589
|
],
|
|
14380
13590
|
description: 'Recursevly calls enclosing function or loop with its evaluated $expressions.',
|
|
14381
13591
|
examples: [
|
|
14382
|
-
"\n(defn foo [n]\n (write! n)\n (
|
|
14383
|
-
"\n(\n (fn [n]\n (write! n)\n (
|
|
14384
|
-
"\n(\n loop [n 3]\n (write! n)\n (
|
|
13592
|
+
"\n(defn foo [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n(foo 3)",
|
|
13593
|
+
"\n(\n (fn [n]\n (write! n)\n (if (! (zero? n))\n (recur\n (dec n))))\n 3)",
|
|
13594
|
+
"\n(\n loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
|
|
14385
13595
|
],
|
|
14386
13596
|
},
|
|
14387
13597
|
'loop': {
|
|
@@ -14406,7 +13616,7 @@ var specialExpressionsReference = {
|
|
|
14406
13616
|
],
|
|
14407
13617
|
description: 'Executes $expressions with initial $bindings. The $bindings will be replaced with the recur parameters for subsequent recursions.',
|
|
14408
13618
|
examples: [
|
|
14409
|
-
"\n(loop [n 3]\n (write! n)\n (
|
|
13619
|
+
"\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))))",
|
|
14410
13620
|
"\n(loop [n 3]\n (write! n)\n (if\n (! (zero? n))\n (recur (dec n))\n n))",
|
|
14411
13621
|
],
|
|
14412
13622
|
},
|
|
@@ -14465,10 +13675,10 @@ var specialExpressionsReference = {
|
|
|
14465
13675
|
"\n(for\n [x [1 2 3] y [1 2 3] z [1 2 3]\n &while (<= x y)]\n \n [x y z])",
|
|
14466
13676
|
],
|
|
14467
13677
|
},
|
|
14468
|
-
'
|
|
14469
|
-
title: '
|
|
13678
|
+
'defined?': {
|
|
13679
|
+
title: 'defined?',
|
|
14470
13680
|
category: 'Special expression',
|
|
14471
|
-
linkName: '
|
|
13681
|
+
linkName: 'defined-question',
|
|
14472
13682
|
returns: {
|
|
14473
13683
|
type: 'boolean',
|
|
14474
13684
|
},
|
|
@@ -14482,11 +13692,11 @@ var specialExpressionsReference = {
|
|
|
14482
13692
|
],
|
|
14483
13693
|
description: 'Returns `true` if $n is a declared variable or a builtin function, otherwise `false`.',
|
|
14484
13694
|
examples: [
|
|
14485
|
-
'(
|
|
14486
|
-
"\n(def foo :foo)\n(
|
|
14487
|
-
'(
|
|
14488
|
-
"\n(def foo nil)\n(
|
|
14489
|
-
'(
|
|
13695
|
+
'(defined? foo)',
|
|
13696
|
+
"\n(def foo :foo)\n(defined? foo)",
|
|
13697
|
+
'(defined? +)',
|
|
13698
|
+
"\n(def foo nil)\n(defined? foo)",
|
|
13699
|
+
'(defined? if)',
|
|
14490
13700
|
],
|
|
14491
13701
|
},
|
|
14492
13702
|
'??': {
|
|
@@ -15753,27 +14963,22 @@ var api = {
|
|
|
15753
14963
|
'def',
|
|
15754
14964
|
'defs',
|
|
15755
14965
|
'let',
|
|
15756
|
-
'if_let',
|
|
15757
|
-
'when_let',
|
|
15758
|
-
'when_first',
|
|
15759
14966
|
'fn',
|
|
15760
14967
|
'defn',
|
|
15761
14968
|
'defns',
|
|
15762
14969
|
'try',
|
|
15763
14970
|
'throw',
|
|
15764
14971
|
'if',
|
|
15765
|
-
'
|
|
14972
|
+
'unless',
|
|
15766
14973
|
'cond',
|
|
15767
14974
|
'switch',
|
|
15768
|
-
'when',
|
|
15769
|
-
'when_not',
|
|
15770
14975
|
'comment',
|
|
15771
14976
|
'do',
|
|
15772
14977
|
'recur',
|
|
15773
14978
|
'loop',
|
|
15774
14979
|
'doseq',
|
|
15775
14980
|
'for',
|
|
15776
|
-
'
|
|
14981
|
+
'defined?',
|
|
15777
14982
|
'??',
|
|
15778
14983
|
],
|
|
15779
14984
|
string: [
|