@mojir/lits 2.1.32 → 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.
@@ -182,21 +182,21 @@ var specialExpressionTypes = {
182
182
  'cond': 4,
183
183
  '0_def': 5,
184
184
  'defined?': 6,
185
- '0_defn': 7,
186
- 'block': 8,
187
- 'doseq': 9,
188
- '0_fn': 10,
189
- 'for': 11,
190
- 'function': 12,
191
- 'if': 13,
192
- 'let': 14,
193
- 'loop': 15,
194
- 'object': 16,
195
- 'recur': 17,
196
- 'switch': 18,
197
- 'throw': 19,
198
- 'try': 20,
199
- 'unless': 21,
185
+ // '0_defn': 7,
186
+ 'block': 7,
187
+ 'doseq': 8,
188
+ '0_lambda': 9,
189
+ 'for': 10,
190
+ // 'function': 10,
191
+ 'if': 11,
192
+ 'let': 12,
193
+ 'loop': 13,
194
+ 'object': 14,
195
+ 'recur': 15,
196
+ 'switch': 16,
197
+ 'throw': 17,
198
+ 'try': 18,
199
+ 'unless': 19,
200
200
  };
201
201
 
202
202
  var NodeTypes = {
@@ -11780,140 +11780,13 @@ var doSpecialExpression = {
11780
11780
  },
11781
11781
  };
11782
11782
 
11783
- var nonNumberReservedSymbolRecord = {
11784
- true: true,
11785
- false: false,
11786
- null: null,
11787
- else: null,
11788
- case: null,
11789
- each: null,
11790
- in: null,
11791
- when: null,
11792
- while: null,
11793
- catch: null,
11794
- function: null,
11795
- export: null,
11796
- as: null,
11797
- _: null,
11798
- };
11799
- var phi = (1 + Math.sqrt(5)) / 2;
11800
- var numberReservedSymbolRecord = {
11801
- 'E': Math.E,
11802
- '-E': -Math.E,
11803
- 'ε': Math.E,
11804
- '-ε': -Math.E,
11805
- 'PI': Math.PI,
11806
- '-PI': -Math.PI,
11807
- 'π': Math.PI,
11808
- '-π': -Math.PI,
11809
- 'PHI': phi,
11810
- '-PHI': -phi,
11811
- 'φ': phi,
11812
- '-φ': -phi,
11813
- 'POSITIVE_INFINITY': Number.POSITIVE_INFINITY,
11814
- '∞': Number.POSITIVE_INFINITY,
11815
- 'NEGATIVE_INFINITY': Number.NEGATIVE_INFINITY,
11816
- '-∞': Number.NEGATIVE_INFINITY,
11817
- 'MAX_SAFE_INTEGER': Number.MAX_SAFE_INTEGER,
11818
- 'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
11819
- 'MAX_VALUE': Number.MAX_VALUE,
11820
- 'MIN_VALUE': Number.MIN_VALUE,
11821
- 'NaN': Number.NaN,
11822
- };
11823
- var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
11824
- function isReservedSymbol(symbol) {
11825
- return symbol in reservedSymbolRecord;
11826
- }
11827
- function isNumberReservedSymbol(symbol) {
11828
- return symbol in numberReservedSymbolRecord;
11829
- }
11830
-
11831
- function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
11832
- if (typeof name !== 'string')
11833
- return;
11834
- // TODO only subset of special expressions are necessary to check (CommonSpecialExpressionType)
11835
- if (specialExpressionTypes[name])
11836
- throw new LitsError("Cannot define variable ".concat(name, ", it's a special expression."), sourceCodeInfo);
11837
- if (builtin.normalExpressions[name])
11838
- throw new LitsError("Cannot define variable ".concat(name, ", it's a builtin function."), sourceCodeInfo);
11839
- if (isReservedSymbol(name))
11840
- throw new LitsError("Cannot define variable ".concat(name, ", it's a reserved name."), sourceCodeInfo);
11841
- if (contextStack.globalContext[name])
11842
- throw new LitsError("Name already defined \"".concat(name, "\"."), sourceCodeInfo);
11843
- }
11844
-
11845
- var functionSpecialExpression = {
11846
- arity: {},
11847
- evaluate: function (node, contextStack, _a) {
11848
- var _b, _c;
11849
- var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
11850
- var _d = __read(node[1], 4), functionSymbol = _d[1], fn = _d[2], docString = _d[3];
11851
- assertUserDefinedSymbolNode(functionSymbol, node[2]);
11852
- assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
11853
- var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
11854
- var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
11855
- var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
11856
- var arity = { min: min > 0 ? min : undefined, max: max };
11857
- var litsFunction = (_b = {},
11858
- _b[FUNCTION_SYMBOL] = true,
11859
- _b.sourceCodeInfo = node[2],
11860
- _b.functionType = 'UserDefined',
11861
- _b.name = functionSymbol[1],
11862
- _b.evaluatedfunction = evaluatedFunction,
11863
- _b.arity = arity,
11864
- _b.docString = docString,
11865
- _b);
11866
- contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
11867
- return litsFunction;
11868
- },
11869
- getUndefinedSymbols: function (node, contextStack, _a) {
11870
- var _b, _c;
11871
- var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
11872
- var functionName = node[1][1][1];
11873
- contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
11874
- var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
11875
- return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
11876
- },
11877
- };
11878
- var defnSpecialExpression = {
11879
- arity: {},
11880
- evaluate: function (node, contextStack, _a) {
11881
- var _b, _c;
11882
- var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
11883
- var _d = __read(node[1], 4), functionSymbol = _d[1], fn = _d[2], docString = _d[3];
11884
- assertUserDefinedSymbolNode(functionSymbol, node[2]);
11885
- assertNameNotDefined(functionSymbol[1], contextStack, builtin, node[2]);
11886
- var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
11887
- var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
11888
- var arity = { min: min };
11889
- var litsFunction = (_b = {},
11890
- _b[FUNCTION_SYMBOL] = true,
11891
- _b.sourceCodeInfo = node[2],
11892
- _b.functionType = 'UserDefined',
11893
- _b.name = functionSymbol[1],
11894
- _b.evaluatedfunction = evaluatedFunction,
11895
- _b.arity = arity,
11896
- _b.docString = docString,
11897
- _b);
11898
- contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
11899
- return litsFunction;
11900
- },
11901
- getUndefinedSymbols: function (node, contextStack, _a) {
11902
- var _b, _c;
11903
- var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
11904
- var functionName = node[1][1][1];
11905
- var fn = node[1][2];
11906
- contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
11907
- var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
11908
- return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
11909
- },
11910
- };
11911
- var fnSpecialExpression = {
11783
+ var lambdaSpecialExpression = {
11912
11784
  arity: {},
11913
11785
  evaluate: function (node, contextStack, _a) {
11914
11786
  var _b;
11915
11787
  var builtin = _a.builtin, getUndefinedSymbols = _a.getUndefinedSymbols, evaluateNode = _a.evaluateNode;
11916
11788
  var fn = node[1][1];
11789
+ var docString = node[1][2];
11917
11790
  var evaluatedFunction = evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode);
11918
11791
  var min = evaluatedFunction[0].filter(function (arg) { return arg[0] !== bindingTargetTypes.rest && arg[1][1] === undefined; }).length;
11919
11792
  var max = evaluatedFunction[0].some(function (arg) { return arg[0] === bindingTargetTypes.rest; }) ? undefined : evaluatedFunction[0].length;
@@ -11925,8 +11798,9 @@ var fnSpecialExpression = {
11925
11798
  _b.name = undefined,
11926
11799
  _b.evaluatedfunction = evaluatedFunction,
11927
11800
  _b.arity = arity,
11928
- _b.docString = '',
11801
+ _b.docString = docString,
11929
11802
  _b);
11803
+ evaluatedFunction[2].self = { value: litsFunction };
11930
11804
  return litsFunction;
11931
11805
  },
11932
11806
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -11957,17 +11831,16 @@ function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evalua
11957
11831
  ];
