@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 +7 -0
- package/lib/ski-interpreter.cjs.js +48 -24
- package/lib/ski-interpreter.cjs.js.map +2 -2
- package/lib/ski-interpreter.esm.js +48 -24
- package/lib/ski-interpreter.esm.js.map +2 -2
- package/lib/ski-interpreter.min.js +7 -7
- package/lib/ski-interpreter.min.js.map +3 -3
- package/lib/ski-quest.min.js +7 -7
- package/lib/ski-quest.min.js.map +3 -3
- package/lib/types/expr.d.ts +54 -19
- package/package.json +1 -1
package/lib/types/expr.d.ts
CHANGED
|
@@ -54,7 +54,11 @@ export declare const FormatOptionsSchema: z.ZodObject<{
|
|
|
54
54
|
inventory: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<Expr, Expr>>>;
|
|
55
55
|
}, z.core.$strip>;
|
|
56
56
|
export type FormatOptions = z.infer<typeof FormatOptionsSchema>;
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @desc A version of FormatOptions with defaults plugged in,
|
|
59
|
+
* use for mandatory formatImpl implementation in Expr subclasses.
|
|
60
|
+
*/
|
|
61
|
+
export type RefinedFormatOptions = {
|
|
58
62
|
terse?: boolean;
|
|
59
63
|
html?: boolean;
|
|
60
64
|
brackets: [string, string];
|
|
@@ -69,14 +73,7 @@ type TraverseOptions = {
|
|
|
69
73
|
order?: 'LO' | 'LI' | 'leftmost-outermost' | 'leftmost-innermost';
|
|
70
74
|
};
|
|
71
75
|
type TraverseCallback = (e: Expr) => TraverseValue<Expr>;
|
|
72
|
-
export declare class Expr {
|
|
73
|
-
static control: {
|
|
74
|
-
descend: <T>(value?: T) => import("./internal").TraverseControl<T>;
|
|
75
|
-
prune: <T>(value?: T) => import("./internal").TraverseControl<T>;
|
|
76
|
-
redo: <T>(value?: T) => import("./internal").TraverseControl<T>;
|
|
77
|
-
stop: <T>(value?: T) => import("./internal").TraverseControl<T>;
|
|
78
|
-
};
|
|
79
|
-
static native: Record<string, Native>;
|
|
76
|
+
export declare abstract class Expr {
|
|
80
77
|
/**
|
|
81
78
|
* @desc A combinatory logic expression.
|
|
82
79
|
*
|
|
@@ -110,7 +107,7 @@ export declare class Expr {
|
|
|
110
107
|
*
|
|
111
108
|
* @desc Define properties of the term based on user supplied options and/or inference results.
|
|
112
109
|
* Typically useful for declaring Native and Alias terms.
|
|
113
|
-
* @
|
|
110
|
+
* @protected
|
|
114
111
|
* @param {Object} options
|
|
115
112
|
* @param {string} [options.note] - a brief description what the term does
|
|
116
113
|
* @param {number} [options.arity] - number of arguments the term is waiting for (if known)
|
|
@@ -165,17 +162,19 @@ export declare class Expr {
|
|
|
165
162
|
* }} [options]
|
|
166
163
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
167
164
|
* @returns {Expr|null}
|
|
165
|
+
* @final
|
|
168
166
|
*/
|
|
169
167
|
traverse(options: TraverseOptions | TraverseCallback, change?: TraverseCallback): Expr | null;
|
|
170
168
|
/**
|
|
171
|
-
* @
|
|
169
|
+
* @protected
|
|
170
|
+
* @final
|
|
172
171
|
* @param {Object} options
|
|
173
172
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
174
173
|
* @returns {TraverseValue<Expr>}
|
|
175
174
|
*/
|
|
176
175
|
_traverse_redo(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
177
176
|
/**
|
|
178
|
-
* @
|
|
177
|
+
* @protected
|
|
179
178
|
* @param {Object} options
|
|
180
179
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
181
180
|
* @returns {TraverseValue<Expr>}
|
|
@@ -201,13 +200,25 @@ export declare class Expr {
|
|
|
201
200
|
*
|
|
202
201
|
* This method is experimental and may change in the future.
|
|
203
202
|
*
|
|
203
|
+
* @example // count the number of nodes in the expression tree
|
|
204
|
+
* expr.fold(0, (acc, e) => acc + 1);
|
|
205
|
+
*
|
|
204
206
|
* @experimental
|
|
207
|
+
* @final
|
|
205
208
|
* @template T
|
|
206
209
|
* @param {T} initial
|
|
207
210
|
* @param {(acc: T, expr: Expr) => TraverseValue<T>} combine
|
|
208
211
|
* @returns {T}
|
|
209
212
|
*/
|
|
210
213
|
fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): T;
|
|
214
|
+
/**
|
|
215
|
+
* @desc Internal method for fold(), which performs the actual folding.
|
|
216
|
+
* Should be implemented in subclasses having any internal structure.
|
|
217
|
+
*
|
|
218
|
+
* @protected
|
|
219
|
+
* @param initial
|
|
220
|
+
* @param combine
|
|
221
|
+
*/
|
|
211
222
|
_fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): TraverseValue<T>;
|
|
212
223
|
/**
|
|
213
224
|
* @experimental
|
|
@@ -246,6 +257,7 @@ export declare class Expr {
|
|
|
246
257
|
*
|
|
247
258
|
* Use toLambda() if you want to get a lambda term in any case.
|
|
248
259
|
*
|
|
260
|
+
* @final
|
|
249
261
|
* @param {{max?: number, maxArgs?: number}} options
|
|
250
262
|
* @return {TermInfo}
|
|
251
263
|
*/
|
|
@@ -288,6 +300,7 @@ export declare class Expr {
|
|
|
288
300
|
*
|
|
289
301
|
* See also Expr.walk() and Expr.toSKI().
|
|
290
302
|
*
|
|
303
|
+
* @final
|
|
291
304
|
* @param {{
|
|
292
305
|
* max?: number,
|
|
293
306
|
* maxArgs?: number,
|
|
@@ -312,6 +325,7 @@ export declare class Expr {
|
|
|
312
325
|
*
|
|
313
326
|
* See also Expr.walk() and Expr.toLambda().
|
|
314
327
|
*
|
|
328
|
+
* @final
|
|
315
329
|
* @param {{max?: number}} [options]
|
|
316
330
|
* @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
|
|
317
331
|
*/
|
|
@@ -321,12 +335,15 @@ export declare class Expr {
|
|
|
321
335
|
final: boolean;
|
|
322
336
|
}, void, unknown>;
|
|
323
337
|
/**
|
|
324
|
-
* Replace all instances of
|
|
338
|
+
* Replace all instances of `search` in the expression with `replace` and return the resulting expression,
|
|
325
339
|
* or null if no changes could be made.
|
|
340
|
+
*
|
|
326
341
|
* Lambda terms and applications will never match if used as plug
|
|
327
|
-
* as they are impossible
|
|
342
|
+
* as they are impossible to compare without extensive computations.
|
|
343
|
+
*
|
|
328
344
|
* Typically used on variables but can also be applied to other terms, e.g. aliases.
|
|
329
|
-
* See also Expr.traverse().
|
|
345
|
+
* See also Expr.traverse() for more flexible replacement of subterms.
|
|
346
|
+
*
|
|
330
347
|
* @param {Expr} search
|
|
331
348
|
* @param {Expr} replace
|
|
332
349
|
* @return {Expr|null}
|
|
@@ -361,6 +378,7 @@ export declare class Expr {
|
|
|
361
378
|
* @desc Run uninterrupted sequence of step() applications
|
|
362
379
|
* until the expression is irreducible, or max number of steps is reached.
|
|
363
380
|
* Default number of steps = 1000.
|
|
381
|
+
* @final
|
|
364
382
|
* @param {{max?: number, steps?: number, throw?: boolean}|Expr} [opt]
|
|
365
383
|
* @param {Expr} args
|
|
366
384
|
* @return {{expr: Expr, steps: number, final: boolean}}
|
|
@@ -368,7 +386,9 @@ export declare class Expr {
|
|
|
368
386
|
run(opt?: RunOptions | Expr, ...args: Expr[]): Run;
|
|
369
387
|
/**
|
|
370
388
|
* Execute step() while possible, yielding a brief description of events after each step.
|
|
389
|
+
*
|
|
371
390
|
* Mnemonics: like run() but slower.
|
|
391
|
+
* @final
|
|
372
392
|
* @param {{max?: number}} options
|
|
373
393
|
* @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
|
|
374
394
|
*/
|
|
@@ -386,6 +406,7 @@ export declare class Expr {
|
|
|
386
406
|
*
|
|
387
407
|
* @param {Expr} other
|
|
388
408
|
* @return {boolean}
|
|
409
|
+
* @final
|
|
389
410
|
*/
|
|
390
411
|
equals(other: Expr): boolean;
|
|
391
412
|
/**
|
|
@@ -402,6 +423,8 @@ export declare class Expr {
|
|
|
402
423
|
* To somewhat alleviate confusion, the output will include
|
|
403
424
|
* the internal id of the variable in square brackets.
|
|
404
425
|
*
|
|
426
|
+
* Do not rely on the exact format of the output as it may change in the future.
|
|
427
|
+
*
|
|
405
428
|
* @example "K(S != I)" is the result of comparing "KS" and "KI"
|
|
406
429
|
* @example "S(K([x[13] != x[14]]))K"
|
|
407
430
|
*
|
|
@@ -416,6 +439,11 @@ export declare class Expr {
|
|
|
416
439
|
* `this` is the expected value and the argument is the actual one.
|
|
417
440
|
* Mnemonic: the expected value is always a combinator, the actual one may be anything.
|
|
418
441
|
*
|
|
442
|
+
* In case of failure, an error is thrown with a message describing the first point of difference
|
|
443
|
+
* and `expected` and `actual` properties like in AssertionError.
|
|
444
|
+
* AssertionError is not used directly to because browsers don't recognize it.
|
|
445
|
+
*
|
|
446
|
+
* @final
|
|
419
447
|
* @param {Expr} actual
|
|
420
448
|
* @param {string} comment
|
|
421
449
|
*/
|
|
@@ -423,27 +451,32 @@ export declare class Expr {
|
|
|
423
451
|
/**
|
|
424
452
|
* @desc Returns string representation of the expression.
|
|
425
453
|
* Same as format() without options.
|
|
454
|
+
*
|
|
455
|
+
* Use formatImpl() to override in subclasses.
|
|
426
456
|
* @return {string}
|
|
457
|
+
* @final
|
|
427
458
|
*/
|
|
428
459
|
toString(): string;
|
|
429
460
|
/**
|
|
430
461
|
* @desc Whether the expression needs parentheses when printed.
|
|
431
462
|
* @param {boolean} [first] - whether this is the first term in a sequence
|
|
432
463
|
* @return {boolean}
|
|
464
|
+
* @protected
|
|
433
465
|
*/
|
|
434
466
|
_braced(_first?: boolean): boolean;
|
|
435
467
|
/**
|
|
436
468
|
* @desc Whether the expression can be printed without a space when followed by arg.
|
|
437
469
|
* @param {Expr} arg
|
|
438
470
|
* @returns {boolean}
|
|
439
|
-
* @
|
|
471
|
+
* @protected
|
|
440
472
|
*/
|
|
441
473
|
_unspaced(arg: Expr): boolean;
|
|
442
474
|
/**
|
|
443
475
|
* @desc Stringify the expression with fancy formatting options.
|
|
444
476
|
* Said options mostly include wrappers around various constructs in form of ['(', ')'],
|
|
445
|
-
* as well as terse and html flags that
|
|
477
|
+
* as well as `terse` and `html` flags that fill in appropriate defaults.
|
|
446
478
|
* Format without options is equivalent to toString() and can be parsed back.
|
|
479
|
+
* @final
|
|
447
480
|
*
|
|
448
481
|
* @param {Object} [options] - formatting options
|
|
449
482
|
* @param {boolean} [options.terse] - whether to use terse formatting (omitting unnecessary spaces and parentheses)
|
|
@@ -478,9 +511,10 @@ export declare class Expr {
|
|
|
478
511
|
* @param {Object} options
|
|
479
512
|
* @param {number} nargs
|
|
480
513
|
* @returns {string}
|
|
481
|
-
* @
|
|
514
|
+
* @protected
|
|
515
|
+
* @abstract
|
|
482
516
|
*/
|
|
483
|
-
formatImpl(options: RefinedFormatOptions, nargs: number): string;
|
|
517
|
+
abstract formatImpl(options: RefinedFormatOptions, nargs: number): string;
|
|
484
518
|
/**
|
|
485
519
|
* @desc Returns a string representation of the expression tree, with indentation to show structure.
|
|
486
520
|
*
|
|
@@ -506,6 +540,7 @@ export declare class Expr {
|
|
|
506
540
|
/**
|
|
507
541
|
* @desc Convert the expression to a JSON-serializable format.
|
|
508
542
|
* @returns {string}
|
|
543
|
+
* @final
|
|
509
544
|
*/
|
|
510
545
|
toJSON(): string | object;
|
|
511
546
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dallaylaen/ski-interpreter",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "Simple Kombinator Interpreter - a combinatory logic & lambda calculus parser and interpreter. Supports SKI, BCKW, Church numerals, and setting up assertions ('quests') involving all of the above.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"combinatory logic",
|