@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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.5.2] - 2026-03-27
9
+
10
+ ### Changed
11
+
12
+ - Make `Expr` class abstract (as was always intended)
13
+ and mark its abstract/final/protected methods appropriately.
14
+
8
15
  ## [2.5.1] - 2026-03-26
9
16
 
10
17
  ### Changed
@@ -13889,17 +13889,11 @@ var FormatOptionsSchema = external_exports.object({
13889
13889
  inventory: external_exports.record(external_exports.string(), external_exports.custom((v) => v instanceof Expr)).optional()
13890
13890
  });
13891
13891
  var Expr = class _Expr {
13892
- static {
13893
- this.control = control;
13894
- }
13895
- static {
13896
- this.native = native;
13897
- }
13898
13892
  /**
13899
13893
  *
13900
13894
  * @desc Define properties of the term based on user supplied options and/or inference results.
13901
13895
  * Typically useful for declaring Native and Alias terms.
13902
- * @private
13896
+ * @protected
13903
13897
  * @param {Object} options
13904
13898
  * @param {string} [options.note] - a brief description what the term does
13905
13899
  * @param {number} [options.arity] - number of arguments the term is waiting for (if known)
@@ -13974,6 +13968,7 @@ var Expr = class _Expr {
13974
13968
  * }} [options]
13975
13969
  * @param {(e:Expr) => TraverseValue<Expr>} change
13976
13970
  * @returns {Expr|null}
13971
+ * @final
13977
13972
  */
13978
13973
  traverse(options, change) {
13979
13974
  if (typeof options === "function") {
@@ -13987,7 +13982,8 @@ var Expr = class _Expr {
13987
13982
  return expr ?? null;
13988
13983
  }
13989
13984
  /**
13990
- * @private
13985
+ * @protected
13986
+ * @final
13991
13987
  * @param {Object} options
13992
13988
  * @param {(e:Expr) => TraverseValue<Expr>} change
13993
13989
  * @returns {TraverseValue<Expr>}
@@ -14006,7 +14002,7 @@ var Expr = class _Expr {
14006
14002
  return action ? action(expr) : expr;
14007
14003
  }
14008
14004
  /**
14009
- * @private
14005
+ * @protected
14010
14006
  * @param {Object} options
14011
14007
  * @param {(e:Expr) => TraverseValue<Expr>} change
14012
14008
  * @returns {TraverseValue<Expr>}
@@ -14036,7 +14032,11 @@ var Expr = class _Expr {
14036
14032
  *
14037
14033
  * This method is experimental and may change in the future.
14038
14034
  *
14035
+ * @example // count the number of nodes in the expression tree
14036
+ * expr.fold(0, (acc, e) => acc + 1);
14037
+ *
14039
14038
  * @experimental
14039
+ * @final
14040
14040
  * @template T
14041
14041
  * @param {T} initial
14042
14042
  * @param {(acc: T, expr: Expr) => TraverseValue<T>} combine
@@ -14046,6 +14046,14 @@ var Expr = class _Expr {
14046
14046
  const [value] = unwrap(this._fold(initial, combine));
14047
14047
  return value ?? initial;
14048
14048
  }
14049
+ /**
14050
+ * @desc Internal method for fold(), which performs the actual folding.
14051
+ * Should be implemented in subclasses having any internal structure.
14052
+ *
14053
+ * @protected
14054
+ * @param initial
14055
+ * @param combine
14056
+ */
14049
14057
  _fold(initial, combine) {
14050
14058
  return combine(initial, this);
14051
14059
  }
@@ -14089,6 +14097,7 @@ var Expr = class _Expr {
14089
14097
  *
14090
14098
  * Use toLambda() if you want to get a lambda term in any case.
14091
14099
  *
14100
+ * @final
14092
14101
  * @param {{max?: number, maxArgs?: number}} options
14093
14102
  * @return {TermInfo}
14094
14103
  */
@@ -14181,6 +14190,7 @@ var Expr = class _Expr {
14181
14190
  *
14182
14191
  * See also Expr.walk() and Expr.toSKI().
14183
14192
  *
14193
+ * @final
14184
14194
  * @param {{
14185
14195
  * max?: number,
14186
14196
  * maxArgs?: number,
@@ -14227,6 +14237,7 @@ var Expr = class _Expr {
14227
14237
  *
14228
14238
  * See also Expr.walk() and Expr.toLambda().
14229
14239
  *
14240
+ * @final
14230
14241
  * @param {{max?: number}} [options]
14231
14242
  * @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
14232
14243
  */
@@ -14257,12 +14268,15 @@ var Expr = class _Expr {
14257
14268
  }
14258
14269
  }
14259
14270
  /**
14260
- * Replace all instances of plug in the expression with value and return the resulting expression,
14271
+ * Replace all instances of `search` in the expression with `replace` and return the resulting expression,
14261
14272
  * or null if no changes could be made.
14273
+ *
14262
14274
  * Lambda terms and applications will never match if used as plug
14263
- * as they are impossible co compare without extensive computations.
14275
+ * as they are impossible to compare without extensive computations.
14276
+ *
14264
14277
  * Typically used on variables but can also be applied to other terms, e.g. aliases.
14265
- * See also Expr.traverse().
14278
+ * See also Expr.traverse() for more flexible replacement of subterms.
14279
+ *
14266
14280
  * @param {Expr} search
14267
14281
  * @param {Expr} replace
14268
14282
  * @return {Expr|null}
@@ -14303,6 +14317,7 @@ var Expr = class _Expr {
14303
14317
  * @desc Run uninterrupted sequence of step() applications
14304
14318
  * until the expression is irreducible, or max number of steps is reached.
14305
14319
  * Default number of steps = 1000.
14320
+ * @final
14306
14321
  * @param {{max?: number, steps?: number, throw?: boolean}|Expr} [opt]
14307
14322
  * @param {Expr} args
14308
14323
  * @return {{expr: Expr, steps: number, final: boolean}}
@@ -14333,7 +14348,9 @@ var Expr = class _Expr {
14333
14348
  }
14334
14349
  /**
14335
14350
  * Execute step() while possible, yielding a brief description of events after each step.
14351
+ *
14336
14352
  * Mnemonics: like run() but slower.
14353
+ * @final
14337
14354
  * @param {{max?: number}} options
14338
14355
  * @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
14339
14356
  */
@@ -14363,6 +14380,7 @@ var Expr = class _Expr {
14363
14380
  *
14364
14381
  * @param {Expr} other
14365
14382
  * @return {boolean}
14383
+ * @final
14366
14384
  */
14367
14385
  equals(other) {
14368
14386
  return !this.diff(other);
@@ -14381,6 +14399,8 @@ var Expr = class _Expr {
14381
14399
  * To somewhat alleviate confusion, the output will include
14382
14400
  * the internal id of the variable in square brackets.
14383
14401
  *
14402
+ * Do not rely on the exact format of the output as it may change in the future.
14403
+ *
14384
14404
  * @example "K(S != I)" is the result of comparing "KS" and "KI"
14385
14405
  * @example "S(K([x[13] != x[14]]))K"
14386
14406
  *
@@ -14401,6 +14421,11 @@ var Expr = class _Expr {
14401
14421
  * `this` is the expected value and the argument is the actual one.
14402
14422
  * Mnemonic: the expected value is always a combinator, the actual one may be anything.
14403
14423
  *
14424
+ * In case of failure, an error is thrown with a message describing the first point of difference
14425
+ * and `expected` and `actual` properties like in AssertionError.
14426
+ * AssertionError is not used directly to because browsers don't recognize it.
14427
+ *
14428
+ * @final
14404
14429
  * @param {Expr} actual
14405
14430
  * @param {string} comment
14406
14431
  */
@@ -14420,7 +14445,10 @@ var Expr = class _Expr {
14420
14445
  /**
14421
14446
  * @desc Returns string representation of the expression.
14422
14447
  * Same as format() without options.
14448
+ *
14449
+ * Use formatImpl() to override in subclasses.
14423
14450
  * @return {string}
14451
+ * @final
14424
14452
  */
14425
14453
  toString() {
14426
14454
  return this.format();
@@ -14429,6 +14457,7 @@ var Expr = class _Expr {
14429
14457
  * @desc Whether the expression needs parentheses when printed.
14430
14458
  * @param {boolean} [first] - whether this is the first term in a sequence
14431
14459
  * @return {boolean}
14460
+ * @protected
14432
14461
  */
14433
14462
  _braced(_first) {
14434
14463
  return false;
@@ -14437,7 +14466,7 @@ var Expr = class _Expr {
14437
14466
  * @desc Whether the expression can be printed without a space when followed by arg.
14438
14467
  * @param {Expr} arg
14439
14468
  * @returns {boolean}
14440
- * @private
14469
+ * @protected
14441
14470
  */
14442
14471
  _unspaced(arg) {
14443
14472
  return this._braced(true);
@@ -14445,8 +14474,9 @@ var Expr = class _Expr {
14445
14474
  /**
14446
14475
  * @desc Stringify the expression with fancy formatting options.
14447
14476
  * Said options mostly include wrappers around various constructs in form of ['(', ')'],
14448
- * as well as terse and html flags that set up the defaults.
14477
+ * as well as `terse` and `html` flags that fill in appropriate defaults.
14449
14478
  * Format without options is equivalent to toString() and can be parsed back.
14479
+ * @final
14450
14480
  *
14451
14481
  * @param {Object} [options] - formatting options
14452
14482
  * @param {boolean} [options.terse] - whether to use terse formatting (omitting unnecessary spaces and parentheses)
@@ -14504,16 +14534,6 @@ var Expr = class _Expr {
14504
14534
  html: options.html ?? false
14505
14535
  }, 0);
14506
14536
  }
14507
- /**
14508
- * @desc Internal method for format(), which performs the actual formatting.
14509
- * @param {Object} options
14510
- * @param {number} nargs
14511
- * @returns {string}
14512
- * @private
14513
- */
14514
- formatImpl(options, nargs) {
14515
- throw new Error("No formatImpl() method defined in class " + this.constructor.name);
14516
- }
14517
14537
  /**
14518
14538
  * @desc Returns a string representation of the expression tree, with indentation to show structure.
14519
14539
  *
@@ -14541,6 +14561,7 @@ var Expr = class _Expr {
14541
14561
  /**
14542
14562
  * @desc Convert the expression to a JSON-serializable format.
14543
14563
  * @returns {string}
14564
+ * @final
14544
14565
  */
14545
14566
  toJSON() {
14546
14567
  return this.format();
@@ -14994,6 +15015,9 @@ var Empty = class extends Expr {
14994
15015
  postParse() {
14995
15016
  throw new Error("Attempt to use empty expression () as a term");
14996
15017
  }
15018
+ formatImpl(options, nargs) {
15019
+ return "()";
15020
+ }
14997
15021
  };
14998
15022
  var PartialLambda = class _PartialLambda extends Empty {
14999
15023
  // TODO mutable! rewrite ro when have time