11958
11832
  return evaluatedFunction;
11959
11833
  }
11960
- function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
11834
+ function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode) {
11961
11835
  var result = new Set();
11962
- var contextStackWithFunctionName = functionNameContext ? contextStack.create(functionNameContext) : contextStack;
11963
- var newContext = {};
11836
+ var newContext = { self: { value: null } };
11964
11837
  fn[0].forEach(function (arg) {
11965
11838
  Object.assign(newContext, getAllBindingTargetNames(arg));
11966
11839
  walkDefaults(arg, function (defaultNode) {
11967
11840
  addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
11968
11841
  });
11969
11842
  });
11970
- var newContextStack = contextStackWithFunctionName.create(newContext);
11843
+ var newContextStack = contextStack.create(newContext);
11971
11844
  var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
11972
11845
  addToSet(result, overloadResult);
11973
11846
  return result;
@@ -12054,22 +11927,9 @@ var loopSpecialExpression = {
12054
11927
  var newContextStack = contextStack.create(bindingContext);
12055
11928
  var body = node[1][2];
12056
11929
  var _loop_1 = function () {
12057
- var e_1, _b;
12058
11930
  var result = null;
12059
11931
  try {
12060
- try {
12061
- for (var body_1 = (e_1 = void 0, __values(body)), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
12062
- var form = body_1_1.value;
12063
- result = evaluateNode(form, newContextStack);
12064
- }
12065
- }
12066
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
12067
- finally {
12068
- try {
12069
- if (body_1_1 && !body_1_1.done && (_b = body_1.return)) _b.call(body_1);
12070
- }
12071
- finally { if (e_1) throw e_1.error; }
12072
- }
11932
+ result = evaluateNode(body, newContextStack);
12073
11933
  }
12074
11934
  catch (error) {
12075
11935
  if (error instanceof RecurSignal) {
@@ -12078,20 +11938,20 @@ var loopSpecialExpression = {
12078
11938
  throw new LitsError("recur expected ".concat(bindingNodes.length, " parameters, got ").concat(valueToString(params_1.length)), node[2]);
12079
11939
  }
12080
11940
  bindingNodes.forEach(function (bindingNode, index) {
12081
- var e_2, _a;
11941
+ var e_1, _a;
12082
11942
  var valueRecord = evalueateBindingNodeValues(bindingNode[1][0], asAny(params_1[index]), function (Node) { return evaluateNode(Node, contextStack); });
12083
11943
  try {
12084
- for (var _b = (e_2 = void 0, __values(Object.entries(valueRecord))), _c = _b.next(); !_c.done; _c = _b.next()) {
11944
+ for (var _b = (e_1 = void 0, __values(Object.entries(valueRecord))), _c = _b.next(); !_c.done; _c = _b.next()) {
12085
11945
  var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
12086
11946
  bindingContext[name_1].value = value;
12087
11947
  }
12088
11948
  }
12089
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
11949
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
12090
11950
  finally {
12091
11951
  try {
12092
11952
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
12093
11953
  }
12094
- finally { if (e_2) throw e_2.error; }
11954
+ finally { if (e_1) throw e_1.error; }
12095
11955
  }
12096
11956
  });
12097
11957
  return "continue";
@@ -12119,7 +11979,7 @@ var loopSpecialExpression = {
12119
11979
  }, {});
12120
11980
  var bindingValueNodes = bindingNodes.map(function (bindingNode) { return bindingNode[1][1]; });
12121
11981
  var bindingsResult = getUndefinedSymbols(bindingValueNodes, contextStack, builtin, evaluateNode);
12122
- var paramsResult = getUndefinedSymbols(node[1][2], contextStack.create(newContext), builtin, evaluateNode);
11982
+ var paramsResult = getUndefinedSymbols([node[1][2]], contextStack.create(newContext), builtin, evaluateNode);
12123
11983
  return joinSets(bindingsResult, paramsResult);
12124
11984
  },
12125
11985
  };
@@ -12514,12 +12374,12 @@ var specialExpressions = [
12514
12374
  condSpecialExpression,
12515
12375
  defSpecialExpression,
12516
12376
  definedSpecialExpression,
12517
- defnSpecialExpression,
12377
+ // defnSpecialExpression,
12518
12378
  doSpecialExpression,
12519
12379
  doseqSpecialExpression,
12520
- fnSpecialExpression,
12380
+ lambdaSpecialExpression,
12521
12381
  forSpecialExpression,
12522
- functionSpecialExpression,
12382
+ // functionSpecialExpression,
12523
12383
  ifSpecialExpression,
12524
12384
  letSpecialExpression,
12525
12385
  loopSpecialExpression,
@@ -12541,6 +12401,53 @@ new Set(specialExpressionKeys);
12541
12401
  // TODO, remove
12542
12402
  // console.log('builtin', [...specialExpressionKeys, ...normalExpressionKeys].length)
12543
12403
 
12404
+ var nonNumberReservedSymbolRecord = {
12405
+ true: true,
12406
+ false: false,
12407
+ null: null,
12408
+ else: null,
12409
+ case: null,
12410
+ each: null,
12411
+ in: null,
12412
+ when: null,
12413
+ while: null,
12414
+ catch: null,
12415
+ function: null,
12416
+ export: null,
12417
+ as: null,
12418
+ then: null,
12419
+ end: null,
12420
+ _: null,
12421
+ };
12422
+ var phi = (1 + Math.sqrt(5)) / 2;
12423
+ var numberReservedSymbolRecord = {
12424
+ 'E': Math.E,
12425
+ '-E': -Math.E,
12426
+ 'ε': Math.E,
12427
+ '-ε': -Math.E,
12428
+ 'PI': Math.PI,
12429
+ '-PI': -Math.PI,
12430
+ 'π': Math.PI,
12431
+ '-π': -Math.PI,
12432
+ 'PHI': phi,
12433
+ '-PHI': -phi,
12434
+ 'φ': phi,
12435
+ '-φ': -phi,
12436
+ 'POSITIVE_INFINITY': Number.POSITIVE_INFINITY,
12437
+ '∞': Number.POSITIVE_INFINITY,
12438
+ 'NEGATIVE_INFINITY': Number.NEGATIVE_INFINITY,
12439
+ '-∞': Number.NEGATIVE_INFINITY,
12440
+ 'MAX_SAFE_INTEGER': Number.MAX_SAFE_INTEGER,
12441
+ 'MIN_SAFE_INTEGER': Number.MIN_SAFE_INTEGER,
12442
+ 'MAX_VALUE': Number.MAX_VALUE,
12443
+ 'MIN_VALUE': Number.MIN_VALUE,
12444
+ 'NaN': Number.NaN,
12445
+ };
12446
+ var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
12447
+ function isNumberReservedSymbol(symbol) {
12448
+ return symbol in numberReservedSymbolRecord;
12449
+ }
12450
+
12544
12451
  var functionExecutors = {
12545
12452
  NativeJsFunction: function (fn, params, sourceCodeInfo) {
12546
12453
  var _a;
@@ -12989,6 +12896,9 @@ var ContextStackImpl = /** @class */ (function () {
12989
12896
  if (normalExpressionKeys.includes(name_1)) {
12990
12897
  throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
12991
12898
  }
12899
+ if (name_1 === 'self') {
12900
+ throw new LitsError("Cannot shadow builtin value \"".concat(name_1, "\""), sourceCodeInfo);
12901
+ }
12992
12902
  this.globalContext[name_1] = { value: value };
12993
12903
  }
12994
12904
  }
@@ -13018,6 +12928,9 @@ var ContextStackImpl = /** @class */ (function () {
13018
12928
  if (normalExpressionKeys.includes(name_2)) {
13019
12929
  throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
13020
12930
  }
12931
+ if (name_2 === 'self') {
12932
+ throw new LitsError("Cannot shadow builtin value \"".concat(name_2, "\""), sourceCodeInfo);
12933
+ }
13021
12934
  currentContext[name_2] = { value: toAny(value) };
13022
12935
  }
13023
12936
  }
@@ -14013,9 +13926,6 @@ var Parser = /** @class */ (function () {
14013
13926
  break;
14014
13927
  }
14015
13928
  }
14016
- else if (isReservedSymbolToken(firstToken, 'function')) {
14017
- return this.parseFunction(firstToken);
14018
- }
14019
13929
  else if (isReservedSymbolToken(firstToken, 'export')) {
14020
13930
  if (!moduleScope) {
14021
13931
  throw new LitsError('export is only allowed in module scope', firstToken[2]);
@@ -14308,9 +14218,8 @@ var Parser = /** @class */ (function () {
14308
14218
  var _c = __read(params, 1), param = _c[0];
14309
14219
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
14310
14220
  }
14311
- case specialExpressionTypes['0_fn']:
14221
+ case specialExpressionTypes['0_lambda']:
14312
14222
  case specialExpressionTypes['0_def']:
14313
- case specialExpressionTypes['0_defn']:
14314
14223
  throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
14315
14224
  /* v8 ignore next 2 */
14316
14225
  default:
@@ -14337,11 +14246,27 @@ var Parser = /** @class */ (function () {
14337
14246
  return null;
14338
14247
  }
14339
14248
  this.advance();
14340
- var body = this.parseExpression();
14341
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
14249
+ var nodes = void 0;
14250
+ var docString = '';
14251
+ if (isLBraceToken(this.peek())) {
14252
+ var parsedBlock = this.parseBlock(true);
14253
+ docString = parsedBlock[1];
14254
+ nodes = parsedBlock[0][1][1];
14255
+ }
14256
+ else {
14257
+ nodes = [this.parseExpression()];
14258
+ }
14259
+ return withSourceCodeInfo([
14260
+ NodeTypes.SpecialExpression,
14261
+ [
14262
+ specialExpressionTypes['0_lambda'],
14263
+ [
14342
14264
  functionArguments,
14343
- [body],
14344
- ]]], firstToken[2]);
14265
+ nodes,
14266
+ ],
14267
+ docString,
14268
+ ],
14269
+ ], firstToken[2]);
14345
14270
  }
14346
14271
  catch (_a) {
14347
14272
  return null;
@@ -14390,7 +14315,16 @@ var Parser = /** @class */ (function () {
14390
14315
  var firstToken = this.asToken(this.peek());
14391
14316
  this.advance();
14392
14317
  var startPos = this.parseState.position;
14393
- var exprNode = this.parseExpression();
14318
+ var nodes;
14319
+ var docString = '';
14320
+ if (isLBraceToken(this.peek())) {
14321
+ var parsedBlock = this.parseBlock(true);
14322
+ docString = parsedBlock[1];
14323
+ nodes = parsedBlock[0][1][1];
14324
+ }
14325
+ else {
14326
+ nodes = [this.parseExpression()];
14327
+ }
14394
14328
  var endPos = this.parseState.position - 1;
14395
14329
  var arity = 0;
14396
14330
  var dollar1 = 'NOT_SET'; // referring to argument bindings. $ = NAKED, $1, $2, $3, etc = WITH_1
@@ -14421,10 +14355,10 @@ var Parser = /** @class */ (function () {
14421
14355
  functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
14422
14356
  }
14423
14357
  }
14424
- var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
14358
+ var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_lambda'], [
14425
14359
  functionArguments,
14426
- [exprNode],
14427
- ]]], firstToken[2]);
14360
+ nodes,
14361
+ ], docString]], firstToken[2]);
14428
14362
  return node;
