@mojir/lits 2.1.32 → 2.1.33
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 +34 -69
- package/dist/cli/cli.js +211 -333
- package/dist/cli/src/builtin/index.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +13 -15
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +3 -7
- package/dist/cli/src/builtin/specialExpressions/loop.d.ts +1 -1
- package/dist/cli/src/parser/Parser.d.ts +5 -4
- package/dist/cli/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/index.esm.js +220 -342
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +220 -342
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +220 -342
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/builtin/index.d.ts +1 -1
- package/dist/src/builtin/specialExpressionTypes.d.ts +13 -15
- package/dist/src/builtin/specialExpressions/functions.d.ts +3 -7
- package/dist/src/builtin/specialExpressions/loop.d.ts +1 -1
- package/dist/src/parser/Parser.d.ts +5 -4
- package/dist/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/testFramework.esm.js +210 -332
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +210 -332
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11698,165 +11698,13 @@ var doSpecialExpression = {
|
|
|
11698
11698
|
},
|
|
11699
11699
|
};
|
|
11700
11700
|
|
|
11701
|
-
var
|
|
11702
|
-
true: true,
|
|
11703
|
-
false: false,
|
|
11704
|
-
null: null,
|
|
11705
|
-
else: null,
|
|
11706
|
-
case: null,
|
|
11707
|
-
each: null,
|
|
11708
|
-
in: null,
|
|
11709
|
-
when: null,
|
|
11710
|
-
while: null,
|
|
11711
|
-
catch: null,
|
|
11712
|
-
function: null,
|
|
11713
|
-
export: null,
|
|
11714
|
-
as: null,
|
|
11715
|
-
_: null,
|
|
11716
|
-
};
|
|
11717
|
-
var phi = (1 + Math.sqrt(5)) / 2;
|
|
11718
|
-
var numberReservedSymbolRecord = {
|
|
11719
|
-
'E': Math.E,
|
|
11720
|
-
'-E': -Math.E,
|
|
11721
|
-
'ε': Math.E,
|
|
11722
|
-
'-ε': -Math.E,
|
|
11723
|
-
'PI': Math.PI,
|
|
11724
|
-
'-PI': -Math.PI,
|
|
11725
|
-
'π': Math.PI,
|
|
11726
|
-
'-π': -Math.PI,
|
|
11727
|
-
'PHI': phi,
|
|
11728
|
-
'-PHI': -phi,
|
|
11729
|
-
'φ': phi,
|
|
11730
|
-
'-φ': -phi,
|
|
11731
|
-
'POSITIVE_INFINITY': Number.POSITIVE_INFINITY,
|
|
11732
|
-
'∞': Number.POSITIVE_INFINITY,
|
|
11733
|
-
'NEGATIVE_INFINITY': Number.NEGATIVE_INFINITY,
|
|
11734
|
-
'-∞': Number.NEGATIVE_INFINITY,
|
|
11735
|
-
'MAX_SAFE_INTEGER': Number.MAX_SAFE_INTEGER,
|
|
11736
|
-
'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
|
|
11737
|
-
'MAX_VALUE': Number.MAX_VALUE,
|
|
11738
|
-
'MIN_VALUE': Number.MIN_VALUE,
|
|
11739
|
-
'NaN': Number.NaN,
|
|
11740
|
-
};
|
|
11741
|
-
var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
11742
|
-
function isReservedSymbol(symbol) {
|
|
11743
|
-
return symbol in reservedSymbolRecord;
|
|
11744
|
-
}
|
|
11745
|
-
function isNumberReservedSymbol(symbol) {
|
|
11746
|
-
return symbol in numberReservedSymbolRecord;
|
|
11747
|
-
}
|
|
11748
|
-
|
|
11749
|
-
var specialExpressionTypes = {
|
|
11750
|
-
'??': 0,
|
|
11751
|
-
'&&': 1,
|
|
11752
|
-
'||': 2,
|
|
11753
|
-
'array': 3,
|
|
11754
|
-
'cond': 4,
|
|
11755
|
-
'0_def': 5,
|
|
11756
|
-
'defined?': 6,
|
|
11757
|
-
'0_defn': 7,
|
|
11758
|
-
'block': 8,
|
|
11759
|
-
'doseq': 9,
|
|
11760
|
-
'0_fn': 10,
|
|
11761
|
-
'for': 11,
|
|
11762
|
-
'function': 12,
|
|
11763
|
-
'if': 13,
|
|
11764
|
-
'let': 14,
|
|
11765
|
-
'loop': 15,
|
|
11766
|
-
'object': 16,
|
|
11767
|
-
'recur': 17,
|
|
11768
|
-
'switch': 18,
|
|
11769
|
-
'throw': 19,
|
|
11770
|
-
'try': 20,
|
|
11771
|
-
'unless': 21,
|
|
11772
|
-
};
|
|
11773
|
-
|
|
11774
|
-
function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
|
|
11775
|
-
if (typeof name !== 'string')
|
|
11776
|
-
return;
|
|
11777
|
-
// TODO only subset of special expressions are necessary to check (CommonSpecialExpressionType)
|
|
11778
|
-
if (specialExpressionTypes[name])
|
|
11779
|
-
throw new LitsError("Cannot define variable ".concat(name, ", it's a special expression."), sourceCodeInfo);
|
|
11780
|
-
if (builtin.normalExpressions[name])
|
|
11781
|
-
throw new LitsError("Cannot define variable ".concat(name, ", it's a builtin function."), sourceCodeInfo);
|
|
11782
|
-
if (isReservedSymbol(name))
|
|
11783
|
-
throw new LitsError("Cannot define variable ".concat(name, ", it's a reserved name."), sourceCodeInfo);
|
|
11784
|
-
if (contextStack.globalContext[name])
|
|
11785
|
-
throw new LitsError("Name already defined \"".concat(name, "\"."), sourceCodeInfo);
|
|
11786
|
-
}
|
|
11787
|
-
|
|
11788
|
-
var functionSpecialExpression = {
|
|
11789
|
-
arity: {},
|
|
11790
|
-
evaluate: function (node, contextStack, _a) {
|
|
11791
|
-
var _b, _c;
|
|
11792
|
-
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11793
|
-
var _d = __read(node[1], 4), functionSymbol = _d[1], fn = _d[2], docString = _d[3];
|
|
11794
|
-
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11795
|
-
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11796
|
-
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11797
|
-
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11798
|
-
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
11799
|
-
var arity = { min: min > 0 ? min : undefined, max: max };
|
|
11800
|
-
var litsFunction = (_b = {},
|
|
11801
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
11802
|
-
_b.sourceCodeInfo = node[2],
|
|
11803
|
-
_b.functionType = 'UserDefined',
|
|
11804
|
-
_b.name = functionSymbol[1],
|
|
11805
|
-
_b.evaluatedfunction = evaluatedFunction,
|
|
11806
|
-
_b.arity = arity,
|
|
11807
|
-
_b.docString = docString,
|
|
11808
|
-
_b);
|
|
11809
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11810
|
-
return litsFunction;
|
|
11811
|
-
},
|
|
11812
|
-
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11813
|
-
var _b, _c;
|
|
11814
|
-
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
11815
|
-
var functionName = node[1][1][1];
|
|
11816
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
11817
|
-
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
11818
|
-
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
11819
|
-
},
|
|
11820
|
-
};
|
|
11821
|
-
var defnSpecialExpression = {
|
|
11822
|
-
arity: {},
|
|
11823
|
-
evaluate: function (node, contextStack, _a) {
|
|
11824
|
-
var _b, _c;
|
|
11825
|
-
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11826
|
-
var _d = __read(node[1], 4), functionSymbol = _d[1], fn = _d[2], docString = _d[3];
|
|
11827
|
-
assertUserDefinedSymbolNode(functionSymbol, node[2]);
|
|
11828
|
-
assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
|
|
11829
|
-
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11830
|
-
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11831
|
-
var arity = { min: min };
|
|
11832
|
-
var litsFunction = (_b = {},
|
|
11833
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
11834
|
-
_b.sourceCodeInfo = node[2],
|
|
11835
|
-
_b.functionType = 'UserDefined',
|
|
11836
|
-
_b.name = functionSymbol[1],
|
|
11837
|
-
_b.evaluatedfunction = evaluatedFunction,
|
|
11838
|
-
_b.arity = arity,
|
|
11839
|
-
_b.docString = docString,
|
|
11840
|
-
_b);
|
|
11841
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11842
|
-
return litsFunction;
|
|
11843
|
-
},
|
|
11844
|
-
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11845
|
-
var _b, _c;
|
|
11846
|
-
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
11847
|
-
var functionName = node[1][1][1];
|
|
11848
|
-
var fn = node[1][2];
|
|
11849
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
11850
|
-
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
11851
|
-
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
11852
|
-
},
|
|
11853
|
-
};
|
|
11854
|
-
var fnSpecialExpression = {
|
|
11701
|
+
var lambdaSpecialExpression = {
|
|
11855
11702
|
arity: {},
|
|
11856
11703
|
evaluate: function (node, contextStack, _a) {
|
|
11857
11704
|
var _b;
|
|
11858
11705
|
var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
|
|
11859
11706
|
var fn = node[1][1];
|
|
11707
|
+
var docString = node[1][2];
|
|
11860
11708
|
var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
|
|
11861
11709
|
var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
|
|
11862
11710
|
var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
|
|
@@ -11868,8 +11716,9 @@ var fnSpecialExpression = {
|
|
|
11868
11716
|
_b.name = undefined,
|
|
11869
11717
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11870
11718
|
_b.arity = arity,
|
|
11871
|
-
_b.docString =
|
|
11719
|
+
_b.docString = docString,
|
|
11872
11720
|
_b);
|
|
11721
|
+
evaluatedFunction[2].self = { value: litsFunction };
|
|
11873
11722
|
return litsFunction;
|
|
11874
11723
|
},
|
|
11875
11724
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -11900,17 +11749,16 @@ function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evalua
|
|
|
11900
11749
|
];
|
|
11901
11750
|
return evaluatedFunction;
|
|
11902
11751
|
}
|
|
11903
|
-
function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode
|
|
11752
|
+
function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode) {
|
|
11904
11753
|
var result = new Set();
|
|
11905
|
-
var
|
|
11906
|
-
var newContext = {};
|
|
11754
|
+
var newContext = { self: { value: null } };
|
|
11907
11755
|
fn[0].forEach(function (arg) {
|
|
11908
11756
|
Object.assign(newContext, getAllBindingTargetNames(arg));
|
|
11909
11757
|
walkDefaults(arg, function (defaultNode) {
|
|
11910
11758
|
addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
11911
11759
|
});
|
|
11912
11760
|
});
|
|
11913
|
-
var newContextStack =
|
|
11761
|
+
var newContextStack = contextStack.create(newContext);
|
|
11914
11762
|
var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
|
|
11915
11763
|
addToSet(result, overloadResult);
|
|
11916
11764
|
return result;
|
|
@@ -11997,22 +11845,9 @@ var loopSpecialExpression = {
|
|
|
11997
11845
|
var newContextStack = contextStack.create(bindingContext);
|
|
11998
11846
|
var body = node[1][2];
|
|
11999
11847
|
var _loop_1 = function () {
|
|
12000
|
-
var e_1, _b;
|
|
12001
11848
|
var result = null;
|
|
12002
11849
|
try {
|
|
12003
|
-
|
|
12004
|
-
for (var body_1 = (e_1 = void 0, __values(body)), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
12005
|
-
var form = body_1_1.value;
|
|
12006
|
-
result = evaluateNode(form, newContextStack);
|
|
12007
|
-
}
|
|
12008
|
-
}
|
|
12009
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
12010
|
-
finally {
|
|
12011
|
-
try {
|
|
12012
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
12013
|
-
}
|
|
12014
|
-
finally { if (e_1) throw e_1.error; }
|
|
12015
|
-
}
|
|
11850
|
+
result = evaluateNode(body, newContextStack);
|
|
12016
11851
|
}
|
|
12017
11852
|
catch (error) {
|
|
12018
11853
|
if (error instanceof RecurSignal) {
|
|
@@ -12021,20 +11856,20 @@ var loopSpecialExpression = {
|
|
|
12021
11856
|
throw new LitsError("recur expected ".concat(bindingNodes.length, " parameters, got ").concat(valueToString(params_1.length)), node[2]);
|
|
12022
11857
|
}
|
|
12023
11858
|
bindingNodes.forEach(function (bindingNode, index) {
|
|
12024
|
-
var
|
|
11859
|
+
var e_1, _a;
|
|
12025
11860
|
var valueRecord = evalueateBindingNodeValues(bindingNode[1][0], asAny(params_1[index]), function (Node) { return evaluateNode(Node, contextStack); });
|
|
12026
11861
|
try {
|
|
12027
|
-
for (var _b = (
|
|
11862
|
+
for (var _b = (e_1 = void 0, __values(Object.entries(valueRecord))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
12028
11863
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
12029
11864
|
bindingContext[name_1].value = value;
|
|
12030
11865
|
}
|
|
12031
11866
|
}
|
|
12032
|
-
catch (
|
|
11867
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
12033
11868
|
finally {
|
|
12034
11869
|
try {
|
|
12035
11870
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
12036
11871
|
}
|
|
12037
|
-
finally { if (
|
|
11872
|
+
finally { if (e_1) throw e_1.error; }
|
|
12038
11873
|
}
|
|
12039
11874
|
});
|
|
12040
11875
|
return "continue";
|
|
@@ -12062,7 +11897,7 @@ var loopSpecialExpression = {
|
|
|
12062
11897
|
}, {});
|
|
12063
11898
|
var bindingValueNodes = bindingNodes.map(function (bindingNode) { return bindingNode[1][1]; });
|
|
12064
11899
|
var bindingsResult = getUndefinedSymbols(bindingValueNodes, contextStack, builtin, evaluateNode);
|
|
12065
|
-
var paramsResult = getUndefinedSymbols(node[1][2], contextStack.create(newContext), builtin, evaluateNode);
|
|
11900
|
+
var paramsResult = getUndefinedSymbols([node[1][2]], contextStack.create(newContext), builtin, evaluateNode);
|
|
12066
11901
|
return joinSets(bindingsResult, paramsResult);
|
|
12067
11902
|
},
|
|
12068
11903
|
};
|
|
@@ -12449,6 +12284,31 @@ var objectSpecialExpression = {
|
|
|
12449
12284
|
},
|
|
12450
12285
|
};
|
|
12451
12286
|
|
|
12287
|
+
var specialExpressionTypes = {
|
|
12288
|
+
'??': 0,
|
|
12289
|
+
'&&': 1,
|
|
12290
|
+
'||': 2,
|
|
12291
|
+
'array': 3,
|
|
12292
|
+
'cond': 4,
|
|
12293
|
+
'0_def': 5,
|
|
12294
|
+
'defined?': 6,
|
|
12295
|
+
// '0_defn': 7,
|
|
12296
|
+
'block': 7,
|
|
12297
|
+
'doseq': 8,
|
|
12298
|
+
'0_lambda': 9,
|
|
12299
|
+
'for': 10,
|
|
12300
|
+
// 'function': 10,
|
|
12301
|
+
'if': 11,
|
|
12302
|
+
'let': 12,
|
|
12303
|
+
'loop': 13,
|
|
12304
|
+
'object': 14,
|
|
12305
|
+
'recur': 15,
|
|
12306
|
+
'switch': 16,
|
|
12307
|
+
'throw': 17,
|
|
12308
|
+
'try': 18,
|
|
12309
|
+
'unless': 19,
|
|
12310
|
+
};
|
|
12311
|
+
|
|
12452
12312
|
var specialExpressions = [
|
|
12453
12313
|
qqSpecialExpression,
|
|
12454
12314
|
andSpecialExpression,
|
|
@@ -12457,12 +12317,12 @@ var specialExpressions = [
|
|
|
12457
12317
|
condSpecialExpression,
|
|
12458
12318
|
defSpecialExpression,
|
|
12459
12319
|
definedSpecialExpression,
|
|
12460
|
-
defnSpecialExpression,
|
|
12320
|
+
// defnSpecialExpression,
|
|
12461
12321
|
doSpecialExpression,
|
|
12462
12322
|
doseqSpecialExpression,
|
|
12463
|
-
|
|
12323
|
+
lambdaSpecialExpression,
|
|
12464
12324
|
forSpecialExpression,
|
|
12465
|
-
functionSpecialExpression,
|
|
12325
|
+
// functionSpecialExpression,
|
|
12466
12326
|
ifSpecialExpression,
|
|
12467
12327
|
letSpecialExpression,
|
|
12468
12328
|
loopSpecialExpression,
|
|
@@ -12574,6 +12434,53 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
12574
12434
|
}
|
|
12575
12435
|
}
|
|
12576
12436
|
|
|
12437
|
+
var nonNumberReservedSymbolRecord = {
|
|
12438
|
+
true: true,
|
|
12439
|
+
false: false,
|
|
12440
|
+
null: null,
|
|
12441
|
+
else: null,
|
|
12442
|
+
case: null,
|
|
12443
|
+
each: null,
|
|
12444
|
+
in: null,
|
|
12445
|
+
when: null,
|
|
12446
|
+
while: null,
|
|
12447
|
+
catch: null,
|
|
12448
|
+
function: null,
|
|
12449
|
+
export: null,
|
|
12450
|
+
as: null,
|
|
12451
|
+
then: null,
|
|
12452
|
+
end: null,
|
|
12453
|
+
_: null,
|
|
12454
|
+
};
|
|
12455
|
+
var phi = (1 + Math.sqrt(5)) / 2;
|
|
12456
|
+
var numberReservedSymbolRecord = {
|
|
12457
|
+
'E': Math.E,
|
|
12458
|
+
'-E': -Math.E,
|
|
12459
|
+
'ε': Math.E,
|
|
12460
|
+
'-ε': -Math.E,
|
|
12461
|
+
'PI': Math.PI,
|
|
12462
|
+
'-PI': -Math.PI,
|
|
12463
|
+
'π': Math.PI,
|
|
12464
|
+
'-π': -Math.PI,
|
|
12465
|
+
'PHI': phi,
|
|
12466
|
+
'-PHI': -phi,
|
|
12467
|
+
'φ': phi,
|
|
12468
|
+
'-φ': -phi,
|
|
12469
|
+
'POSITIVE_INFINITY': Number.POSITIVE_INFINITY,
|
|
12470
|
+
'∞': Number.POSITIVE_INFINITY,
|
|
12471
|
+
'NEGATIVE_INFINITY': Number.NEGATIVE_INFINITY,
|
|
12472
|
+
'-∞': Number.NEGATIVE_INFINITY,
|
|
12473
|
+
'MAX_SAFE_INTEGER': Number.MAX_SAFE_INTEGER,
|
|
12474
|
+
'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
|
|
12475
|
+
'MAX_VALUE': Number.MAX_VALUE,
|
|
12476
|
+
'MIN_VALUE': Number.MIN_VALUE,
|
|
12477
|
+
'NaN': Number.NaN,
|
|
12478
|
+
};
|
|
12479
|
+
var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
12480
|
+
function isNumberReservedSymbol(symbol) {
|
|
12481
|
+
return symbol in numberReservedSymbolRecord;
|
|
12482
|
+
}
|
|
12483
|
+
|
|
12577
12484
|
var functionExecutors = {
|
|
12578
12485
|
NativeJsFunction: function (fn, params, sourceCodeInfo) {
|
|
12579
12486
|
var _a;
|
|
@@ -13022,6 +12929,9 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
13022
12929
|
if (normalExpressionKeys.includes(name_1)) {
|
|
13023
12930
|
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
13024
12931
|
}
|
|
12932
|
+
if (name_1 === 'self') {
|
|
12933
|
+
throw new LitsError("Cannot shadow builtin value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
12934
|
+
}
|
|
13025
12935
|
this.globalContext[name_1] = { value: value };
|
|
13026
12936
|
}
|
|
13027
12937
|
}
|
|
@@ -13051,6 +12961,9 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
13051
12961
|
if (normalExpressionKeys.includes(name_2)) {
|
|
13052
12962
|
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
13053
12963
|
}
|
|
12964
|
+
if (name_2 === 'self') {
|
|
12965
|
+
throw new LitsError("Cannot shadow builtin value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
12966
|
+
}
|
|
13054
12967
|
currentContext[name_2] = { value: toAny(value) };
|
|
13055
12968
|
}
|
|
13056
12969
|
}
|
|
@@ -14046,9 +13959,6 @@ var Parser = /** @class */ (function () {
|
|
|
14046
13959
|
break;
|
|
14047
13960
|
}
|
|
14048
13961
|
}
|
|
14049
|
-
else if (isReservedSymbolToken(firstToken, 'function')) {
|
|
14050
|
-
return this.parseFunction(firstToken);
|
|
14051
|
-
}
|
|
14052
13962
|
else if (isReservedSymbolToken(firstToken, 'export')) {
|
|
14053
13963
|
if (!moduleScope) {
|
|
14054
13964
|
throw new LitsError('export is only allowed in module scope', firstToken[2]);
|
|
@@ -14341,9 +14251,8 @@ var Parser = /** @class */ (function () {
|
|
|
14341
14251
|
var _c = __read(params, 1), param = _c[0];
|
|
14342
14252
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
14343
14253
|
}
|
|
14344
|
-
case specialExpressionTypes['
|
|
14254
|
+
case specialExpressionTypes['0_lambda']:
|
|
14345
14255
|
case specialExpressionTypes['0_def']:
|
|
14346
|
-
case specialExpressionTypes['0_defn']:
|
|
14347
14256
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
14348
14257
|
/* v8 ignore next 2 */
|
|
14349
14258
|
default:
|
|
@@ -14370,11 +14279,27 @@ var Parser = /** @class */ (function () {
|
|
|
14370
14279
|
return null;
|
|
14371
14280
|
}
|
|
14372
14281
|
this.advance();
|
|
14373
|
-
var
|
|
14374
|
-
|
|
14282
|
+
var nodes = void 0;
|
|
14283
|
+
var docString = '';
|
|
14284
|
+
if (isLBraceToken(this.peek())) {
|
|
14285
|
+
var parsedBlock = this.parseBlock(true);
|
|
14286
|
+
docString = parsedBlock[1];
|
|
14287
|
+
nodes = parsedBlock[0][1][1];
|
|
14288
|
+
}
|
|
14289
|
+
else {
|
|
14290
|
+
nodes = [this.parseExpression()];
|
|
14291
|
+
}
|
|
14292
|
+
return withSourceCodeInfo([
|
|
14293
|
+
NodeTypes.SpecialExpression,
|
|
14294
|
+
[
|
|
14295
|
+
specialExpressionTypes['0_lambda'],
|
|
14296
|
+
[
|
|
14375
14297
|
functionArguments,
|
|
14376
|
-
|
|
14377
|
-
]
|
|
14298
|
+
nodes,
|
|
14299
|
+
],
|
|
14300
|
+
docString,
|
|
14301
|
+
],
|
|
14302
|
+
], firstToken[2]);
|
|
14378
14303
|
}
|
|
14379
14304
|
catch (_a) {
|
|
14380
14305
|
return null;
|
|
@@ -14423,7 +14348,16 @@ var Parser = /** @class */ (function () {
|
|
|
14423
14348
|
var firstToken = this.asToken(this.peek());
|
|
14424
14349
|
this.advance();
|
|
14425
14350
|
var startPos = this.parseState.position;
|
|
14426
|
-
var
|
|
14351
|
+
var nodes;
|
|
14352
|
+
var docString = '';
|
|
14353
|
+
if (isLBraceToken(this.peek())) {
|
|
14354
|
+
var parsedBlock = this.parseBlock(true);
|
|
14355
|
+
docString = parsedBlock[1];
|
|
14356
|
+
nodes = parsedBlock[0][1][1];
|
|
14357
|
+
}
|
|
14358
|
+
else {
|
|
14359
|
+
nodes = [this.parseExpression()];
|
|
14360
|
+
}
|
|
14427
14361
|
var endPos = this.parseState.position - 1;
|
|
14428
14362
|
var arity = 0;
|
|
14429
14363
|
var dollar1 = 'NOT_SET'; // referring to argument bindings. $ = NAKED, $1, $2, $3, etc = WITH_1
|
|
@@ -14454,10 +14388,10 @@ var Parser = /** @class */ (function () {
|
|
|
14454
14388
|
functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
|
|
14455
14389
|
}
|
|
14456
14390
|
}
|
|
14457
|
-
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['
|
|
14391
|
+
var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_lambda'], [
|
|
14458
14392
|
functionArguments,
|
|
14459
|
-
|
|
14460
|
-
]]], firstToken[2]);
|
|
14393
|
+
nodes,
|
|
14394
|
+
], docString]], firstToken[2]);
|
|
14461
14395
|
return node;
|
|
14462
14396
|
};
|
|
14463
14397
|
Parser.prototype.parseOptionalDefaulValue = function () {
|
|
@@ -14648,21 +14582,10 @@ var Parser = /** @class */ (function () {
|
|
|
14648
14582
|
}
|
|
14649
14583
|
assertRParenToken(token);
|
|
14650
14584
|
this.advance();
|
|
14651
|
-
|
|
14652
|
-
this.advance();
|
|
14653
|
-
var params = [];
|
|
14654
|
-
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14655
|
-
params.push(this.parseExpression());
|
|
14656
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14657
|
-
this.advance();
|
|
14658
|
-
}
|
|
14659
|
-
else if (!isRBraceToken(this.peek())) {
|
|
14660
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14661
|
-
}
|
|
14662
|
-
}
|
|
14663
|
-
assertRBraceToken(this.peek());
|
|
14585
|
+
assertOperatorToken(this.peek(), '->');
|
|
14664
14586
|
this.advance();
|
|
14665
|
-
|
|
14587
|
+
var expression = this.parseExpression();
|
|
14588
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, expression]], firstToken[2]);
|
|
14666
14589
|
};
|
|
14667
14590
|
Parser.prototype.parseTry = function (token) {
|
|
14668
14591
|
this.advance();
|
|
@@ -14693,7 +14616,7 @@ var Parser = /** @class */ (function () {
|
|
|
14693
14616
|
throw new LitsError('Duplicate binding', loopBinding[0][2]);
|
|
14694
14617
|
}
|
|
14695
14618
|
forLoopBindings.push(loopBinding);
|
|
14696
|
-
if (isOperatorToken(this_1.peek(), '
|
|
14619
|
+
if (isOperatorToken(this_1.peek(), ',')) {
|
|
14697
14620
|
this_1.advance();
|
|
14698
14621
|
}
|
|
14699
14622
|
};
|
|
@@ -14703,6 +14626,8 @@ var Parser = /** @class */ (function () {
|
|
|
14703
14626
|
}
|
|
14704
14627
|
assertRParenToken(this.peek());
|
|
14705
14628
|
this.advance();
|
|
14629
|
+
assertOperatorToken(this.peek(), '->');
|
|
14630
|
+
this.advance();
|
|
14706
14631
|
var expression = this.parseExpression();
|
|
14707
14632
|
return isDoseq
|
|
14708
14633
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expression]], firstToken[2])
|
|
@@ -14712,20 +14637,7 @@ var Parser = /** @class */ (function () {
|
|
|
14712
14637
|
var bindingNode = this.parseBinding();
|
|
14713
14638
|
var modifiers = [];
|
|
14714
14639
|
var token = this.asToken(this.peek());
|
|
14715
|
-
|
|
14716
|
-
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14717
|
-
}
|
|
14718
|
-
if (isOperatorToken(token, ',')) {
|
|
14719
|
-
this.advance();
|
|
14720
|
-
token = this.asToken(this.peek());
|
|
14721
|
-
}
|
|
14722
|
-
if (!isSymbolToken(token, 'let')
|
|
14723
|
-
&& !isReservedSymbolToken(token, 'when')
|
|
14724
|
-
&& !isReservedSymbolToken(token, 'while')
|
|
14725
|
-
&& !isRParenToken(token)
|
|
14726
|
-
&& !isOperatorToken(token, ';')) {
|
|
14727
|
-
throw new LitsError('Expected symbol ";", ")", let, when or while', token[2]);
|
|
14728
|
-
}
|
|
14640
|
+
this.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
|
|
14729
14641
|
var letBindings = [];
|
|
14730
14642
|
if (token[1] === 'let') {
|
|
14731
14643
|
modifiers.push('&let');
|
|
@@ -14738,12 +14650,7 @@ var Parser = /** @class */ (function () {
|
|
|
14738
14650
|
}
|
|
14739
14651
|
letBindings.push(letNode[1][1]);
|
|
14740
14652
|
token = this_2.asToken(this_2.peek());
|
|
14741
|
-
|
|
14742
|
-
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14743
|
-
}
|
|
14744
|
-
if (isOperatorToken(token, ',')) {
|
|
14745
|
-
this_2.advance();
|
|
14746
|
-
}
|
|
14653
|
+
this_2.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
|
|
14747
14654
|
token = this_2.asToken(this_2.peek());
|
|
14748
14655
|
};
|
|
14749
14656
|
var this_2 = this;
|
|
@@ -14757,33 +14664,57 @@ var Parser = /** @class */ (function () {
|
|
|
14757
14664
|
|| isReservedSymbolToken(token, 'while')) {
|
|
14758
14665
|
this.advance();
|
|
14759
14666
|
if (token[1] === 'when') {
|
|
14760
|
-
if (modifiers.includes('&when')) {
|
|
14761
|
-
throw new LitsError('Multiple when modifiers in for loop', token[2]);
|
|
14762
|
-
}
|
|
14763
14667
|
modifiers.push('&when');
|
|
14764
14668
|
whenNode = this.parseExpression();
|
|
14765
14669
|
}
|
|
14766
14670
|
else {
|
|
14767
|
-
if (modifiers.includes('&while')) {
|
|
14768
|
-
throw new LitsError('Multiple while modifiers in for loop', token[2]);
|
|
14769
|
-
}
|
|
14770
14671
|
modifiers.push('&while');
|
|
14771
14672
|
whileNode = this.parseExpression();
|
|
14772
14673
|
}
|
|
14773
14674
|
token = this.asToken(this.peek());
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
|
|
14777
|
-
|
|
14778
|
-
|
|
14779
|
-
|
|
14675
|
+
var symbols = modifiers.includes('&when') && modifiers.includes('&while')
|
|
14676
|
+
? []
|
|
14677
|
+
: modifiers.includes('&when')
|
|
14678
|
+
? ['while']
|
|
14679
|
+
: ['when'];
|
|
14680
|
+
this.assertInternalLoopBindingDelimiter(token, symbols);
|
|
14780
14681
|
token = this.asToken(this.peek());
|
|
14781
14682
|
}
|
|
14782
|
-
|
|
14783
|
-
throw new LitsError('Expected "{" or ";"', token[2]);
|
|
14784
|
-
}
|
|
14683
|
+
this.assertInternalLoopBindingDelimiter(token, []);
|
|
14785
14684
|
return [bindingNode, letBindings, whenNode, whileNode];
|
|
14786
14685
|
};
|
|
14686
|
+
Parser.prototype.assertInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14687
|
+
if (!this.isInternalLoopBindingDelimiter(token, symbols)) {
|
|
14688
|
+
var symbolsString = "".concat(__spreadArray(__spreadArray([], __read(symbols), false), [','], false).map(function (symbol) { return "\"".concat(symbol, "\""); }).join(', '), " or \")\"");
|
|
14689
|
+
throw new LitsError("Expected symbol ".concat(symbolsString), token[2]);
|
|
14690
|
+
}
|
|
14691
|
+
};
|
|
14692
|
+
Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14693
|
+
var e_1, _a;
|
|
14694
|
+
// end of loop binding
|
|
14695
|
+
if (isOperatorToken(token, ',') || isRParenToken(token)) {
|
|
14696
|
+
return true;
|
|
14697
|
+
}
|
|
14698
|
+
try {
|
|
14699
|
+
for (var symbols_1 = __values(symbols), symbols_1_1 = symbols_1.next(); !symbols_1_1.done; symbols_1_1 = symbols_1.next()) {
|
|
14700
|
+
var symbol = symbols_1_1.value;
|
|
14701
|
+
if (symbol === 'let' && isSymbolToken(token, 'let')) {
|
|
14702
|
+
return true;
|
|
14703
|
+
}
|
|
14704
|
+
if (['when', 'while'].includes(symbol) && isReservedSymbolToken(token, symbol)) {
|
|
14705
|
+
return true;
|
|
14706
|
+
}
|
|
14707
|
+
}
|
|
14708
|
+
}
|
|
14709
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
14710
|
+
finally {
|
|
14711
|
+
try {
|
|
14712
|
+
if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
|
|
14713
|
+
}
|
|
14714
|
+
finally { if (e_1) throw e_1.error; }
|
|
14715
|
+
}
|
|
14716
|
+
return false;
|
|
14717
|
+
};
|
|
14787
14718
|
Parser.prototype.parseBinding = function () {
|
|
14788
14719
|
var firstToken = asSymbolToken(this.peek());
|
|
14789
14720
|
var name = asUserDefinedSymbolNode(this.parseSymbol());
|
|
@@ -14802,10 +14733,8 @@ var Parser = /** @class */ (function () {
|
|
|
14802
14733
|
Parser.prototype.parseIfOrUnless = function (token) {
|
|
14803
14734
|
var isUnless = token[1] === 'unless';
|
|
14804
14735
|
this.advance();
|
|
14805
|
-
assertLParenToken(this.peek());
|
|
14806
|
-
this.advance();
|
|
14807
14736
|
var condition = this.parseExpression();
|
|
14808
|
-
|
|
14737
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14809
14738
|
this.advance();
|
|
14810
14739
|
var thenExpression = this.parseExpression();
|
|
14811
14740
|
var elseExpression;
|
|
@@ -14818,100 +14747,74 @@ var Parser = /** @class */ (function () {
|
|
|
14818
14747
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
14819
14748
|
};
|
|
14820
14749
|
Parser.prototype.parseCond = function (token) {
|
|
14821
|
-
this.advance();
|
|
14822
|
-
assertLBraceToken(this.peek());
|
|
14823
14750
|
this.advance();
|
|
14824
14751
|
var params = [];
|
|
14825
|
-
while (!this.isAtEnd() && !
|
|
14752
|
+
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14826
14753
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14827
14754
|
this.advance();
|
|
14828
14755
|
var caseExpression = this.parseExpression();
|
|
14829
|
-
|
|
14756
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14830
14757
|
this.advance();
|
|
14831
14758
|
var expressions = [];
|
|
14832
14759
|
while (!this.isAtEnd()
|
|
14833
14760
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14834
|
-
&& !
|
|
14761
|
+
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14835
14762
|
expressions.push(this.parseExpression());
|
|
14836
14763
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14837
14764
|
this.advance();
|
|
14838
14765
|
}
|
|
14839
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14840
|
-
throw new LitsError('Expected
|
|
14766
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14767
|
+
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14841
14768
|
}
|
|
14842
14769
|
}
|
|
14843
14770
|
var thenExpression = expressions.length === 1
|
|
14844
14771
|
? expressions[0]
|
|
14845
14772
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14846
14773
|
params.push([caseExpression, thenExpression]);
|
|
14847
|
-
if (
|
|
14774
|
+
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14848
14775
|
break;
|
|
14849
14776
|
}
|
|
14850
14777
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14851
14778
|
}
|
|
14852
|
-
|
|
14779
|
+
assertReservedSymbolToken(this.peek());
|
|
14853
14780
|
this.advance();
|
|
14854
14781
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
|
|
14855
14782
|
};
|
|
14856
14783
|
Parser.prototype.parseSwitch = function (token) {
|
|
14857
|
-
this.advance();
|
|
14858
|
-
assertLParenToken(this.peek());
|
|
14859
14784
|
this.advance();
|
|
14860
14785
|
var valueExpression = this.parseExpression();
|
|
14861
|
-
assertRParenToken(this.peek());
|
|
14862
|
-
this.advance();
|
|
14863
|
-
assertLBraceToken(this.peek());
|
|
14864
|
-
this.advance();
|
|
14865
14786
|
var params = [];
|
|
14866
|
-
while (!this.isAtEnd() && !
|
|
14787
|
+
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14867
14788
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14868
14789
|
this.advance();
|
|
14869
14790
|
var caseExpression = this.parseExpression();
|
|
14870
|
-
|
|
14791
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14871
14792
|
this.advance();
|
|
14872
14793
|
var expressions = [];
|
|
14873
14794
|
while (!this.isAtEnd()
|
|
14874
14795
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14875
|
-
&& !
|
|
14796
|
+
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14876
14797
|
expressions.push(this.parseExpression());
|
|
14877
14798
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14878
14799
|
this.advance();
|
|
14879
14800
|
}
|
|
14880
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14881
|
-
throw new LitsError('Expected
|
|
14801
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14802
|
+
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14882
14803
|
}
|
|
14883
14804
|
}
|
|
14884
14805
|
var thenExpression = expressions.length === 1
|
|
14885
14806
|
? expressions[0]
|
|
14886
14807
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14887
14808
|
params.push([caseExpression, thenExpression]);
|
|
14888
|
-
if (
|
|
14809
|
+
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14889
14810
|
break;
|
|
14890
14811
|
}
|
|
14891
14812
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14892
14813
|
}
|
|
14893
|
-
|
|
14814
|
+
assertReservedSymbolToken(this.peek(), 'end');
|
|
14894
14815
|
this.advance();
|
|
14895
14816
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
|
|
14896
14817
|
};
|
|
14897
|
-
Parser.prototype.parseFunction = function (token) {
|
|
14898
|
-
this.advance();
|
|
14899
|
-
var symbol = this.parseSymbol();
|
|
14900
|
-
var functionArguments = this.parseFunctionArguments();
|
|
14901
|
-
var _a = __read(this.parseBlock(true), 2), block = _a[0], docString = _a[1];
|
|
14902
|
-
return withSourceCodeInfo([
|
|
14903
|
-
NodeTypes.SpecialExpression,
|
|
14904
|
-
[
|
|
14905
|
-
specialExpressionTypes.function,
|
|
14906
|
-
symbol,
|
|
14907
|
-
[
|
|
14908
|
-
functionArguments,
|
|
14909
|
-
block[1][1],
|
|
14910
|
-
],
|
|
14911
|
-
docString,
|
|
14912
|
-
],
|
|
14913
|
-
], token[2]);
|
|
14914
|
-
};
|
|
14915
14818
|
Parser.prototype.isAtEnd = function () {
|
|
14916
14819
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
14917
14820
|
};
|
|
@@ -14924,7 +14827,7 @@ var Parser = /** @class */ (function () {
|
|
|
14924
14827
|
return [';', ',', ':'].includes(token[1]);
|
|
14925
14828
|
}
|
|
14926
14829
|
if (isReservedSymbolToken(token)) {
|
|
14927
|
-
return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
|
|
14830
|
+
return ['else', 'when', 'while', 'case', 'catch', 'let', 'then'].includes(token[1]);
|
|
14928
14831
|
}
|
|
14929
14832
|
return false;
|
|
14930
14833
|
};
|
|
@@ -14935,13 +14838,8 @@ var Parser = /** @class */ (function () {
|
|
|
14935
14838
|
var letNode = this.parseLet(asSymbolToken(token));
|
|
14936
14839
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], exportToken[2]);
|
|
14937
14840
|
}
|
|
14938
|
-
else if (isReservedSymbolToken(token, 'function')) {
|
|
14939
|
-
var functionNode = this.parseFunction(token);
|
|
14940
|
-
functionNode[1][0] = specialExpressionTypes['0_defn'];
|
|
14941
|
-
return functionNode;
|
|
14942
|
-
}
|
|
14943
14841
|
else {
|
|
14944
|
-
throw new LitsError('Expected let
|
|
14842
|
+
throw new LitsError('Expected let', this.peekSourceCodeInfo());
|
|
14945
14843
|
}
|
|
14946
14844
|
};
|
|
14947
14845
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -15131,7 +15029,7 @@ var AutoCompleter = /** @class */ (function () {
|
|
|
15131
15029
|
};
|
|
15132
15030
|
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
15133
15031
|
var _this = this;
|
|
15134
|
-
var blacklist = new Set(['0_def', '0_defn', '
|
|
15032
|
+
var blacklist = new Set(['0_def', '0_defn', '0_lambda']);
|
|
15135
15033
|
var startsWithCaseSensitive = this.generateWithPredicate(params, function (suggestion) {
|
|
15136
15034
|
return !blacklist.has(suggestion) && suggestion.startsWith(_this.searchString);
|
|
15137
15035
|
});
|
|
@@ -15781,7 +15679,7 @@ var arrayReference = {
|
|
|
15781
15679
|
'[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse',
|
|
15782
15680
|
'mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)',
|
|
15783
15681
|
'[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse',
|
|
15784
|
-
"\
|
|
15682
|
+
"\nlet foo = (n) -> {\n [n - 1, n, n + 1]\n};\n[1, 2, 3] mapcat foo",
|
|
15785
15683
|
"\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ remove even?\n)",
|
|
15786
15684
|
],
|
|
15787
15685
|
},
|
|
@@ -20512,7 +20410,7 @@ var metaReference = {
|
|
|
20512
20410
|
description: 'Returns documentation string of the $fun.',
|
|
20513
20411
|
examples: [
|
|
20514
20412
|
'doc(+)',
|
|
20515
|
-
"\
|
|
20413
|
+
"\nlet add = (x, y) -> {\n \"\"\"\n Adds two numbers.\n Args:\n x: First number.\n y: Second number.\n Returns:\n Sum of x and y.\n \"\"\"\n x + y;\n};\n\ndoc(add)",
|
|
20516
20414
|
],
|
|
20517
20415
|
},
|
|
20518
20416
|
arity: {
|
|
@@ -20533,8 +20431,8 @@ var metaReference = {
|
|
|
20533
20431
|
examples: [
|
|
20534
20432
|
'arity(+)',
|
|
20535
20433
|
'arity(defined?)',
|
|
20536
|
-
"\
|
|
20537
|
-
"\
|
|
20434
|
+
"\nlet add = (x, y = 0) -> {\n x + y;\n};\n\narity(add)",
|
|
20435
|
+
"\nlet foo = (k, ...x) -> {\n k + x;\n};\n arity(foo)",
|
|
20538
20436
|
],
|
|
20539
20437
|
},
|
|
20540
20438
|
};
|
|
@@ -26414,8 +26312,8 @@ var sequenceReference = {
|
|
|
26414
26312
|
examples: [
|
|
26415
26313
|
'[3, 1, 2] sort (a, b) -> b - a',
|
|
26416
26314
|
'sort([3, 1, 2])',
|
|
26417
|
-
"\nsort(\n [3, 1, 2],\n (a, b) -> cond
|
|
26418
|
-
"\nsort(\n [3, 1, 2],\n (a, b) -> cond
|
|
26315
|
+
"\nsort(\n [3, 1, 2],\n (a, b) -> cond case a < b then -1 case a > b then 1 case true then -1 end\n)",
|
|
26316
|
+
"\nsort(\n [3, 1, 2],\n (a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end\n)",
|
|
26419
26317
|
],
|
|
26420
26318
|
},
|
|
26421
26319
|
'sort-by': {
|
|
@@ -26892,26 +26790,6 @@ var specialExpressionsReference = {
|
|
|
26892
26790
|
description: "\n Binds local variables s to `value`. `value` can be any expression. The scope of the variables is the body of the let expression.",
|
|
26893
26791
|
examples: ["\nlet a = 1 + 2 + 3 + 4;\nlet b = -> $ * ( $ + 1 );\nwrite!(\"a\", a, \"b\", b)"],
|
|
26894
26792
|
},
|
|
26895
|
-
'function': {
|
|
26896
|
-
title: 'function',
|
|
26897
|
-
category: 'Special expression',
|
|
26898
|
-
customVariants: ['function name(...arg) { body }'],
|
|
26899
|
-
details: [
|
|
26900
|
-
['name', 'symbol', 'The name of the function.'],
|
|
26901
|
-
['arg', '[...]arg-name [= value]', 'Arguments of the function.'],
|
|
26902
|
-
['...', 'rest-symbol', 'Optional. The rest argument of the function.'],
|
|
26903
|
-
['arg-name', 'symbol', 'The name of the argument.'],
|
|
26904
|
-
['value', 'any', 'Optional. The default value of the argument.'],
|
|
26905
|
-
['let-binding', 'symbol', 'Optional. The let bindings of the function.'],
|
|
26906
|
-
['body', 'one or more expressions', 'The body of the function.'],
|
|
26907
|
-
],
|
|
26908
|
-
description: 'Creates a named function. When called, evaluation of the last expression in the body is returned.',
|
|
26909
|
-
examples: [
|
|
26910
|
-
"\nfunction hyp (a, b) {\n sqrt(a * a + b * b)\n};\n\nhyp(3, 4)",
|
|
26911
|
-
"\nfunction sumOfSquares(...s) {\n apply(\n +,\n map(s, -> $ ^ 2)\n )\n};\n\nsumOfSquares(1, 2, 3, 4, 5)",
|
|
26912
|
-
"\nfunction withOptional(a, b = 42) {\n a + b\n};\n\nwrite!(withOptional(1), withOptional(1, 2))",
|
|
26913
|
-
],
|
|
26914
|
-
},
|
|
26915
26793
|
'try': {
|
|
26916
26794
|
title: 'try',
|
|
26917
26795
|
category: 'Special expression',
|
|
@@ -26951,7 +26829,7 @@ var specialExpressionsReference = {
|
|
|
26951
26829
|
'if': {
|
|
26952
26830
|
title: 'if',
|
|
26953
26831
|
category: 'Special expression',
|
|
26954
|
-
customVariants: ['if
|
|
26832
|
+
customVariants: ['if test then true-expr else false-expr', 'if test then true-expr'],
|
|
26955
26833
|
details: [
|
|
26956
26834
|
['test', 'expression', 'The condition to test.'],
|
|
26957
26835
|
['true-expr', 'expression', 'The expression to evaluate if the test is truthy.'],
|
|
@@ -26959,16 +26837,16 @@ var specialExpressionsReference = {
|
|
|
26959
26837
|
],
|
|
26960
26838
|
description: 'Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is truthy. If $test is falsy `false-expr` is executed, if no `false-expr` exists, `null` is returned.',
|
|
26961
26839
|
examples: [
|
|
26962
|
-
"\nif
|
|
26963
|
-
'if
|
|
26964
|
-
'if
|
|
26965
|
-
'if
|
|
26840
|
+
"\nif true then {\n write!(\"TRUE\")\n} else {\n write!(\"FALSE\")\n}",
|
|
26841
|
+
'if false then write!("TRUE") else write!("FALSE")',
|
|
26842
|
+
'if true then write!("TRUE")',
|
|
26843
|
+
'if false then write!("TRUE")',
|
|
26966
26844
|
],
|
|
26967
26845
|
},
|
|
26968
26846
|
'unless': {
|
|
26969
26847
|
title: 'unless',
|
|
26970
26848
|
category: 'Special expression',
|
|
26971
|
-
customVariants: ['unless
|
|
26849
|
+
customVariants: ['unless test then true-expr else false-expr end', 'unless test true-expr end'],
|
|
26972
26850
|
details: [
|
|
26973
26851
|
['test', 'expression', 'The condition to test.'],
|
|
26974
26852
|
['true-expr', 'expression', 'The expressions to evaluate if the test is falsy.'],
|
|
@@ -26976,16 +26854,16 @@ var specialExpressionsReference = {
|
|
|
26976
26854
|
],
|
|
26977
26855
|
description: 'Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is falsy. If $test is truthy `false-expr` is executed, if no `false-expr` exists, `null` is returned.',
|
|
26978
26856
|
examples: [
|
|
26979
|
-
"\nunless
|
|
26980
|
-
'unless
|
|
26981
|
-
'unless
|
|
26982
|
-
'unless
|
|
26857
|
+
"\nunless true then {\n write!(\"TRUE\")\n} else {\n write!(\"FALSE\")\n}",
|
|
26858
|
+
'unless false then write!("TRUE") else write!("FALSE")',
|
|
26859
|
+
'unless true then write!("TRUE")',
|
|
26860
|
+
'unless false then write!("TRUE")',
|
|
26983
26861
|
],
|
|
26984
26862
|
},
|
|
26985
26863
|
'cond': {
|
|
26986
26864
|
title: 'cond',
|
|
26987
26865
|
category: 'Special expression',
|
|
26988
|
-
customVariants: ['cond
|
|
26866
|
+
customVariants: ['cond cond-branch cond-branch ... end'],
|
|
26989
26867
|
details: [
|
|
26990
26868
|
['cond-branch', 'case test then body', 'A branch of the cond expression.'],
|
|
26991
26869
|
['test', 'expression', 'The condition to test.'],
|
|
@@ -26993,15 +26871,15 @@ var specialExpressionsReference = {
|
|
|
26993
26871
|
],
|
|
26994
26872
|
description: 'Used for branching. `cond-branches` are tested sequentially from the top. If no branch is tested truthy, `null` is returned.',
|
|
26995
26873
|
examples: [
|
|
26996
|
-
"\ncond
|
|
26997
|
-
"\ncond
|
|
26998
|
-
"\ncond
|
|
26874
|
+
"\ncond\n case false then write!(\"FALSE\")\n case true then write!(\"TRUE\")\nend",
|
|
26875
|
+
"\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
|
|
26876
|
+
"\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
|
|
26999
26877
|
],
|
|
27000
26878
|
},
|
|
27001
26879
|
'switch': {
|
|
27002
26880
|
title: 'switch',
|
|
27003
26881
|
category: 'Special expression',
|
|
27004
|
-
customVariants: ['switch
|
|
26882
|
+
customVariants: ['switch value switch-branch switch-branch ... end'],
|
|
27005
26883
|
details: [
|
|
27006
26884
|
['value', 'any', 'The value to test.'],
|
|
27007
26885
|
['switch-branch', 'case test then body', 'A branch of the switch expression.'],
|
|
@@ -27010,9 +26888,9 @@ var specialExpressionsReference = {
|
|
|
27010
26888
|
],
|
|
27011
26889
|
description: 'Used for branching. `switch-branches` are tested sequentially from the top against `value`. If no branch is tested truthy, `null` is returned.',
|
|
27012
26890
|
examples: [
|
|
27013
|
-
"\nswitch
|
|
27014
|
-
"\nswitch
|
|
27015
|
-
"\nswitch
|
|
26891
|
+
"\nswitch 1\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
26892
|
+
"\nswitch 2\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
26893
|
+
"\nswitch 3\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
27016
26894
|
],
|
|
27017
26895
|
},
|
|
27018
26896
|
'block': {
|
|
@@ -27033,9 +26911,9 @@ var specialExpressionsReference = {
|
|
|
27033
26911
|
customVariants: ['recur(...recur-args)'],
|
|
27034
26912
|
description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
|
|
27035
26913
|
examples: [
|
|
27036
|
-
"\
|
|
27037
|
-
"\n(n -> {\n write!(n);\n if
|
|
27038
|
-
"\nloop (n = 3) {\n write!(n);\n if
|
|
26914
|
+
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then {\n recur(n - 1)\n }\n};\nfoo(3)",
|
|
26915
|
+
"\n(n -> {\n write!(n);\n if !(zero?(n)) then {\n recur(n - 1)\n }\n})(3)",
|
|
26916
|
+
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then {\n recur(n - 1)\n }\n}",
|
|
27039
26917
|
],
|
|
27040
26918
|
},
|
|
27041
26919
|
};
|