@mojir/lits 2.1.13 → 2.1.15
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 +0 -6
- package/dist/cli/cli.js +351 -1312
- package/dist/cli/reference/api.d.ts +2 -2
- package/dist/cli/reference/index.d.ts +3 -5
- package/dist/cli/src/Lits/Lits.d.ts +1 -5
- package/dist/cli/src/builtin/index.d.ts +2 -2
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressions/{do.d.ts → block.d.ts} +1 -1
- package/dist/cli/src/builtin/specialExpressions/def.d.ts +2 -1
- package/dist/cli/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/cli/src/builtin/specialExpressions/loops.d.ts +2 -2
- package/dist/cli/src/evaluator/ContextStack.d.ts +2 -4
- package/dist/cli/src/parser/Parser.d.ts +1 -1
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/cli/src/tokenizer/reservedNames.d.ts +0 -16
- package/dist/index.esm.js +350 -1311
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +350 -1311
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +350 -1311
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +2 -2
- package/dist/reference/index.d.ts +3 -5
- package/dist/src/Lits/Lits.d.ts +1 -5
- package/dist/src/builtin/index.d.ts +2 -2
- package/dist/src/builtin/specialExpressionTypes.d.ts +1 -1
- package/dist/src/builtin/specialExpressions/{do.d.ts → block.d.ts} +1 -1
- package/dist/src/builtin/specialExpressions/def.d.ts +2 -1
- package/dist/src/builtin/specialExpressions/functions.d.ts +2 -2
- package/dist/src/builtin/specialExpressions/loops.d.ts +2 -2
- package/dist/src/evaluator/ContextStack.d.ts +2 -4
- package/dist/src/index.d.ts +1 -1
- package/dist/src/parser/Parser.d.ts +1 -1
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/src/tokenizer/reservedNames.d.ts +0 -16
- package/dist/testFramework.esm.js +145 -244
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +145 -244
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -181,7 +181,7 @@ var specialExpressionTypes = {
|
|
|
181
181
|
'0_def': 5,
|
|
182
182
|
'defined?': 6,
|
|
183
183
|
'0_defn': 7,
|
|
184
|
-
'
|
|
184
|
+
'block': 8,
|
|
185
185
|
'doseq': 9,
|
|
186
186
|
'0_fn': 10,
|
|
187
187
|
'for': 11,
|
|
@@ -319,7 +319,7 @@ var getUndefinedSymbols = function (ast, contextStack, builtin, evaluateNode) {
|
|
|
319
319
|
var _b;
|
|
320
320
|
var nodes = Array.isArray(ast)
|
|
321
321
|
? ast
|
|
322
|
-
: [[NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
322
|
+
: [[NodeTypes.SpecialExpression, [specialExpressionTypes.block, ast.body]]];
|
|
323
323
|
var unresolvedSymbols = new Set();
|
|
324
324
|
try {
|
|
325
325
|
for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
|
|
@@ -3455,7 +3455,7 @@ function isIdentical(_a) {
|
|
|
3455
3455
|
return true;
|
|
3456
3456
|
}
|
|
3457
3457
|
var miscNormalExpression = {
|
|
3458
|
-
'
|
|
3458
|
+
'==': {
|
|
3459
3459
|
evaluate: function (params, sourceCodeInfo) {
|
|
3460
3460
|
return isEqual(params, sourceCodeInfo);
|
|
3461
3461
|
},
|
|
@@ -11598,7 +11598,7 @@ var defSpecialExpression = {
|
|
|
11598
11598
|
var bindingValue = evaluateNode(value, contextStack);
|
|
11599
11599
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
11600
11600
|
contextStack.exportValues(values, target[2]);
|
|
11601
|
-
return
|
|
11601
|
+
return bindingValue;
|
|
11602
11602
|
},
|
|
11603
11603
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11604
11604
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
@@ -11647,9 +11647,7 @@ var nonNumberReservedSymbolRecord = {
|
|
|
11647
11647
|
true: true,
|
|
11648
11648
|
false: false,
|
|
11649
11649
|
null: null,
|
|
11650
|
-
then: null,
|
|
11651
11650
|
else: null,
|
|
11652
|
-
end: null,
|
|
11653
11651
|
case: null,
|
|
11654
11652
|
each: null,
|
|
11655
11653
|
in: null,
|
|
@@ -11683,10 +11681,6 @@ var numberReservedSymbolRecord = {
|
|
|
11683
11681
|
'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
|
|
11684
11682
|
'MAX_VALUE': Number.MAX_VALUE,
|
|
11685
11683
|
'MIN_VALUE': Number.MIN_VALUE,
|
|
11686
|
-
'DELTA': Number.EPSILON, // TODO use DELTA instead of DELTA δ
|
|
11687
|
-
'-DELTA': -Number.EPSILON,
|
|
11688
|
-
'δ': Number.EPSILON, // TODO use DELTA instead of DELTA δ
|
|
11689
|
-
'-δ': -Number.EPSILON,
|
|
11690
11684
|
'NaN': Number.NaN,
|
|
11691
11685
|
};
|
|
11692
11686
|
var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
@@ -11729,7 +11723,7 @@ var functionSpecialExpression = {
|
|
|
11729
11723
|
_b.evaluatedfunction = evaluatedFunction,
|
|
11730
11724
|
_b);
|
|
11731
11725
|
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11732
|
-
return
|
|
11726
|
+
return litsFunction;
|
|
11733
11727
|
},
|
|
11734
11728
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11735
11729
|
var _b, _c;
|
|
@@ -11757,7 +11751,7 @@ var defnSpecialExpression = {
|
|
|
11757
11751
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
11758
11752
|
_b);
|
|
11759
11753
|
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
11760
|
-
return
|
|
11754
|
+
return litsFunction;
|
|
11761
11755
|
},
|
|
11762
11756
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11763
11757
|
var _b, _c;
|
|
@@ -11877,7 +11871,7 @@ var letSpecialExpression = {
|
|
|
11877
11871
|
var bindingValue = evaluateNode(value, contextStack);
|
|
11878
11872
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
11879
11873
|
contextStack.addValues(values, target[2]);
|
|
11880
|
-
return
|
|
11874
|
+
return bindingValue;
|
|
11881
11875
|
},
|
|
11882
11876
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
11883
11877
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
@@ -12009,13 +12003,12 @@ function evaluateLoop(returnResult, loopNode, contextStack, evaluateNode) {
|
|
|
12009
12003
|
var bindingIndices = loopBindings.map(function () { return 0; });
|
|
12010
12004
|
var abort = false;
|
|
12011
12005
|
var _loop_1 = function () {
|
|
12012
|
-
var e_2, _b;
|
|
12013
12006
|
var context = {};
|
|
12014
12007
|
var newContextStack = contextStack.create(context);
|
|
12015
12008
|
var skip = false;
|
|
12016
12009
|
bindingsLoop: for (var bindingIndex = 0; bindingIndex < loopBindings.length; bindingIndex += 1) {
|
|
12017
|
-
var
|
|
12018
|
-
var
|
|
12010
|
+
var _b = __read(loopBindings[bindingIndex], 4), bindingNode = _b[0], letBindings = _b[1], whenNode = _b[2], whileNode = _b[3];
|
|
12011
|
+
var _c = __read(bindingNode[1], 2), targetNode = _c[0], valueNode = _c[1];
|
|
12019
12012
|
var coll = asColl(evaluateNode(valueNode, newContextStack), sourceCodeInfo);
|
|
12020
12013
|
var seq = isSeq(coll) ? coll : Object.entries(coll);
|
|
12021
12014
|
if (seq.length === 0) {
|
|
@@ -12055,20 +12048,7 @@ function evaluateLoop(returnResult, loopNode, contextStack, evaluateNode) {
|
|
|
12055
12048
|
}
|
|
12056
12049
|
}
|
|
12057
12050
|
if (!skip) {
|
|
12058
|
-
var value =
|
|
12059
|
-
try {
|
|
12060
|
-
for (var body_1 = (e_2 = void 0, __values(body)), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
12061
|
-
var form = body_1_1.value;
|
|
12062
|
-
value = evaluateNode(form, newContextStack);
|
|
12063
|
-
}
|
|
12064
|
-
}
|
|
12065
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12066
|
-
finally {
|
|
12067
|
-
try {
|
|
12068
|
-
if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
|
|
12069
|
-
}
|
|
12070
|
-
finally { if (e_2) throw e_2.error; }
|
|
12071
|
-
}
|
|
12051
|
+
var value = evaluateNode(body, newContextStack);
|
|
12072
12052
|
if (returnResult)
|
|
12073
12053
|
result.push(value);
|
|
12074
12054
|
if (bindingIndices.length > 0)
|
|
@@ -12111,7 +12091,7 @@ function analyze(loopNode, contextStack, getUndefinedSymbols, builtin, evaluateN
|
|
|
12111
12091
|
});
|
|
12112
12092
|
}
|
|
12113
12093
|
});
|
|
12114
|
-
getUndefinedSymbols(body, contextStack.create(newContext), builtin, evaluateNode).forEach(function (symbol) {
|
|
12094
|
+
getUndefinedSymbols([body], contextStack.create(newContext), builtin, evaluateNode).forEach(function (symbol) {
|
|
12115
12095
|
return result.add(symbol);
|
|
12116
12096
|
});
|
|
12117
12097
|
return result;
|
|
@@ -12421,10 +12401,7 @@ var functionExecutors = {
|
|
|
12421
12401
|
NativeJsFunction: function (fn, params, sourceCodeInfo) {
|
|
12422
12402
|
var _a;
|
|
12423
12403
|
try {
|
|
12424
|
-
|
|
12425
|
-
var clonedParams = JSON.parse(JSON.stringify(params));
|
|
12426
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
|
12427
|
-
return toAny((_a = fn.nativeFn).fn.apply(_a, __spreadArray([], __read(clonedParams), false)));
|
|
12404
|
+
return toAny((_a = fn.nativeFn).fn.apply(_a, __spreadArray([], __read(params), false)));
|
|
12428
12405
|
}
|
|
12429
12406
|
catch (error) {
|
|
12430
12407
|
var message = typeof error === 'string'
|
|
@@ -12829,11 +12806,10 @@ function isContextEntry(value) {
|
|
|
12829
12806
|
|
|
12830
12807
|
var ContextStackImpl = /** @class */ (function () {
|
|
12831
12808
|
function ContextStackImpl(_a) {
|
|
12832
|
-
var contexts = _a.contexts, hostValues = _a.values,
|
|
12809
|
+
var contexts = _a.contexts, hostValues = _a.values, nativeJsFunctions = _a.nativeJsFunctions;
|
|
12833
12810
|
this.globalContext = asNonUndefined(contexts[0]);
|
|
12834
12811
|
this.contexts = contexts;
|
|
12835
12812
|
this.values = hostValues;
|
|
12836
|
-
this.lazyValues = lazyHostValues;
|
|
12837
12813
|
this.nativeJsFunctions = nativeJsFunctions;
|
|
12838
12814
|
}
|
|
12839
12815
|
ContextStackImpl.prototype.create = function (context) {
|
|
@@ -12841,7 +12817,6 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12841
12817
|
var contextStack = new ContextStackImpl({
|
|
12842
12818
|
contexts: __spreadArray([context], __read(this.contexts), false),
|
|
12843
12819
|
values: this.values,
|
|
12844
|
-
lazyValues: this.lazyValues,
|
|
12845
12820
|
nativeJsFunctions: this.nativeJsFunctions,
|
|
12846
12821
|
});
|
|
12847
12822
|
contextStack.globalContext = globalContext;
|
|
@@ -12875,7 +12850,9 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12875
12850
|
}
|
|
12876
12851
|
finally { if (e_1) throw e_1.error; }
|
|
12877
12852
|
}
|
|
12878
|
-
this.
|
|
12853
|
+
if (this.contexts[0] !== this.globalContext) {
|
|
12854
|
+
this.addValues(values, sourceCodeInfo);
|
|
12855
|
+
}
|
|
12879
12856
|
};
|
|
12880
12857
|
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
12881
12858
|
var e_2, _a;
|
|
@@ -12905,10 +12882,10 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12905
12882
|
};
|
|
12906
12883
|
ContextStackImpl.prototype.getValue = function (name) {
|
|
12907
12884
|
var e_3, _a;
|
|
12908
|
-
var _b, _c
|
|
12885
|
+
var _b, _c;
|
|
12909
12886
|
try {
|
|
12910
|
-
for (var
|
|
12911
|
-
var context =
|
|
12887
|
+
for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12888
|
+
var context = _e.value;
|
|
12912
12889
|
var contextEntry = context[name];
|
|
12913
12890
|
if (contextEntry)
|
|
12914
12891
|
return contextEntry.value;
|
|
@@ -12917,26 +12894,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12917
12894
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12918
12895
|
finally {
|
|
12919
12896
|
try {
|
|
12920
|
-
if (
|
|
12897
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
12921
12898
|
}
|
|
12922
12899
|
finally { if (e_3) throw e_3.error; }
|
|
12923
12900
|
}
|
|
12924
|
-
var
|
|
12925
|
-
if (lazyHostValue)
|
|
12926
|
-
return lazyHostValue.read();
|
|
12927
|
-
var nativeJsFunction = (_c = this.nativeJsFunctions) === null || _c === void 0 ? void 0 : _c[name];
|
|
12901
|
+
var nativeJsFunction = (_b = this.nativeJsFunctions) === null || _b === void 0 ? void 0 : _b[name];
|
|
12928
12902
|
if (nativeJsFunction)
|
|
12929
12903
|
return nativeJsFunction;
|
|
12930
|
-
return (
|
|
12904
|
+
return (_c = this.values) === null || _c === void 0 ? void 0 : _c[name];
|
|
12931
12905
|
};
|
|
12932
12906
|
ContextStackImpl.prototype.lookUp = function (node) {
|
|
12933
12907
|
var e_4, _a;
|
|
12934
|
-
var _b, _c
|
|
12908
|
+
var _b, _c;
|
|
12935
12909
|
var value = node[1];
|
|
12936
12910
|
try {
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
var context = _f.value;
|
|
12911
|
+
for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12912
|
+
var context = _e.value;
|
|
12940
12913
|
var contextEntry = context[value];
|
|
12941
12914
|
if (contextEntry)
|
|
12942
12915
|
return contextEntry;
|
|
@@ -12945,23 +12918,17 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12945
12918
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12946
12919
|
finally {
|
|
12947
12920
|
try {
|
|
12948
|
-
if (
|
|
12921
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
12949
12922
|
}
|
|
12950
12923
|
finally { if (e_4) throw e_4.error; }
|
|
12951
12924
|
}
|
|
12952
|
-
var
|
|
12953
|
-
if (lazyHostValue !== undefined) {
|
|
12954
|
-
return {
|
|
12955
|
-
value: toAny(lazyHostValue.read()),
|
|
12956
|
-
};
|
|
12957
|
-
}
|
|
12958
|
-
var hostValue = (_c = this.values) === null || _c === void 0 ? void 0 : _c[value];
|
|
12925
|
+
var hostValue = (_b = this.values) === null || _b === void 0 ? void 0 : _b[value];
|
|
12959
12926
|
if (hostValue !== undefined) {
|
|
12960
12927
|
return {
|
|
12961
12928
|
value: toAny(hostValue),
|
|
12962
12929
|
};
|
|
12963
12930
|
}
|
|
12964
|
-
var nativeJsFunction = (
|
|
12931
|
+
var nativeJsFunction = (_c = this.nativeJsFunctions) === null || _c === void 0 ? void 0 : _c[value];
|
|
12965
12932
|
if (nativeJsFunction) {
|
|
12966
12933
|
return {
|
|
12967
12934
|
value: nativeJsFunction,
|
|
@@ -13017,7 +12984,6 @@ function createContextStack(params) {
|
|
|
13017
12984
|
var contextStack = new ContextStackImpl({
|
|
13018
12985
|
contexts: contexts,
|
|
13019
12986
|
values: params.values,
|
|
13020
|
-
lazyValues: params.lazyValues,
|
|
13021
12987
|
nativeJsFunctions: params.jsFunctions
|
|
13022
12988
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
13023
12989
|
var _b;
|
|
@@ -13040,7 +13006,7 @@ function createContextStack(params) {
|
|
|
13040
13006
|
return acc;
|
|
13041
13007
|
}, {}),
|
|
13042
13008
|
});
|
|
13043
|
-
return contextStack.create({});
|
|
13009
|
+
return params.globalModuleScope ? contextStack : contextStack.create({});
|
|
13044
13010
|
}
|
|
13045
13011
|
|
|
13046
13012
|
var binaryOperators = [
|
|
@@ -13060,7 +13026,7 @@ var binaryOperators = [
|
|
|
13060
13026
|
'>', // greater than
|
|
13061
13027
|
'>=', // greater than or equal
|
|
13062
13028
|
'≥', // greater than or equal
|
|
13063
|
-
'
|
|
13029
|
+
'==', // equal
|
|
13064
13030
|
'!=', // not equal
|
|
13065
13031
|
'≠', // not equal
|
|
13066
13032
|
'&', // bitwise AND
|
|
@@ -13078,7 +13044,8 @@ var otherOperators = [
|
|
|
13078
13044
|
'...', // rest
|
|
13079
13045
|
'.', // property accessor
|
|
13080
13046
|
',', // item separator
|
|
13081
|
-
'
|
|
13047
|
+
'=', // assignment
|
|
13048
|
+
':', // property assignment
|
|
13082
13049
|
';', // statement terminator
|
|
13083
13050
|
];
|
|
13084
13051
|
var symbolicOperators = __spreadArray(__spreadArray([], __read(binaryOperators), false), __read(otherOperators), false);
|
|
@@ -13087,7 +13054,7 @@ var nonFunctionOperators = [
|
|
|
13087
13054
|
'cond',
|
|
13088
13055
|
'def',
|
|
13089
13056
|
'defined?',
|
|
13090
|
-
'
|
|
13057
|
+
'block',
|
|
13091
13058
|
'doseq',
|
|
13092
13059
|
'if',
|
|
13093
13060
|
'let',
|
|
@@ -13287,7 +13254,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
13287
13254
|
return NO_MATCH;
|
|
13288
13255
|
}
|
|
13289
13256
|
var nextChar = input[i];
|
|
13290
|
-
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
13257
|
+
if (nextChar && nextChar !== ':' && !postNumberRegExp.test(nextChar)) {
|
|
13291
13258
|
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
13292
13259
|
}
|
|
13293
13260
|
return [length, ['Number', input.substring(position, i)]];
|
|
@@ -13364,7 +13331,10 @@ var tokenizeSymbol = function (input, position) {
|
|
|
13364
13331
|
position += 1;
|
|
13365
13332
|
char = input[position];
|
|
13366
13333
|
}
|
|
13367
|
-
|
|
13334
|
+
// : can be used as symbol character, but it must not be the last character
|
|
13335
|
+
return value.endsWith(':')
|
|
13336
|
+
? [position - initialPosition - 1, ['Symbol', value.slice(0, -1)]]
|
|
13337
|
+
: [position - initialPosition, ['Symbol', value]];
|
|
13368
13338
|
}
|
|
13369
13339
|
return NO_MATCH;
|
|
13370
13340
|
};
|
|
@@ -13700,7 +13670,7 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13700
13670
|
case '>=': // greater than or equal
|
|
13701
13671
|
case '≥': // greater than or equal
|
|
13702
13672
|
return 7;
|
|
13703
|
-
case '
|
|
13673
|
+
case '==': // equal
|
|
13704
13674
|
case '!=': // not equal
|
|
13705
13675
|
case '≠': // not equal
|
|
13706
13676
|
return 6;
|
|
@@ -13751,7 +13721,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13751
13721
|
case '>':
|
|
13752
13722
|
case '>=':
|
|
13753
13723
|
case '≥':
|
|
13754
|
-
case '
|
|
13724
|
+
case '==':
|
|
13755
13725
|
case '!=':
|
|
13756
13726
|
case '≠':
|
|
13757
13727
|
case '&':
|
|
@@ -13766,12 +13736,12 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13766
13736
|
/* v8 ignore next 11 */
|
|
13767
13737
|
case '.':
|
|
13768
13738
|
case ';':
|
|
13769
|
-
case '
|
|
13739
|
+
case ':':
|
|
13740
|
+
case '=':
|
|
13770
13741
|
case ',':
|
|
13771
13742
|
case '->':
|
|
13772
13743
|
case '...':
|
|
13773
13744
|
case '?':
|
|
13774
|
-
case ':':
|
|
13775
13745
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
13776
13746
|
default:
|
|
13777
13747
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
@@ -13834,9 +13804,9 @@ var Parser = /** @class */ (function () {
|
|
|
13834
13804
|
case 'doseq':
|
|
13835
13805
|
left = this.parseForOrDoseq(firstToken);
|
|
13836
13806
|
break;
|
|
13837
|
-
|
|
13838
|
-
|
|
13839
|
-
|
|
13807
|
+
// cas:
|
|
13808
|
+
// left = this.parseDo(firstToken)
|
|
13809
|
+
// break
|
|
13840
13810
|
case 'loop':
|
|
13841
13811
|
left = this.parseLoop(firstToken);
|
|
13842
13812
|
break;
|
|
@@ -13979,9 +13949,17 @@ var Parser = /** @class */ (function () {
|
|
|
13979
13949
|
throw new LitsError("Illegal operator: ".concat(operatorName), token[2]);
|
|
13980
13950
|
}
|
|
13981
13951
|
}
|
|
13982
|
-
// Object litteral, e.g. {a
|
|
13952
|
+
// Object litteral, e.g. {a: 1, b: 2}
|
|
13953
|
+
// Or block.
|
|
13983
13954
|
if (isLBraceToken(token)) {
|
|
13984
|
-
|
|
13955
|
+
var positionBefore = this.parseState.position;
|
|
13956
|
+
try {
|
|
13957
|
+
return this.parseObject();
|
|
13958
|
+
}
|
|
13959
|
+
catch (_a) {
|
|
13960
|
+
this.parseState.position = positionBefore;
|
|
13961
|
+
return this.parseBlock();
|
|
13962
|
+
}
|
|
13985
13963
|
}
|
|
13986
13964
|
// Array litteral, e.g. [1, 2]
|
|
13987
13965
|
if (isLBracketToken(token)) {
|
|
@@ -14036,7 +14014,7 @@ var Parser = /** @class */ (function () {
|
|
|
14036
14014
|
else {
|
|
14037
14015
|
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
14038
14016
|
}
|
|
14039
|
-
assertOperatorToken(this.peek(), '
|
|
14017
|
+
assertOperatorToken(this.peek(), ':');
|
|
14040
14018
|
this.advance();
|
|
14041
14019
|
params.push(this.parseExpression());
|
|
14042
14020
|
}
|
|
@@ -14257,7 +14235,7 @@ var Parser = /** @class */ (function () {
|
|
|
14257
14235
|
return node;
|
|
14258
14236
|
};
|
|
14259
14237
|
Parser.prototype.parseOptionalDefaulValue = function () {
|
|
14260
|
-
if (isOperatorToken(this.peek(), '
|
|
14238
|
+
if (isOperatorToken(this.peek(), '=')) {
|
|
14261
14239
|
this.advance();
|
|
14262
14240
|
return this.parseExpression();
|
|
14263
14241
|
}
|
|
@@ -14285,7 +14263,7 @@ var Parser = /** @class */ (function () {
|
|
|
14285
14263
|
}
|
|
14286
14264
|
this.advance();
|
|
14287
14265
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
14288
|
-
if (isOperatorToken(this.peek(), '
|
|
14266
|
+
if (isOperatorToken(this.peek(), '=')) {
|
|
14289
14267
|
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
14290
14268
|
}
|
|
14291
14269
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
@@ -14352,11 +14330,11 @@ var Parser = /** @class */ (function () {
|
|
|
14352
14330
|
}
|
|
14353
14331
|
elements[key[1]] = withSourceCodeInfo([bindingTargetTypes.symbol, [name_2, this.parseOptionalDefaulValue()]], firstToken[2]);
|
|
14354
14332
|
}
|
|
14355
|
-
else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, '
|
|
14333
|
+
else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, '=')) {
|
|
14356
14334
|
if (elements[key[1]]) {
|
|
14357
14335
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
14358
14336
|
}
|
|
14359
|
-
if (rest && isOperatorToken(this.peek(), '
|
|
14337
|
+
if (rest && isOperatorToken(this.peek(), '=')) {
|
|
14360
14338
|
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
14361
14339
|
}
|
|
14362
14340
|
elements[key[1]] = rest
|
|
@@ -14382,45 +14360,45 @@ var Parser = /** @class */ (function () {
|
|
|
14382
14360
|
}
|
|
14383
14361
|
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
14384
14362
|
};
|
|
14385
|
-
Parser.prototype.parseLet = function (token
|
|
14386
|
-
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
14363
|
+
Parser.prototype.parseLet = function (token) {
|
|
14387
14364
|
this.advance();
|
|
14388
14365
|
var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
|
|
14389
14366
|
var value = target[1][1];
|
|
14390
14367
|
target[1][1] = undefined;
|
|
14391
|
-
if (!optionalSemicolon) {
|
|
14392
|
-
assertOperatorToken(this.peek(), ';');
|
|
14393
|
-
}
|
|
14394
14368
|
var bindingTarget = withSourceCodeInfo([NodeTypes.Binding, [target, value]], token[2]);
|
|
14395
14369
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.let, bindingTarget]], token[2]);
|
|
14396
14370
|
};
|
|
14397
|
-
Parser.prototype.
|
|
14371
|
+
Parser.prototype.parseBlock = function () {
|
|
14372
|
+
var token = asLBraceToken(this.peek());
|
|
14398
14373
|
this.advance();
|
|
14399
14374
|
var expressions = [];
|
|
14400
|
-
while (!this.isAtEnd() && !
|
|
14375
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14401
14376
|
expressions.push(this.parseExpression());
|
|
14402
14377
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14403
14378
|
this.advance();
|
|
14404
14379
|
}
|
|
14405
|
-
else if (!
|
|
14406
|
-
throw new LitsError('Expected
|
|
14380
|
+
else if (!isRBraceToken(this.peek())) {
|
|
14381
|
+
throw new LitsError('Expected }', this.peekSourceCodeInfo());
|
|
14407
14382
|
}
|
|
14408
14383
|
}
|
|
14409
|
-
|
|
14384
|
+
if (expressions.length === 0) {
|
|
14385
|
+
expressions.push(withSourceCodeInfo([NodeTypes.ReservedSymbol, 'null'], token[2]));
|
|
14386
|
+
}
|
|
14387
|
+
assertRBraceToken(this.peek());
|
|
14410
14388
|
this.advance();
|
|
14411
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14389
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14412
14390
|
};
|
|
14413
14391
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14392
|
+
this.advance();
|
|
14393
|
+
assertLParenToken(this.peek());
|
|
14414
14394
|
this.advance();
|
|
14415
14395
|
var bindingNodes = [];
|
|
14416
14396
|
var token = this.peek();
|
|
14417
|
-
while (!this.isAtEnd() && !
|
|
14418
|
-
assertSymbolToken(token, 'let');
|
|
14419
|
-
this.advance();
|
|
14397
|
+
while (!this.isAtEnd() && !isRParenToken(token)) {
|
|
14420
14398
|
var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
|
|
14421
14399
|
var value = target[1][1];
|
|
14422
14400
|
target[1][1] = undefined;
|
|
14423
|
-
bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]],
|
|
14401
|
+
bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]], target[2]));
|
|
14424
14402
|
if (isOperatorToken(this.peek(), ',')) {
|
|
14425
14403
|
this.advance();
|
|
14426
14404
|
}
|
|
@@ -14429,37 +14407,27 @@ var Parser = /** @class */ (function () {
|
|
|
14429
14407
|
if (bindingNodes.length === 0) {
|
|
14430
14408
|
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
14431
14409
|
}
|
|
14432
|
-
|
|
14410
|
+
assertRParenToken(token);
|
|
14411
|
+
this.advance();
|
|
14412
|
+
assertLBraceToken(this.peek());
|
|
14433
14413
|
this.advance();
|
|
14434
14414
|
var params = [];
|
|
14435
|
-
while (!this.isAtEnd() && !
|
|
14415
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14436
14416
|
params.push(this.parseExpression());
|
|
14437
14417
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14438
14418
|
this.advance();
|
|
14439
14419
|
}
|
|
14440
|
-
else if (!
|
|
14420
|
+
else if (!isRBraceToken(this.peek())) {
|
|
14441
14421
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14442
14422
|
}
|
|
14443
14423
|
}
|
|
14444
|
-
|
|
14424
|
+
assertRBraceToken(this.peek());
|
|
14445
14425
|
this.advance();
|
|
14446
14426
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, params]], firstToken[2]);
|
|
14447
14427
|
};
|
|
14448
14428
|
Parser.prototype.parseTry = function (token) {
|
|
14449
14429
|
this.advance();
|
|
14450
|
-
var
|
|
14451
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14452
|
-
tryExpressions.push(this.parseExpression());
|
|
14453
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14454
|
-
this.advance();
|
|
14455
|
-
}
|
|
14456
|
-
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14457
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14458
|
-
}
|
|
14459
|
-
}
|
|
14460
|
-
var tryExpression = tryExpressions.length === 1
|
|
14461
|
-
? tryExpressions[0]
|
|
14462
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, tryExpressions]], token[2]);
|
|
14430
|
+
var tryExpression = this.parseBlock();
|
|
14463
14431
|
assertReservedSymbolToken(this.peek(), 'catch');
|
|
14464
14432
|
this.advance();
|
|
14465
14433
|
var errorSymbol;
|
|
@@ -14469,26 +14437,14 @@ var Parser = /** @class */ (function () {
|
|
|
14469
14437
|
assertRParenToken(this.peek());
|
|
14470
14438
|
this.advance();
|
|
14471
14439
|
}
|
|
14472
|
-
var
|
|
14473
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14474
|
-
catchExpressions.push(this.parseExpression());
|
|
14475
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14476
|
-
this.advance();
|
|
14477
|
-
}
|
|
14478
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14479
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14480
|
-
}
|
|
14481
|
-
}
|
|
14482
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14483
|
-
this.advance();
|
|
14484
|
-
var catchExpression = catchExpressions.length === 1
|
|
14485
|
-
? catchExpressions[0]
|
|
14486
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, catchExpressions]], token[2]);
|
|
14440
|
+
var catchExpression = this.parseBlock();
|
|
14487
14441
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.try, tryExpression, errorSymbol, catchExpression]], token[2]);
|
|
14488
14442
|
};
|
|
14489
14443
|
Parser.prototype.parseForOrDoseq = function (firstToken) {
|
|
14490
14444
|
var isDoseq = firstToken[1] === 'doseq';
|
|
14491
14445
|
this.advance();
|
|
14446
|
+
assertLParenToken(this.peek());
|
|
14447
|
+
this.advance();
|
|
14492
14448
|
var forLoopBindings = [];
|
|
14493
14449
|
var _loop_1 = function () {
|
|
14494
14450
|
var loopBinding = this_1.parseForLoopBinding();
|
|
@@ -14498,37 +14454,27 @@ var Parser = /** @class */ (function () {
|
|
|
14498
14454
|
throw new LitsError('Duplicate binding', loopBinding[0][2]);
|
|
14499
14455
|
}
|
|
14500
14456
|
forLoopBindings.push(loopBinding);
|
|
14457
|
+
if (isOperatorToken(this_1.peek(), ';')) {
|
|
14458
|
+
this_1.advance();
|
|
14459
|
+
}
|
|
14501
14460
|
};
|
|
14502
14461
|
var this_1 = this;
|
|
14503
|
-
while (!this.isAtEnd() && !
|
|
14462
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
14504
14463
|
_loop_1();
|
|
14505
14464
|
}
|
|
14506
|
-
|
|
14507
|
-
this.advance();
|
|
14508
|
-
var expressions = [];
|
|
14509
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14510
|
-
expressions.push(this.parseExpression());
|
|
14511
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14512
|
-
this.advance();
|
|
14513
|
-
}
|
|
14514
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14515
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14516
|
-
}
|
|
14517
|
-
}
|
|
14518
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14465
|
+
assertRParenToken(this.peek());
|
|
14519
14466
|
this.advance();
|
|
14467
|
+
var expression = this.parseExpression();
|
|
14520
14468
|
return isDoseq
|
|
14521
|
-
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings,
|
|
14522
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.for, forLoopBindings,
|
|
14469
|
+
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expression]], firstToken[2])
|
|
14470
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.for, forLoopBindings, expression]], firstToken[2]);
|
|
14523
14471
|
};
|
|
14524
14472
|
Parser.prototype.parseForLoopBinding = function () {
|
|
14525
|
-
assertReservedSymbolToken(this.peek(), 'each');
|
|
14526
|
-
this.advance();
|
|
14527
14473
|
var bindingNode = this.parseBinding();
|
|
14528
14474
|
var modifiers = [];
|
|
14529
14475
|
var token = this.asToken(this.peek());
|
|
14530
|
-
if (!
|
|
14531
|
-
throw new LitsError('Expected
|
|
14476
|
+
if (!isRParenToken(token) && !isOperatorToken(this.peek(), ';') && !isOperatorToken(token, ',')) {
|
|
14477
|
+
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14532
14478
|
}
|
|
14533
14479
|
if (isOperatorToken(token, ',')) {
|
|
14534
14480
|
this.advance();
|
|
@@ -14537,15 +14483,15 @@ var Parser = /** @class */ (function () {
|
|
|
14537
14483
|
if (!isSymbolToken(token, 'let')
|
|
14538
14484
|
&& !isReservedSymbolToken(token, 'when')
|
|
14539
14485
|
&& !isReservedSymbolToken(token, 'while')
|
|
14540
|
-
&& !
|
|
14541
|
-
&& !
|
|
14542
|
-
throw new LitsError('Expected symbol
|
|
14486
|
+
&& !isRParenToken(token)
|
|
14487
|
+
&& !isOperatorToken(token, ';')) {
|
|
14488
|
+
throw new LitsError('Expected symbol ";", ")", let, when or while', token[2]);
|
|
14543
14489
|
}
|
|
14544
14490
|
var letBindings = [];
|
|
14545
14491
|
if (token[1] === 'let') {
|
|
14546
14492
|
modifiers.push('&let');
|
|
14547
14493
|
var _loop_2 = function () {
|
|
14548
|
-
var letNode = this_2.parseLet(token
|
|
14494
|
+
var letNode = this_2.parseLet(token);
|
|
14549
14495
|
var existingBoundNames = letBindings.flatMap(function (b) { return Object.keys(getAllBindingTargetNames(b[1][0])); });
|
|
14550
14496
|
var newBoundNames = Object.keys(getAllBindingTargetNames(letNode[1][1][1][0]));
|
|
14551
14497
|
if (newBoundNames.some(function (n) { return existingBoundNames.includes(n); })) {
|
|
@@ -14553,8 +14499,8 @@ var Parser = /** @class */ (function () {
|
|
|
14553
14499
|
}
|
|
14554
14500
|
letBindings.push(letNode[1][1]);
|
|
14555
14501
|
token = this_2.asToken(this_2.peek());
|
|
14556
|
-
if (!
|
|
14557
|
-
throw new LitsError('Expected
|
|
14502
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
|
|
14503
|
+
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14558
14504
|
}
|
|
14559
14505
|
if (isOperatorToken(token, ',')) {
|
|
14560
14506
|
this_2.advance();
|
|
@@ -14586,7 +14532,7 @@ var Parser = /** @class */ (function () {
|
|
|
14586
14532
|
whileNode = this.parseExpression();
|
|
14587
14533
|
}
|
|
14588
14534
|
token = this.asToken(this.peek());
|
|
14589
|
-
if (!
|
|
14535
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
|
|
14590
14536
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14591
14537
|
}
|
|
14592
14538
|
if (isOperatorToken(token, ',')) {
|
|
@@ -14594,8 +14540,8 @@ var Parser = /** @class */ (function () {
|
|
|
14594
14540
|
}
|
|
14595
14541
|
token = this.asToken(this.peek());
|
|
14596
14542
|
}
|
|
14597
|
-
if (!
|
|
14598
|
-
throw new LitsError('Expected
|
|
14543
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';')) {
|
|
14544
|
+
throw new LitsError('Expected "{" or ";"', token[2]);
|
|
14599
14545
|
}
|
|
14600
14546
|
return [bindingNode, letBindings, whenNode, whileNode];
|
|
14601
14547
|
};
|
|
@@ -14617,113 +14563,95 @@ var Parser = /** @class */ (function () {
|
|
|
14617
14563
|
Parser.prototype.parseIfOrUnless = function (token) {
|
|
14618
14564
|
var isUnless = token[1] === 'unless';
|
|
14619
14565
|
this.advance();
|
|
14566
|
+
assertLParenToken(this.peek());
|
|
14567
|
+
this.advance();
|
|
14620
14568
|
var condition = this.parseExpression();
|
|
14621
|
-
|
|
14569
|
+
assertRParenToken(this.peek());
|
|
14622
14570
|
this.advance();
|
|
14623
|
-
var
|
|
14624
|
-
while (!this.isAtEnd()
|
|
14625
|
-
&& !isReservedSymbolToken(this.peek(), 'else')
|
|
14626
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14627
|
-
thenExpressions.push(this.parseExpression());
|
|
14628
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14629
|
-
this.advance();
|
|
14630
|
-
}
|
|
14631
|
-
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14632
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14633
|
-
}
|
|
14634
|
-
}
|
|
14635
|
-
var thenExpression = thenExpressions.length === 1
|
|
14636
|
-
? thenExpressions[0]
|
|
14637
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, thenExpressions]], token[2]);
|
|
14571
|
+
var thenExpression = this.parseExpression();
|
|
14638
14572
|
var elseExpression;
|
|
14639
14573
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14640
14574
|
this.advance();
|
|
14641
|
-
|
|
14642
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14643
|
-
elseExpressions.push(this.parseExpression());
|
|
14644
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14645
|
-
this.advance();
|
|
14646
|
-
}
|
|
14647
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14648
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14649
|
-
}
|
|
14650
|
-
}
|
|
14651
|
-
elseExpression = elseExpressions.length === 1
|
|
14652
|
-
? elseExpressions[0]
|
|
14653
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, elseExpressions]], token[2]);
|
|
14575
|
+
elseExpression = this.parseExpression();
|
|
14654
14576
|
}
|
|
14655
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14656
|
-
this.advance();
|
|
14657
14577
|
return isUnless
|
|
14658
14578
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14659
14579
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
14660
14580
|
};
|
|
14661
14581
|
Parser.prototype.parseCond = function (token) {
|
|
14582
|
+
this.advance();
|
|
14583
|
+
assertLBraceToken(this.peek());
|
|
14662
14584
|
this.advance();
|
|
14663
14585
|
var params = [];
|
|
14664
|
-
while (!this.isAtEnd() && !
|
|
14586
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14665
14587
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14666
14588
|
this.advance();
|
|
14667
14589
|
var caseExpression = this.parseExpression();
|
|
14668
|
-
|
|
14590
|
+
assertOperatorToken(this.peek(), ':');
|
|
14669
14591
|
this.advance();
|
|
14670
14592
|
var expressions = [];
|
|
14671
14593
|
while (!this.isAtEnd()
|
|
14672
14594
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14673
|
-
&& !
|
|
14595
|
+
&& !isRBraceToken(this.peek())) {
|
|
14674
14596
|
expressions.push(this.parseExpression());
|
|
14675
14597
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14676
14598
|
this.advance();
|
|
14677
14599
|
}
|
|
14678
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14600
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14679
14601
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14680
14602
|
}
|
|
14681
14603
|
}
|
|
14682
14604
|
var thenExpression = expressions.length === 1
|
|
14683
14605
|
? expressions[0]
|
|
14684
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14606
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14685
14607
|
params.push([caseExpression, thenExpression]);
|
|
14686
|
-
if (
|
|
14608
|
+
if (isRBraceToken(this.peek())) {
|
|
14687
14609
|
break;
|
|
14688
14610
|
}
|
|
14689
14611
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14690
14612
|
}
|
|
14691
|
-
|
|
14613
|
+
assertRBraceToken(this.peek());
|
|
14692
14614
|
this.advance();
|
|
14693
14615
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
|
|
14694
14616
|
};
|
|
14695
14617
|
Parser.prototype.parseSwitch = function (token) {
|
|
14618
|
+
this.advance();
|
|
14619
|
+
assertLParenToken(this.peek());
|
|
14696
14620
|
this.advance();
|
|
14697
14621
|
var valueExpression = this.parseExpression();
|
|
14622
|
+
assertRParenToken(this.peek());
|
|
14623
|
+
this.advance();
|
|
14624
|
+
assertLBraceToken(this.peek());
|
|
14625
|
+
this.advance();
|
|
14698
14626
|
var params = [];
|
|
14699
|
-
while (!this.isAtEnd() && !
|
|
14627
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14700
14628
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14701
14629
|
this.advance();
|
|
14702
14630
|
var caseExpression = this.parseExpression();
|
|
14703
|
-
|
|
14631
|
+
assertOperatorToken(this.peek(), ':');
|
|
14704
14632
|
this.advance();
|
|
14705
14633
|
var expressions = [];
|
|
14706
14634
|
while (!this.isAtEnd()
|
|
14707
14635
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14708
|
-
&& !
|
|
14636
|
+
&& !isRBraceToken(this.peek())) {
|
|
14709
14637
|
expressions.push(this.parseExpression());
|
|
14710
14638
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14711
14639
|
this.advance();
|
|
14712
14640
|
}
|
|
14713
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14641
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14714
14642
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14715
14643
|
}
|
|
14716
14644
|
}
|
|
14717
14645
|
var thenExpression = expressions.length === 1
|
|
14718
14646
|
? expressions[0]
|
|
14719
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14647
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14720
14648
|
params.push([caseExpression, thenExpression]);
|
|
14721
|
-
if (
|
|
14649
|
+
if (isRBraceToken(this.peek())) {
|
|
14722
14650
|
break;
|
|
14723
14651
|
}
|
|
14724
14652
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14725
14653
|
}
|
|
14726
|
-
|
|
14654
|
+
assertRBraceToken(this.peek());
|
|
14727
14655
|
this.advance();
|
|
14728
14656
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
|
|
14729
14657
|
};
|
|
@@ -14731,22 +14659,10 @@ var Parser = /** @class */ (function () {
|
|
|
14731
14659
|
this.advance();
|
|
14732
14660
|
var symbol = this.parseSymbol();
|
|
14733
14661
|
var functionArguments = this.parseFunctionArguments();
|
|
14734
|
-
var
|
|
14735
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14736
|
-
body.push(this.parseExpression());
|
|
14737
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14738
|
-
this.advance();
|
|
14739
|
-
}
|
|
14740
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14741
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14742
|
-
}
|
|
14743
|
-
}
|
|
14744
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14745
|
-
this.advance();
|
|
14746
|
-
assertOperatorToken(this.peek(), ';');
|
|
14662
|
+
var block = this.parseBlock();
|
|
14747
14663
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.function, symbol, [
|
|
14748
14664
|
functionArguments,
|
|
14749
|
-
|
|
14665
|
+
block[1][1],
|
|
14750
14666
|
]]], token[2]);
|
|
14751
14667
|
};
|
|
14752
14668
|
Parser.prototype.isAtEnd = function () {
|
|
@@ -14758,39 +14674,24 @@ var Parser = /** @class */ (function () {
|
|
|
14758
14674
|
}
|
|
14759
14675
|
var token = this.peek();
|
|
14760
14676
|
if (isOperatorToken(token)) {
|
|
14761
|
-
return [';', ',', '
|
|
14677
|
+
return [';', ',', ':'].includes(token[1]);
|
|
14762
14678
|
}
|
|
14763
14679
|
if (isReservedSymbolToken(token)) {
|
|
14764
|
-
return ['else', 'when', 'while', '
|
|
14680
|
+
return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
|
|
14765
14681
|
}
|
|
14766
14682
|
return false;
|
|
14767
14683
|
};
|
|
14768
|
-
Parser.prototype.parseExport = function (
|
|
14684
|
+
Parser.prototype.parseExport = function (exportToken) {
|
|
14769
14685
|
this.advance();
|
|
14770
|
-
|
|
14771
|
-
|
|
14772
|
-
|
|
14773
|
-
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
var
|
|
14777
|
-
|
|
14778
|
-
|
|
14779
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14780
|
-
body.push(this.parseExpression());
|
|
14781
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14782
|
-
this.advance();
|
|
14783
|
-
}
|
|
14784
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14785
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14786
|
-
}
|
|
14787
|
-
}
|
|
14788
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14789
|
-
this.advance();
|
|
14790
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
|
|
14791
|
-
functionArguments,
|
|
14792
|
-
body,
|
|
14793
|
-
]]], token[2]);
|
|
14686
|
+
var token = this.peek();
|
|
14687
|
+
if (isSymbolToken(token, 'let')) {
|
|
14688
|
+
var letNode = this.parseLet(asSymbolToken(token));
|
|
14689
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], exportToken[2]);
|
|
14690
|
+
}
|
|
14691
|
+
else if (isReservedSymbolToken(token, 'function')) {
|
|
14692
|
+
var functionNode = this.parseFunction(token);
|
|
14693
|
+
functionNode[1][0] = specialExpressionTypes['0_defn'];
|
|
14694
|
+
return functionNode;
|
|
14794
14695
|
}
|
|
14795
14696
|
else {
|
|
14796
14697
|
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|