14429
14363
  };
14430
14364
  Parser.prototype.parseOptionalDefaulValue = function () {
@@ -14594,6 +14528,48 @@ var Parser = /** @class */ (function () {
14594
14528
  docString,
14595
14529
  ];
14596
14530
  };
14531
+ Parser.prototype.parseImplicitBlock = function (ends) {
14532
+ var nodes = [];
14533
+ while (!this.isAtEnd() && !this.isImplicitBlockEnd(ends)) {
14534
+ if (isOperatorToken(this.peek(), ';')) {
14535
+ this.advance();
14536
+ }
14537
+ else {
14538
+ nodes.push(this.parseExpression());
14539
+ }
14540
+ }
14541
+ this.assertImplicitBlockEnd(ends);
14542
+ if (nodes.length === 0) {
14543
+ throw new LitsError('Expected expression', this.peekSourceCodeInfo());
14544
+ }
14545
+ return nodes.length === 1
14546
+ ? nodes[0]
14547
+ : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, nodes]], this.peekSourceCodeInfo());
14548
+ };
14549
+ Parser.prototype.assertImplicitBlockEnd = function (ends) {
14550
+ if (!this.isImplicitBlockEnd(ends)) {
14551
+ throw new LitsError("Expected ".concat(ends.map(function (e) { return e[1]; }).join(' or ')), this.peekSourceCodeInfo());
14552
+ }
14553
+ };
14554
+ Parser.prototype.isImplicitBlockEnd = function (ends) {
14555
+ var e_1, _a;
14556
+ try {
14557
+ for (var ends_1 = __values(ends), ends_1_1 = ends_1.next(); !ends_1_1.done; ends_1_1 = ends_1.next()) {
14558
+ var end = ends_1_1.value;
14559
+ if (isReservedSymbolToken(this.peek(), end)) {
14560
+ return true;
14561
+ }
14562
+ }
14563
+ }
14564
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
14565
+ finally {
14566
+ try {
14567
+ if (ends_1_1 && !ends_1_1.done && (_a = ends_1.return)) _a.call(ends_1);
14568
+ }
14569
+ finally { if (e_1) throw e_1.error; }
14570
+ }
14571
+ return false;
14572
+ };
14597
14573
  Parser.prototype.parseLoop = function (firstToken) {
14598
14574
  this.advance();
14599
14575
  assertLParenToken(this.peek());
@@ -14615,21 +14591,10 @@ var Parser = /** @class */ (function () {
14615
14591
  }
14616
14592
  assertRParenToken(token);
14617
14593
  this.advance();
14618
- assertLBraceToken(this.peek());
14619
- this.advance();
14620
- var params = [];
14621
- while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14622
- params.push(this.parseExpression());
14623
- if (isOperatorToken(this.peek(), ';')) {
14624
- this.advance();
14625
- }
14626
- else if (!isRBraceToken(this.peek())) {
14627
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14628
- }
14629
- }
14630
- assertRBraceToken(this.peek());
14594
+ assertOperatorToken(this.peek(), '->');
14631
14595
  this.advance();
14632
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, params]], firstToken[2]);
14596
+ var expression = this.parseExpression();
14597
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.loop, bindingNodes, expression]], firstToken[2]);
14633
14598
  };
