@dallaylaen/ski-interpreter 2.5.1 → 2.5.2

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.
@@ -13869,17 +13869,11 @@ var FormatOptionsSchema = external_exports.object({
13869
13869
  inventory: external_exports.record(external_exports.string(), external_exports.custom((v) => v instanceof Expr)).optional()
13870
13870
  });
13871
13871
  var Expr = class _Expr {
13872
- static {
13873
- this.control = control;
13874
- }
13875
- static {
13876
- this.native = native;
13877
- }
13878
13872
  /**
13879
13873
  *
13880
13874
  * @desc Define properties of the term based on user supplied options and/or inference results.
13881
13875
  * Typically useful for declaring Native and Alias terms.
13882
- * @private
13876
+ * @protected
13883
13877
  * @param {Object} options
13884
13878
  * @param {string} [options.note] - a brief description what the term does
13885
13879
  * @param {number} [options.arity] - number of arguments the term is waiting for (if known)
@@ -13954,6 +13948,7 @@ var Expr = class _Expr {
13954
13948
  * }} [options]
13955
13949
  * @param {(e:Expr) => TraverseValue<Expr>} change
13956
13950
  * @returns {Expr|null}
13951
+ * @final
13957
13952
  */
13958
13953
  traverse(options, change) {
13959
13954
  if (typeof options === "function") {
@@ -13967,7 +13962,8 @@ var Expr = class _Expr {
13967
13962
  return expr ?? null;
13968
13963
  }
13969
13964
  /**
13970
- * @private
13965
+ * @protected
13966
+ * @final
13971
13967
  * @param {Object} options
13972
13968
  * @param {(e:Expr) => TraverseValue<Expr>} change
13973
13969
  * @returns {TraverseValue<Expr>}
@@ -13986,7 +13982,7 @@ var Expr = class _Expr {
13986
13982
  return action ? action(expr) : expr;
13987
13983
  }
13988
13984
  /**
13989
- * @private
13985
+ * @protected
13990
13986
  * @param {Object} options
13991
13987
  * @param {(e:Expr) => TraverseValue<Expr>} change
13992
13988
  * @returns {TraverseValue<Expr>}
@@ -14016,7 +14012,11 @@ var Expr = class _Expr {
14016
14012
  *
14017
14013
  * This method is experimental and may change in the future.
14018
14014
  *
14015
+ * @example // count the number of nodes in the expression tree
14016
+ * expr.fold(0, (acc, e) => acc + 1);
14017
+ *
14019
14018
  * @experimental
14019
+ * @final
14020
14020
  * @template T
14021
14021
  * @param {T} initial
14022
14022
  * @param {(acc: T, expr: Expr) => TraverseValue<T>} combine
@@ -14026,6 +14026,14 @@ var Expr = class _Expr {
14026
14026
  const [value] = unwrap(this._fold(initial, combine));
14027
14027
  return value ?? initial;
14028
14028
  }
14029
+ /**
14030
+ * @desc Internal method for fold(), which performs the actual folding.
14031
+ * Should be implemented in subclasses having any internal structure.
14032
+ *
14033
+ * @protected
14034
+ * @param initial
14035
+ * @param combine
14036
+ */
14029
14037
  _fold(initial, combine) {
14030
14038
  return combine(initial, this);
14031
14039
  }
@@ -14069,6 +14077,7 @@ var Expr = class _Expr {
14069
14077
  *
14070
14078
  * Use toLambda() if you want to get a lambda term in any case.
14071
14079
  *
14080
+ * @final
14072
14081
  * @param {{max?: number, maxArgs?: number}} options
14073
14082
  * @return {TermInfo}
14074
14083
  */
@@ -14161,6 +14170,7 @@ var Expr = class _Expr {
14161
14170
  *
14162
14171
  * See also Expr.walk() and Expr.toSKI().
14163
14172
  *
14173
+ * @final
14164
14174
  * @param {{
14165
14175
  * max?: number,
14166
14176
  * maxArgs?: number,
@@ -14207,6 +14217,7 @@ var Expr = class _Expr {
14207
14217
  *
14208
14218
  * See also Expr.walk() and Expr.toLambda().
14209
14219
  *
14220
+ * @final
14210
14221
  * @param {{max?: number}} [options]
14211
14222
  * @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
14212
14223
  */
@@ -14237,12 +14248,15 @@ var Expr = class _Expr {
14237
14248
  }
14238
14249
  }
14239
14250
  /**
14240
- * Replace all instances of plug in the expression with value and return the resulting expression,
14251
+ * Replace all instances of `search` in the expression with `replace` and return the resulting expression,
14241
14252
  * or null if no changes could be made.
14253
+ *
14242
14254
  * Lambda terms and applications will never match if used as plug
14243
- * as they are impossible co compare without extensive computations.
14255
+ * as they are impossible to compare without extensive computations.
14256
+ *
14244
14257
  * Typically used on variables but can also be applied to other terms, e.g. aliases.
14245
- * See also Expr.traverse().
14258
+ * See also Expr.traverse() for more flexible replacement of subterms.
14259
+ *
14246
14260
  * @param {Expr} search
14247
14261
  * @param {Expr} replace
14248
14262
  * @return {Expr|null}
@@ -14283,6 +14297,7 @@ var Expr = class _Expr {
14283
14297
  * @desc Run uninterrupted sequence of step() applications
14284
14298
  * until the expression is irreducible, or max number of steps is reached.
14285
14299
  * Default number of steps = 1000.
14300
+ * @final
14286
14301
  * @param {{max?: number, steps?: number, throw?: boolean}|Expr} [opt]
14287
14302
  * @param {Expr} args
14288
14303
  * @return {{expr: Expr, steps: number, final: boolean}}
@@ -14313,7 +14328,9 @@ var Expr = class _Expr {
14313
14328
  }
14314
14329
  /**
14315
14330
  * Execute step() while possible, yielding a brief description of events after each step.
14331
+ *
14316
14332
  * Mnemonics: like run() but slower.
14333
+ * @final
14317
14334
  * @param {{max?: number}} options
14318
14335
  * @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
14319
14336
  */
@@ -14343,6 +14360,7 @@ var Expr = class _Expr {
14343
14360
  *
14344
14361
  * @param {Expr} other
14345
14362
  * @return {boolean}
14363
+ * @final
14346
14364
  */
14347
14365
  equals(other) {
14348
14366
  return !this.diff(other);
@@ -14361,6 +14379,8 @@ var Expr = class _Expr {
14361
14379
  * To somewhat alleviate confusion, the output will include
14362
14380
  * the internal id of the variable in square brackets.
14363
14381
  *
14382
+ * Do not rely on the exact format of the output as it may change in the future.
14383
+ *
14364
14384
  * @example "K(S != I)" is the result of comparing "KS" and "KI"
14365
14385
  * @example "S(K([x[13] != x[14]]))K"
14366
14386
  *
@@ -14381,6 +14401,11 @@ var Expr = class _Expr {
14381
14401
  * `this` is the expected value and the argument is the actual one.
14382
14402
  * Mnemonic: the expected value is always a combinator, the actual one may be anything.
14383
14403
  *
14404
+ * In case of failure, an error is thrown with a message describing the first point of difference
14405
+ * and `expected` and `actual` properties like in AssertionError.
14406
+ * AssertionError is not used directly to because browsers don't recognize it.
14407
+ *
14408
+ * @final
14384
14409
  * @param {Expr} actual
14385
14410
  * @param {string} comment
14386
14411
  */
@@ -14400,7 +14425,10 @@ var Expr = class _Expr {
14400
14425
  /**
14401
14426
  * @desc Returns string representation of the expression.
14402
14427
  * Same as format() without options.
14428
+ *
14429
+ * Use formatImpl() to override in subclasses.
14403
14430
  * @return {string}
14431
+ * @final
14404
14432
  */
14405
14433
  toString() {
14406
14434
  return this.format();
@@ -14409,6 +14437,7 @@ var Expr = class _Expr {
14409
14437
  * @desc Whether the expression needs parentheses when printed.
14410
14438
  * @param {boolean} [first] - whether this is the first term in a sequence
14411
14439
  * @return {boolean}
14440
+ * @protected
14412
14441
  */
14413
14442
  _braced(_first) {
14414
14443
  return false;
@@ -14417,7 +14446,7 @@ var Expr = class _Expr {
14417
14446
  * @desc Whether the expression can be printed without a space when followed by arg.
14418
14447
  * @param {Expr} arg
14419
14448
  * @returns {boolean}
14420
- * @private
14449
+ * @protected
14421
14450
  */
14422
14451
  _unspaced(arg) {
14423
14452
  return this._braced(true);
@@ -14425,8 +14454,9 @@ var Expr = class _Expr {
14425
14454
  /**
14426
14455
  * @desc Stringify the expression with fancy formatting options.
14427
14456
  * Said options mostly include wrappers around various constructs in form of ['(', ')'],
14428
- * as well as terse and html flags that set up the defaults.
14457
+ * as well as `terse` and `html` flags that fill in appropriate defaults.
14429
14458
  * Format without options is equivalent to toString() and can be parsed back.
14459
+ * @final
14430
14460
  *
14431
14461
  * @param {Object} [options] - formatting options
14432
14462
  * @param {boolean} [options.terse] - whether to use terse formatting (omitting unnecessary spaces and parentheses)
@@ -14484,16 +14514,6 @@ var Expr = class _Expr {
14484
14514
  html: options.html ?? false
14485
14515
  }, 0);
14486
14516
  }
14487
- /**
14488
- * @desc Internal method for format(), which performs the actual formatting.
14489
- * @param {Object} options
14490
- * @param {number} nargs
14491
- * @returns {string}
14492
- * @private
14493
- */
14494
- formatImpl(options, nargs) {
14495
- throw new Error("No formatImpl() method defined in class " + this.constructor.name);
14496
- }
14497
14517
  /**
14498
14518
  * @desc Returns a string representation of the expression tree, with indentation to show structure.
14499
14519
  *
@@ -14521,6 +14541,7 @@ var Expr = class _Expr {
14521
14541
  /**
14522
14542
  * @desc Convert the expression to a JSON-serializable format.
14523
14543
  * @returns {string}
14544
+ * @final
14524
14545
  */
14525
14546
  toJSON() {
14526
14547
  return this.format();
@@ -14974,6 +14995,9 @@ var Empty = class extends Expr {
14974
14995
  postParse() {
14975
14996
  throw new Error("Attempt to use empty expression () as a term");
14976
14997
  }
14998
+ formatImpl(options, nargs) {
14999
+ return "()";
15000
+ }
14977
15001
  };
14978
15002
  var PartialLambda = class _PartialLambda extends Empty {
14979
15003
  // TODO mutable! rewrite ro when have time