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