14634
14599
  Parser.prototype.parseTry = function (token) {
14635
14600
  this.advance();
@@ -14660,7 +14625,7 @@ var Parser = /** @class */ (function () {
14660
14625
  throw new LitsError('Duplicate binding', loopBinding[0][2]);
14661
14626
  }
14662
14627
  forLoopBindings.push(loopBinding);
14663
- if (isOperatorToken(this_1.peek(), ';')) {
14628
+ if (isOperatorToken(this_1.peek(), ',')) {
14664
14629
  this_1.advance();
14665
14630
  }
14666
14631
  };
@@ -14670,6 +14635,8 @@ var Parser = /** @class */ (function () {
14670
14635
  }
14671
14636
  assertRParenToken(this.peek());
14672
14637
  this.advance();
14638
+ assertOperatorToken(this.peek(), '->');
14639
+ this.advance();
14673
14640
  var expression = this.parseExpression();
14674
14641
  return isDoseq
14675
14642
  ? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.doseq, forLoopBindings, expression]], firstToken[2])
@@ -14679,20 +14646,7 @@ var Parser = /** @class */ (function () {
14679
14646
  var bindingNode = this.parseBinding();
14680
14647
  var modifiers = [];
14681
14648
  var token = this.asToken(this.peek());
14682
- if (!isRParenToken(token) && !isOperatorToken(this.peek(), ';') && !isOperatorToken(token, ',')) {
14683
- throw new LitsError('Expected ")", ";" or ","', token[2]);
14684
- }
14685
- if (isOperatorToken(token, ',')) {
14686
- this.advance();
14687
- token = this.asToken(this.peek());
14688
- }
14689
- if (!isSymbolToken(token, 'let')
14690
- && !isReservedSymbolToken(token, 'when')
14691
- && !isReservedSymbolToken(token, 'while')
14692
- && !isRParenToken(token)
14693
- && !isOperatorToken(token, ';')) {
14694
- throw new LitsError('Expected symbol ";", ")", let, when or while', token[2]);
14695
- }
14649
+ this.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
14696
14650
  var letBindings = [];
14697
14651
  if (token[1] === 'let') {
14698
14652
  modifiers.push('&let');
@@ -14705,12 +14659,7 @@ var Parser = /** @class */ (function () {
14705
14659
  }
14706
14660
  letBindings.push(letNode[1][1]);
14707
14661
  token = this_2.asToken(this_2.peek());
14708
- if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
14709
- throw new LitsError('Expected ")", ";" or ","', token[2]);
14710
- }
14711
- if (isOperatorToken(token, ',')) {
14712
- this_2.advance();
14713
- }
14662
+ this_2.assertInternalLoopBindingDelimiter(token, ['let', 'when', 'while']);
14714
14663
  token = this_2.asToken(this_2.peek());
14715
14664
  };
14716
14665
  var this_2 = this;
@@ -14724,33 +14673,57 @@ var Parser = /** @class */ (function () {
14724
14673
  || isReservedSymbolToken(token, 'while')) {
14725
14674
  this.advance();
14726
14675
  if (token[1] === 'when') {
14727
- if (modifiers.includes('&when')) {
14728
- throw new LitsError('Multiple when modifiers in for loop', token[2]);
14729
- }
14730
14676
  modifiers.push('&when');
14731
14677
  whenNode = this.parseExpression();
14732
14678
  }
14733
14679
  else {
14734
- if (modifiers.includes('&while')) {
14735
- throw new LitsError('Multiple while modifiers in for loop', token[2]);
14736
- }
14737
14680
  modifiers.push('&while');
14738
14681
  whileNode = this.parseExpression();
14739
14682
  }
14740
14683
  token = this.asToken(this.peek());
14741
- if (!isRParenToken(token) && !isOperatorToken(token, ';') && !isOperatorToken(token, ',')) {
14742
- throw new LitsError('Expected do or comma', token[2]);
14743
- }
14744
- if (isOperatorToken(token, ',')) {
14745
- this.advance();
14746
- }
14684
+ var symbols = modifiers.includes('&when') && modifiers.includes('&while')
14685
+ ? []
14686
+ : modifiers.includes('&when')
14687
+ ? ['while']
14688
+ : ['when'];
14689
+ this.assertInternalLoopBindingDelimiter(token, symbols);
14747
14690
  token = this.asToken(this.peek());
14748
14691
  }
14749
- if (!isRParenToken(token) && !isOperatorToken(token, ';')) {
14750
- throw new LitsError('Expected "{" or ";"', token[2]);
14751
- }
14692
+ this.assertInternalLoopBindingDelimiter(token, []);
14752
14693
  return [bindingNode, letBindings, whenNode, whileNode];
14753
14694
  };
14695
+ Parser.prototype.assertInternalLoopBindingDelimiter = function (token, symbols) {
14696
+ if (!this.isInternalLoopBindingDelimiter(token, symbols)) {
14697
+ var symbolsString = "".concat(__spreadArray(__spreadArray([], __read(symbols), false), [','], false).map(function (symbol) { return "\"".concat(symbol, "\""); }).join(', '), " or \")\"");
14698
+ throw new LitsError("Expected symbol ".concat(symbolsString), token[2]);
14699
+ }
14700
+ };
14701
+ Parser.prototype.isInternalLoopBindingDelimiter = function (token, symbols) {
14702
+ var e_2, _a;
14703
+ // end of loop binding
14704
+ if (isOperatorToken(token, ',') || isRParenToken(token)) {
14705
+ return true;
14706
+ }
14707
+ try {
14708
+ for (var symbols_1 = __values(symbols), symbols_1_1 = symbols_1.next(); !symbols_1_1.done; symbols_1_1 = symbols_1.next()) {
14709
+ var symbol = symbols_1_1.value;
14710
+ if (symbol === 'let' && isSymbolToken(token, 'let')) {
14711
+ return true;
14712
+ }
14713
+ if (['when', 'while'].includes(symbol) && isReservedSymbolToken(token, symbol)) {
14714
+ return true;
14715
+ }
14716
+ }
14717
+ }
14718
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
14719
+ finally {
14720
+ try {
14721
+ if (symbols_1_1 && !symbols_1_1.done && (_a = symbols_1.return)) _a.call(symbols_1);
14722
+ }
14723
+ finally { if (e_2) throw e_2.error; }
14724
+ }
14725
+ return false;
14726
+ };
14754
14727
  Parser.prototype.parseBinding = function () {
14755
14728
  var firstToken = asSymbolToken(this.peek());
14756
14729
  var name = asUserDefinedSymbolNode(this.parseSymbol());
@@ -14769,116 +14742,59 @@ var Parser = /** @class */ (function () {
14769
14742
  Parser.prototype.parseIfOrUnless = function (token) {
14770
14743
  var isUnless = token[1] === 'unless';
14771
14744
  this.advance();
14772
- assertLParenToken(this.peek());
14773
- this.advance();
14774
14745
  var condition = this.parseExpression();
14775
- assertRParenToken(this.peek());
14746
+ assertReservedSymbolToken(this.peek(), 'then');
14776
14747
  this.advance();
14777
- var thenExpression = this.parseExpression();
14748
+ var thenExpression = this.parseImplicitBlock(['else', 'end']);
14778
14749
  var elseExpression;
14779
14750
  if (isReservedSymbolToken(this.peek(), 'else')) {
14780
14751
  this.advance();
14781
- elseExpression = this.parseExpression();
14752
+ elseExpression = this.parseImplicitBlock(['end']);
14782
14753
  }
14754
+ this.advance();
14783
14755
  return isUnless
14784
14756
  ? withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.unless, [condition, thenExpression, elseExpression]]], token[2])
14785
14757
  : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [condition, thenExpression, elseExpression]]], token[2]);
