@mojir/lits 2.1.33 → 2.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +554 -184
- package/dist/cli/cli.js +68 -53
- package/dist/cli/src/parser/Parser.d.ts +7 -2
- package/dist/index.esm.js +61 -48
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +61 -48
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +61 -48
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/parser/Parser.d.ts +7 -2
- package/dist/testFramework.esm.js +61 -48
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +61 -48
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/lits.iife.js
CHANGED
|
@@ -14562,6 +14562,48 @@ var Lits = (function (exports) {
|
|
|
14562
14562
|
docString,
|
|
14563
14563
|
];
|
|
14564
14564
|
};
|
|
14565
|
+
Parser.prototype.parseImplicitBlock = function (ends) {
|
|
14566
|
+
var nodes = [];
|
|
14567
|
+
while (!this.isAtEnd() && !this.isImplicitBlockEnd(ends)) {
|
|
14568
|
+
if (isOperatorToken(this.peek(), ';')) {
|
|
14569
|
+
this.advance();
|
|
14570
|
+
}
|
|
14571
|
+
else {
|
|
14572
|
+
nodes.push(this.parseExpression());
|
|
14573
|
+
}
|
|
14574
|
+
}
|
|
14575
|
+
this.assertImplicitBlockEnd(ends);
|
|
14576
|
+
if (nodes.length === 0) {
|
|
14577
|
+
throw new LitsError('Expected expression', this.peekSourceCodeInfo());
|
|
14578
|
+
}
|
|
14579
|
+
return nodes.length === 1
|
|
14580
|
+
? nodes[0]
|
|
14581
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, nodes]], this.peekSourceCodeInfo());
|
|
14582
|
+
};
|
|
14583
|
+
Parser.prototype.assertImplicitBlockEnd = function (ends) {
|
|
14584
|
+
if (!this.isImplicitBlockEnd(ends)) {
|
|
14585
|
+
throw new LitsError("Expected ".concat(ends.map(function (e) { return e[1]; }).join(' or ')), this.peekSourceCodeInfo());
|
|
14586
|
+
}
|
|
14587
|
+
};
|
|
14588
|
+
Parser.prototype.isImplicitBlockEnd = function (ends) {
|
|
14589
|
+
var e_1, _a;
|
|
14590
|
+
try {
|
|
14591
|
+
for (var ends_1 = __values(ends), ends_1_1 = ends_1.next(); !ends_1_1.done; ends_1_1 = ends_1.next()) {
|
|
14592
|
+
var end = ends_1_1.value;
|
|
14593
|
+
if (isReservedSymbolToken(this.peek(), end)) {
|
|
14594
|
+
return true;
|
|
14595
|
+
}
|
|
14596
|
+
}
|
|
14597
|
+
}
|
|
14598
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
14599
|
+
finally {
|
|
14600
|
+
try {
|
|
14601
|
+
if (ends_1_1 && !ends_1_1.done && (_a = ends_1.return)) _a.call(ends_1);
|
|
14602
|
+
}
|
|
14603
|
+
finally { if (e_1) throw e_1.error; }
|
|
14604
|
+
}
|
|
14605
|
+
return false;
|
|
14606
|
+
};
|
|
14565
14607
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14566
14608
|
this.advance();
|
|
14567
14609
|
assertLParenToken(this.peek());
|
|
@@ -14691,7 +14733,7 @@ var Lits = (function (exports) {
|
|
|
14691
14733
|
}
|
|
14692
14734
|
};
|
|
14693
14735
|
Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14694
|
-
var
|
|
14736
|
+
var e_2, _a;
|
|
14695
14737
|
// end of loop binding
|
|
14696
14738
|
if (isOperatorToken(token, ',') || isRParenToken(token)) {
|
|
14697
14739
|
return true;
|
|
@@ -14707,12 +14749,12 @@ var Lits = (function (exports) {
|
|
|
14707
14749
|
}
|
|
14708
14750
|
}
|
|
14709
14751
|
}
|
|
14710
|
-
catch (
|
|
14752
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
14711
14753
|
finally {
|
|
14712
14754
|
try {
|
|
14713
14755
|
if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
|
|
14714
14756
|
}
|
|
14715
|
-
finally { if (
|
|
14757
|
+
finally { if (e_2) throw e_2.error; }
|
|
14716
14758
|
}
|
|
14717
14759
|
return false;
|
|
14718
14760
|
};
|
|
@@ -14737,12 +14779,13 @@ var Lits = (function (exports) {
|
|
|
14737
14779
|
var condition = this.parseExpression();
|
|
14738
14780
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14739
14781
|
this.advance();
|
|
14740
|
-
var thenExpression = this.
|
|
14782
|
+
var thenExpression = this.parseImplicitBlock(['else', 'end']);
|
|
14741
14783
|
var elseExpression;
|
|
14742
14784
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14743
14785
|
this.advance();
|
|
14744
|
-
elseExpression = this.
|
|
14786
|
+
elseExpression = this.parseImplicitBlock(['end']);
|
|
14745
14787
|
}
|
|
14788
|
+
this.advance();
|
|
14746
14789
|
return isUnless
|
|
14747
14790
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14748
14791
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
@@ -14756,26 +14799,11 @@ var Lits = (function (exports) {
|
|
|
14756
14799
|
var caseExpression = this.parseExpression();
|
|
14757
14800
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14758
14801
|
this.advance();
|
|
14759
|
-
var
|
|
14760
|
-
while (!this.isAtEnd()
|
|
14761
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14762
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14763
|
-
expressions.push(this.parseExpression());
|
|
14764
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14765
|
-
this.advance();
|
|
14766
|
-
}
|
|
14767
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14768
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14769
|
-
}
|
|
14770
|
-
}
|
|
14771
|
-
var thenExpression = expressions.length === 1
|
|
14772
|
-
? expressions[0]
|
|
14773
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14802
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14774
14803
|
params.push([caseExpression, thenExpression]);
|
|
14775
14804
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14776
14805
|
break;
|
|
14777
14806
|
}
|
|
14778
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14779
14807
|
}
|
|
14780
14808
|
assertReservedSymbolToken(this.peek());
|
|
14781
14809
|
this.advance();
|
|
@@ -14791,26 +14819,11 @@ var Lits = (function (exports) {
|
|
|
14791
14819
|
var caseExpression = this.parseExpression();
|
|
14792
14820
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14793
14821
|
this.advance();
|
|
14794
|
-
var
|
|
14795
|
-
while (!this.isAtEnd()
|
|
14796
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14797
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14798
|
-
expressions.push(this.parseExpression());
|
|
14799
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14800
|
-
this.advance();
|
|
14801
|
-
}
|
|
14802
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14803
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14804
|
-
}
|
|
14805
|
-
}
|
|
14806
|
-
var thenExpression = expressions.length === 1
|
|
14807
|
-
? expressions[0]
|
|
14808
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14822
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14809
14823
|
params.push([caseExpression, thenExpression]);
|
|
14810
14824
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14811
14825
|
break;
|
|
14812
14826
|
}
|
|
14813
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14814
14827
|
}
|
|
14815
14828
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
14816
14829
|
this.advance();
|
|
@@ -26838,10 +26851,10 @@ var Lits = (function (exports) {
|
|
|
26838
26851
|
],
|
|
26839
26852
|
description: 'Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is truthy. If $test is falsy `false-expr` is executed, if no `false-expr` exists, `null` is returned.',
|
|
26840
26853
|
examples: [
|
|
26841
|
-
"\nif true then
|
|
26842
|
-
'if false then write!("TRUE") else write!("FALSE")',
|
|
26843
|
-
'if true then write!("TRUE")',
|
|
26844
|
-
'if false then write!("TRUE")',
|
|
26854
|
+
"\nif true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26855
|
+
'if false then write!("TRUE") else write!("FALSE") end',
|
|
26856
|
+
'if true then write!("TRUE") end',
|
|
26857
|
+
'if false then write!("TRUE") end',
|
|
26845
26858
|
],
|
|
26846
26859
|
},
|
|
26847
26860
|
'unless': {
|
|
@@ -26855,10 +26868,10 @@ var Lits = (function (exports) {
|
|
|
26855
26868
|
],
|
|
26856
26869
|
description: 'Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is falsy. If $test is truthy `false-expr` is executed, if no `false-expr` exists, `null` is returned.',
|
|
26857
26870
|
examples: [
|
|
26858
|
-
"\nunless true then
|
|
26859
|
-
'unless false then write!("TRUE") else write!("FALSE")',
|
|
26860
|
-
'unless true then write!("TRUE")',
|
|
26861
|
-
'unless false then write!("TRUE")',
|
|
26871
|
+
"\nunless true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26872
|
+
'unless false then write!("TRUE") else write!("FALSE") end',
|
|
26873
|
+
'unless true then write!("TRUE") end',
|
|
26874
|
+
'unless false then write!("TRUE") end',
|
|
26862
26875
|
],
|
|
26863
26876
|
},
|
|
26864
26877
|
'cond': {
|
|
@@ -26912,9 +26925,9 @@ var Lits = (function (exports) {
|
|
|
26912
26925
|
customVariants: ['recur(...recur-args)'],
|
|
26913
26926
|
description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
|
|
26914
26927
|
examples: [
|
|
26915
|
-
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26916
|
-
"\n(n -> {\n write!(n);\n if !(zero?(n)) then
|
|
26917
|
-
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26928
|
+
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n};\nfoo(3)",
|
|
26929
|
+
"\n(n -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n})(3)",
|
|
26930
|
+
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n}",
|
|
26918
26931
|
],
|
|
26919
26932
|
},
|
|
26920
26933
|
};
|