@mojir/lits 2.1.32 → 2.1.34
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 +561 -226
- package/dist/cli/cli.js +258 -365
- 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 +10 -4
- package/dist/cli/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/index.esm.js +261 -370
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +261 -370
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +261 -370
- 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 +10 -4
- package/dist/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/testFramework.esm.js +251 -360
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +251 -360
- 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 () {
|
|
@@ -14627,6 +14561,48 @@ var Parser = /** @class */ (function () {
|
|
|
14627
14561
|
docString,
|
|
14628
14562
|
];
|
|
14629
14563
|
};
|
|
14564
|
+
Parser.prototype.parseImplicitBlock = function (ends) {
|
|
14565
|
+
var nodes = [];
|
|
14566
|
+
while (!this.isAtEnd() && !this.isImplicitBlockEnd(ends)) {
|
|
14567
|
+
if (isOperatorToken(this.peek(), ';')) {
|
|
14568
|
+
this.advance();
|
|
14569
|
+
}
|
|
14570
|
+
else {
|
|
14571
|
+
nodes.push(this.parseExpression());
|
|
14572
|
+
}
|
|
14573
|
+
}
|
|
14574
|
+
this.assertImplicitBlockEnd(ends);
|
|
14575
|
+
if (nodes.length === 0) {
|
|
14576
|
+
throw new LitsError('Expected expression', this.peekSourceCodeInfo());
|
|
14577
|
+
}
|
|
14578
|
+
return nodes.length === 1
|
|
14579
|
+
? nodes[0]
|
|
14580
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, nodes]], this.peekSourceCodeInfo());
|
|
14581
|
+
};
|
|
14582
|
+
Parser.prototype.assertImplicitBlockEnd = function (ends) {
|
|
14583
|
+
if (!this.isImplicitBlockEnd(ends)) {
|
|
14584
|
+
throw new LitsError("Expected ".concat(ends.map(function (e) { return e[1]; }).join(' or ')), this.peekSourceCodeInfo());
|
|
14585
|
+
}
|
|
14586
|
+
};
|
|
14587
|
+
Parser.prototype.isImplicitBlockEnd = function (ends) {
|
|
14588
|
+
var e_1, _a;
|
|
14589
|
+
try {
|
|
14590
|
+
for (var ends_1 = __values(ends), ends_1_1 = ends_1.next(); !ends_1_1.done; ends_1_1 = ends_1.next()) {
|
|
14591
|
+
var end = ends_1_1.value;
|
|
14592
|
+
if (isReservedSymbolToken(this.peek(), end)) {
|
|
14593
|
+
return true;
|
|
14594
|
+
}
|
|
14595
|
+
}
|
|
14596
|
+
}
|
|
14597
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
14598
|
+
finally {
|
|
14599
|
+
try {
|
|
14600
|
+
if (ends_1_1 && !ends_1_1.done && (_a = ends_1.return)) _a.call(ends_1);
|
|
14601
|
+
}
|
|
14602
|
+
finally { if (e_1) throw e_1.error; }
|
|
14603
|
+
}
|
|
14604
|
+
return false;
|
|
14605
|
+
};
|
|
14630
14606
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14631
14607
|
this.advance();
|
|
14632
14608
|
assertLParenToken(this.peek());
|
|
@@ -14648,21 +14624,10 @@ var Parser = /** @class */ (function () {
|
|
|
14648
14624
|
}
|
|
14649
14625
|
assertRParenToken(token);
|
|
14650
14626
|
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());
|
|
14627
|
+
assertOperatorToken(this.peek(), '->');
|
|
14664
14628
|
this.advance();
|
|
14665
|
-
|
|
14629
|
+
var expression = this.parseExpression();
|
|
14630
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, expression]], firstToken[2]);
|
|
14666
14631
|
};
|
|
14667
14632
|
Parser.prototype.parseTry = function (token) {
|
|
14668
14633
|
this.advance();
|
|
@@ -14693,7 +14658,7 @@ var Parser = /** @class */ (function () {
|
|
|
14693
14658
|
throw new LitsError('Duplicate binding', loopBinding[0][2]);
|
|
14694
14659
|
}
|
|
14695
14660
|
forLoopBindings.push(loopBinding);
|
|
14696
|
-
if (isOperatorToken(this_1.peek(), '
|
|
14661
|
+
if (isOperatorToken(this_1.peek(), ',')) {
|
|
14697
14662
|
this_1.advance();
|
|
14698
14663
|
}
|
|
14699
14664
|
};
|
|
@@ -14703,6 +14668,8 @@ var Parser = /** @class */ (function () {
|
|
|
14703
14668
|
}
|
|
14704
14669
|
assertRParenToken(this.peek());
|
|
14705
14670
|
this.advance();
|
|
14671
|
+
assertOperatorToken(this.peek(), '->');
|
|
14672
|
+
this.advance();
|
|
14706
14673
|
var expression = this.parseExpression();
|
|
14707
14674
|
return isDoseq
|
|
14708
14675
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expression]], firstToken[2])
|
|
@@ -14712,20 +14679,7 @@ var Parser = /** @class */ (function () {
|
|
|
14712
14679
|
var bindingNode = this.parseBinding();
|
|
14713
14680
|
var modifiers = [];
|
|
14714
14681
|
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
|
-
}
|
|
14682
|
+
this.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
|
|
14729
14683
|
var letBindings = [];
|
|
14730
14684
|
if (token[1] === 'let') {
|
|
14731
14685
|
modifiers.push('&let');
|
|
@@ -14738,12 +14692,7 @@ var Parser = /** @class */ (function () {
|
|
|
14738
14692
|
}
|
|
14739
14693
|
letBindings.push(letNode[1][1]);
|
|
14740
14694
|
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
|
-
}
|
|
14695
|
+
this_2.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
|
|
14747
14696
|
token = this_2.asToken(this_2.peek());
|
|
14748
14697
|
};
|
|
14749
14698
|
var this_2 = this;
|
|
@@ -14757,33 +14706,57 @@ var Parser = /** @class */ (function () {
|
|
|
14757
14706
|
|| isReservedSymbolToken(token, 'while')) {
|
|
14758
14707
|
this.advance();
|
|
14759
14708
|
if (token[1] === 'when') {
|
|
14760
|
-
if (modifiers.includes('&when')) {
|
|
14761
|
-
throw new LitsError('Multiple when modifiers in for loop', token[2]);
|
|
14762
|
-
}
|
|
14763
14709
|
modifiers.push('&when');
|
|
14764
14710
|
whenNode = this.parseExpression();
|
|
14765
14711
|
}
|
|
14766
14712
|
else {
|
|
14767
|
-
if (modifiers.includes('&while')) {
|
|
14768
|
-
throw new LitsError('Multiple while modifiers in for loop', token[2]);
|
|
14769
|
-
}
|
|
14770
14713
|
modifiers.push('&while');
|
|
14771
14714
|
whileNode = this.parseExpression();
|
|
14772
14715
|
}
|
|
14773
14716
|
token = this.asToken(this.peek());
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
|
|
14777
|
-
|
|
14778
|
-
|
|
14779
|
-
|
|
14717
|
+
var symbols = modifiers.includes('&when') && modifiers.includes('&while')
|
|
14718
|
+
? []
|
|
14719
|
+
: modifiers.includes('&when')
|
|
14720
|
+
? ['while']
|
|
14721
|
+
: ['when'];
|
|
14722
|
+
this.assertInternalLoopBindingDelimiter(token, symbols);
|
|
14780
14723
|
token = this.asToken(this.peek());
|
|
14781
14724
|
}
|
|
14782
|
-
|
|
14783
|
-
throw new LitsError('Expected "{" or ";"', token[2]);
|
|
14784
|
-
}
|
|
14725
|
+
this.assertInternalLoopBindingDelimiter(token, []);
|
|
14785
14726
|
return [bindingNode, letBindings, whenNode, whileNode];
|
|
14786
14727
|
};
|
|
14728
|
+
Parser.prototype.assertInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14729
|
+
if (!this.isInternalLoopBindingDelimiter(token, symbols)) {
|
|
14730
|
+
var symbolsString = "".concat(__spreadArray(__spreadArray([], __read(symbols), false), [','], false).map(function (symbol) { return "\"".concat(symbol, "\""); }).join(', '), " or \")\"");
|
|
14731
|
+
throw new LitsError("Expected symbol ".concat(symbolsString), token[2]);
|
|
14732
|
+
}
|
|
14733
|
+
};
|
|
14734
|
+
Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14735
|
+
var e_2, _a;
|
|
14736
|
+
// end of loop binding
|
|
14737
|
+
if (isOperatorToken(token, ',') || isRParenToken(token)) {
|
|
14738
|
+
return true;
|
|
14739
|
+
}
|
|
14740
|
+
try {
|
|
14741
|
+
for (var symbols_1 = __values(symbols), symbols_1_1 = symbols_1.next(); !symbols_1_1.done; symbols_1_1 = symbols_1.next()) {
|
|
14742
|
+
var symbol = symbols_1_1.value;
|
|
14743
|
+
if (symbol === 'let' && isSymbolToken(token, 'let')) {
|
|
14744
|
+
return true;
|
|
14745
|
+
}
|
|
14746
|
+
if (['when', 'while'].includes(symbol) && isReservedSymbolToken(token, symbol)) {
|
|
14747
|
+
return true;
|
|
14748
|
+
}
|
|
14749
|
+
}
|
|
14750
|
+
}
|
|
14751
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
14752
|
+
finally {
|
|
14753
|
+
try {
|
|
14754
|
+
if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
|
|
14755
|
+
}
|
|
14756
|
+
finally { if (e_2) throw e_2.error; }
|
|
14757
|
+
}
|
|
14758
|
+
return false;
|
|
14759
|
+
};
|
|
14787
14760
|
Parser.prototype.parseBinding = function () {
|
|
14788
14761
|
var firstToken = asSymbolToken(this.peek());
|
|
14789
14762
|
var name = asUserDefinedSymbolNode(this.parseSymbol());
|
|
@@ -14802,116 +14775,59 @@ var Parser = /** @class */ (function () {
|
|
|
14802
14775
|
Parser.prototype.parseIfOrUnless = function (token) {
|
|
14803
14776
|
var isUnless = token[1] === 'unless';
|
|
14804
14777
|
this.advance();
|
|
14805
|
-
assertLParenToken(this.peek());
|
|
14806
|
-
this.advance();
|
|
14807
14778
|
var condition = this.parseExpression();
|
|
14808
|
-
|
|
14779
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14809
14780
|
this.advance();
|
|
14810
|
-
var thenExpression = this.
|
|
14781
|
+
var thenExpression = this.parseImplicitBlock(['else', 'end']);
|
|
14811
14782
|
var elseExpression;
|
|
14812
14783
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14813
14784
|
this.advance();
|
|
14814
|
-
elseExpression = this.
|
|
14785
|
+
elseExpression = this.parseImplicitBlock(['end']);
|
|
14815
14786
|
}
|
|
14787
|
+
this.advance();
|
|
14816
14788
|
return isUnless
|
|
14817
14789
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14818
14790
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
14819
14791
|
};
|
|
14820
14792
|
Parser.prototype.parseCond = function (token) {
|
|
14821
|
-
this.advance();
|
|
14822
|
-
assertLBraceToken(this.peek());
|
|
14823
14793
|
this.advance();
|
|
14824
14794
|
var params = [];
|
|
14825
|
-
while (!this.isAtEnd() && !
|
|
14795
|
+
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14826
14796
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14827
14797
|
this.advance();
|
|
14828
14798
|
var caseExpression = this.parseExpression();
|
|
14829
|
-
|
|
14799
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14830
14800
|
this.advance();
|
|
14831
|
-
var
|
|
14832
|
-
while (!this.isAtEnd()
|
|
14833
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14834
|
-
&& !isRBraceToken(this.peek())) {
|
|
14835
|
-
expressions.push(this.parseExpression());
|
|
14836
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14837
|
-
this.advance();
|
|
14838
|
-
}
|
|
14839
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14840
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14841
|
-
}
|
|
14842
|
-
}
|
|
14843
|
-
var thenExpression = expressions.length === 1
|
|
14844
|
-
? expressions[0]
|
|
14845
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14801
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14846
14802
|
params.push([caseExpression, thenExpression]);
|
|
14847
|
-
if (
|
|
14803
|
+
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14848
14804
|
break;
|
|
14849
14805
|
}
|
|
14850
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14851
14806
|
}
|
|
14852
|
-
|
|
14807
|
+
assertReservedSymbolToken(this.peek());
|
|
14853
14808
|
this.advance();
|
|
14854
14809
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
|
|
14855
14810
|
};
|
|
14856
14811
|
Parser.prototype.parseSwitch = function (token) {
|
|
14857
|
-
this.advance();
|
|
14858
|
-
assertLParenToken(this.peek());
|
|
14859
14812
|
this.advance();
|
|
14860
14813
|
var valueExpression = this.parseExpression();
|
|
14861
|
-
assertRParenToken(this.peek());
|
|
14862
|
-
this.advance();
|
|
14863
|
-
assertLBraceToken(this.peek());
|
|
14864
|
-
this.advance();
|
|
14865
14814
|
var params = [];
|
|
14866
|
-
while (!this.isAtEnd() && !
|
|
14815
|
+
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14867
14816
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14868
14817
|
this.advance();
|
|
14869
14818
|
var caseExpression = this.parseExpression();
|
|
14870
|
-
|
|
14819
|
+
assertReservedSymbolToken(this.peek(), 'then');
|
|
14871
14820
|
this.advance();
|
|
14872
|
-
var
|
|
14873
|
-
while (!this.isAtEnd()
|
|
14874
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14875
|
-
&& !isRBraceToken(this.peek())) {
|
|
14876
|
-
expressions.push(this.parseExpression());
|
|
14877
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14878
|
-
this.advance();
|
|
14879
|
-
}
|
|
14880
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14881
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14882
|
-
}
|
|
14883
|
-
}
|
|
14884
|
-
var thenExpression = expressions.length === 1
|
|
14885
|
-
? expressions[0]
|
|
14886
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14821
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14887
14822
|
params.push([caseExpression, thenExpression]);
|
|
14888
|
-
if (
|
|
14823
|
+
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14889
14824
|
break;
|
|
14890
14825
|
}
|
|
14891
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14892
14826
|
}
|
|
14893
|
-
|
|
14827
|
+
assertReservedSymbolToken(this.peek(), 'end');
|
|
14894
14828
|
this.advance();
|
|
14895
14829
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
|
|
14896
14830
|
};
|
|
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
14831
|
Parser.prototype.isAtEnd = function () {
|
|
14916
14832
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
14917
14833
|
};
|
|
@@ -14924,7 +14840,7 @@ var Parser = /** @class */ (function () {
|
|
|
14924
14840
|
return [';', ',', ':'].includes(token[1]);
|
|
14925
14841
|
}
|
|
14926
14842
|
if (isReservedSymbolToken(token)) {
|
|
14927
|
-
return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
|
|
14843
|
+
return ['else', 'when', 'while', 'case', 'catch', 'let', 'then'].includes(token[1]);
|
|
14928
14844
|
}
|
|
14929
14845
|
return false;
|
|
14930
14846
|
};
|
|
@@ -14935,13 +14851,8 @@ var Parser = /** @class */ (function () {
|
|
|
14935
14851
|
var letNode = this.parseLet(asSymbolToken(token));
|
|
14936
14852
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], exportToken[2]);
|
|
14937
14853
|
}
|
|
14938
|
-
else if (isReservedSymbolToken(token, 'function')) {
|
|
14939
|
-
var functionNode = this.parseFunction(token);
|
|
14940
|
-
functionNode[1][0] = specialExpressionTypes['0_defn'];
|
|
14941
|
-
return functionNode;
|
|
14942
|
-
}
|
|
14943
14854
|
else {
|
|
14944
|
-
throw new LitsError('Expected let
|
|
14855
|
+
throw new LitsError('Expected let', this.peekSourceCodeInfo());
|
|
14945
14856
|
}
|
|
14946
14857
|
};
|
|
14947
14858
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -15131,7 +15042,7 @@ var AutoCompleter = /** @class */ (function () {
|
|
|
15131
15042
|
};
|
|
15132
15043
|
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
15133
15044
|
var _this = this;
|
|
15134
|
-
var blacklist = new Set(['0_def', '0_defn', '
|
|
15045
|
+
var blacklist = new Set(['0_def', '0_defn', '0_lambda']);
|
|
15135
15046
|
var startsWithCaseSensitive = this.generateWithPredicate(params, function (suggestion) {
|
|
15136
15047
|
return !blacklist.has(suggestion) && suggestion.startsWith(_this.searchString);
|
|
15137
15048
|
});
|
|
@@ -15781,7 +15692,7 @@ var arrayReference = {
|
|
|
15781
15692
|
'[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse',
|
|
15782
15693
|
'mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)',
|
|
15783
15694
|
'[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse',
|
|
15784
|
-
"\
|
|
15695
|
+
"\nlet foo = (n) -> {\n [n - 1, n, n + 1]\n};\n[1, 2, 3] mapcat foo",
|
|
15785
15696
|
"\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ remove even?\n)",
|
|
15786
15697
|
],
|
|
15787
15698
|
},
|
|
@@ -20512,7 +20423,7 @@ var metaReference = {
|
|
|
20512
20423
|
description: 'Returns documentation string of the $fun.',
|
|
20513
20424
|
examples: [
|
|
20514
20425
|
'doc(+)',
|
|
20515
|
-
"\
|
|
20426
|
+
"\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
20427
|
],
|
|
20517
20428
|
},
|
|
20518
20429
|
arity: {
|
|
@@ -20533,8 +20444,8 @@ var metaReference = {
|
|
|
20533
20444
|
examples: [
|
|
20534
20445
|
'arity(+)',
|
|
20535
20446
|
'arity(defined?)',
|
|
20536
|
-
"\
|
|
20537
|
-
"\
|
|
20447
|
+
"\nlet add = (x, y = 0) -> {\n x + y;\n};\n\narity(add)",
|
|
20448
|
+
"\nlet foo = (k, ...x) -> {\n k + x;\n};\n arity(foo)",
|
|
20538
20449
|
],
|
|
20539
20450
|
},
|
|
20540
20451
|
};
|
|
@@ -26414,8 +26325,8 @@ var sequenceReference = {
|
|
|
26414
26325
|
examples: [
|
|
26415
26326
|
'[3, 1, 2] sort (a, b) -> b - a',
|
|
26416
26327
|
'sort([3, 1, 2])',
|
|
26417
|
-
"\nsort(\n [3, 1, 2],\n (a, b) -> cond
|
|
26418
|
-
"\nsort(\n [3, 1, 2],\n (a, b) -> cond
|
|
26328
|
+
"\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)",
|
|
26329
|
+
"\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
26330
|
],
|
|
26420
26331
|
},
|
|
26421
26332
|
'sort-by': {
|
|
@@ -26892,26 +26803,6 @@ var specialExpressionsReference = {
|
|
|
26892
26803
|
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
26804
|
examples: ["\nlet a = 1 + 2 + 3 + 4;\nlet b = -> $ * ( $ + 1 );\nwrite!(\"a\", a, \"b\", b)"],
|
|
26894
26805
|
},
|
|
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
26806
|
'try': {
|
|
26916
26807
|
title: 'try',
|
|
26917
26808
|
category: 'Special expression',
|
|
@@ -26951,7 +26842,7 @@ var specialExpressionsReference = {
|
|
|
26951
26842
|
'if': {
|
|
26952
26843
|
title: 'if',
|
|
26953
26844
|
category: 'Special expression',
|
|
26954
|
-
customVariants: ['if
|
|
26845
|
+
customVariants: ['if test then true-expr else false-expr', 'if test then true-expr'],
|
|
26955
26846
|
details: [
|
|
26956
26847
|
['test', 'expression', 'The condition to test.'],
|
|
26957
26848
|
['true-expr', 'expression', 'The expression to evaluate if the test is truthy.'],
|
|
@@ -26959,16 +26850,16 @@ var specialExpressionsReference = {
|
|
|
26959
26850
|
],
|
|
26960
26851
|
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
26852
|
examples: [
|
|
26962
|
-
"\nif
|
|
26963
|
-
'if
|
|
26964
|
-
'if
|
|
26965
|
-
'if
|
|
26853
|
+
"\nif true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26854
|
+
'if false then write!("TRUE") else write!("FALSE") end',
|
|
26855
|
+
'if true then write!("TRUE") end',
|
|
26856
|
+
'if false then write!("TRUE") end',
|
|
26966
26857
|
],
|
|
26967
26858
|
},
|
|
26968
26859
|
'unless': {
|
|
26969
26860
|
title: 'unless',
|
|
26970
26861
|
category: 'Special expression',
|
|
26971
|
-
customVariants: ['unless
|
|
26862
|
+
customVariants: ['unless test then true-expr else false-expr end', 'unless test true-expr end'],
|
|
26972
26863
|
details: [
|
|
26973
26864
|
['test', 'expression', 'The condition to test.'],
|
|
26974
26865
|
['true-expr', 'expression', 'The expressions to evaluate if the test is falsy.'],
|
|
@@ -26976,16 +26867,16 @@ var specialExpressionsReference = {
|
|
|
26976
26867
|
],
|
|
26977
26868
|
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
26869
|
examples: [
|
|
26979
|
-
"\nunless
|
|
26980
|
-
'unless
|
|
26981
|
-
'unless
|
|
26982
|
-
'unless
|
|
26870
|
+
"\nunless true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26871
|
+
'unless false then write!("TRUE") else write!("FALSE") end',
|
|
26872
|
+
'unless true then write!("TRUE") end',
|
|
26873
|
+
'unless false then write!("TRUE") end',
|
|
26983
26874
|
],
|
|
26984
26875
|
},
|
|
26985
26876
|
'cond': {
|
|
26986
26877
|
title: 'cond',
|
|
26987
26878
|
category: 'Special expression',
|
|
26988
|
-
customVariants: ['cond
|
|
26879
|
+
customVariants: ['cond cond-branch cond-branch ... end'],
|
|
26989
26880
|
details: [
|
|
26990
26881
|
['cond-branch', 'case test then body', 'A branch of the cond expression.'],
|
|
26991
26882
|
['test', 'expression', 'The condition to test.'],
|
|
@@ -26993,15 +26884,15 @@ var specialExpressionsReference = {
|
|
|
26993
26884
|
],
|
|
26994
26885
|
description: 'Used for branching. `cond-branches` are tested sequentially from the top. If no branch is tested truthy, `null` is returned.',
|
|
26995
26886
|
examples: [
|
|
26996
|
-
"\ncond
|
|
26997
|
-
"\ncond
|
|
26998
|
-
"\ncond
|
|
26887
|
+
"\ncond\n case false then write!(\"FALSE\")\n case true then write!(\"TRUE\")\nend",
|
|
26888
|
+
"\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
|
|
26889
|
+
"\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
|
|
26999
26890
|
],
|
|
27000
26891
|
},
|
|
27001
26892
|
'switch': {
|
|
27002
26893
|
title: 'switch',
|
|
27003
26894
|
category: 'Special expression',
|
|
27004
|
-
customVariants: ['switch
|
|
26895
|
+
customVariants: ['switch value switch-branch switch-branch ... end'],
|
|
27005
26896
|
details: [
|
|
27006
26897
|
['value', 'any', 'The value to test.'],
|
|
27007
26898
|
['switch-branch', 'case test then body', 'A branch of the switch expression.'],
|
|
@@ -27010,9 +26901,9 @@ var specialExpressionsReference = {
|
|
|
27010
26901
|
],
|
|
27011
26902
|
description: 'Used for branching. `switch-branches` are tested sequentially from the top against `value`. If no branch is tested truthy, `null` is returned.',
|
|
27012
26903
|
examples: [
|
|
27013
|
-
"\nswitch
|
|
27014
|
-
"\nswitch
|
|
27015
|
-
"\nswitch
|
|
26904
|
+
"\nswitch 1\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
26905
|
+
"\nswitch 2\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
26906
|
+
"\nswitch 3\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
|
|
27016
26907
|
],
|
|
27017
26908
|
},
|
|
27018
26909
|
'block': {
|
|
@@ -27033,9 +26924,9 @@ var specialExpressionsReference = {
|
|
|
27033
26924
|
customVariants: ['recur(...recur-args)'],
|
|
27034
26925
|
description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
|
|
27035
26926
|
examples: [
|
|
27036
|
-
"\
|
|
27037
|
-
"\n(n -> {\n write!(n);\n if
|
|
27038
|
-
"\nloop (n = 3) {\n write!(n);\n if
|
|
26927
|
+
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n};\nfoo(3)",
|
|
26928
|
+
"\n(n -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n})(3)",
|
|
26929
|
+
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n}",
|
|
27039
26930
|
],
|
|
27040
26931
|
},
|
|
27041
26932
|
};
|