@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/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "2.1.
|
|
95
|
+
var version = "2.1.34";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -14533,6 +14533,48 @@ var Parser = /** @class */ (function () {
|
|
|
14533
14533
|
docString,
|
|
14534
14534
|
];
|
|
14535
14535
|
};
|
|
14536
|
+
Parser.prototype.parseImplicitBlock = function (ends) {
|
|
14537
|
+
var nodes = [];
|
|
14538
|
+
while (!this.isAtEnd() && !this.isImplicitBlockEnd(ends)) {
|
|
14539
|
+
if (isOperatorToken(this.peek(), ';')) {
|
|
14540
|
+
this.advance();
|
|
14541
|
+
}
|
|
14542
|
+
else {
|
|
14543
|
+
nodes.push(this.parseExpression());
|
|
14544
|
+
}
|
|
14545
|
+
}
|
|
14546
|
+
this.assertImplicitBlockEnd(ends);
|
|
14547
|
+
if (nodes.length === 0) {
|
|
14548
|
+
throw new LitsError('Expected expression', this.peekSourceCodeInfo());
|
|
14549
|
+
}
|
|
14550
|
+
return nodes.length === 1
|
|
14551
|
+
? nodes[0]
|
|
14552
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, nodes]], this.peekSourceCodeInfo());
|
|
14553
|
+
};
|
|
14554
|
+
Parser.prototype.assertImplicitBlockEnd = function (ends) {
|
|
14555
|
+
if (!this.isImplicitBlockEnd(ends)) {
|
|
14556
|
+
throw new LitsError("Expected ".concat(ends.map(function (e) { return e[1]; }).join(' or ')), this.peekSourceCodeInfo());
|
|
14557
|
+
}
|
|
14558
|
+
};
|
|
14559
|
+
Parser.prototype.isImplicitBlockEnd = function (ends) {
|
|
14560
|
+
var e_1, _a;
|
|
14561
|
+
try {
|
|
14562
|
+
for (var ends_1 = __values(ends), ends_1_1 = ends_1.next(); !ends_1_1.done; ends_1_1 = ends_1.next()) {
|
|
14563
|
+
var end = ends_1_1.value;
|
|
14564
|
+
if (isReservedSymbolToken(this.peek(), end)) {
|
|
14565
|
+
return true;
|
|
14566
|
+
}
|
|
14567
|
+
}
|
|
14568
|
+
}
|
|
14569
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
14570
|
+
finally {
|
|
14571
|
+
try {
|
|
14572
|
+
if (ends_1_1 && !ends_1_1.done && (_a = ends_1.return)) _a.call(ends_1);
|
|
14573
|
+
}
|
|
14574
|
+
finally { if (e_1) throw e_1.error; }
|
|
14575
|
+
}
|
|
14576
|
+
return false;
|
|
14577
|
+
};
|
|
14536
14578
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14537
14579
|
this.advance();
|
|
14538
14580
|
assertLParenToken(this.peek());
|
|
@@ -14662,7 +14704,7 @@ var Parser = /** @class */ (function () {
|
|
|
14662
14704
|
}
|
|
14663
14705
|
};
|
|
14664
14706
|
Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14665
|
-
var
|
|
14707
|
+
var e_2, _a;
|
|
14666
14708
|
// end of loop binding
|
|
14667
14709
|
if (isOperatorToken(token, ',') || isRParenToken(token)) {
|
|
14668
14710
|
return true;
|
|
@@ -14678,12 +14720,12 @@ var Parser = /** @class */ (function () {
|
|
|
14678
14720
|
}
|
|
14679
14721
|
}
|
|
14680
14722
|
}
|
|
14681
|
-
catch (
|
|
14723
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
14682
14724
|
finally {
|
|
14683
14725
|
try {
|
|
14684
14726
|
if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
|
|
14685
14727
|
}
|
|
14686
|
-
finally { if (
|
|
14728
|
+
finally { if (e_2) throw e_2.error; }
|
|
14687
14729
|
}
|
|
14688
14730
|
return false;
|
|
14689
14731
|
};
|
|
@@ -14708,12 +14750,13 @@ var Parser = /** @class */ (function () {
|
|
|
14708
14750
|
var condition = this.parseExpression();
|
|
14709
14751
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14710
14752
|
this.advance();
|
|
14711
|
-
var thenExpression = this.
|
|
14753
|
+
var thenExpression = this.parseImplicitBlock(['else', 'end']);
|
|
14712
14754
|
var elseExpression;
|
|
14713
14755
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14714
14756
|
this.advance();
|
|
14715
|
-
elseExpression = this.
|
|
14757
|
+
elseExpression = this.parseImplicitBlock(['end']);
|
|
14716
14758
|
}
|
|
14759
|
+
this.advance();
|
|
14717
14760
|
return isUnless
|
|
14718
14761
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14719
14762
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
@@ -14727,26 +14770,11 @@ var Parser = /** @class */ (function () {
|
|
|
14727
14770
|
var caseExpression = this.parseExpression();
|
|
14728
14771
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14729
14772
|
this.advance();
|
|
14730
|
-
var
|
|
14731
|
-
while (!this.isAtEnd()
|
|
14732
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14733
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14734
|
-
expressions.push(this.parseExpression());
|
|
14735
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14736
|
-
this.advance();
|
|
14737
|
-
}
|
|
14738
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14739
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14740
|
-
}
|
|
14741
|
-
}
|
|
14742
|
-
var thenExpression = expressions.length === 1
|
|
14743
|
-
? expressions[0]
|
|
14744
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14773
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14745
14774
|
params.push([caseExpression, thenExpression]);
|
|
14746
14775
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14747
14776
|
break;
|
|
14748
14777
|
}
|
|
14749
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14750
14778
|
}
|
|
14751
14779
|
assertReservedSymbolToken(this.peek());
|
|
14752
14780
|
this.advance();
|
|
@@ -14762,26 +14790,11 @@ var Parser = /** @class */ (function () {
|
|
|
14762
14790
|
var caseExpression = this.parseExpression();
|
|
14763
14791
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14764
14792
|
this.advance();
|
|
14765
|
-
var
|
|
14766
|
-
while (!this.isAtEnd()
|
|
14767
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14768
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14769
|
-
expressions.push(this.parseExpression());
|
|
14770
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14771
|
-
this.advance();
|
|
14772
|
-
}
|
|
14773
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14774
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14775
|
-
}
|
|
14776
|
-
}
|
|
14777
|
-
var thenExpression = expressions.length === 1
|
|
14778
|
-
? expressions[0]
|
|
14779
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14793
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14780
14794
|
params.push([caseExpression, thenExpression]);
|
|
14781
14795
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14782
14796
|
break;
|
|
14783
14797
|
}
|
|
14784
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14785
14798
|
}
|
|
14786
14799
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
14787
14800
|
this.advance();
|
|
@@ -26788,10 +26801,10 @@ var specialExpressionsReference = {
|
|
|
26788
26801
|
],
|
|
26789
26802
|
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.',
|
|
26790
26803
|
examples: [
|
|
26791
|
-
"\nif true then
|
|
26792
|
-
'if false then write!("TRUE") else write!("FALSE")',
|
|
26793
|
-
'if true then write!("TRUE")',
|
|
26794
|
-
'if false then write!("TRUE")',
|
|
26804
|
+
"\nif true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26805
|
+
'if false then write!("TRUE") else write!("FALSE") end',
|
|
26806
|
+
'if true then write!("TRUE") end',
|
|
26807
|
+
'if false then write!("TRUE") end',
|
|
26795
26808
|
],
|
|
26796
26809
|
},
|
|
26797
26810
|
'unless': {
|
|
@@ -26805,10 +26818,10 @@ var specialExpressionsReference = {
|
|
|
26805
26818
|
],
|
|
26806
26819
|
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.',
|
|
26807
26820
|
examples: [
|
|
26808
|
-
"\nunless true then
|
|
26809
|
-
'unless false then write!("TRUE") else write!("FALSE")',
|
|
26810
|
-
'unless true then write!("TRUE")',
|
|
26811
|
-
'unless false then write!("TRUE")',
|
|
26821
|
+
"\nunless true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26822
|
+
'unless false then write!("TRUE") else write!("FALSE") end',
|
|
26823
|
+
'unless true then write!("TRUE") end',
|
|
26824
|
+
'unless false then write!("TRUE") end',
|
|
26812
26825
|
],
|
|
26813
26826
|
},
|
|
26814
26827
|
'cond': {
|
|
@@ -26862,9 +26875,9 @@ var specialExpressionsReference = {
|
|
|
26862
26875
|
customVariants: ['recur(...recur-args)'],
|
|
26863
26876
|
description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
|
|
26864
26877
|
examples: [
|
|
26865
|
-
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26866
|
-
"\n(n -> {\n write!(n);\n if !(zero?(n)) then
|
|
26867
|
-
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26878
|
+
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n};\nfoo(3)",
|
|
26879
|
+
"\n(n -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n})(3)",
|
|
26880
|
+
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n}",
|
|
26868
26881
|
],
|
|
26869
26882
|
},
|
|
26870
26883
|
};
|
|
@@ -32025,13 +32038,13 @@ var helpRegExp = new RegExp("^`help\\s+(".concat(polishSymbolFirstCharacterClass
|
|
|
32025
32038
|
var expressions = __spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false);
|
|
32026
32039
|
var config = processArguments(process.argv.slice(2));
|
|
32027
32040
|
if (config.eval) {
|
|
32028
|
-
execute(config.eval);
|
|
32029
|
-
process.exit(0);
|
|
32041
|
+
var success = execute(config.eval);
|
|
32042
|
+
process.exit(success ? 0 : 1);
|
|
32030
32043
|
}
|
|
32031
32044
|
else if (config.evalFilename) {
|
|
32032
32045
|
var content = fs.readFileSync(config.evalFilename, { encoding: 'utf-8' });
|
|
32033
|
-
execute(content);
|
|
32034
|
-
process.exit(0);
|
|
32046
|
+
var success = execute(content);
|
|
32047
|
+
process.exit(success ? 0 : 1);
|
|
32035
32048
|
}
|
|
32036
32049
|
else if (config.loadFilename) {
|
|
32037
32050
|
var content = fs.readFileSync(config.loadFilename, { encoding: 'utf-8' });
|
|
@@ -32071,10 +32084,12 @@ function execute(expression) {
|
|
|
32071
32084
|
historyResults.length = 9;
|
|
32072
32085
|
setReplHistoryVariables();
|
|
32073
32086
|
console.log(formatValue(stringifyValue(result, false)));
|
|
32087
|
+
return true;
|
|
32074
32088
|
}
|
|
32075
32089
|
catch (error) {
|
|
32076
32090
|
printErrorMessage("".concat(error));
|
|
32077
32091
|
config.context['*e*'] = { value: getErrorMessage(error) };
|
|
32092
|
+
return false;
|
|
32078
32093
|
}
|
|
32079
32094
|
}
|
|
32080
32095
|
function getErrorMessage(error) {
|
|
@@ -6,6 +6,7 @@ import type { UnlessNode } from '../builtin/specialExpressions/unless';
|
|
|
6
6
|
import type { SymbolToken, Token } from '../tokenizer/token';
|
|
7
7
|
import type { TokenStream } from '../tokenizer/tokenize';
|
|
8
8
|
import { type BindingTarget, type Node, type ParseState } from './types';
|
|
9
|
+
type InternalLoopBindingDelimiter = 'let' | 'when' | 'while';
|
|
9
10
|
export declare class Parser {
|
|
10
11
|
private readonly tokenStream;
|
|
11
12
|
private parseState;
|
|
@@ -29,12 +30,15 @@ export declare class Parser {
|
|
|
29
30
|
private parseBindingTarget;
|
|
30
31
|
private parseLet;
|
|
31
32
|
private parseBlock;
|
|
33
|
+
private parseImplicitBlock;
|
|
34
|
+
private assertImplicitBlockEnd;
|
|
35
|
+
private isImplicitBlockEnd;
|
|
32
36
|
private parseLoop;
|
|
33
37
|
private parseTry;
|
|
34
38
|
private parseForOrDoseq;
|
|
35
39
|
private parseForLoopBinding;
|
|
36
|
-
assertInternalLoopBindingDelimiter(token: Token, symbols:
|
|
37
|
-
isInternalLoopBindingDelimiter(token: Token, symbols:
|
|
40
|
+
assertInternalLoopBindingDelimiter(token: Token, symbols: InternalLoopBindingDelimiter[]): void;
|
|
41
|
+
isInternalLoopBindingDelimiter(token: Token, symbols: InternalLoopBindingDelimiter[]): boolean;
|
|
38
42
|
private parseBinding;
|
|
39
43
|
parseIfOrUnless(token: SymbolToken): IfNode | UnlessNode;
|
|
40
44
|
parseCond(token: SymbolToken): CondNode;
|
|
@@ -51,3 +55,4 @@ export declare class Parser {
|
|
|
51
55
|
private parseString;
|
|
52
56
|
private parseRegexpShorthand;
|
|
53
57
|
}
|
|
58
|
+
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -14559,6 +14559,48 @@ var Parser = /** @class */ (function () {
|
|
|
14559
14559
|
docString,
|
|
14560
14560
|
];
|
|
14561
14561
|
};
|
|
14562
|
+
Parser.prototype.parseImplicitBlock = function (ends) {
|
|
14563
|
+
var nodes = [];
|
|
14564
|
+
while (!this.isAtEnd() && !this.isImplicitBlockEnd(ends)) {
|
|
14565
|
+
if (isOperatorToken(this.peek(), ';')) {
|
|
14566
|
+
this.advance();
|
|
14567
|
+
}
|
|
14568
|
+
else {
|
|
14569
|
+
nodes.push(this.parseExpression());
|
|
14570
|
+
}
|
|
14571
|
+
}
|
|
14572
|
+
this.assertImplicitBlockEnd(ends);
|
|
14573
|
+
if (nodes.length === 0) {
|
|
14574
|
+
throw new LitsError('Expected expression', this.peekSourceCodeInfo());
|
|
14575
|
+
}
|
|
14576
|
+
return nodes.length === 1
|
|
14577
|
+
? nodes[0]
|
|
14578
|
+
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, nodes]], this.peekSourceCodeInfo());
|
|
14579
|
+
};
|
|
14580
|
+
Parser.prototype.assertImplicitBlockEnd = function (ends) {
|
|
14581
|
+
if (!this.isImplicitBlockEnd(ends)) {
|
|
14582
|
+
throw new LitsError("Expected ".concat(ends.map(function (e) { return e[1]; }).join(' or ')), this.peekSourceCodeInfo());
|
|
14583
|
+
}
|
|
14584
|
+
};
|
|
14585
|
+
Parser.prototype.isImplicitBlockEnd = function (ends) {
|
|
14586
|
+
var e_1, _a;
|
|
14587
|
+
try {
|
|
14588
|
+
for (var ends_1 = __values(ends), ends_1_1 = ends_1.next(); !ends_1_1.done; ends_1_1 = ends_1.next()) {
|
|
14589
|
+
var end = ends_1_1.value;
|
|
14590
|
+
if (isReservedSymbolToken(this.peek(), end)) {
|
|
14591
|
+
return true;
|
|
14592
|
+
}
|
|
14593
|
+
}
|
|
14594
|
+
}
|
|
14595
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
14596
|
+
finally {
|
|
14597
|
+
try {
|
|
14598
|
+
if (ends_1_1 && !ends_1_1.done && (_a = ends_1.return)) _a.call(ends_1);
|
|
14599
|
+
}
|
|
14600
|
+
finally { if (e_1) throw e_1.error; }
|
|
14601
|
+
}
|
|
14602
|
+
return false;
|
|
14603
|
+
};
|
|
14562
14604
|
Parser.prototype.parseLoop = function (firstToken) {
|
|
14563
14605
|
this.advance();
|
|
14564
14606
|
assertLParenToken(this.peek());
|
|
@@ -14688,7 +14730,7 @@ var Parser = /** @class */ (function () {
|
|
|
14688
14730
|
}
|
|
14689
14731
|
};
|
|
14690
14732
|
Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
|
|
14691
|
-
var
|
|
14733
|
+
var e_2, _a;
|
|
14692
14734
|
// end of loop binding
|
|
14693
14735
|
if (isOperatorToken(token, ',') || isRParenToken(token)) {
|
|
14694
14736
|
return true;
|
|
@@ -14704,12 +14746,12 @@ var Parser = /** @class */ (function () {
|
|
|
14704
14746
|
}
|
|
14705
14747
|
}
|
|
14706
14748
|
}
|
|
14707
|
-
catch (
|
|
14749
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
14708
14750
|
finally {
|
|
14709
14751
|
try {
|
|
14710
14752
|
if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
|
|
14711
14753
|
}
|
|
14712
|
-
finally { if (
|
|
14754
|
+
finally { if (e_2) throw e_2.error; }
|
|
14713
14755
|
}
|
|
14714
14756
|
return false;
|
|
14715
14757
|
};
|
|
@@ -14734,12 +14776,13 @@ var Parser = /** @class */ (function () {
|
|
|
14734
14776
|
var condition = this.parseExpression();
|
|
14735
14777
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14736
14778
|
this.advance();
|
|
14737
|
-
var thenExpression = this.
|
|
14779
|
+
var thenExpression = this.parseImplicitBlock(['else', 'end']);
|
|
14738
14780
|
var elseExpression;
|
|
14739
14781
|
if (isReservedSymbolToken(this.peek(), 'else')) {
|
|
14740
14782
|
this.advance();
|
|
14741
|
-
elseExpression = this.
|
|
14783
|
+
elseExpression = this.parseImplicitBlock(['end']);
|
|
14742
14784
|
}
|
|
14785
|
+
this.advance();
|
|
14743
14786
|
return isUnless
|
|
14744
14787
|
? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
|
|
14745
14788
|
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
|
|
@@ -14753,26 +14796,11 @@ var Parser = /** @class */ (function () {
|
|
|
14753
14796
|
var caseExpression = this.parseExpression();
|
|
14754
14797
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14755
14798
|
this.advance();
|
|
14756
|
-
var
|
|
14757
|
-
while (!this.isAtEnd()
|
|
14758
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14759
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14760
|
-
expressions.push(this.parseExpression());
|
|
14761
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14762
|
-
this.advance();
|
|
14763
|
-
}
|
|
14764
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14765
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14766
|
-
}
|
|
14767
|
-
}
|
|
14768
|
-
var thenExpression = expressions.length === 1
|
|
14769
|
-
? expressions[0]
|
|
14770
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14799
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14771
14800
|
params.push([caseExpression, thenExpression]);
|
|
14772
14801
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14773
14802
|
break;
|
|
14774
14803
|
}
|
|
14775
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14776
14804
|
}
|
|
14777
14805
|
assertReservedSymbolToken(this.peek());
|
|
14778
14806
|
this.advance();
|
|
@@ -14788,26 +14816,11 @@ var Parser = /** @class */ (function () {
|
|
|
14788
14816
|
var caseExpression = this.parseExpression();
|
|
14789
14817
|
assertReservedSymbolToken(this.peek(), 'then');
|
|
14790
14818
|
this.advance();
|
|
14791
|
-
var
|
|
14792
|
-
while (!this.isAtEnd()
|
|
14793
|
-
&& !isReservedSymbolToken(this.peek(), 'case')
|
|
14794
|
-
&& !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14795
|
-
expressions.push(this.parseExpression());
|
|
14796
|
-
if (isOperatorToken(this.peek(), ';')) {
|
|
14797
|
-
this.advance();
|
|
14798
|
-
}
|
|
14799
|
-
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14800
|
-
throw new LitsError('Expected case or end', this.peekSourceCodeInfo());
|
|
14801
|
-
}
|
|
14802
|
-
}
|
|
14803
|
-
var thenExpression = expressions.length === 1
|
|
14804
|
-
? expressions[0]
|
|
14805
|
-
: withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
|
|
14819
|
+
var thenExpression = this.parseImplicitBlock(['case', 'end']);
|
|
14806
14820
|
params.push([caseExpression, thenExpression]);
|
|
14807
14821
|
if (isReservedSymbolToken(this.peek(), 'end')) {
|
|
14808
14822
|
break;
|
|
14809
14823
|
}
|
|
14810
|
-
assertReservedSymbolToken(this.peek(), 'case');
|
|
14811
14824
|
}
|
|
14812
14825
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
14813
14826
|
this.advance();
|
|
@@ -26835,10 +26848,10 @@ var specialExpressionsReference = {
|
|
|
26835
26848
|
],
|
|
26836
26849
|
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.',
|
|
26837
26850
|
examples: [
|
|
26838
|
-
"\nif true then
|
|
26839
|
-
'if false then write!("TRUE") else write!("FALSE")',
|
|
26840
|
-
'if true then write!("TRUE")',
|
|
26841
|
-
'if false then write!("TRUE")',
|
|
26851
|
+
"\nif true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26852
|
+
'if false then write!("TRUE") else write!("FALSE") end',
|
|
26853
|
+
'if true then write!("TRUE") end',
|
|
26854
|
+
'if false then write!("TRUE") end',
|
|
26842
26855
|
],
|
|
26843
26856
|
},
|
|
26844
26857
|
'unless': {
|
|
@@ -26852,10 +26865,10 @@ var specialExpressionsReference = {
|
|
|
26852
26865
|
],
|
|
26853
26866
|
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.',
|
|
26854
26867
|
examples: [
|
|
26855
|
-
"\nunless true then
|
|
26856
|
-
'unless false then write!("TRUE") else write!("FALSE")',
|
|
26857
|
-
'unless true then write!("TRUE")',
|
|
26858
|
-
'unless false then write!("TRUE")',
|
|
26868
|
+
"\nunless true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
|
|
26869
|
+
'unless false then write!("TRUE") else write!("FALSE") end',
|
|
26870
|
+
'unless true then write!("TRUE") end',
|
|
26871
|
+
'unless false then write!("TRUE") end',
|
|
26859
26872
|
],
|
|
26860
26873
|
},
|
|
26861
26874
|
'cond': {
|
|
@@ -26909,9 +26922,9 @@ var specialExpressionsReference = {
|
|
|
26909
26922
|
customVariants: ['recur(...recur-args)'],
|
|
26910
26923
|
description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
|
|
26911
26924
|
examples: [
|
|
26912
|
-
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26913
|
-
"\n(n -> {\n write!(n);\n if !(zero?(n)) then
|
|
26914
|
-
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then
|
|
26925
|
+
"\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n};\nfoo(3)",
|
|
26926
|
+
"\n(n -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n})(3)",
|
|
26927
|
+
"\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n}",
|
|
26915
26928
|
],
|
|
26916
26929
|
},
|
|
26917
26930
|
};
|