14786
14758
  };
14787
14759
  Parser.prototype.parseCond = function (token) {
14788
- this.advance();
14789
- assertLBraceToken(this.peek());
14790
14760
  this.advance();
14791
14761
  var params = [];
14792
- while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14762
+ while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14793
14763
  assertReservedSymbolToken(this.peek(), 'case');
14794
14764
  this.advance();
14795
14765
  var caseExpression = this.parseExpression();
14796
- assertOperatorToken(this.peek(), ':');
14766
+ assertReservedSymbolToken(this.peek(), 'then');
14797
14767
  this.advance();
14798
- var expressions = [];
14799
- while (!this.isAtEnd()
14800
- && !isReservedSymbolToken(this.peek(), 'case')
14801
- && !isRBraceToken(this.peek())) {
14802
- expressions.push(this.parseExpression());
14803
- if (isOperatorToken(this.peek(), ';')) {
14804
- this.advance();
14805
- }
14806
- else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
14807
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14808
- }
14809
- }
14810
- var thenExpression = expressions.length === 1
14811
- ? expressions[0]
14812
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
14768
+ var thenExpression = this.parseImplicitBlock(['case', 'end']);
14813
14769
  params.push([caseExpression, thenExpression]);
14814
- if (isRBraceToken(this.peek())) {
14770
+ if (isReservedSymbolToken(this.peek(), 'end')) {
14815
14771
  break;
14816
14772
  }
14817
- assertReservedSymbolToken(this.peek(), 'case');
14818
14773
  }
