@dallaylaen/ski-interpreter 2.8.0 → 2.8.1
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 +12 -0
- package/bin/ski.js +17 -0
- package/lib/ski-interpreter.cjs.js +78 -61
- package/lib/ski-interpreter.cjs.js.map +2 -2
- package/lib/ski-interpreter.min.js +5 -5
- package/lib/ski-interpreter.min.js.map +3 -3
- package/lib/ski-interpreter.mjs +78 -61
- package/lib/ski-interpreter.mjs.map +2 -2
- package/lib/ski-quest.min.js +4 -4
- package/lib/ski-quest.min.js.map +3 -3
- package/lib/types/extras.d.ts +37 -13
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
package/lib/ski-interpreter.mjs
CHANGED
|
@@ -331,11 +331,9 @@ var Expr = class _Expr {
|
|
|
331
331
|
let steps = 0;
|
|
332
332
|
let expr = this;
|
|
333
333
|
main: for (let i = 0; i < options.maxArgs; i++) {
|
|
334
|
-
const next = expr.run({ max: options.max - steps, maxSize: options.maxSize });
|
|
334
|
+
const next = expr.run({ max: Math.max((options.max - steps) / 2, 10), maxSize: options.maxSize });
|
|
335
335
|
steps += next.steps;
|
|
336
|
-
if (
|
|
337
|
-
break;
|
|
338
|
-
if (firstVar(next.expr)) {
|
|
336
|
+
if (next.final && firstVar(next.expr)) {
|
|
339
337
|
expr = next.expr;
|
|
340
338
|
if (!expr.any((e) => !(e instanceof FreeVar || e instanceof App)))
|
|
341
339
|
return maybeLambda(probe, expr, { steps });
|
|
@@ -2061,6 +2059,77 @@ function canonize(term, options = {}) {
|
|
|
2061
2059
|
}
|
|
2062
2060
|
|
|
2063
2061
|
// src/extras.ts
|
|
2062
|
+
var formatSchema = {
|
|
2063
|
+
html: (x) => typeof x === "boolean" ? void 0 : "must be a boolean",
|
|
2064
|
+
terse: (x) => typeof x === "boolean" ? void 0 : "must be a boolean",
|
|
2065
|
+
space: (x) => typeof x === "string" ? void 0 : "must be a string",
|
|
2066
|
+
brackets: isStringPair,
|
|
2067
|
+
var: isStringPair,
|
|
2068
|
+
around: isStringPair,
|
|
2069
|
+
redex: isStringPair,
|
|
2070
|
+
lambda: isStringTriple,
|
|
2071
|
+
inventory: (x) => {
|
|
2072
|
+
if (typeof x !== "object" || x === null || x.constructor !== Object)
|
|
2073
|
+
return "must be an object, not " + (x?.constructor?.name ?? typeof x);
|
|
2074
|
+
const refined = x;
|
|
2075
|
+
for (const key of Object.keys(refined)) {
|
|
2076
|
+
if (!(refined[key] instanceof Expr))
|
|
2077
|
+
return "key " + key + "is not an Expr";
|
|
2078
|
+
}
|
|
2079
|
+
return void 0;
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
function checkFormatOptions(raw) {
|
|
2083
|
+
if (raw === null || raw === void 0)
|
|
2084
|
+
return { value: {} };
|
|
2085
|
+
if (typeof raw !== "object" || Array.isArray(raw) || raw.constructor !== Object)
|
|
2086
|
+
return { error: { object: "Format options must be an object, not " + (raw?.constructor?.name ?? typeof raw) } };
|
|
2087
|
+
const rec = raw;
|
|
2088
|
+
const error = {};
|
|
2089
|
+
for (const key in rec) {
|
|
2090
|
+
if (formatSchema[key]) {
|
|
2091
|
+
const err = formatSchema[key](rec[key]);
|
|
2092
|
+
if (err)
|
|
2093
|
+
error[key] = err;
|
|
2094
|
+
} else
|
|
2095
|
+
error[key] = "unknown option";
|
|
2096
|
+
}
|
|
2097
|
+
return Object.keys(error).length > 0 ? { error } : { value: rec };
|
|
2098
|
+
}
|
|
2099
|
+
function equiv(e1, e2, options = {}) {
|
|
2100
|
+
let steps = 0;
|
|
2101
|
+
const [n1, n2] = [e1, e2].map((x) => x.traverse((e) => {
|
|
2102
|
+
const props = e.infer(options);
|
|
2103
|
+
steps += props.steps ?? 0;
|
|
2104
|
+
return props.expr;
|
|
2105
|
+
}));
|
|
2106
|
+
const normal = !!(n1 && n2);
|
|
2107
|
+
return {
|
|
2108
|
+
steps,
|
|
2109
|
+
normal,
|
|
2110
|
+
equal: normal ? n1.equals(n2) : false,
|
|
2111
|
+
canonical: [n1, n2]
|
|
2112
|
+
};
|
|
2113
|
+
}
|
|
2114
|
+
function declare(expr, env) {
|
|
2115
|
+
return expr.declare({ inventory: env });
|
|
2116
|
+
}
|
|
2117
|
+
function deepFormat(obj, options = {}) {
|
|
2118
|
+
if (obj instanceof Expr)
|
|
2119
|
+
return obj.format(options);
|
|
2120
|
+
if (obj instanceof Quest)
|
|
2121
|
+
return "Quest(" + obj.name + ")";
|
|
2122
|
+
if (obj instanceof Quest.Case)
|
|
2123
|
+
return "Quest.Case";
|
|
2124
|
+
if (Array.isArray(obj))
|
|
2125
|
+
return obj.map((item) => deepFormat(item, options));
|
|
2126
|
+
if (typeof obj !== "object" || obj === null || obj.constructor !== Object)
|
|
2127
|
+
return obj;
|
|
2128
|
+
const out = {};
|
|
2129
|
+
for (const key in obj)
|
|
2130
|
+
out[key] = deepFormat(obj[key], options);
|
|
2131
|
+
return out;
|
|
2132
|
+
}
|
|
2064
2133
|
function search(seed, options, predicate) {
|
|
2065
2134
|
const {
|
|
2066
2135
|
depth = 16,
|
|
@@ -2124,65 +2193,13 @@ function search(seed, options, predicate) {
|
|
|
2124
2193
|
}
|
|
2125
2194
|
return { total, probed, gen: depth, ...options.retain ? { cache } : {} };
|
|
2126
2195
|
}
|
|
2127
|
-
function
|
|
2128
|
-
|
|
2129
|
-
return obj.format(options);
|
|
2130
|
-
if (obj instanceof Quest)
|
|
2131
|
-
return "Quest(" + obj.name + ")";
|
|
2132
|
-
if (obj instanceof Quest.Case)
|
|
2133
|
-
return "Quest.Case";
|
|
2134
|
-
if (Array.isArray(obj))
|
|
2135
|
-
return obj.map((item) => deepFormat(item, options));
|
|
2136
|
-
if (typeof obj !== "object" || obj === null || obj.constructor !== Object)
|
|
2137
|
-
return obj;
|
|
2138
|
-
const out = {};
|
|
2139
|
-
for (const key in obj)
|
|
2140
|
-
out[key] = deepFormat(obj[key], options);
|
|
2141
|
-
return out;
|
|
2142
|
-
}
|
|
2143
|
-
function declare(expr, env) {
|
|
2144
|
-
return expr.declare({ inventory: env });
|
|
2196
|
+
function isStringPair(x) {
|
|
2197
|
+
return Array.isArray(x) && x.length === 2 && typeof x[0] === "string" && typeof x[1] === "string" ? void 0 : "must be a pair of strings";
|
|
2145
2198
|
}
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
var schema = {
|
|
2149
|
-
html: (x) => typeof x === "boolean" ? void 0 : "must be a boolean",
|
|
2150
|
-
terse: (x) => typeof x === "boolean" ? void 0 : "must be a boolean",
|
|
2151
|
-
space: (x) => typeof x === "string" ? void 0 : "must be a string",
|
|
2152
|
-
brackets: isStringPair,
|
|
2153
|
-
var: isStringPair,
|
|
2154
|
-
around: isStringPair,
|
|
2155
|
-
redex: isStringPair,
|
|
2156
|
-
lambda: isStringTriple,
|
|
2157
|
-
inventory: (x) => {
|
|
2158
|
-
if (typeof x !== "object" || x === null || x.constructor !== Object)
|
|
2159
|
-
return "must be an object, not " + (x?.constructor?.name ?? typeof x);
|
|
2160
|
-
const refined = x;
|
|
2161
|
-
for (const key of Object.keys(refined)) {
|
|
2162
|
-
if (!(refined[key] instanceof Expr))
|
|
2163
|
-
return "key " + key + "is not an Expr";
|
|
2164
|
-
}
|
|
2165
|
-
return void 0;
|
|
2166
|
-
}
|
|
2167
|
-
};
|
|
2168
|
-
function checkFormatOptions(raw) {
|
|
2169
|
-
if (raw === null || raw === void 0)
|
|
2170
|
-
return { value: {} };
|
|
2171
|
-
if (typeof raw !== "object" || Array.isArray(raw) || raw.constructor !== Object)
|
|
2172
|
-
return { error: { object: "Format options must be an object, not " + (raw?.constructor?.name ?? typeof raw) } };
|
|
2173
|
-
const rec = raw;
|
|
2174
|
-
const error = {};
|
|
2175
|
-
for (const key in rec) {
|
|
2176
|
-
if (schema[key]) {
|
|
2177
|
-
const err = schema[key](rec[key]);
|
|
2178
|
-
if (err)
|
|
2179
|
-
error[key] = err;
|
|
2180
|
-
} else
|
|
2181
|
-
error[key] = "unknown option";
|
|
2182
|
-
}
|
|
2183
|
-
return Object.keys(error).length > 0 ? { error } : { value: rec };
|
|
2199
|
+
function isStringTriple(x) {
|
|
2200
|
+
return Array.isArray(x) && x.length === 3 && typeof x[0] === "string" && typeof x[1] === "string" && typeof x[2] === "string" ? void 0 : "must be a triplet of strings";
|
|
2184
2201
|
}
|
|
2185
|
-
var extras = { search, deepFormat, declare, toposort, checkFormatOptions };
|
|
2202
|
+
var extras = { search, deepFormat, declare, toposort, checkFormatOptions, equiv };
|
|
2186
2203
|
|
|
2187
2204
|
// src/index.ts
|
|
2188
2205
|
extras.toposort = toposort;
|