@mojir/lits 2.1.35 → 2.1.37
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/README.md +939 -165
- package/dist/cli/cli/src/modules/index.d.ts +4 -0
- package/dist/cli/cli/src/modules/sys/index.d.ts +3 -0
- package/dist/cli/cli.js +214 -57
- package/dist/cli/src/evaluator/ContextStack.d.ts +2 -2
- package/dist/cli/src/modules/index.d.ts +4 -0
- package/dist/cli/src/modules/sys/index.d.ts +3 -0
- package/dist/cli/src/parser/types.d.ts +3 -0
- package/dist/index.esm.js +135 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +135 -34
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +135 -34
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/evaluator/ContextStack.d.ts +2 -2
- package/dist/src/parser/types.d.ts +3 -0
- package/dist/testFramework.esm.js +135 -34
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +135 -34
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/testFramework.js
CHANGED
|
@@ -11800,7 +11800,6 @@ var lambdaSpecialExpression = {
|
|
|
11800
11800
|
_b.arity = arity,
|
|
11801
11801
|
_b.docString = docString,
|
|
11802
11802
|
_b);
|
|
11803
|
-
evaluatedFunction[2].self = { value: litsFunction };
|
|
11804
11803
|
return litsFunction;
|
|
11805
11804
|
},
|
|
11806
11805
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -12475,13 +12474,13 @@ var functionExecutors = {
|
|
|
12475
12474
|
var args = evaluatedFunction[0];
|
|
12476
12475
|
var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
|
|
12477
12476
|
var newContextStack = contextStack.create(fn.evaluatedfunction[2]);
|
|
12478
|
-
var newContext = {};
|
|
12477
|
+
var newContext = { self: { value: fn } };
|
|
12479
12478
|
var rest = [];
|
|
12480
12479
|
for (var i = 0; i < params.length; i += 1) {
|
|
12481
12480
|
if (i < nbrOfNonRestArgs) {
|
|
12482
12481
|
var param = toAny(params[i]);
|
|
12483
|
-
var valueRecord = evalueateBindingNodeValues(args[i], param, function (
|
|
12484
|
-
return evaluateNode(
|
|
12482
|
+
var valueRecord = evalueateBindingNodeValues(args[i], param, function (node) {
|
|
12483
|
+
return evaluateNode(node, newContextStack.create(newContext));
|
|
12485
12484
|
});
|
|
12486
12485
|
Object.entries(valueRecord).forEach(function (_a) {
|
|
12487
12486
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
@@ -12495,8 +12494,8 @@ var functionExecutors = {
|
|
|
12495
12494
|
for (var i = params.length; i < nbrOfNonRestArgs; i++) {
|
|
12496
12495
|
var arg = args[i];
|
|
12497
12496
|
var defaultValue = evaluateNode(arg[1][1], contextStack.create(newContext));
|
|
12498
|
-
var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (
|
|
12499
|
-
return evaluateNode(
|
|
12497
|
+
var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (node) {
|
|
12498
|
+
return evaluateNode(node, contextStack.create(newContext));
|
|
12500
12499
|
});
|
|
12501
12500
|
Object.entries(valueRecord).forEach(function (_a) {
|
|
12502
12501
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
@@ -12505,7 +12504,7 @@ var functionExecutors = {
|
|
|
12505
12504
|
}
|
|
12506
12505
|
var restArgument = args.find(function (arg) { return arg[0] === bindingTargetTypes.rest; });
|
|
12507
12506
|
if (restArgument !== undefined) {
|
|
12508
|
-
var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (
|
|
12507
|
+
var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (node) { return evaluateNode(node, contextStack.create(newContext)); });
|
|
12509
12508
|
Object.entries(valueRecord).forEach(function (_a) {
|
|
12510
12509
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
12511
12510
|
newContext[key] = { value: value };
|
|
@@ -13044,6 +13043,21 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
13044
13043
|
};
|
|
13045
13044
|
return ContextStackImpl;
|
|
13046
13045
|
}());
|
|
13046
|
+
function checkNotDefined(name) {
|
|
13047
|
+
if (specialExpressionKeys.includes(name)) {
|
|
13048
|
+
console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
|
|
13049
|
+
return false;
|
|
13050
|
+
}
|
|
13051
|
+
if (normalExpressionKeys.includes(name)) {
|
|
13052
|
+
console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
|
|
13053
|
+
return false;
|
|
13054
|
+
}
|
|
13055
|
+
if (name === 'self') {
|
|
13056
|
+
console.warn("Cannot shadow builtin value \"".concat(name, "\", ignoring."));
|
|
13057
|
+
return false;
|
|
13058
|
+
}
|
|
13059
|
+
return true;
|
|
13060
|
+
}
|
|
13047
13061
|
function createContextStack(params) {
|
|
13048
13062
|
var _a;
|
|
13049
13063
|
if (params === void 0) { params = {}; }
|
|
@@ -13055,26 +13069,53 @@ function createContextStack(params) {
|
|
|
13055
13069
|
values: params.values,
|
|
13056
13070
|
nativeJsFunctions: params.jsFunctions
|
|
13057
13071
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
13058
|
-
var _b;
|
|
13059
|
-
var
|
|
13060
|
-
var
|
|
13061
|
-
|
|
13062
|
-
|
|
13072
|
+
var e_5, _b, _c;
|
|
13073
|
+
var _d, _e;
|
|
13074
|
+
var _f = __read(_a, 2), identifier = _f[0], entry = _f[1];
|
|
13075
|
+
var identifierParts = identifier.split('.');
|
|
13076
|
+
var name = identifierParts.pop();
|
|
13077
|
+
if (/^[A-Z]/.test(name)) {
|
|
13078
|
+
console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, function name must not start with an uppercase letter"), undefined);
|
|
13063
13079
|
return acc;
|
|
13064
13080
|
}
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
|
|
13081
|
+
var scope = acc;
|
|
13082
|
+
try {
|
|
13083
|
+
for (var identifierParts_1 = __values(identifierParts), identifierParts_1_1 = identifierParts_1.next(); !identifierParts_1_1.done; identifierParts_1_1 = identifierParts_1.next()) {
|
|
13084
|
+
var part = identifierParts_1_1.value;
|
|
13085
|
+
if (part.length === 0) {
|
|
13086
|
+
console.warn("Invalid empty identifier \"".concat(identifier, "\" in nativeJsFunctions"), undefined);
|
|
13087
|
+
return acc;
|
|
13088
|
+
}
|
|
13089
|
+
if (!/^[A-Z]/.test(part)) {
|
|
13090
|
+
console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, namespace must start with an uppercase letter"), undefined);
|
|
13091
|
+
return acc;
|
|
13092
|
+
}
|
|
13093
|
+
if (!scope[part]) {
|
|
13094
|
+
scope[part] = {};
|
|
13095
|
+
}
|
|
13096
|
+
scope = scope[part];
|
|
13097
|
+
}
|
|
13068
13098
|
}
|
|
13069
|
-
|
|
13099
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
13100
|
+
finally {
|
|
13101
|
+
try {
|
|
13102
|
+
if (identifierParts_1_1 && !identifierParts_1_1.done && (_b = identifierParts_1.return)) _b.call(identifierParts_1);
|
|
13103
|
+
}
|
|
13104
|
+
finally { if (e_5) throw e_5.error; }
|
|
13105
|
+
}
|
|
13106
|
+
var natifeFn = (_c = {
|
|
13070
13107
|
functionType: 'NativeJsFunction',
|
|
13071
|
-
nativeFn:
|
|
13108
|
+
nativeFn: entry,
|
|
13072
13109
|
name: name
|
|
13073
13110
|
},
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
|
|
13077
|
-
|
|
13111
|
+
_c[FUNCTION_SYMBOL] = true,
|
|
13112
|
+
_c.arity = (_d = entry.arity) !== null && _d !== void 0 ? _d : {},
|
|
13113
|
+
_c.docString = (_e = entry.docString) !== null && _e !== void 0 ? _e : '',
|
|
13114
|
+
_c);
|
|
13115
|
+
if (scope === acc && !checkNotDefined(name)) {
|
|
13116
|
+
return acc;
|
|
13117
|
+
}
|
|
13118
|
+
scope[name] = natifeFn;
|
|
13078
13119
|
return acc;
|
|
13079
13120
|
}, {}),
|
|
13080
13121
|
});
|
|
@@ -13915,9 +13956,6 @@ var Parser = /** @class */ (function () {
|
|
|
13915
13956
|
case 'doseq':
|
|
13916
13957
|
left = this.parseForOrDoseq(firstToken);
|
|
13917
13958
|
break;
|
|
13918
|
-
// cas:
|
|
13919
|
-
// left = this.parseDo(firstToken)
|
|
13920
|
-
// break
|
|
13921
13959
|
case 'loop':
|
|
13922
13960
|
left = this.parseLoop(firstToken);
|
|
13923
13961
|
break;
|
|
@@ -14119,6 +14157,12 @@ var Parser = /** @class */ (function () {
|
|
|
14119
14157
|
params.push(withSourceCodeInfo([NodeTypes.String, value], token[2]));
|
|
14120
14158
|
this.advance();
|
|
14121
14159
|
}
|
|
14160
|
+
else if (isLBracketToken(token)) {
|
|
14161
|
+
this.advance();
|
|
14162
|
+
params.push(this.parseExpression());
|
|
14163
|
+
assertRBracketToken(this.peek());
|
|
14164
|
+
this.advance();
|
|
14165
|
+
}
|
|
14122
14166
|
else {
|
|
14123
14167
|
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
14124
14168
|
}
|
|
@@ -14249,9 +14293,17 @@ var Parser = /** @class */ (function () {
|
|
|
14249
14293
|
var nodes = void 0;
|
|
14250
14294
|
var docString = '';
|
|
14251
14295
|
if (isLBraceToken(this.peek())) {
|
|
14252
|
-
var
|
|
14253
|
-
|
|
14254
|
-
|
|
14296
|
+
var positionBefore = this.parseState.position;
|
|
14297
|
+
try {
|
|
14298
|
+
var objectNode = this.parseObject();
|
|
14299
|
+
nodes = [objectNode];
|
|
14300
|
+
}
|
|
14301
|
+
catch (_a) {
|
|
14302
|
+
this.parseState.position = positionBefore;
|
|
14303
|
+
var parsedBlock = this.parseBlock(true);
|
|
14304
|
+
docString = parsedBlock[1];
|
|
14305
|
+
nodes = parsedBlock[0][1][1];
|
|
14306
|
+
}
|
|
14255
14307
|
}
|
|
14256
14308
|
else {
|
|
14257
14309
|
nodes = [this.parseExpression()];
|
|
@@ -14268,7 +14320,7 @@ var Parser = /** @class */ (function () {
|
|
|
14268
14320
|
],
|
|
14269
14321
|
], firstToken[2]);
|
|
14270
14322
|
}
|
|
14271
|
-
catch (
|
|
14323
|
+
catch (_b) {
|
|
14272
14324
|
return null;
|
|
14273
14325
|
}
|
|
14274
14326
|
};
|
|
@@ -14318,9 +14370,17 @@ var Parser = /** @class */ (function () {
|
|
|
14318
14370
|
var nodes;
|
|
14319
14371
|
var docString = '';
|
|
14320
14372
|
if (isLBraceToken(this.peek())) {
|
|
14321
|
-
var
|
|
14322
|
-
|
|
14323
|
-
|
|
14373
|
+
var positionBefore = this.parseState.position;
|
|
14374
|
+
try {
|
|
14375
|
+
var objectNode = this.parseObject();
|
|
14376
|
+
nodes = [objectNode];
|
|
14377
|
+
}
|
|
14378
|
+
catch (_b) {
|
|
14379
|
+
this.parseState.position = positionBefore;
|
|
14380
|
+
var parsedBlock = this.parseBlock(true);
|
|
14381
|
+
docString = parsedBlock[1];
|
|
14382
|
+
nodes = parsedBlock[0][1][1];
|
|
14383
|
+
}
|
|
14324
14384
|
}
|
|
14325
14385
|
else {
|
|
14326
14386
|
nodes = [this.parseExpression()];
|
|
@@ -14518,9 +14578,6 @@ var Parser = /** @class */ (function () {
|
|
|
14518
14578
|
throw new LitsError('Expected }', this.peekSourceCodeInfo());
|
|
14519
14579
|
}
|
|
14520
14580
|
}
|
|
14521
|
-
if (expressions.length === 0) {
|
|
14522
|
-
expressions.push(withSourceCodeInfo([NodeTypes.ReservedSymbol, 'null'], token[2]));
|
|
14523
|
-
}
|
|
14524
14581
|
assertRBraceToken(this.peek());
|
|
14525
14582
|
this.advance();
|
|
14526
14583
|
return [
|
|
@@ -26633,6 +26690,50 @@ var sequenceReference = {
|
|
|
26633
26690
|
};
|
|
26634
26691
|
|
|
26635
26692
|
var specialExpressionsReference = {
|
|
26693
|
+
'doseq': {
|
|
26694
|
+
title: 'doseq',
|
|
26695
|
+
category: 'Special expression',
|
|
26696
|
+
customVariants: ['doseq (...binding) -> body'],
|
|
26697
|
+
details: [
|
|
26698
|
+
['binding', 'loop-var in collection [...let-binding] [where whereExpr] [while whileExp]', 'A doseq loop binding'],
|
|
26699
|
+
['loop-var', 'symbol', 'The name of the loop variable.'],
|
|
26700
|
+
['collection', 'any', 'The collection to iterate over.'],
|
|
26701
|
+
['let-binding', 'let binding', 'A let binding to create a local variable.'],
|
|
26702
|
+
['whereExpr', 'expression', 'An expression that must evaluate to truthy for the loop body to be executed.'],
|
|
26703
|
+
['whileExp', 'expression', 'An expression that must evaluate to truthy for the loop to continue.'],
|
|
26704
|
+
['body', 'expressions', 'The expressions to evaluate for each iteration of the loop.'],
|
|
26705
|
+
],
|
|
26706
|
+
returns: {
|
|
26707
|
+
type: 'null',
|
|
26708
|
+
},
|
|
26709
|
+
description: 'Iterates over `bindings`, evaluates `body` for each `binding` and returns `null`. This is useful for side effects.',
|
|
26710
|
+
examples: [
|
|
26711
|
+
"\ndoseq (i in [1, 2, 3]) -> write!(i * 2)\n ",
|
|
26712
|
+
],
|
|
26713
|
+
},
|
|
26714
|
+
'for': {
|
|
26715
|
+
title: 'for',
|
|
26716
|
+
category: 'Special expression',
|
|
26717
|
+
customVariants: ['for (...binding) -> body'],
|
|
26718
|
+
details: [
|
|
26719
|
+
['binding', 'loop-var in collection [...let-binding] [where whereExpr] [while whileExp]', 'A for loop binding'],
|
|
26720
|
+
['loop-var', 'symbol', 'The name of the loop variable.'],
|
|
26721
|
+
['collection', 'any', 'The collection to iterate over.'],
|
|
26722
|
+
['let-binding', 'let binding', 'A let binding to create a local variable.'],
|
|
26723
|
+
['whereExpr', 'expression', 'An expression that must evaluate to truthy for the loop body to be executed.'],
|
|
26724
|
+
['whileExp', 'expression', 'An expression that must evaluate to truthy for the loop to continue.'],
|
|
26725
|
+
['body', 'expressions', 'The expressions to evaluate for each iteration of the loop.'],
|
|
26726
|
+
],
|
|
26727
|
+
returns: {
|
|
26728
|
+
type: 'any',
|
|
26729
|
+
array: true,
|
|
26730
|
+
},
|
|
26731
|
+
description: 'Iterates over `bindings`, evaluates `body` for each `binding` and returns an `array` of results.',
|
|
26732
|
+
examples: [
|
|
26733
|
+
"\nfor (i in [1, 2, 3]) -> i * 2\n ",
|
|
26734
|
+
"\nfor (\n i in range(10) let ii = i ^ 2 while ii < 40 when ii % 3 == 0,\n j in range(10) when j % 2 == 1\n) -> ii + j\n ",
|
|
26735
|
+
],
|
|
26736
|
+
},
|
|
26636
26737
|
'array': {
|
|
26637
26738
|
title: 'array',
|
|
26638
26739
|
category: 'Special expression',
|