@dallaylaen/ski-interpreter 2.3.2 → 2.4.0
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 +26 -0
- package/README.md +9 -2
- package/bin/ski.js +10 -7
- package/lib/ski-interpreter.cjs.js +2082 -2187
- package/lib/ski-interpreter.cjs.js.map +4 -4
- package/lib/ski-interpreter.esm.js +2065 -2198
- package/lib/ski-interpreter.esm.js.map +4 -4
- package/lib/ski-interpreter.min.js +3 -3
- package/lib/ski-interpreter.min.js.map +4 -4
- package/lib/ski-quest.min.js +3 -3
- package/lib/ski-quest.min.js.map +4 -4
- package/{types/src → lib/types}/expr.d.ts +238 -248
- package/{types/src → lib/types}/extras.d.ts +24 -23
- package/lib/types/index.d.ts +68 -0
- package/{types/src → lib/types}/internal.d.ts +27 -23
- package/{types/src → lib/types}/parser.d.ts +40 -83
- package/lib/types/quest.d.ts +232 -0
- package/lib/types/toposort.d.ts +30 -0
- package/package.json +13 -12
- package/types/index.d.ts +0 -3
- package/types/src/quest.d.ts +0 -257
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dallaylaen/ski-interpreter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
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",
|
|
@@ -11,26 +11,26 @@
|
|
|
11
11
|
],
|
|
12
12
|
"type": "commonjs",
|
|
13
13
|
"main": "lib/ski-interpreter.cjs.js",
|
|
14
|
+
"types": "lib/types/index.d.ts",
|
|
14
15
|
"module": "lib/ski-interpreter.esm.js",
|
|
15
16
|
"exports": {
|
|
16
17
|
"import": "./lib/ski-interpreter.esm.js",
|
|
17
18
|
"require": "./lib/ski-interpreter.cjs.js"
|
|
18
19
|
},
|
|
19
|
-
"types": "types/index.d.ts",
|
|
20
20
|
"bin": {
|
|
21
21
|
"ski": "bin/ski.js"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"lint": "npx eslint --ext .js,.ts src test
|
|
25
|
-
"
|
|
26
|
-
"test": "npx nyc mocha --recursive test",
|
|
27
|
-
"build-web": "npx esbuild --bundle --minify --sourcemap --format=iife ./index.
|
|
28
|
-
"build-cjs": "npx esbuild --bundle --sourcemap --format=cjs ./index.
|
|
29
|
-
"build-esm": "npx esbuild --bundle --sourcemap --format=esm ./index.
|
|
24
|
+
"lint": "npx eslint --ext .js,.ts src test bin",
|
|
25
|
+
"tsc": "npx tsc",
|
|
26
|
+
"test": "npm run tsc; npx nyc mocha --recursive test",
|
|
27
|
+
"build-web": "npx esbuild --bundle --minify --sourcemap --format=iife ./src/index.ts --outfile=docs/build/js/ski-interpreter.min.js",
|
|
28
|
+
"build-cjs": "npx esbuild --bundle --sourcemap --format=cjs ./src/index.ts --outfile=lib/ski-interpreter.cjs.js",
|
|
29
|
+
"build-esm": "npx esbuild --bundle --sourcemap --format=esm ./src/index.ts --outfile=lib/ski-interpreter.esm.js",
|
|
30
30
|
"build-site": "npx esbuild --bundle --minify --sourcemap ./site-src/index.js --outfile=docs/build/js/util.min.js",
|
|
31
31
|
"build-quest": "npx esbuild --bundle --minify --sourcemap --format=iife ./site-src/index-quest.js --outfile=docs/build/js/ski-quest.min.js",
|
|
32
|
-
"build-all": "npm run build-cjs && npm run build-esm && npm run build-web && npm run build-quest",
|
|
33
|
-
"build": "npm run lint && npm run
|
|
32
|
+
"build-all": "npm run build-cjs && npm run build-esm && npm run build-web && npm run build-site && npm run build-quest",
|
|
33
|
+
"build": "npm run lint && npm run tsc && npm run test && npm run build-all",
|
|
34
34
|
"prepack": "npm run build && cp docs/build/js/ski-* lib/"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"README.md",
|
|
39
39
|
"LICENSE",
|
|
40
40
|
"CHANGELOG.md",
|
|
41
|
-
"lib"
|
|
42
|
-
"types"
|
|
41
|
+
"lib"
|
|
43
42
|
],
|
|
44
43
|
"repository": {
|
|
45
44
|
"type": "git",
|
|
@@ -52,6 +51,8 @@
|
|
|
52
51
|
},
|
|
53
52
|
"homepage": "https://dallaylaen.github.io/ski-interpreter/index.html",
|
|
54
53
|
"devDependencies": {
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
55
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
55
56
|
"chai": "^4.3.7",
|
|
56
57
|
"esbuild": "^0.25.10",
|
|
57
58
|
"eslint": "^8.57.0",
|
package/types/index.d.ts
DELETED
package/types/src/quest.d.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
export type CaseResult = {
|
|
2
|
-
pass: boolean;
|
|
3
|
-
reason?: string;
|
|
4
|
-
steps: number;
|
|
5
|
-
start: typeof import("./expr").Expr;
|
|
6
|
-
found: typeof import("./expr").Expr;
|
|
7
|
-
expected: typeof import("./expr").Expr;
|
|
8
|
-
note?: string;
|
|
9
|
-
args: typeof import("./expr").Expr[];
|
|
10
|
-
case: Case;
|
|
11
|
-
};
|
|
12
|
-
export type Capability = {
|
|
13
|
-
linear?: boolean;
|
|
14
|
-
affine?: boolean;
|
|
15
|
-
normal?: boolean;
|
|
16
|
-
proper?: boolean;
|
|
17
|
-
discard?: boolean;
|
|
18
|
-
duplicate?: boolean;
|
|
19
|
-
arity?: number;
|
|
20
|
-
};
|
|
21
|
-
export type InputSpec = string | {
|
|
22
|
-
name: string;
|
|
23
|
-
fancy?: string;
|
|
24
|
-
allow?: string;
|
|
25
|
-
numbers?: boolean;
|
|
26
|
-
lambdas?: boolean;
|
|
27
|
-
};
|
|
28
|
-
export type QuestResult = {
|
|
29
|
-
pass: boolean;
|
|
30
|
-
details: CaseResult[];
|
|
31
|
-
expr?: typeof import("./expr").Expr;
|
|
32
|
-
input: typeof import("./expr").Expr[] | string[];
|
|
33
|
-
exception?: Error;
|
|
34
|
-
steps: number;
|
|
35
|
-
weight?: number;
|
|
36
|
-
};
|
|
37
|
-
export type SelfCheck = {
|
|
38
|
-
accepted?: string[][];
|
|
39
|
-
rejected?: string[][];
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {{
|
|
43
|
-
* pass: boolean,
|
|
44
|
-
* reason?: string,
|
|
45
|
-
* steps: number,
|
|
46
|
-
* start: Expr,
|
|
47
|
-
* found: Expr,
|
|
48
|
-
* expected: Expr,
|
|
49
|
-
* note?: string,
|
|
50
|
-
* args: Expr[],
|
|
51
|
-
* case: Case
|
|
52
|
-
* }} CaseResult
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* @typedef {{
|
|
56
|
-
* linear?: boolean,
|
|
57
|
-
* affine?: boolean,
|
|
58
|
-
* normal?: boolean,
|
|
59
|
-
* proper?: boolean,
|
|
60
|
-
* discard?: boolean,
|
|
61
|
-
* duplicate?: boolean,
|
|
62
|
-
* arity?: number,
|
|
63
|
-
* }} Capability
|
|
64
|
-
*/
|
|
65
|
-
/**
|
|
66
|
-
* @typedef {
|
|
67
|
-
* [string, string]
|
|
68
|
-
* | [{max?: number}, string, string]
|
|
69
|
-
* | [{caps: Capability, max?: number}, string]
|
|
70
|
-
* } TestCase
|
|
71
|
-
*/
|
|
72
|
-
/**
|
|
73
|
-
* @typedef {string | {name: string, fancy?: string, allow?: string, numbers?: boolean, lambdas?: boolean}} InputSpec
|
|
74
|
-
*/
|
|
75
|
-
/**
|
|
76
|
-
* @typedef {{
|
|
77
|
-
* pass: boolean,
|
|
78
|
-
* details: CaseResult[],
|
|
79
|
-
* expr?: Expr,
|
|
80
|
-
* input: Expr[]|string[],
|
|
81
|
-
* exception?: Error,
|
|
82
|
-
* steps: number,
|
|
83
|
-
* weight?: number
|
|
84
|
-
* }} QuestResult
|
|
85
|
-
*/
|
|
86
|
-
/**
|
|
87
|
-
* @typedef {{
|
|
88
|
-
* input: InputSpec | InputSpec[],
|
|
89
|
-
* cases: TestCase[],
|
|
90
|
-
*
|
|
91
|
-
* // the rest is optional
|
|
92
|
-
*
|
|
93
|
-
* allow?: string,
|
|
94
|
-
* numbers?: boolean,
|
|
95
|
-
* env?: string[],
|
|
96
|
-
* engine?: SKI,
|
|
97
|
-
* engineFull?: SKI,
|
|
98
|
-
*
|
|
99
|
-
* // metadata, also any fields not listed here will go to quest.meta.???
|
|
100
|
-
* id?: string|number,
|
|
101
|
-
* name?: string,
|
|
102
|
-
* intro?: string|string[], // multiple strings will be concatenated with spaces
|
|
103
|
-
* }} QuestSpec
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
|
-
* @typedef {{ accepted?: string[][], rejected?: string[][] }} SelfCheck
|
|
107
|
-
*/
|
|
108
|
-
export class Quest {
|
|
109
|
-
/**
|
|
110
|
-
* @description A combinator problem with a set of test cases for the proposed solution.
|
|
111
|
-
* @param {QuestSpec} options
|
|
112
|
-
* @example const quest = new Quest({
|
|
113
|
-
* input: 'identity',
|
|
114
|
-
* cases: [
|
|
115
|
-
* ['identity x', 'x'],
|
|
116
|
-
* ],
|
|
117
|
-
* allow: 'SK',
|
|
118
|
-
* intro: 'Find a combinator that behaves like the identity function.',
|
|
119
|
-
* });
|
|
120
|
-
* quest.check('S K K'); // { pass: true, details: [...], ... }
|
|
121
|
-
* quest.check('K S'); // { pass: false, details: [...], ... }
|
|
122
|
-
* quest.check('K x'); // fail! internal variable x is not equal to free variable x,
|
|
123
|
-
* // despite having the same name.
|
|
124
|
-
* quest.check('I'); // fail! I not in the allowed list.
|
|
125
|
-
*/
|
|
126
|
-
constructor(options: QuestSpec);
|
|
127
|
-
engine: any;
|
|
128
|
-
engineFull: any;
|
|
129
|
-
restrict: {
|
|
130
|
-
allow: QuestSpec;
|
|
131
|
-
numbers: any;
|
|
132
|
-
lambdas: any;
|
|
133
|
-
};
|
|
134
|
-
env: {};
|
|
135
|
-
input: any[];
|
|
136
|
-
envFull: {};
|
|
137
|
-
cases: any[];
|
|
138
|
-
name: any;
|
|
139
|
-
intro: any;
|
|
140
|
-
id: any;
|
|
141
|
-
meta: QuestSpec;
|
|
142
|
-
/**
|
|
143
|
-
* Display allowed terms based on what engine thinks of this.env + this.restrict.allow
|
|
144
|
-
* @return {string}
|
|
145
|
-
*/
|
|
146
|
-
allowed(): string;
|
|
147
|
-
addInput(term: any): void;
|
|
148
|
-
/**
|
|
149
|
-
*
|
|
150
|
-
* @param {{} | string} opt
|
|
151
|
-
* @param {string} terms
|
|
152
|
-
* @return {Quest}
|
|
153
|
-
*/
|
|
154
|
-
add(opt: {} | string, ...terms: string): Quest;
|
|
155
|
-
/**
|
|
156
|
-
* @description Statefully parse a list of strings into expressions or fancy aliases thereof.
|
|
157
|
-
* @param {string[]} input
|
|
158
|
-
* @return {{terms: Expr[], weight: number}}
|
|
159
|
-
*/
|
|
160
|
-
prepare(...input: string[]): {
|
|
161
|
-
terms: typeof import("./expr").Expr[];
|
|
162
|
-
weight: number;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {string} input
|
|
167
|
-
* @return {QuestResult}
|
|
168
|
-
*/
|
|
169
|
-
check(...input: string): QuestResult;
|
|
170
|
-
verify(options: any): {
|
|
171
|
-
date: string;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* @desc Verify that solutions that are expected to pass/fail do so.
|
|
175
|
-
* @param {SelfCheck|{[key: string]: SelfCheck}} dataset
|
|
176
|
-
* @return {{shouldPass: {input: string[], result: QuestResult}[], shouldFail: {input: string[], result: QuestResult}[]} | null}
|
|
177
|
-
*/
|
|
178
|
-
verifySolutions(dataset: SelfCheck | {
|
|
179
|
-
[key: string]: SelfCheck;
|
|
180
|
-
}): {
|
|
181
|
-
shouldPass: {
|
|
182
|
-
input: string[];
|
|
183
|
-
result: QuestResult;
|
|
184
|
-
}[];
|
|
185
|
-
shouldFail: {
|
|
186
|
-
input: string[];
|
|
187
|
-
result: QuestResult;
|
|
188
|
-
}[];
|
|
189
|
-
} | null;
|
|
190
|
-
verifyMeta(options?: {}): {
|
|
191
|
-
date: string;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
*
|
|
195
|
-
* @return {TestCase[]}
|
|
196
|
-
*/
|
|
197
|
-
show(): TestCase[];
|
|
198
|
-
}
|
|
199
|
-
export namespace Quest {
|
|
200
|
-
export { Group };
|
|
201
|
-
export { Case };
|
|
202
|
-
}
|
|
203
|
-
declare class Case {
|
|
204
|
-
/**
|
|
205
|
-
* @param {FreeVar[]} input
|
|
206
|
-
* @param {{
|
|
207
|
-
* max?: number,
|
|
208
|
-
* note?: string,
|
|
209
|
-
* env?: {[key:string]: Expr},
|
|
210
|
-
* engine: SKI
|
|
211
|
-
* }} options
|
|
212
|
-
*/
|
|
213
|
-
constructor(input: typeof import("./expr").FreeVar[], options: {
|
|
214
|
-
max?: number;
|
|
215
|
-
note?: string;
|
|
216
|
-
env?: {
|
|
217
|
-
[key: string]: typeof import("./expr").Expr;
|
|
218
|
-
};
|
|
219
|
-
engine: SKI;
|
|
220
|
-
});
|
|
221
|
-
max: number;
|
|
222
|
-
note: string;
|
|
223
|
-
env: {
|
|
224
|
-
[key: string]: typeof import("./expr").Expr;
|
|
225
|
-
};
|
|
226
|
-
input: typeof import("./expr").FreeVar[];
|
|
227
|
-
engine: SKI;
|
|
228
|
-
parse(src: any): Subst;
|
|
229
|
-
/**
|
|
230
|
-
* @param {Expr} expr
|
|
231
|
-
* @return {CaseResult}
|
|
232
|
-
*/
|
|
233
|
-
check(...expr: typeof import("./expr").Expr): CaseResult;
|
|
234
|
-
}
|
|
235
|
-
declare class Group {
|
|
236
|
-
constructor(options: any);
|
|
237
|
-
name: any;
|
|
238
|
-
intro: string;
|
|
239
|
-
id: any;
|
|
240
|
-
content: any;
|
|
241
|
-
verify(options: any): {
|
|
242
|
-
content: any;
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
import { SKI } from "./parser";
|
|
246
|
-
declare class Subst {
|
|
247
|
-
/**
|
|
248
|
-
* @descr A placeholder object with exactly n free variables to be substituted later.
|
|
249
|
-
* @param {Expr} expr
|
|
250
|
-
* @param {FreeVar[]} env
|
|
251
|
-
*/
|
|
252
|
-
constructor(expr: typeof import("./expr").Expr, env: typeof import("./expr").FreeVar[]);
|
|
253
|
-
expr: typeof import("./expr").Expr;
|
|
254
|
-
env: typeof import("./expr").FreeVar[];
|
|
255
|
-
apply(list: any): typeof import("./expr").Expr;
|
|
256
|
-
}
|
|
257
|
-
export {};
|