@mojir/lits 2.1.14 → 2.1.16
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 +353 -1311
- 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 +2 -2
|
@@ -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;
|
|
@@ -12826,11 +12806,10 @@ function isContextEntry(value) {
|
|
|
12826
12806
|
|
|
12827
12807
|
var ContextStackImpl = /** @class */ (function () {
|
|
12828
12808
|
function ContextStackImpl(_a) {
|
|
12829
|
-
var contexts = _a.contexts, hostValues = _a.values,
|
|
12809
|
+
var contexts = _a.contexts, hostValues = _a.values, nativeJsFunctions = _a.nativeJsFunctions;
|
|
12830
12810
|
this.globalContext = asNonUndefined(contexts[0]);
|
|
12831
12811
|
this.contexts = contexts;
|
|
12832
12812
|
this.values = hostValues;
|
|
12833
|
-
this.lazyValues = lazyHostValues;
|
|
12834
12813
|
this.nativeJsFunctions = nativeJsFunctions;
|
|
12835
12814
|
}
|
|
12836
12815
|
ContextStackImpl.prototype.create = function (context) {
|
|
@@ -12838,7 +12817,6 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12838
12817
|
var contextStack = new ContextStackImpl({
|
|
12839
12818
|
contexts: __spreadArray([context], __read(this.contexts), false),
|
|
12840
12819
|
values: this.values,
|
|
12841
|
-
lazyValues: this.lazyValues,
|
|
12842
12820
|
nativeJsFunctions: this.nativeJsFunctions,
|
|
12843
12821
|
});
|
|
12844
12822
|
contextStack.globalContext = globalContext;
|
|
@@ -12872,7 +12850,9 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12872
12850
|
}
|
|
12873
12851
|
finally { if (e_1) throw e_1.error; }
|
|
12874
12852
|
}
|
|
12875
|
-
this.
|
|
12853
|
+
if (this.contexts[0] !== this.globalContext) {
|
|
12854
|
+
this.addValues(values, sourceCodeInfo);
|
|
12855
|
+
}
|
|
12876
12856
|
};
|
|
12877
12857
|
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
12878
12858
|
var e_2, _a;
|
|
@@ -12902,10 +12882,10 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12902
12882
|
};
|
|
12903
12883
|
ContextStackImpl.prototype.getValue = function (name) {
|
|
12904
12884
|
var e_3, _a;
|
|
12905
|
-
var _b, _c
|
|
12885
|
+
var _b, _c;
|
|
12906
12886
|
try {
|
|
12907
|
-
for (var
|
|
12908
|
-
var context =
|
|
12887
|
+
for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12888
|
+
var context = _e.value;
|
|
12909
12889
|
var contextEntry = context[name];
|
|
12910
12890
|
if (contextEntry)
|
|
12911
12891
|
return contextEntry.value;
|
|
@@ -12914,26 +12894,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12914
12894
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12915
12895
|
finally {
|
|
12916
12896
|
try {
|
|
12917
|
-
if (
|
|
12897
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
12918
12898
|
}
|
|
12919
12899
|
finally { if (e_3) throw e_3.error; }
|
|
12920
12900
|
}
|
|
12921
|
-
var
|
|
12922
|
-
if (lazyHostValue)
|
|
12923
|
-
return lazyHostValue.read();
|
|
12924
|
-
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];
|
|
12925
12902
|
if (nativeJsFunction)
|
|
12926
12903
|
return nativeJsFunction;
|
|
12927
|
-
return (
|
|
12904
|
+
return (_c = this.values) === null || _c === void 0 ? void 0 : _c[name];
|
|
12928
12905
|
};
|
|
12929
12906
|
ContextStackImpl.prototype.lookUp = function (node) {
|
|
12930
12907
|
var e_4, _a;
|
|
12931
|
-
var _b, _c
|
|
12908
|
+
var _b, _c;
|
|
12932
12909
|
var value = node[1];
|
|
12933
12910
|
try {
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
var context = _f.value;
|
|
12911
|
+
for (var _d = __values(this.contexts), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12912
|
+
var context = _e.value;
|
|
12937
12913
|
var contextEntry = context[value];
|
|
12938
12914
|
if (contextEntry)
|
|
12939
12915
|
return contextEntry;
|
|
@@ -12942,23 +12918,17 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
12942
12918
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12943
12919
|
finally {
|
|
12944
12920
|
try {
|
|
12945
|
-
if (
|
|
12921
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
12946
12922
|
}
|
|
12947
12923
|
finally { if (e_4) throw e_4.error; }
|
|
12948
12924
|
}
|
|
12949
|
-
var
|
|
12950
|
-
if (lazyHostValue !== undefined) {
|
|
12951
|
-
return {
|
|
12952
|
-
value: toAny(lazyHostValue.read()),
|
|
12953
|
-
};
|
|
12954
|
-
}
|
|
12955
|
-
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];
|
|
12956
12926
|
if (hostValue !== undefined) {
|
|
12957
12927
|
return {
|
|
12958
12928
|
value: toAny(hostValue),
|
|
12959
12929
|
};
|
|
12960
12930
|
}
|
|
12961
|
-
var nativeJsFunction = (
|
|
12931
|
+
var nativeJsFunction = (_c = this.nativeJsFunctions) === null || _c === void 0 ? void 0 : _c[value];
|
|
12962
12932
|
if (nativeJsFunction) {
|
|
12963
12933
|
return {
|
|
12964
12934
|
value: nativeJsFunction,
|
|
@@ -13014,7 +12984,6 @@ function createContextStack(params) {
|
|
|
13014
12984
|
var contextStack = new ContextStackImpl({
|
|
13015
12985
|
contexts: contexts,
|
|
13016
12986
|
values: params.values,
|
|
13017
|
-
lazyValues: params.lazyValues,
|
|
13018
12987
|
nativeJsFunctions: params.jsFunctions
|
|
13019
12988
|
&& Object.entries(params.jsFunctions).reduce(function (acc, _a) {
|
|
13020
12989
|
var _b;
|
|
@@ -13037,7 +13006,7 @@ function createContextStack(params) {
|
|
|
13037
13006
|
return acc;
|
|
13038
13007
|
}, {}),
|
|
13039
13008
|
});
|
|
13040
|
-
return contextStack.create({});
|
|
13009
|
+
return params.globalModuleScope ? contextStack : contextStack.create({});
|
|
13041
13010
|
}
|
|
13042
13011
|
|
|
13043
13012
|
var binaryOperators = [
|
|
@@ -13057,7 +13026,7 @@ var binaryOperators = [
|
|
|
13057
13026
|
'>', // greater than
|
|
13058
13027
|
'>=', // greater than or equal
|
|
13059
13028
|
'≥', // greater than or equal
|
|
13060
|
-
'
|
|
13029
|
+
'==', // equal
|
|
13061
13030
|
'!=', // not equal
|
|
13062
13031
|
'≠', // not equal
|
|
13063
13032
|
'&', // bitwise AND
|
|
@@ -13075,7 +13044,8 @@ var otherOperators = [
|
|
|
13075
13044
|
'...', // rest
|
|
13076
13045
|
'.', // property accessor
|
|
13077
13046
|
',', // item separator
|
|
13078
|
-
'
|
|
13047
|
+
'=', // assignment
|
|
13048
|
+
':', // property assignment
|
|
13079
13049
|
';', // statement terminator
|
|
13080
13050
|
];
|
|
13081
13051
|
var symbolicOperators = __spreadArray(__spreadArray([], __read(binaryOperators), false), __read(otherOperators), false);
|
|
@@ -13084,7 +13054,7 @@ var nonFunctionOperators = [
|
|
|
13084
13054
|
'cond',
|
|
13085
13055
|
'def',
|
|
13086
13056
|
'defined?',
|
|
13087
|
-
'
|
|
13057
|
+
'block',
|
|
13088
13058
|
'doseq',
|
|
13089
13059
|
'if',
|
|
13090
13060
|
'let',
|
|
@@ -13284,7 +13254,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
13284
13254
|
return NO_MATCH;
|
|
13285
13255
|
}
|
|
13286
13256
|
var nextChar = input[i];
|
|
13287
|
-
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
13257
|
+
if (nextChar && nextChar !== ':' && !postNumberRegExp.test(nextChar)) {
|
|
13288
13258
|
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
13289
13259
|
}
|
|
13290
13260
|
return [length, ['Number', input.substring(position, i)]];
|
|
@@ -13361,7 +13331,10 @@ var tokenizeSymbol = function (input, position) {
|
|
|
13361
13331
|
position += 1;
|
|
13362
13332
|
char = input[position];
|
|
13363
13333
|
}
|
|
13364
|
-
|
|
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]];
|
|
13365
13338
|
}
|
|
13366
13339
|
return NO_MATCH;
|
|
13367
13340
|
};
|
|
@@ -13697,7 +13670,7 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13697
13670
|
case '>=': // greater than or equal
|
|
13698
13671
|
case '≥': // greater than or equal
|
|
13699
13672
|
return 7;
|
|
13700
|
-
case '
|
|
13673
|
+
case '==': // equal
|
|
13701
13674
|
case '!=': // not equal
|
|
13702
13675
|
case '≠': // not equal
|
|
13703
13676
|
return 6;
|
|
@@ -13748,7 +13721,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13748
13721
|
case '>':
|
|
13749
13722
|
case '>=':
|
|
13750
13723
|
case '≥':
|
|
13751
|
-
case '
|
|
13724
|
+
case '==':
|
|
13752
13725
|
case '!=':
|
|
13753
13726
|
case '≠':
|
|
13754
13727
|
case '&':
|
|
@@ -13763,12 +13736,12 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13763
13736
|
/* v8 ignore next 11 */
|
|
13764
13737
|
case '.':
|
|
13765
13738
|
case ';':
|
|
13766
|
-
case '
|
|
13739
|
+
case ':':
|
|
13740
|
+
case '=':
|
|
13767
13741
|
case ',':
|
|
13768
13742
|
case '->':
|
|
13769
13743
|
case '...':
|
|
13770
13744
|
case '?':
|
|
13771
|
-
case ':':
|
|
13772
13745
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
13773
13746
|
default:
|
|
13774
13747
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
@@ -13831,9 +13804,9 @@ var Parser = /** @class */ (function () {
|
|
|
13831
13804
|
case 'doseq':
|
|
13832
13805
|
left = this.parseForOrDoseq(firstToken);
|
|
13833
13806
|
break;
|
|
13834
|
-
|
|
13835
|
-
|
|
13836
|
-
|
|
13807
|
+
// cas:
|
|
13808
|
+
// left = this.parseDo(firstToken)
|
|
13809
|
+
// break
|
|
13837
13810
|
case 'loop':
|
|
13838
13811
|
left = this.parseLoop(firstToken);
|
|
13839
13812
|
break;
|
|
@@ -13976,9 +13949,17 @@ var Parser = /** @class */ (function () {
|
|
|
13976
13949
|
throw new LitsError("Illegal operator: ".concat(operatorName), token[2]);
|
|
13977
13950
|
}
|
|
13978
13951
|
}
|
|
13979
|
-
// Object litteral, e.g. {a
|
|
13952
|
+
// Object litteral, e.g. {a: 1, b: 2}
|
|
13953
|
+
// Or block.
|
|
13980
13954
|
if (isLBraceToken(token)) {
|
|
13981
|
-
|
|
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
|
+
}
|
|
13982
13963
|
}
|
|
13983
13964
|
// Array litteral, e.g. [1, 2]
|
|
13984
13965
|
if (isLBracketToken(token)) {
|
|
@@ -14033,7 +14014,7 @@ var Parser = /** @class */ (function () {
|
|
|
14033
14014
|
else {
|
|
14034
14015
|
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
14035
14016
|
}
|
|
14036
|
-
assertOperatorToken(this.peek(), '
|
|
14017
|
+
assertOperatorToken(this.peek(), ':');
|
|
14037
14018
|
this.advance();
|
|
14038
14019
|
params.push(this.parseExpression());
|
|
14039
14020
|
}
|
|
@@ -14254,7 +14235,7 @@ var Parser = /** @class */ (function () {
|
|
|
14254
14235
|
return node;
|
|
14255
14236
|
};
|
|
14256
14237
|
Parser.prototype.parseOptionalDefaulValue = function () {
|
|
14257
|
-
if (isOperatorToken(this.peek(), '
|
|
14238
|
+
if (isOperatorToken(this.peek(), '=')) {
|
|
14258
14239
|
this.advance();
|
|
14259
14240
|
return this.parseExpression();
|
|
14260
14241
|
}
|
|
@@ -14282,7 +14263,7 @@ var Parser = /** @class */ (function () {
|
|
|
14282
14263
|
}
|
|
14283
14264
|
this.advance();
|
|
14284
14265
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
14285
|
-
if (isOperatorToken(this.peek(), '
|
|
14266
|
+
if (isOperatorToken(this.peek(), '=')) {
|
|
14286
14267
|
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
14287
14268
|
}
|
|
14288
14269
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
@@ -14349,11 +14330,11 @@ var Parser = /** @class */ (function () {
|
|
|
14349
14330
|
}
|
|
14350
14331
|
elements[key[1]] = withSourceCodeInfo([bindingTargetTypes.symbol, [name_2, this.parseOptionalDefaulValue()]], firstToken[2]);
|
|
14351
14332
|
}
|
|
14352
|
-
else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, '
|
|
14333
|
+
else if (isRBraceToken(token) || isOperatorToken(token, ',') || isOperatorToken(token, '=')) {
|
|
14353
14334
|
if (elements[key[1]]) {
|
|
14354
14335
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
14355
14336
|
}
|
|
14356
|
-
if (rest && isOperatorToken(this.peek(), '
|
|
14337
|
+
if (rest && isOperatorToken(this.peek(), '=')) {
|
|
14357
14338
|
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
14358
14339
|
}
|
|
14359
14340
|
elements[key[1]] = rest
|
|
@@ -14379,45 +14360,45 @@ var Parser = /** @class */ (function () {
|
|
|
14379
14360
|
}
|
|
14380
14361
|
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
14381
14362
|
};
|
|
14382
|
-
Parser.prototype.parseLet = function (token
|
|
14383
|
-
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
14363
|
+
Parser.prototype.parseLet = function (token) {
|
|
14384
14364
|
this.advance();
|
|
14385
14365
|
var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
|
|
14386
14366
|
var value = target[1][1];
|
|
14387
14367
|
target[1][1] = undefined;
|
|
14388
|
-
if (!optionalSemicolon) {
|
|
14389
|
-
assertOperatorToken(this.peek(), ';');
|
|
14390
|
-
}
|
|
14391
14368
|
var bindingTarget = withSourceCodeInfo([NodeTypes.Binding, [target, value]], token[2]);
|
|
14392
14369
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.let, bindingTarget]], token[2]);
|
|
14393
14370
|
};
|
|
14394
|
-
Parser.prototype.
|
|
14371
|
+
Parser.prototype.parseBlock = function () {
|
|
14372
|
+
var token = asLBraceToken(this.peek());
|
|
14395
14373
|
this.advance();
|
|
14396
14374
|
var expressions = [];
|
|
14397
|
-
while (!this.isAtEnd() && !
|
|
14375
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14398
14376
|
expressions.push(this.parseExpression());
|
|
14399
14377
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14400
14378
|
this.advance();
|
|
14401
14379
|
}
|
|
14402
|
-
else if (!
|
|
14403
|
-
throw new LitsError('Expected
|
|
14380
|
+
else if (!isRBraceToken(this.peek())) {
|
|
14381
|
+
throw new LitsError('Expected }', this.peekSourceCodeInfo());
|
|
14404
14382
|
}
|
|
14405
14383
|
}
|
|
14406
|
-
|
|
14384
|
+
if (expressions.length === 0) {
|
|
14385
|
+
expressions.push(withSourceCodeInfo([NodeTypes.ReservedSymbol, 'null'], token[2]));
|
|
14386
|
+
}
|
|
14387
|
+
assertRBraceToken(this.peek());
|
|
14407
14388
|
this.advance();
|
|
14408
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14389
|
+
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14409
14390
|
};
|
|
14410
14391
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14392
|
+
this.advance();
|
|
14393
|
+
assertLParenToken(this.peek());
|
|
14411
14394
|
this.advance();
|
|
14412
14395
|
var bindingNodes = [];
|
|
14413
14396
|
var token = this.peek();
|
|
14414
|
-
while (!this.isAtEnd() && !
|
|
14415
|
-
assertSymbolToken(token, 'let');
|
|
14416
|
-
this.advance();
|
|
14397
|
+
while (!this.isAtEnd() && !isRParenToken(token)) {
|
|
14417
14398
|
var target = this.parseBindingTarget({ requireDefaultValue: true, noRest: true });
|
|
14418
14399
|
var value = target[1][1];
|
|
14419
14400
|
target[1][1] = undefined;
|
|
14420
|
-
bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]],
|
|
14401
|
+
bindingNodes.push(withSourceCodeInfo([NodeTypes.Binding, [target, value]], target[2]));
|
|
14421
14402
|
if (isOperatorToken(this.peek(), ',')) {
|
|
14422
14403
|
this.advance();
|
|
14423
14404
|
}
|
|
@@ -14426,37 +14407,27 @@ var Parser = /** @class */ (function () {
|
|
|
14426
14407
|
if (bindingNodes.length === 0) {
|
|
14427
14408
|
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
14428
14409
|
}
|
|
14429
|
-
|
|
14410
|
+
assertRParenToken(token);
|
|
14411
|
+
this.advance();
|
|
14412
|
+
assertLBraceToken(this.peek());
|
|
14430
14413
|
this.advance();
|
|
14431
14414
|
var params = [];
|
|
14432
|
-
while (!this.isAtEnd() && !
|
|
14415
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14433
14416
|
params.push(this.parseExpression());
|
|
14434
14417
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14435
14418
|
this.advance();
|
|
14436
14419
|
}
|
|
14437
|
-
else if (!
|
|
14420
|
+
else if (!isRBraceToken(this.peek())) {
|
|
14438
14421
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14439
14422
|
}
|
|
14440
14423
|
}
|
|
14441
|
-
|
|
14424
|
+
assertRBraceToken(this.peek());
|
|
14442
14425
|
this.advance();
|
|
14443
14426
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, params]], firstToken[2]);
|
|
14444
14427
|
};
|
|
14445
14428
|
Parser.prototype.parseTry = function (token) {
|
|
14446
14429
|
this.advance();
|
|
14447
|
-
var
|
|
14448
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14449
|
-
tryExpressions.push(this.parseExpression());
|
|
14450
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14451
|
-
this.advance();
|
|
14452
|
-
}
|
|
14453
|
-
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14454
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14455
|
-
}
|
|
14456
|
-
}
|
|
14457
|
-
var tryExpression = tryExpressions.length === 1
|
|
14458
|
-
? tryExpressions[0]
|
|
14459
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, tryExpressions]], token[2]);
|
|
14430
|
+
var tryExpression = this.parseBlock();
|
|
14460
14431
|
assertReservedSymbolToken(this.peek(), 'catch');
|
|
14461
14432
|
this.advance();
|
|
14462
14433
|
var errorSymbol;
|
|
@@ -14466,26 +14437,14 @@ var Parser = /** @class */ (function () {
|
|
|
14466
14437
|
assertRParenToken(this.peek());
|
|
14467
14438
|
this.advance();
|
|
14468
14439
|
}
|
|
14469
|
-
var
|
|
14470
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14471
|
-
catchExpressions.push(this.parseExpression());
|
|
14472
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14473
|
-
this.advance();
|
|
14474
|
-
}
|
|
14475
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14476
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14477
|
-
}
|
|
14478
|
-
}
|
|
14479
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14480
|
-
this.advance();
|
|
14481
|
-
var catchExpression = catchExpressions.length === 1
|
|
14482
|
-
? catchExpressions[0]
|
|
14483
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, catchExpressions]], token[2]);
|
|
14440
|
+
var catchExpression = this.parseBlock();
|
|
14484
14441
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.try, tryExpression, errorSymbol, catchExpression]], token[2]);
|
|
14485
14442
|
};
|
|
14486
14443
|
Parser.prototype.parseForOrDoseq = function (firstToken) {
|
|
14487
14444
|
var isDoseq = firstToken[1] === 'doseq';
|
|
14488
14445
|
this.advance();
|
|
14446
|
+
assertLParenToken(this.peek());
|
|
14447
|
+
this.advance();
|
|
14489
14448
|
var forLoopBindings = [];
|
|
14490
14449
|
var _loop_1 = function () {
|
|
14491
14450
|
var loopBinding = this_1.parseForLoopBinding();
|
|
@@ -14495,37 +14454,27 @@ var Parser = /** @class */ (function () {
|
|
|
14495
14454
|
throw new LitsError('Duplicate binding', loopBinding[0][2]);
|
|
14496
14455
|
}
|
|
14497
14456
|
forLoopBindings.push(loopBinding);
|
|
14457
|
+
if (isOperatorToken(this_1.peek(), ';')) {
|
|
14458
|
+
this_1.advance();
|
|
14459
|
+
}
|
|
14498
14460
|
};
|
|
14499
14461
|
var this_1 = this;
|
|
14500
|
-
while (!this.isAtEnd() && !
|
|
14462
|
+
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
14501
14463
|
_loop_1();
|
|
14502
14464
|
}
|
|
14503
|
-
|
|
14504
|
-
this.advance();
|
|
14505
|
-
var expressions = [];
|
|
14506
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14507
|
-
expressions.push(this.parseExpression());
|
|
14508
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14509
|
-
this.advance();
|
|
14510
|
-
}
|
|
14511
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14512
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14513
|
-
}
|
|
14514
|
-
}
|
|
14515
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14465
|
+
assertRParenToken(this.peek());
|
|
14516
14466
|
this.advance();
|
|
14467
|
+
var expression = this.parseExpression();
|
|
14517
14468
|
return isDoseq
|
|
14518
|
-
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings,
|
|
14519
|
-
: 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]);
|
|
14520
14471
|
};
|
|
14521
14472
|
Parser.prototype.parseForLoopBinding = function () {
|
|
14522
|
-
assertReservedSymbolToken(this.peek(), 'each');
|
|
14523
|
-
this.advance();
|
|
14524
14473
|
var bindingNode = this.parseBinding();
|
|
14525
14474
|
var modifiers = [];
|
|
14526
14475
|
var token = this.asToken(this.peek());
|
|
14527
|
-
if (!
|
|
14528
|
-
throw new LitsError('Expected
|
|
14476
|
+
if (!isRParenToken(token) && !isOperatorToken(this.peek(), ';') && !isOperatorToken(token, ',')) {
|
|
14477
|
+
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14529
14478
|
}
|
|
14530
14479
|
if (isOperatorToken(token, ',')) {
|
|
14531
14480
|
this.advance();
|
|
@@ -14534,15 +14483,15 @@ var Parser = /** @class */ (function () {
|
|
|
14534
14483
|
if (!isSymbolToken(token, 'let')
|
|
14535
14484
|
&& !isReservedSymbolToken(token, 'when')
|
|
14536
14485
|
&& !isReservedSymbolToken(token, 'while')
|
|
14537
|
-
&& !
|
|
14538
|
-
&& !
|
|
14539
|
-
throw new LitsError('Expected symbol
|
|
14486
|
+
&& !isRParenToken(token)
|
|
14487
|
+
&& !isOperatorToken(token, ';')) {
|
|
14488
|
+
throw new LitsError('Expected symbol ";", ")", let, when or while', token[2]);
|
|
14540
14489
|
}
|
|
14541
14490
|
var letBindings = [];
|
|
14542
14491
|
if (token[1] === 'let') {
|
|
14543
14492
|
modifiers.push('&let');
|
|
14544
14493
|
var _loop_2 = function () {
|
|
14545
|
-
var letNode = this_2.parseLet(token
|
|
14494
|
+
var letNode = this_2.parseLet(token);
|
|
14546
14495
|
var existingBoundNames = letBindings.flatMap(function (b) { return Object.keys(getAllBindingTargetNames(b[1][0])); });
|
|
14547
14496
|
var newBoundNames = Object.keys(getAllBindingTargetNames(letNode[1][1][1][0]));
|
|
14548
14497
|
if (newBoundNames.some(function (n) { return existingBoundNames.includes(n); })) {
|
|
@@ -14550,8 +14499,8 @@ var Parser = /** @class */ (function () {
|
|
|
14550
14499
|
}
|
|
14551
14500
|
letBindings.push(letNode[1][1]);
|
|
14552
14501
|
token = this_2.asToken(this_2.peek());
|
|
14553
|
-
if (!
|
|
14554
|
-
throw new LitsError('Expected
|
|
14502
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
|
|
14503
|
+
throw new LitsError('Expected ")", ";" or ","', token[2]);
|
|
14555
14504
|
}
|
|
14556
14505
|
if (isOperatorToken(token, ',')) {
|
|
14557
14506
|
this_2.advance();
|
|
@@ -14583,7 +14532,7 @@ var Parser = /** @class */ (function () {
|
|
|
14583
14532
|
whileNode = this.parseExpression();
|
|
14584
14533
|
}
|
|
14585
14534
|
token = this.asToken(this.peek());
|
|
14586
|
-
if (!
|
|
14535
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
|
|
14587
14536
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14588
14537
|
}
|
|
14589
14538
|
if (isOperatorToken(token, ',')) {
|
|
@@ -14591,8 +14540,8 @@ var Parser = /** @class */ (function () {
|
|
|
14591
14540
|
}
|
|
14592
14541
|
token = this.asToken(this.peek());
|
|
14593
14542
|
}
|
|
14594
|
-
if (!
|
|
14595
|
-
throw new LitsError('Expected
|
|
14543
|
+
if (!isRParenToken(token) && !isOperatorToken(token, ';')) {
|
|
14544
|
+
throw new LitsError('Expected "{" or ";"', token[2]);
|
|
14596
14545
|
}
|
|
14597
14546
|
return [bindingNode, letBindings, whenNode, whileNode];
|
|
14598
14547
|
};
|
|
@@ -14614,113 +14563,95 @@ var Parser = /** @class */ (function () {
|
|
|
14614
14563
|
Parser.prototype.parseIfOrUnless = function (token) {
|
|
14615
14564
|
var isUnless = token[1] === 'unless';
|
|
14616
14565
|
this.advance();
|
|
14566
|
+
assertLParenToken(this.peek());
|
|
14567
|
+
this.advance();
|
|
14617
14568
|
var condition = this.parseExpression();
|
|
14618
|
-
|
|
14569
|
+
assertRParenToken(this.peek());
|
|
14619
14570
|
this.advance();
|
|
14620
|
-
var
|
|
14621
|
-
while (!this.isAtEnd()
|
|
14622
|
-
&& !isReservedSymbolToken(this.peek(), 'else')
|
|
14623
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14624
|
-
thenExpressions.push(this.parseExpression());
|
|
14625
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14626
|
-
this.advance();
|
|
14627
|
-
}
|
|
14628
|
-
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14629
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14630
|
-
}
|
|
14631
|
-
}
|
|
14632
|
-
var thenExpression = thenExpressions.length === 1
|
|
14633
|
-
? thenExpressions[0]
|
|
14634
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, thenExpressions]], token[2]);
|
|
14571
|
+
var thenExpression = this.parseExpression();
|
|
14635
14572
|
var elseExpression;
|
|
14636
14573
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14637
14574
|
this.advance();
|
|
14638
|
-
|
|
14639
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14640
|
-
elseExpressions.push(this.parseExpression());
|
|
14641
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14642
|
-
this.advance();
|
|
14643
|
-
}
|
|
14644
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14645
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14646
|
-
}
|
|
14647
|
-
}
|
|
14648
|
-
elseExpression = elseExpressions.length === 1
|
|
14649
|
-
? elseExpressions[0]
|
|
14650
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.do, elseExpressions]], token[2]);
|
|
14575
|
+
elseExpression = this.parseExpression();
|
|
14651
14576
|
}
|
|
14652
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14653
|
-
this.advance();
|
|
14654
14577
|
return isUnless
|
|
14655
14578
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14656
14579
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
14657
14580
|
};
|
|
14658
14581
|
Parser.prototype.parseCond = function (token) {
|
|
14582
|
+
this.advance();
|
|
14583
|
+
assertLBraceToken(this.peek());
|
|
14659
14584
|
this.advance();
|
|
14660
14585
|
var params = [];
|
|
14661
|
-
while (!this.isAtEnd() && !
|
|
14586
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14662
14587
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14663
14588
|
this.advance();
|
|
14664
14589
|
var caseExpression = this.parseExpression();
|
|
14665
|
-
|
|
14590
|
+
assertOperatorToken(this.peek(), ':');
|
|
14666
14591
|
this.advance();
|
|
14667
14592
|
var expressions = [];
|
|
14668
14593
|
while (!this.isAtEnd()
|
|
14669
14594
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14670
|
-
&& !
|
|
14595
|
+
&& !isRBraceToken(this.peek())) {
|
|
14671
14596
|
expressions.push(this.parseExpression());
|
|
14672
14597
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14673
14598
|
this.advance();
|
|
14674
14599
|
}
|
|
14675
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14600
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14676
14601
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14677
14602
|
}
|
|
14678
14603
|
}
|
|
14679
14604
|
var thenExpression = expressions.length === 1
|
|
14680
14605
|
? expressions[0]
|
|
14681
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14606
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14682
14607
|
params.push([caseExpression, thenExpression]);
|
|
14683
|
-
if (
|
|
14608
|
+
if (isRBraceToken(this.peek())) {
|
|
14684
14609
|
break;
|
|
14685
14610
|
}
|
|
14686
14611
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14687
14612
|
}
|
|
14688
|
-
|
|
14613
|
+
assertRBraceToken(this.peek());
|
|
14689
14614
|
this.advance();
|
|
14690
14615
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
|
|
14691
14616
|
};
|
|
14692
14617
|
Parser.prototype.parseSwitch = function (token) {
|
|
14618
|
+
this.advance();
|
|
14619
|
+
assertLParenToken(this.peek());
|
|
14693
14620
|
this.advance();
|
|
14694
14621
|
var valueExpression = this.parseExpression();
|
|
14622
|
+
assertRParenToken(this.peek());
|
|
14623
|
+
this.advance();
|
|
14624
|
+
assertLBraceToken(this.peek());
|
|
14625
|
+
this.advance();
|
|
14695
14626
|
var params = [];
|
|
14696
|
-
while (!this.isAtEnd() && !
|
|
14627
|
+
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
14697
14628
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14698
14629
|
this.advance();
|
|
14699
14630
|
var caseExpression = this.parseExpression();
|
|
14700
|
-
|
|
14631
|
+
assertOperatorToken(this.peek(), ':');
|
|
14701
14632
|
this.advance();
|
|
14702
14633
|
var expressions = [];
|
|
14703
14634
|
while (!this.isAtEnd()
|
|
14704
14635
|
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14705
|
-
&& !
|
|
14636
|
+
&& !isRBraceToken(this.peek())) {
|
|
14706
14637
|
expressions.push(this.parseExpression());
|
|
14707
14638
|
if (isOperatorToken(this.peek(), ';')) {
|
|
14708
14639
|
this.advance();
|
|
14709
14640
|
}
|
|
14710
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !
|
|
14641
|
+
else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
|
|
14711
14642
|
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14712
14643
|
}
|
|
14713
14644
|
}
|
|
14714
14645
|
var thenExpression = expressions.length === 1
|
|
14715
14646
|
? expressions[0]
|
|
14716
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.
|
|
14647
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14717
14648
|
params.push([caseExpression, thenExpression]);
|
|
14718
|
-
if (
|
|
14649
|
+
if (isRBraceToken(this.peek())) {
|
|
14719
14650
|
break;
|
|
14720
14651
|
}
|
|
14721
14652
|
assertReservedSymbolToken(this.peek(), 'case');
|
|
14722
14653
|
}
|
|
14723
|
-
|
|
14654
|
+
assertRBraceToken(this.peek());
|
|
14724
14655
|
this.advance();
|
|
14725
14656
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
|
|
14726
14657
|
};
|
|
@@ -14728,22 +14659,10 @@ var Parser = /** @class */ (function () {
|
|
|
14728
14659
|
this.advance();
|
|
14729
14660
|
var symbol = this.parseSymbol();
|
|
14730
14661
|
var functionArguments = this.parseFunctionArguments();
|
|
14731
|
-
var
|
|
14732
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14733
|
-
body.push(this.parseExpression());
|
|
14734
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14735
|
-
this.advance();
|
|
14736
|
-
}
|
|
14737
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14738
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14739
|
-
}
|
|
14740
|
-
}
|
|
14741
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14742
|
-
this.advance();
|
|
14743
|
-
assertOperatorToken(this.peek(), ';');
|
|
14662
|
+
var block = this.parseBlock();
|
|
14744
14663
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.function, symbol, [
|
|
14745
14664
|
functionArguments,
|
|
14746
|
-
|
|
14665
|
+
block[1][1],
|
|
14747
14666
|
]]], token[2]);
|
|
14748
14667
|
};
|
|
14749
14668
|
Parser.prototype.isAtEnd = function () {
|
|
@@ -14755,39 +14674,24 @@ var Parser = /** @class */ (function () {
|
|
|
14755
14674
|
}
|
|
14756
14675
|
var token = this.peek();
|
|
14757
14676
|
if (isOperatorToken(token)) {
|
|
14758
|
-
return [';', ',', '
|
|
14677
|
+
return [';', ',', ':'].includes(token[1]);
|
|
14759
14678
|
}
|
|
14760
14679
|
if (isReservedSymbolToken(token)) {
|
|
14761
|
-
return ['else', 'when', 'while', '
|
|
14680
|
+
return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
|
|
14762
14681
|
}
|
|
14763
14682
|
return false;
|
|
14764
14683
|
};
|
|
14765
|
-
Parser.prototype.parseExport = function (
|
|
14684
|
+
Parser.prototype.parseExport = function (exportToken) {
|
|
14766
14685
|
this.advance();
|
|
14767
|
-
|
|
14768
|
-
|
|
14769
|
-
|
|
14770
|
-
|
|
14771
|
-
|
|
14772
|
-
|
|
14773
|
-
var
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14777
|
-
body.push(this.parseExpression());
|
|
14778
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14779
|
-
this.advance();
|
|
14780
|
-
}
|
|
14781
|
-
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14782
|
-
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14783
|
-
}
|
|
14784
|
-
}
|
|
14785
|
-
assertReservedSymbolToken(this.peek(), 'end');
|
|
14786
|
-
this.advance();
|
|
14787
|
-
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
|
|
14788
|
-
functionArguments,
|
|
14789
|
-
body,
|
|
14790
|
-
]]], 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;
|
|
14791
14695
|
}
|
|
14792
14696
|
else {
|
|
14793
14697
|
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|