@mojir/lits 2.1.1 → 2.1.3
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 +228 -107
- package/dist/cli/reference/api.d.ts +0 -1
- package/dist/cli/src/builtin/bindingNode.d.ts +1 -0
- package/dist/cli/src/builtin/interface.d.ts +1 -0
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +3 -5
- package/dist/cli/src/builtin/specialExpressions/def.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/cli/src/constants/constants.d.ts +1 -1
- package/dist/cli/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/cli/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/cli/src/parser/types.d.ts +6 -1
- package/dist/cli/src/tokenizer/token.d.ts +2 -2
- package/dist/cli/src/typeGuards/astNode.d.ts +1 -6
- package/dist/index.esm.js +249 -125
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +249 -125
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +249 -125
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +0 -1
- package/dist/src/builtin/bindingNode.d.ts +1 -0
- package/dist/src/builtin/interface.d.ts +1 -0
- package/dist/src/builtin/specialExpressionTypes.d.ts +3 -5
- package/dist/src/builtin/specialExpressions/def.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/src/constants/constants.d.ts +1 -1
- package/dist/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/src/parser/types.d.ts +6 -1
- package/dist/src/tokenizer/token.d.ts +2 -2
- package/dist/src/typeGuards/astNode.d.ts +1 -6
- package/dist/testFramework.esm.js +227 -84
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +227 -84
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -96,9 +96,15 @@ function getCodeMarker(sourceCodeInfo) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (!sourceCodeInfo) {
|
|
100
|
+
return message;
|
|
101
|
+
}
|
|
102
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
103
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
104
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
105
|
+
: "\nLocation ".concat(location);
|
|
106
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
107
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
102
108
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
103
109
|
}
|
|
104
110
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -183,12 +189,12 @@ var specialExpressionTypes = {
|
|
|
183
189
|
'||': 2,
|
|
184
190
|
'array': 3,
|
|
185
191
|
'cond': 4,
|
|
186
|
-
'
|
|
192
|
+
'0_def': 5,
|
|
187
193
|
'defined?': 6,
|
|
188
|
-
'
|
|
194
|
+
'0_defn': 7,
|
|
189
195
|
'do': 8,
|
|
190
196
|
'doseq': 9,
|
|
191
|
-
'
|
|
197
|
+
'0_fn': 10,
|
|
192
198
|
'for': 11,
|
|
193
199
|
'function': 12,
|
|
194
200
|
'if': 13,
|
|
@@ -233,6 +239,7 @@ var functionTypes = [
|
|
|
233
239
|
'SomePred',
|
|
234
240
|
'Fnull',
|
|
235
241
|
'Builtin',
|
|
242
|
+
'SpecialBuiltin',
|
|
236
243
|
'NativeJsFunction',
|
|
237
244
|
];
|
|
238
245
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -302,25 +309,9 @@ function assertUserDefinedSymbolNode(node, sourceCodeInfo) {
|
|
|
302
309
|
function isNormalBuiltinSymbolNode(node) {
|
|
303
310
|
return NodeTypes.NormalBuiltinSymbol === node[0];
|
|
304
311
|
}
|
|
305
|
-
function isSpecialBuiltinSymbolNode(node
|
|
306
|
-
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
{
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
+
function isSpecialBuiltinSymbolNode(node) {
|
|
313
|
+
return NodeTypes.SpecialBuiltinSymbol === node[0];
|
|
312
314
|
}
|
|
313
|
-
// export function isNumberNode(node: Node): node is NumberNode {
|
|
314
|
-
// return node[0] === NodeTypes.Number
|
|
315
|
-
// }
|
|
316
|
-
// export function asNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): NumberNode {
|
|
317
|
-
// assertNumberNode(node, sourceCodeInfo)
|
|
318
|
-
// return node
|
|
319
|
-
// }
|
|
320
|
-
// export function assertNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): asserts node is NumberNode {
|
|
321
|
-
// if (!isNumberNode(node))
|
|
322
|
-
// throw getAssertionError('NumberNode', node, sourceCodeInfo)
|
|
323
|
-
// }
|
|
324
315
|
function isNormalExpressionNode(node) {
|
|
325
316
|
return node[0] === NodeTypes.NormalExpression;
|
|
326
317
|
}
|
|
@@ -373,6 +364,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
373
364
|
case NodeTypes.String:
|
|
374
365
|
case NodeTypes.Number:
|
|
375
366
|
case NodeTypes.ReservedSymbol:
|
|
367
|
+
case NodeTypes.Binding:
|
|
376
368
|
return null;
|
|
377
369
|
case NodeTypes.NormalExpression: {
|
|
378
370
|
var normalExpressionNode = node;
|
|
@@ -417,12 +409,9 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
417
409
|
}
|
|
418
410
|
case NodeTypes.Spread:
|
|
419
411
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
420
|
-
|
|
421
|
-
var bindingNode = node;
|
|
422
|
-
return findUnresolvedSymbolsInNode(bindingNode[1][1], contextStack, builtin, evaluateNode);
|
|
423
|
-
}
|
|
412
|
+
/* v8 ignore next 2 */
|
|
424
413
|
default:
|
|
425
|
-
throw new
|
|
414
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
426
415
|
}
|
|
427
416
|
}
|
|
428
417
|
|
|
@@ -689,9 +678,6 @@ function assertLitsFunction(value, sourceCodeInfo) {
|
|
|
689
678
|
if (!isLitsFunction(value))
|
|
690
679
|
throw getAssertionError('LitsFunction', value, sourceCodeInfo);
|
|
691
680
|
}
|
|
692
|
-
function isBuiltinFunction(value) {
|
|
693
|
-
return isUnknownRecord(value) && value.functionType === 'Builtin';
|
|
694
|
-
}
|
|
695
681
|
|
|
696
682
|
function isAny(value) {
|
|
697
683
|
// TODO weak test
|
|
@@ -3790,6 +3776,26 @@ var andSpecialExpression = {
|
|
|
3790
3776
|
}
|
|
3791
3777
|
return value;
|
|
3792
3778
|
},
|
|
3779
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3780
|
+
var e_2, _a;
|
|
3781
|
+
var value = true;
|
|
3782
|
+
try {
|
|
3783
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3784
|
+
var param = params_1_1.value;
|
|
3785
|
+
value = asAny(param, sourceCodeInfo);
|
|
3786
|
+
if (!value)
|
|
3787
|
+
break;
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3791
|
+
finally {
|
|
3792
|
+
try {
|
|
3793
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3794
|
+
}
|
|
3795
|
+
finally { if (e_2) throw e_2.error; }
|
|
3796
|
+
}
|
|
3797
|
+
return value;
|
|
3798
|
+
},
|
|
3793
3799
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3794
3800
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3795
3801
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -3881,6 +3887,29 @@ var bindingTargetTypes = {
|
|
|
3881
3887
|
array: 14,
|
|
3882
3888
|
};
|
|
3883
3889
|
|
|
3890
|
+
function walkDefaults(bindingTarget, onDefault) {
|
|
3891
|
+
var _a;
|
|
3892
|
+
if (bindingTarget[0] === bindingTargetTypes.object) {
|
|
3893
|
+
Object.values(bindingTarget[1][0]).forEach(function (element) {
|
|
3894
|
+
if (element[1][1]) {
|
|
3895
|
+
onDefault(element[1][1]);
|
|
3896
|
+
}
|
|
3897
|
+
walkDefaults(element, onDefault);
|
|
3898
|
+
});
|
|
3899
|
+
}
|
|
3900
|
+
else if (bindingTarget[0] === bindingTargetTypes.array) {
|
|
3901
|
+
for (var index = 0; index < bindingTarget[1][0].length; index += 1) {
|
|
3902
|
+
var element = (_a = bindingTarget[1][0][index]) !== null && _a !== void 0 ? _a : null;
|
|
3903
|
+
if (element === null) {
|
|
3904
|
+
continue;
|
|
3905
|
+
}
|
|
3906
|
+
if (element[1][1]) {
|
|
3907
|
+
onDefault(element[1][1]);
|
|
3908
|
+
}
|
|
3909
|
+
walkDefaults(element, onDefault);
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3884
3913
|
function evalueateBindingNodeValues(target, value, evaluate) {
|
|
3885
3914
|
var sourceCodeInfo = target[2];
|
|
3886
3915
|
var record = {};
|
|
@@ -4011,7 +4040,7 @@ var defSpecialExpression = {
|
|
|
4011
4040
|
var value = bindingNode[1][1];
|
|
4012
4041
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4013
4042
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4014
|
-
contextStack.exportValues(values);
|
|
4043
|
+
contextStack.exportValues(values, target[2]);
|
|
4015
4044
|
return null;
|
|
4016
4045
|
},
|
|
4017
4046
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4020,7 +4049,10 @@ var defSpecialExpression = {
|
|
|
4020
4049
|
var target = bindingNode[1][0];
|
|
4021
4050
|
var value = bindingNode[1][1];
|
|
4022
4051
|
var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
|
|
4023
|
-
|
|
4052
|
+
walkDefaults(target, function (defaultNode) {
|
|
4053
|
+
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4054
|
+
});
|
|
4055
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4024
4056
|
return bindingResult;
|
|
4025
4057
|
},
|
|
4026
4058
|
};
|
|
@@ -4138,16 +4170,16 @@ var functionSpecialExpression = {
|
|
|
4138
4170
|
_b.name = functionSymbol[1],
|
|
4139
4171
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4140
4172
|
_b);
|
|
4141
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4173
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4142
4174
|
return null;
|
|
4143
4175
|
},
|
|
4144
4176
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4145
4177
|
var _b, _c;
|
|
4146
4178
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4147
4179
|
var functionName = node[1][1][1];
|
|
4148
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4180
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4149
4181
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4150
|
-
return
|
|
4182
|
+
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4151
4183
|
},
|
|
4152
4184
|
};
|
|
4153
4185
|
var defnSpecialExpression = {
|
|
@@ -4166,7 +4198,7 @@ var defnSpecialExpression = {
|
|
|
4166
4198
|
_b.name = functionSymbol[1],
|
|
4167
4199
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4168
4200
|
_b);
|
|
4169
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4201
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4170
4202
|
return null;
|
|
4171
4203
|
},
|
|
4172
4204
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4174,9 +4206,9 @@ var defnSpecialExpression = {
|
|
|
4174
4206
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4175
4207
|
var functionName = node[1][1][1];
|
|
4176
4208
|
var fn = node[1][2];
|
|
4177
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4209
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4178
4210
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4179
|
-
return
|
|
4211
|
+
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4180
4212
|
},
|
|
4181
4213
|
};
|
|
4182
4214
|
var fnSpecialExpression = {
|
|
@@ -4198,7 +4230,7 @@ var fnSpecialExpression = {
|
|
|
4198
4230
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4199
4231
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4200
4232
|
var fn = node[1][1];
|
|
4201
|
-
return
|
|
4233
|
+
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
|
|
4202
4234
|
},
|
|
4203
4235
|
};
|
|
4204
4236
|
function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode) {
|
|
@@ -4223,12 +4255,15 @@ function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evalua
|
|
|
4223
4255
|
];
|
|
4224
4256
|
return evaluatedFunction;
|
|
4225
4257
|
}
|
|
4226
|
-
function
|
|
4258
|
+
function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
|
|
4227
4259
|
var result = new Set();
|
|
4228
4260
|
var contextStackWithFunctionName = functionNameContext ? contextStack.create(functionNameContext) : contextStack;
|
|
4229
4261
|
var newContext = {};
|
|
4230
4262
|
fn[0].forEach(function (arg) {
|
|
4231
4263
|
Object.assign(newContext, getAllBindingTargetNames(arg));
|
|
4264
|
+
walkDefaults(arg, function (defaultNode) {
|
|
4265
|
+
addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4266
|
+
});
|
|
4232
4267
|
});
|
|
4233
4268
|
var newContextStack = contextStackWithFunctionName.create(newContext);
|
|
4234
4269
|
var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
|
|
@@ -4283,7 +4318,7 @@ var letSpecialExpression = {
|
|
|
4283
4318
|
var value = bindingNode[1][1];
|
|
4284
4319
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4285
4320
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4286
|
-
contextStack.addValues(values);
|
|
4321
|
+
contextStack.addValues(values, target[2]);
|
|
4287
4322
|
return null;
|
|
4288
4323
|
},
|
|
4289
4324
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4292,7 +4327,10 @@ var letSpecialExpression = {
|
|
|
4292
4327
|
var target = bindingNode[1][0];
|
|
4293
4328
|
var value = bindingNode[1][1];
|
|
4294
4329
|
var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
|
|
4295
|
-
|
|
4330
|
+
walkDefaults(target, function (defaultNode) {
|
|
4331
|
+
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4332
|
+
});
|
|
4333
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4296
4334
|
return bindingResult;
|
|
4297
4335
|
},
|
|
4298
4336
|
};
|
|
@@ -4563,6 +4601,26 @@ var orSpecialExpression = {
|
|
|
4563
4601
|
}
|
|
4564
4602
|
return value;
|
|
4565
4603
|
},
|
|
4604
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4605
|
+
var e_2, _a;
|
|
4606
|
+
var value = false;
|
|
4607
|
+
try {
|
|
4608
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4609
|
+
var param = params_1_1.value;
|
|
4610
|
+
value = asAny(param, sourceCodeInfo);
|
|
4611
|
+
if (value)
|
|
4612
|
+
break;
|
|
4613
|
+
}
|
|
4614
|
+
}
|
|
4615
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4616
|
+
finally {
|
|
4617
|
+
try {
|
|
4618
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4619
|
+
}
|
|
4620
|
+
finally { if (e_2) throw e_2.error; }
|
|
4621
|
+
}
|
|
4622
|
+
return value;
|
|
4623
|
+
},
|
|
4566
4624
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4567
4625
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4568
4626
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4581,6 +4639,11 @@ var qqSpecialExpression = {
|
|
|
4581
4639
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4582
4640
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4583
4641
|
},
|
|
4642
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4643
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4644
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4645
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4646
|
+
},
|
|
4584
4647
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4585
4648
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4586
4649
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4595,6 +4658,9 @@ var recurSpecialExpression = {
|
|
|
4595
4658
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4596
4659
|
throw new RecurSignal(evaluatedParams);
|
|
4597
4660
|
},
|
|
4661
|
+
evaluateAsNormalExpression: function (params) {
|
|
4662
|
+
throw new RecurSignal(params);
|
|
4663
|
+
},
|
|
4598
4664
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4599
4665
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4600
4666
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4610,6 +4676,12 @@ var throwSpecialExpression = {
|
|
|
4610
4676
|
});
|
|
4611
4677
|
throw new UserDefinedError(message, node[2]);
|
|
4612
4678
|
},
|
|
4679
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4680
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4681
|
+
nonEmpty: true,
|
|
4682
|
+
});
|
|
4683
|
+
throw new UserDefinedError(message, undefined);
|
|
4684
|
+
},
|
|
4613
4685
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4614
4686
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4615
4687
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4677,6 +4749,24 @@ var arraySpecialExpression = {
|
|
|
4677
4749
|
}
|
|
4678
4750
|
return result;
|
|
4679
4751
|
},
|
|
4752
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4753
|
+
var e_2, _a;
|
|
4754
|
+
var result = [];
|
|
4755
|
+
try {
|
|
4756
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4757
|
+
var param = params_1_1.value;
|
|
4758
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4762
|
+
finally {
|
|
4763
|
+
try {
|
|
4764
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4765
|
+
}
|
|
4766
|
+
finally { if (e_2) throw e_2.error; }
|
|
4767
|
+
}
|
|
4768
|
+
return result;
|
|
4769
|
+
},
|
|
4680
4770
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4681
4771
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4682
4772
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4708,6 +4798,16 @@ var objectSpecialExpression = {
|
|
|
4708
4798
|
}
|
|
4709
4799
|
return result;
|
|
4710
4800
|
},
|
|
4801
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4802
|
+
var result = {};
|
|
4803
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4804
|
+
var key = params[i];
|
|
4805
|
+
var value = params[i + 1];
|
|
4806
|
+
assertString(key, sourceCodeInfo);
|
|
4807
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4808
|
+
}
|
|
4809
|
+
return result;
|
|
4810
|
+
},
|
|
4711
4811
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4712
4812
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4713
4813
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4951,6 +5051,16 @@ var functionExecutors = {
|
|
|
4951
5051
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
4952
5052
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
4953
5053
|
},
|
|
5054
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5055
|
+
var executeFunction = _a.executeFunction;
|
|
5056
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5057
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5058
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5059
|
+
}
|
|
5060
|
+
else {
|
|
5061
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5062
|
+
}
|
|
5063
|
+
},
|
|
4954
5064
|
};
|
|
4955
5065
|
|
|
4956
5066
|
function evaluate(ast, contextStack) {
|
|
@@ -5006,7 +5116,21 @@ function evaluateReservedSymbol(node) {
|
|
|
5006
5116
|
function evaluateNormalExpression(node, contextStack) {
|
|
5007
5117
|
var sourceCodeInfo = node[2];
|
|
5008
5118
|
var paramNodes = node[1][1];
|
|
5009
|
-
var params =
|
|
5119
|
+
var params = [];
|
|
5120
|
+
paramNodes.forEach(function (paramNode) {
|
|
5121
|
+
if (isSpreadNode(paramNode)) {
|
|
5122
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5123
|
+
if (Array.isArray(spreadValue)) {
|
|
5124
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5125
|
+
}
|
|
5126
|
+
else {
|
|
5127
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
else {
|
|
5131
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5132
|
+
}
|
|
5133
|
+
});
|
|
5010
5134
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5011
5135
|
var nameSymbol = node[1][0];
|
|
5012
5136
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5108,19 +5232,19 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5108
5232
|
var contexts = [{}, context];
|
|
5109
5233
|
return new ContextStackImpl({ contexts: contexts });
|
|
5110
5234
|
};
|
|
5111
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5235
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5112
5236
|
var e_1, _a;
|
|
5113
5237
|
try {
|
|
5114
5238
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5115
5239
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5116
5240
|
if (this.globalContext[name_1]) {
|
|
5117
|
-
throw new
|
|
5241
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5118
5242
|
}
|
|
5119
5243
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5120
|
-
throw new
|
|
5244
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5121
5245
|
}
|
|
5122
5246
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5123
|
-
throw new
|
|
5247
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5124
5248
|
}
|
|
5125
5249
|
this.globalContext[name_1] = { value: value };
|
|
5126
5250
|
}
|
|
@@ -5132,22 +5256,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5132
5256
|
}
|
|
5133
5257
|
finally { if (e_1) throw e_1.error; }
|
|
5134
5258
|
}
|
|
5135
|
-
this.addValues(values);
|
|
5259
|
+
this.addValues(values, sourceCodeInfo);
|
|
5136
5260
|
};
|
|
5137
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5261
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5138
5262
|
var e_2, _a;
|
|
5139
5263
|
var currentContext = this.contexts[0];
|
|
5140
5264
|
try {
|
|
5141
5265
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5142
5266
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5143
5267
|
if (currentContext[name_2]) {
|
|
5144
|
-
throw new
|
|
5268
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5145
5269
|
}
|
|
5146
5270
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5147
|
-
throw new
|
|
5271
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5148
5272
|
}
|
|
5149
5273
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5150
|
-
throw new
|
|
5274
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5151
5275
|
}
|
|
5152
5276
|
currentContext[name_2] = { value: toAny(value) };
|
|
5153
5277
|
}
|
|
@@ -5227,24 +5351,40 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5227
5351
|
return null;
|
|
5228
5352
|
};
|
|
5229
5353
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5230
|
-
var _a;
|
|
5354
|
+
var _a, _b;
|
|
5231
5355
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5232
|
-
|
|
5356
|
+
var functionType = node[1];
|
|
5357
|
+
switch (functionType) {
|
|
5358
|
+
case specialExpressionTypes['&&']:
|
|
5359
|
+
case specialExpressionTypes['||']:
|
|
5360
|
+
case specialExpressionTypes.array:
|
|
5361
|
+
case specialExpressionTypes.object:
|
|
5362
|
+
case specialExpressionTypes['defined?']:
|
|
5363
|
+
case specialExpressionTypes.recur:
|
|
5364
|
+
case specialExpressionTypes.throw:
|
|
5365
|
+
case specialExpressionTypes['??']:
|
|
5366
|
+
return _a = {},
|
|
5367
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5368
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5369
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5370
|
+
_a.sourceCodeInfo = node[2],
|
|
5371
|
+
_a;
|
|
5372
|
+
default:
|
|
5373
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5374
|
+
}
|
|
5233
5375
|
}
|
|
5234
5376
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5235
5377
|
var type = node[1];
|
|
5236
|
-
return
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5378
|
+
return _b = {},
|
|
5379
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5380
|
+
_b.functionType = 'Builtin',
|
|
5381
|
+
_b.normalBuitinSymbolType = type,
|
|
5382
|
+
_b.sourceCodeInfo = node[2],
|
|
5383
|
+
_b;
|
|
5242
5384
|
}
|
|
5243
5385
|
var lookUpResult = this.lookUp(node);
|
|
5244
5386
|
if (isContextEntry(lookUpResult))
|
|
5245
5387
|
return lookUpResult.value;
|
|
5246
|
-
else if (isBuiltinFunction(lookUpResult))
|
|
5247
|
-
return lookUpResult;
|
|
5248
5388
|
throw new UndefinedSymbolError(node[1], node[2]);
|
|
5249
5389
|
};
|
|
5250
5390
|
return ContextStackImpl;
|
|
@@ -5328,10 +5468,10 @@ var nonFunctionOperators = [
|
|
|
5328
5468
|
'cond',
|
|
5329
5469
|
'def',
|
|
5330
5470
|
'defined?',
|
|
5331
|
-
'defn',
|
|
5471
|
+
// 'defn',
|
|
5332
5472
|
'do',
|
|
5333
5473
|
'doseq',
|
|
5334
|
-
'fn',
|
|
5474
|
+
// 'fn',
|
|
5335
5475
|
'if',
|
|
5336
5476
|
'let',
|
|
5337
5477
|
'loop',
|
|
@@ -5912,7 +6052,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
|
5912
6052
|
}
|
|
5913
6053
|
return node;
|
|
5914
6054
|
}
|
|
5915
|
-
function getPrecedence(operatorSign) {
|
|
6055
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5916
6056
|
switch (operatorSign) {
|
|
5917
6057
|
case '**': // exponentiation
|
|
5918
6058
|
return exponentiationPrecedence;
|
|
@@ -5951,7 +6091,7 @@ function getPrecedence(operatorSign) {
|
|
|
5951
6091
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
5952
6092
|
/* v8 ignore next 2 */
|
|
5953
6093
|
default:
|
|
5954
|
-
throw new
|
|
6094
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
5955
6095
|
}
|
|
5956
6096
|
}
|
|
5957
6097
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6084,7 +6224,7 @@ var Parser = /** @class */ (function () {
|
|
|
6084
6224
|
while (!this.isAtExpressionEnd()) {
|
|
6085
6225
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6086
6226
|
var name_1 = operator[1];
|
|
6087
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6227
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6088
6228
|
if (newPrecedece <= precedence
|
|
6089
6229
|
// ** (exponentiation) is right associative
|
|
6090
6230
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6164,7 +6304,7 @@ var Parser = /** @class */ (function () {
|
|
|
6164
6304
|
this.advance();
|
|
6165
6305
|
var expression = this.parseExpression();
|
|
6166
6306
|
if (!isRParenToken(this.peek())) {
|
|
6167
|
-
throw new
|
|
6307
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6168
6308
|
}
|
|
6169
6309
|
this.advance();
|
|
6170
6310
|
return expression;
|
|
@@ -6176,10 +6316,7 @@ var Parser = /** @class */ (function () {
|
|
|
6176
6316
|
if (specialExpressionTypes[operatorName] !== undefined) {
|
|
6177
6317
|
return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[operatorName]], token[2]);
|
|
6178
6318
|
}
|
|
6179
|
-
|
|
6180
|
-
return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
|
|
6181
|
-
}
|
|
6182
|
-
return withSourceCodeInfo([NodeTypes.UserDefinedSymbol, operatorName], token[2]);
|
|
6319
|
+
return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
|
|
6183
6320
|
}
|
|
6184
6321
|
if (operatorName === '->') {
|
|
6185
6322
|
return this.parseShorthandLamdaFunction();
|
|
@@ -6289,7 +6426,13 @@ var Parser = /** @class */ (function () {
|
|
|
6289
6426
|
this.advance();
|
|
6290
6427
|
var params = [];
|
|
6291
6428
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6292
|
-
|
|
6429
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6430
|
+
this.advance();
|
|
6431
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6432
|
+
}
|
|
6433
|
+
else {
|
|
6434
|
+
params.push(this.parseExpression());
|
|
6435
|
+
}
|
|
6293
6436
|
var nextToken = this.peek();
|
|
6294
6437
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6295
6438
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6339,13 +6482,13 @@ var Parser = /** @class */ (function () {
|
|
|
6339
6482
|
var _b = __read(params, 1), param = _b[0];
|
|
6340
6483
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
6341
6484
|
}
|
|
6342
|
-
case specialExpressionTypes
|
|
6343
|
-
case specialExpressionTypes
|
|
6344
|
-
case specialExpressionTypes
|
|
6485
|
+
case specialExpressionTypes['0_fn']:
|
|
6486
|
+
case specialExpressionTypes['0_def']:
|
|
6487
|
+
case specialExpressionTypes['0_defn']:
|
|
6345
6488
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6346
6489
|
/* v8 ignore next 2 */
|
|
6347
6490
|
default:
|
|
6348
|
-
throw new
|
|
6491
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6349
6492
|
}
|
|
6350
6493
|
}
|
|
6351
6494
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|
|
@@ -6369,7 +6512,7 @@ var Parser = /** @class */ (function () {
|
|
|
6369
6512
|
}
|
|
6370
6513
|
this.advance();
|
|
6371
6514
|
var body = this.parseExpression();
|
|
6372
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
6515
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
|
|
6373
6516
|
functionArguments,
|
|
6374
6517
|
[body],
|
|
6375
6518
|
]]], firstToken[2]);
|
|
@@ -6452,7 +6595,7 @@ var Parser = /** @class */ (function () {
|
|
|
6452
6595
|
functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
|
|
6453
6596
|
}
|
|
6454
6597
|
}
|
|
6455
|
-
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
6598
|
+
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
|
|
6456
6599
|
functionArguments,
|
|
6457
6600
|
[exprNode],
|
|
6458
6601
|
]]], firstToken[2]);
|
|
@@ -6971,7 +7114,7 @@ var Parser = /** @class */ (function () {
|
|
|
6971
7114
|
this.advance();
|
|
6972
7115
|
if (isSymbolToken(this.peek(), 'let')) {
|
|
6973
7116
|
var letNode = this.parseLet(asSymbolToken(this.peek()));
|
|
6974
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
7117
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], token[2]);
|
|
6975
7118
|
}
|
|
6976
7119
|
else if (isReservedSymbolToken(this.peek(), 'function')) {
|
|
6977
7120
|
this.advance();
|
|
@@ -6989,7 +7132,7 @@ var Parser = /** @class */ (function () {
|
|
|
6989
7132
|
}
|
|
6990
7133
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
6991
7134
|
this.advance();
|
|
6992
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes
|
|
7135
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
|
|
6993
7136
|
functionArguments,
|
|
6994
7137
|
body,
|
|
6995
7138
|
]]], token[2]);
|
|
@@ -6999,7 +7142,7 @@ var Parser = /** @class */ (function () {
|
|
|
6999
7142
|
}
|
|
7000
7143
|
};
|
|
7001
7144
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
7002
|
-
if (specialExpressionTypes[value] !== undefined) {
|
|
7145
|
+
if (specialExpressionTypes[value] !== undefined && value !== 'fn' && value !== 'def' && value !== 'defn') {
|
|
7003
7146
|
return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[value]], sourceCodeInfo);
|
|
7004
7147
|
}
|
|
7005
7148
|
if (normalExpressionTypes[value] !== undefined) {
|