14819
- assertRBraceToken(this.peek());
14774
+ assertReservedSymbolToken(this.peek());
14820
14775
  this.advance();
14821
14776
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.cond, params]], token[2]);
14822
14777
  };
14823
14778
  Parser.prototype.parseSwitch = function (token) {
14824
- this.advance();
14825
- assertLParenToken(this.peek());
14826
14779
  this.advance();
14827
14780
  var valueExpression = this.parseExpression();
14828
- assertRParenToken(this.peek());
14829
- this.advance();
14830
- assertLBraceToken(this.peek());
14831
- this.advance();
14832
14781
  var params = [];
14833
- while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
14782
+ while (!this.isAtEnd() && !isReservedSymbolToken(this.peek(), 'end')) {
14834
14783
  assertReservedSymbolToken(this.peek(), 'case');
14835
14784
  this.advance();
14836
14785
  var caseExpression = this.parseExpression();
14837
- assertOperatorToken(this.peek(), ':');
14786
+ assertReservedSymbolToken(this.peek(), 'then');
14838
14787
  this.advance();
14839
- var expressions = [];
14840
- while (!this.isAtEnd()
14841
- && !isReservedSymbolToken(this.peek(), 'case')
14842
- && !isRBraceToken(this.peek())) {
14843
- expressions.push(this.parseExpression());
14844
- if (isOperatorToken(this.peek(), ';')) {
14845
- this.advance();
14846
- }
14847
- else if (!isReservedSymbolToken(this.peek(), 'case') && !isRBraceToken(this.peek())) {
14848
- throw new LitsError('Expected ;', this.peekSourceCodeInfo());
14849
- }
14850
- }
14851
- var thenExpression = expressions.length === 1
14852
- ? expressions[0]
14853
- : withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.block, expressions]], token[2]);
14788
+ var thenExpression = this.parseImplicitBlock(['case', 'end']);
14854
14789
  params.push([caseExpression, thenExpression]);
14855
- if (isRBraceToken(this.peek())) {
14790
+ if (isReservedSymbolToken(this.peek(), 'end')) {
14856
14791
  break;
14857
14792
  }
14858
- assertReservedSymbolToken(this.peek(), 'case');
14859
14793
  }
14860
- assertRBraceToken(this.peek());
14794
+ assertReservedSymbolToken(this.peek(), 'end');
14861
14795
  this.advance();
14862
14796
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.switch, valueExpression, params]], token[2]);
14863
14797
  };
14864
- Parser.prototype.parseFunction = function (token) {
14865
- this.advance();
14866
- var symbol = this.parseSymbol();
14867
- var functionArguments = this.parseFunctionArguments();
14868
- var _a = __read(this.parseBlock(true), 2), block = _a[0], docString = _a[1];
14869
- return withSourceCodeInfo([
14870
- NodeTypes.SpecialExpression,
14871
- [
14872
- specialExpressionTypes.function,
14873
- symbol,
14874
- [
14875
- functionArguments,
14876
- block[1][1],
14877
- ],
14878
- docString,
14879
- ],
14880
- ], token[2]);
14881
- };
14882
14798
  Parser.prototype.isAtEnd = function () {
14883
14799
  return this.parseState.position >= this.tokenStream.tokens.length;
14884
14800
  };
@@ -14891,7 +14807,7 @@ var Parser = /** @class */ (function () {
14891
14807
  return [';', ',', ':'].includes(token[1]);
14892
14808
  }
14893
14809
  if (isReservedSymbolToken(token)) {
14894
- return ['else', 'when', 'while', 'case', 'catch'].includes(token[1]);
14810
+ return ['else', 'when', 'while', 'case', 'catch', 'let', 'then'].includes(token[1]);
14895
14811
  }
14896
14812
  return false;
14897
14813
  };
@@ -14902,13 +14818,8 @@ var Parser = /** @class */ (function () {
14902
14818
  var letNode = this.parseLet(asSymbolToken(token));
14903
14819
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], exportToken[2]);
14904
14820
  }
