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