@dallaylaen/ski-interpreter 2.8.2 → 2.9.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 +25 -0
- package/bin/ski.js +38 -15
- package/example/collatz.ski +1 -1
- package/example/find-monobase.js +108 -0
- package/lib/ski-interpreter.cjs.js +42 -28
- 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 +42 -28
- package/lib/ski-interpreter.mjs.map +2 -2
- package/lib/ski-quest.min.js +5 -5
- package/lib/ski-quest.min.js.map +3 -3
- package/lib/types/extras.d.ts +49 -40
- package/lib/types/index.d.ts +1 -1
- package/lib/types/quest.d.ts +1 -0
- package/package.json +1 -1
package/lib/ski-interpreter.mjs
CHANGED
|
@@ -1686,6 +1686,8 @@ var Quest = class {
|
|
|
1686
1686
|
this.intro = list2str(options.intro);
|
|
1687
1687
|
this.id = options.id;
|
|
1688
1688
|
this.meta = meta;
|
|
1689
|
+
if (meta.created_at)
|
|
1690
|
+
this.created = new Date(meta.created_at);
|
|
1689
1691
|
for (const c of cases ?? [])
|
|
1690
1692
|
this.add(...c);
|
|
1691
1693
|
}
|
|
@@ -1833,10 +1835,9 @@ var Quest = class {
|
|
|
1833
1835
|
findings[field] = found;
|
|
1834
1836
|
}
|
|
1835
1837
|
if (options.date) {
|
|
1836
|
-
|
|
1837
|
-
if (isNaN(date.getTime()))
|
|
1838
|
+
if (!this.created || isNaN(this.created.getTime()))
|
|
1838
1839
|
findings.date = "invalid date format: " + this.meta?.created_at;
|
|
1839
|
-
else if (
|
|
1840
|
+
else if (this.created < /* @__PURE__ */ new Date("2024-07-15") || this.created > /* @__PURE__ */ new Date())
|
|
1840
1841
|
findings.date = "date out of range: " + this.meta?.created_at;
|
|
1841
1842
|
}
|
|
1842
1843
|
return findings;
|
|
@@ -2130,7 +2131,7 @@ function deepFormat(obj, options = {}) {
|
|
|
2130
2131
|
out[key] = deepFormat(obj[key], options);
|
|
2131
2132
|
return out;
|
|
2132
2133
|
}
|
|
2133
|
-
function search(seed, options, predicate) {
|
|
2134
|
+
function* search(seed, options, predicate) {
|
|
2134
2135
|
const {
|
|
2135
2136
|
depth = 16,
|
|
2136
2137
|
infer = true,
|
|
@@ -2141,57 +2142,70 @@ function search(seed, options, predicate) {
|
|
|
2141
2142
|
let total = 0;
|
|
2142
2143
|
let probed = 0;
|
|
2143
2144
|
const seen = {};
|
|
2145
|
+
const parseResult = (raw) => {
|
|
2146
|
+
if (raw === null || raw === void 0)
|
|
2147
|
+
return {};
|
|
2148
|
+
if (typeof raw === "number")
|
|
2149
|
+
return raw > 0 ? { found: true, stop: true } : raw < 0 ? { offset: -1 } : {};
|
|
2150
|
+
return raw;
|
|
2151
|
+
};
|
|
2144
2152
|
const maybeProbe = (term) => {
|
|
2145
2153
|
total++;
|
|
2146
2154
|
const props = infer ? term.infer({ max: options.max, maxArgs: options.maxArgs }) : null;
|
|
2147
2155
|
if (hasSeen && props && props.expr) {
|
|
2148
2156
|
const key = String(props.expr);
|
|
2149
2157
|
if (seen[key])
|
|
2150
|
-
return { res: -1, props };
|
|
2158
|
+
return { res: { offset: -1 }, props };
|
|
2151
2159
|
seen[key] = true;
|
|
2152
2160
|
}
|
|
2153
2161
|
probed++;
|
|
2154
|
-
const res = predicate(term, props);
|
|
2162
|
+
const res = parseResult(predicate(term, props));
|
|
2155
2163
|
return { res, props };
|
|
2156
2164
|
};
|
|
2157
2165
|
for (const term of seed) {
|
|
2158
|
-
const { res
|
|
2159
|
-
if (res
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2166
|
+
const { res } = maybeProbe(term);
|
|
2167
|
+
if (res.found)
|
|
2168
|
+
yield { expr: term, found: true, step: false, gen: 0, total, probed, cache };
|
|
2169
|
+
if (res.stop)
|
|
2170
|
+
return;
|
|
2171
|
+
if ((res.offset ?? 0) >= 0)
|
|
2172
|
+
cache[0].push(term);
|
|
2164
2173
|
}
|
|
2165
2174
|
let lastProgress = 0;
|
|
2166
2175
|
for (let gen = 1; gen < depth; gen++) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
lastProgress = total;
|
|
2170
|
-
}
|
|
2176
|
+
yield { found: false, step: true, gen, total, probed, cache };
|
|
2177
|
+
lastProgress = total;
|
|
2171
2178
|
for (let i = 0; i < gen; i++) {
|
|
2172
2179
|
for (const a of cache[gen - i - 1] || []) {
|
|
2173
2180
|
for (const b of cache[i] || []) {
|
|
2174
|
-
if (total >= (options.tries ?? Infinity))
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2181
|
+
if (total >= (options.tries ?? Infinity)) {
|
|
2182
|
+
yield { found: false, step: false, gen, total, probed, cache };
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
if (total - lastProgress >= progressInterval) {
|
|
2186
|
+
yield { found: false, step: false, gen, total, probed, cache };
|
|
2178
2187
|
lastProgress = total;
|
|
2179
2188
|
}
|
|
2180
2189
|
const term = a.apply(b);
|
|
2181
2190
|
const { res, props } = maybeProbe(term);
|
|
2182
|
-
if (
|
|
2183
|
-
|
|
2184
|
-
|
|
2191
|
+
if (res.found)
|
|
2192
|
+
yield { expr: term, found: true, step: false, gen, total, probed, cache };
|
|
2193
|
+
if (res.stop) {
|
|
2194
|
+
yield { found: false, step: false, gen, total, probed, cache };
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
if ((res.offset ?? 0) < 0)
|
|
2185
2198
|
continue;
|
|
2186
|
-
const
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2199
|
+
const autoOffset = infer && props ? (props.expr ? 0 : 3) + (props.dup ? 1 : 0) + (props.proper ? 0 : 1) : 0;
|
|
2200
|
+
const finalOffset = res.offset ?? autoOffset;
|
|
2201
|
+
if (!cache[gen + finalOffset])
|
|
2202
|
+
cache[gen + finalOffset] = [];
|
|
2203
|
+
cache[gen + finalOffset].push(term);
|
|
2190
2204
|
}
|
|
2191
2205
|
}
|
|
2192
2206
|
}
|
|
2193
2207
|
}
|
|
2194
|
-
|
|
2208
|
+
yield { found: false, step: false, gen: depth, total, probed, cache };
|
|
2195
2209
|
}
|
|
2196
2210
|
function isStringPair(x) {
|
|
2197
2211
|
return Array.isArray(x) && x.length === 2 && typeof x[0] === "string" && typeof x[1] === "string" ? void 0 : "must be a pair of strings";
|