14905
- else if (isReservedSymbolToken(token, 'function')) {
14906
- var functionNode = this.parseFunction(token);
14907
- functionNode[1][0] = specialExpressionTypes['0_defn'];
14908
- return functionNode;
14909
- }
14910
14821
  else {
14911
- throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
14822
+ throw new LitsError('Expected let', this.peekSourceCodeInfo());
14912
14823
  }
14913
14824
  };
14914
14825
  Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
@@ -15098,7 +15009,7 @@ var AutoCompleter = /** @class */ (function () {
15098
15009
  };
15099
15010
  AutoCompleter.prototype.generateSuggestions = function (params) {
15100
15011
  var _this = this;
15101
- var blacklist = new Set(['0_def', '0_defn', '0_fn']);
15012
+ var blacklist = new Set(['0_def', '0_defn', '0_lambda']);
15102
15013
  var startsWithCaseSensitive = this.generateWithPredicate(params, function (suggestion) {
15103
15014
  return !blacklist.has(suggestion) && suggestion.startsWith(_this.searchString);
15104
15015
  });
@@ -15724,7 +15635,7 @@ var arrayReference = {
15724
15635
  '[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse',
15725
15636
  'mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)',
15726
15637
  '[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse',
15727
- "\nfunction foo(n) {\n [n - 1, n, n + 1]\n};\n[1, 2, 3] mapcat foo",
15638
+ "\nlet foo = (n) -> {\n [n - 1, n, n + 1]\n};\n[1, 2, 3] mapcat foo",
15728
15639
  "\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ remove even?\n)",
15729
15640
  ],
15730
15641
  },
@@ -20455,7 +20366,7 @@ var metaReference = {
20455
20366
  description: 'Returns documentation string of the $fun.',
20456
20367
  examples: [
20457
20368
  'doc(+)',
20458
- "\nfunction add(x, y) {\n \"\"\"\n Adds two numbers.\n Args:\n x: First number.\n y: Second number.\n Returns:\n Sum of x and y.\n \"\"\"\n x + y;\n};\n\ndoc(add)",
20369
+ "\nlet add = (x, y) -> {\n \"\"\"\n Adds two numbers.\n Args:\n x: First number.\n y: Second number.\n Returns:\n Sum of x and y.\n \"\"\"\n x + y;\n};\n\ndoc(add)",
20459
20370
  ],
20460
20371
  },
20461
20372
  arity: {
@@ -20476,8 +20387,8 @@ var metaReference = {
20476
20387
  examples: [
20477
20388
  'arity(+)',
20478
20389
  'arity(defined?)',
20479
- "\nfunction add(x, y = 0) {\n x + y;\n};\n\narity(add)",
20480
- "\nfunction foo(k, ...x) {\n k + x;\n};\n arity(foo)",
20390
+ "\nlet add = (x, y = 0) -> {\n x + y;\n};\n\narity(add)",
20391
+ "\nlet foo = (k, ...x) -> {\n k + x;\n};\n arity(foo)",
20481
20392
  ],
20482
20393
  },
20483
20394
  };
@@ -26357,8 +26268,8 @@ var sequenceReference = {
26357
26268
  examples: [
26358
26269
  '[3, 1, 2] sort (a, b) -> b - a',
26359
26270
  'sort([3, 1, 2])',
26360
- "\nsort(\n [3, 1, 2],\n (a, b) -> cond { case a < b: -1 case a > b: 1 case true: -1 }\n)",
26361
- "\nsort(\n [3, 1, 2],\n (a, b) -> cond { case a > b: -1 case a < b: 1 case true: -1 }\n)",
26271
+ "\nsort(\n [3, 1, 2],\n (a, b) -> cond case a < b then -1 case a > b then 1 case true then -1 end\n)",
26272
+ "\nsort(\n [3, 1, 2],\n (a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end\n)",
26362
26273
  ],
26363
26274
  },
26364
26275
  'sort-by': {
@@ -26835,26 +26746,6 @@ var specialExpressionsReference = {
26835
26746
  description: "\n Binds local variables s to `value`. `value` can be any expression. The scope of the variables is the body of the let expression.",
26836
26747
  examples: ["\nlet a = 1 + 2 + 3 + 4;\nlet b = -> $ * ( $ + 1 );\nwrite!(\"a\", a, \"b\", b)"],
26837
26748
  },
26838
- 'function': {
26839
- title: 'function',
26840
- category: 'Special expression',
26841
- customVariants: ['function name(...arg) { body }'],
26842
- details: [
26843
- ['name', 'symbol', 'The name of the function.'],
26844
- ['arg', '[...]arg-name [= value]', 'Arguments of the function.'],
26845
- ['...', 'rest-symbol', 'Optional. The rest argument of the function.'],
26846
- ['arg-name', 'symbol', 'The name of the argument.'],
26847
- ['value', 'any', 'Optional. The default value of the argument.'],
26848
- ['let-binding', 'symbol', 'Optional. The let bindings of the function.'],
26849
- ['body', 'one or more expressions', 'The body of the function.'],
26850
- ],
26851
- description: 'Creates a named function. When called, evaluation of the last expression in the body is returned.',
26852
- examples: [
26853
- "\nfunction hyp (a, b) {\n sqrt(a * a + b * b)\n};\n\nhyp(3, 4)",
26854
- "\nfunction sumOfSquares(...s) {\n apply(\n +,\n map(s, -> $ ^ 2)\n )\n};\n\nsumOfSquares(1, 2, 3, 4, 5)",
26855
- "\nfunction withOptional(a, b = 42) {\n a + b\n};\n\nwrite!(withOptional(1), withOptional(1, 2))",
26856
- ],
26857
- },
26858
26749
  'try': {
26859
26750
  title: 'try',
26860
26751
  category: 'Special expression',
@@ -26894,7 +26785,7 @@ var specialExpressionsReference = {
26894
26785
  'if': {
26895
26786
  title: 'if',
26896
26787
  category: 'Special expression',
26897
- customVariants: ['if (test) true-expr else false-expr', 'if (test) true-expr'],
26788
+ customVariants: ['if test then true-expr else false-expr', 'if test then true-expr'],
26898
26789
  details: [
26899
26790
  ['test', 'expression', 'The condition to test.'],
26900
26791
  ['true-expr', 'expression', 'The expression to evaluate if the test is truthy.'],
@@ -26902,16 +26793,16 @@ var specialExpressionsReference = {
26902
26793
  ],
26903
26794
  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.',
26904
26795
  examples: [
26905
- "\nif (true) {\n write!(\"TRUE\")\n} else {\n write!(\"FALSE\")\n}",
26906
- 'if (false) write!("TRUE") else write!("FALSE")',
26907
- 'if (true) write!("TRUE")',
26908
- 'if (false) write!("TRUE")',
26796
+ "\nif true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
26797
+ 'if false then write!("TRUE") else write!("FALSE") end',
26798
+ 'if true then write!("TRUE") end',
26799
+ 'if false then write!("TRUE") end',
26909
26800
  ],
26910
26801
  },
26911
26802
  'unless': {
26912
26803
  title: 'unless',
26913
26804
  category: 'Special expression',
26914
- customVariants: ['unless (test) true-expr else false-expr end', 'unless test true-expr end'],
26805
+ customVariants: ['unless test then true-expr else false-expr end', 'unless test true-expr end'],
26915
26806
  details: [
26916
26807
  ['test', 'expression', 'The condition to test.'],
26917
26808
  ['true-expr', 'expression', 'The expressions to evaluate if the test is falsy.'],
@@ -26919,16 +26810,16 @@ var specialExpressionsReference = {
26919
26810
  ],
26920
26811
  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.',
26921
26812
  examples: [
26922
- "\nunless (true) {\n write!(\"TRUE\")\n} else {\n write!(\"FALSE\")\n}",
26923
- 'unless (false) write!("TRUE") else write!("FALSE")',
26924
- 'unless (true) write!("TRUE")',
26925
- 'unless (false) write!("TRUE")',
26813
+ "\nunless true then\n write!(\"TRUE\")\nelse\n write!(\"FALSE\")\nend",
26814
+ 'unless false then write!("TRUE") else write!("FALSE") end',
26815
+ 'unless true then write!("TRUE") end',
26816
+ 'unless false then write!("TRUE") end',
26926
26817
  ],
26927
26818
  },
26928
26819
  'cond': {
26929
26820
  title: 'cond',
26930
26821
  category: 'Special expression',
26931
- customVariants: ['cond { cond-branch cond-branch ... }'],
26822
+ customVariants: ['cond cond-branch cond-branch ... end'],
26932
26823
  details: [
26933
26824
  ['cond-branch', 'case test then body', 'A branch of the cond expression.'],
26934
26825
  ['test', 'expression', 'The condition to test.'],
@@ -26936,15 +26827,15 @@ var specialExpressionsReference = {
26936
26827
  ],
26937
26828
  description: 'Used for branching. `cond-branches` are tested sequentially from the top. If no branch is tested truthy, `null` is returned.',
26938
26829
  examples: [
26939
- "\ncond {\n case false: write!(\"FALSE\")\n case true: write!(\"TRUE\")\n}",
26940
- "\ncond {\n case false: write!(\"FALSE\")\n case null: write!(\"null\")\n} ?? write!(\"TRUE\")",
26941
- "\ncond {\n case false: write!(\"FALSE\")\n case null: write!(\"null\")\n} ?? write!(\"TRUE\")",
26830
+ "\ncond\n case false then write!(\"FALSE\")\n case true then write!(\"TRUE\")\nend",
26831
+ "\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
26832
+ "\ncond\n case false then write!(\"FALSE\")\n case null then write!(\"null\")\nend ?? write!(\"TRUE\")",
26942
26833
  ],
26943
26834
  },
26944
26835
  'switch': {
26945
26836
  title: 'switch',
26946
26837
  category: 'Special expression',
26947
- customVariants: ['switch (value) { switch-branch switch-branch ... }'],
26838
+ customVariants: ['switch value switch-branch switch-branch ... end'],
26948
26839
  details: [
26949
26840
  ['value', 'any', 'The value to test.'],
26950
26841
  ['switch-branch', 'case test then body', 'A branch of the switch expression.'],
@@ -26953,9 +26844,9 @@ var specialExpressionsReference = {
26953
26844
  ],
26954
26845
  description: 'Used for branching. `switch-branches` are tested sequentially from the top against `value`. If no branch is tested truthy, `null` is returned.',
26955
26846
  examples: [
26956
- "\nswitch (1) {\n case 1: write!(\"One\")\n case 2: write!(\"Two\")\n}",
26957
- "\nswitch (2) {\n case 1: write!(\"One\")\n case 2: write!(\"Two\")\n}",
26958
- "\nswitch (3) {\n case 1: write!(\"One\")\n case 2: write!(\"Two\")\n}",
26847
+ "\nswitch 1\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
26848
+ "\nswitch 2\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
26849
+ "\nswitch 3\n case 1 then write!(\"One\")\n case 2 then write!(\"Two\")\nend",
26959
26850
  ],
26960
26851
  },
26961
26852
  'block': {
@@ -26976,9 +26867,9 @@ var specialExpressionsReference = {
26976
26867
  customVariants: ['recur(...recur-args)'],
26977
26868
  description: 'Recursevly calls enclosing function or loop with its evaluated `recur-args`.',
26978
26869
  examples: [
26979
- "\nfunction foo(n) {\n write!(n);\n if (!(zero?(n))) {\n recur(n - 1)\n }\n};\nfoo(3)",
26980
- "\n(n -> {\n write!(n);\n if (!(zero?(n))) {\n recur(n - 1)\n }\n})(3)",
26981
- "\nloop (n = 3) {\n write!(n);\n if (!(zero?(n))) {\n recur(n - 1)\n }\n}",
26870
+ "\nlet foo = (n) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n};\nfoo(3)",
26871
+ "\n(n -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n})(3)",
26872
+ "\nloop (n = 3) -> {\n write!(n);\n if !(zero?(n)) then\n recur(n - 1)\n end\n}",
26982
26873
  ],
26983
26874
  },
26984
26875
  };