@skillstech/thunderlang 1.5.0 → 1.6.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 +37 -0
- package/dist/core.cjs +1135 -161
- package/dist/index.cjs +5641 -4650
- package/dist/learn.cjs +12 -1
- package/package.json +1 -1
- package/src/cli.mjs +7 -4
- package/src/emit.mjs +1 -1
- package/src/mcp.mjs +18 -1
- package/src/write-steps.mjs +164 -24
- package/src/write-words.mjs +239 -0
- package/src/write.mjs +12 -0
package/dist/core.cjs
CHANGED
|
@@ -1778,7 +1778,7 @@ function literalDecimal(n) {
|
|
|
1778
1778
|
return null;
|
|
1779
1779
|
}
|
|
1780
1780
|
function renderExpr(src, inputs, D, money = {}, dialect = "js") {
|
|
1781
|
-
const
|
|
1781
|
+
const known2 = new Set(inputs);
|
|
1782
1782
|
const isMoney = (n) => n.k === "ref" && Object.prototype.hasOwnProperty.call(money, n.path);
|
|
1783
1783
|
const moneyRefs = (n, out = []) => {
|
|
1784
1784
|
if (isMoney(n)) out.push(n.path);
|
|
@@ -1839,7 +1839,7 @@ function renderExpr(src, inputs, D, money = {}, dialect = "js") {
|
|
|
1839
1839
|
case "lit":
|
|
1840
1840
|
return typeof n.v === "string" ? JSON.stringify(n.v) : typeof n.v === "boolean" ? D.bool(n.v) : D.num ? D.num(n.v) : String(n.v);
|
|
1841
1841
|
case "ref":
|
|
1842
|
-
return
|
|
1842
|
+
return known2.has(n.path) || known2.has(n.path.split(".")[0]) ? n.path : JSON.stringify(n.path);
|
|
1843
1843
|
default:
|
|
1844
1844
|
return D.nil;
|
|
1845
1845
|
}
|
|
@@ -4278,8 +4278,8 @@ var Parser = class {
|
|
|
4278
4278
|
}
|
|
4279
4279
|
const type = `${flatName(callee2)}${typeArgs ?? ""}${"[]".repeat(sizes.length)}`;
|
|
4280
4280
|
if (this.isOp("{")) {
|
|
4281
|
-
const
|
|
4282
|
-
return this.postfix({ kind: "array", items:
|
|
4281
|
+
const lit5 = this.objectLit();
|
|
4282
|
+
return this.postfix({ kind: "array", items: lit5.kind === "array" ? lit5.items : lit5.entries.length ? fail2("array initializer") : [], type, new: true });
|
|
4283
4283
|
}
|
|
4284
4284
|
return this.postfix({ kind: "call", callee: { kind: "name", name: type, type: true }, args: sizes.filter(Boolean), new: true, array: true });
|
|
4285
4285
|
}
|
|
@@ -9787,20 +9787,20 @@ function clause(n, negate = false) {
|
|
|
9787
9787
|
}
|
|
9788
9788
|
if (n.cmp) {
|
|
9789
9789
|
const l = n.l, r = n.r;
|
|
9790
|
-
const path = l.path ?? r.path,
|
|
9790
|
+
const path = l.path ?? r.path, lit5 = l.path ? r.lit : l.lit;
|
|
9791
9791
|
const isNot = n.cmp === "!=" !== negate;
|
|
9792
9792
|
if (["<", ">", "<=", ">="].includes(n.cmp)) {
|
|
9793
9793
|
const words15 = { "<": "less than", ">": "more than", "<=": "at most", ">=": "at least" }[n.cmp];
|
|
9794
9794
|
return `${valueOf(l)} is ${negate ? "not " : ""}${words15} ${valueOf(r)}`;
|
|
9795
9795
|
}
|
|
9796
|
-
if (path === "github.ref" &&
|
|
9797
|
-
if (
|
|
9798
|
-
if (
|
|
9796
|
+
if (path === "github.ref" && lit5 != null) {
|
|
9797
|
+
if (lit5.startsWith("refs/heads/")) return `the branch is ${isNot ? "not " : ""}${lit5.slice(11)}`;
|
|
9798
|
+
if (lit5.startsWith("refs/tags/")) return `the tag is ${isNot ? "not " : ""}${lit5.slice(10)}`;
|
|
9799
9799
|
}
|
|
9800
|
-
if (path === "github.event_name" &&
|
|
9801
|
-
if (
|
|
9800
|
+
if (path === "github.event_name" && lit5 != null) return `it was ${isNot ? "not " : ""}started by ${EVENT_WORDS[lit5] ?? `the ${lit5.replace(/_/g, " ")} event`}`;
|
|
9801
|
+
if (lit5 === "true" || lit5 === "false") {
|
|
9802
9802
|
const v = valueOf(l.path ? l : r);
|
|
9803
|
-
const yes =
|
|
9803
|
+
const yes = lit5 === "true" !== isNot;
|
|
9804
9804
|
const w = /^whether (.+?) (is|was) (.+)$/.exec(v);
|
|
9805
9805
|
if (w) return `${w[1]} ${w[2]} ${yes ? "" : "not "}${w[3]}`;
|
|
9806
9806
|
return `${v} is ${yes ? "true" : "false"}`;
|
|
@@ -10134,8 +10134,8 @@ function commandSays(cmd) {
|
|
|
10134
10134
|
case "bunx": {
|
|
10135
10135
|
const rest2 = args.filter((a) => a !== "--yes" && a !== "-y" && !a.startsWith("--package"));
|
|
10136
10136
|
const name = (rest2[0] ?? "").replace(/^(@[^/]+\/)?([^@]+).*$/, "$2");
|
|
10137
|
-
const
|
|
10138
|
-
return
|
|
10137
|
+
const known2 = JS_TOOLS[name]?.(rest2.slice(1));
|
|
10138
|
+
return known2 ?? (name ? `Runs ${name}` : null);
|
|
10139
10139
|
}
|
|
10140
10140
|
case "node": {
|
|
10141
10141
|
if (args[0] === "-p" || args[0] === "-e" || args[0] === "--eval" || args[0] === "--print") {
|
|
@@ -11648,7 +11648,7 @@ function actionWords(uses, w) {
|
|
|
11648
11648
|
if (w.cache) s += ", reusing saved downloads";
|
|
11649
11649
|
return s;
|
|
11650
11650
|
}
|
|
11651
|
-
const
|
|
11651
|
+
const known2 = {
|
|
11652
11652
|
"pnpm/action-setup": () => `Sets up pnpm${ver(w.version)}`,
|
|
11653
11653
|
"oven-sh/setup-bun": () => `Sets up Bun${ver(w["bun-version"])}`,
|
|
11654
11654
|
"denoland/setup-deno": () => "Sets up Deno",
|
|
@@ -11685,7 +11685,7 @@ function actionWords(uses, w) {
|
|
|
11685
11685
|
"codecov/codecov-action": () => "Sends test coverage to Codecov",
|
|
11686
11686
|
"actions/dependency-review-action": () => "Checks new dependencies for known problems"
|
|
11687
11687
|
}[key];
|
|
11688
|
-
if (
|
|
11688
|
+
if (known2) return known2();
|
|
11689
11689
|
return `Uses ${repo}`;
|
|
11690
11690
|
}
|
|
11691
11691
|
function readWorkflow(src, file = "workflow.yml") {
|
|
@@ -12148,8 +12148,8 @@ var Parser2 = class _Parser {
|
|
|
12148
12148
|
this.next();
|
|
12149
12149
|
const yes = this.withNl(true, () => this.expr());
|
|
12150
12150
|
this.withNl(true, () => this.expect(":"));
|
|
12151
|
-
const
|
|
12152
|
-
return this.node("cond", s,
|
|
12151
|
+
const no3 = this.expr();
|
|
12152
|
+
return this.node("cond", s, no3.e, { test, yes, no: no3 });
|
|
12153
12153
|
}
|
|
12154
12154
|
return test;
|
|
12155
12155
|
}
|
|
@@ -12212,8 +12212,8 @@ var Parser2 = class _Parser {
|
|
|
12212
12212
|
}
|
|
12213
12213
|
const idx = this.expr();
|
|
12214
12214
|
const close = this.expect("]");
|
|
12215
|
-
const
|
|
12216
|
-
return { part:
|
|
12215
|
+
const lit5 = idx.t === "num" ? `[${idx.v}]` : idx.t === "str" && !idx.template ? `[${JSON.stringify(idx.v)}]` : "[\u2026]";
|
|
12216
|
+
return { part: lit5, idx, e: close.e };
|
|
12217
12217
|
});
|
|
12218
12218
|
n = this.extend(n, r.part, r.idx, this.toks[this.i - 1].e);
|
|
12219
12219
|
continue;
|
|
@@ -12409,36 +12409,36 @@ var Parser2 = class _Parser {
|
|
|
12409
12409
|
template(s, from, to, e, raw) {
|
|
12410
12410
|
const src = this.src, hcl = this.hcl;
|
|
12411
12411
|
const parts = [];
|
|
12412
|
-
let
|
|
12412
|
+
let lit5 = "", template = false;
|
|
12413
12413
|
for (let i = from; i < to; ) {
|
|
12414
12414
|
const c = src[i];
|
|
12415
12415
|
if (!raw && c === "\\" && i + 1 < to) {
|
|
12416
12416
|
const n = src[i + 1];
|
|
12417
12417
|
if (n === "u" && hcl) {
|
|
12418
|
-
|
|
12418
|
+
lit5 += String.fromCharCode(parseInt(src.slice(i + 2, i + 6), 16) || 0);
|
|
12419
12419
|
i += 6;
|
|
12420
12420
|
continue;
|
|
12421
12421
|
}
|
|
12422
12422
|
if (n === "u" && src[i + 2] === "{") {
|
|
12423
12423
|
const close = src.indexOf("}", i);
|
|
12424
|
-
|
|
12424
|
+
lit5 += String.fromCodePoint(parseInt(src.slice(i + 3, close), 16) || 0);
|
|
12425
12425
|
i = close + 1;
|
|
12426
12426
|
continue;
|
|
12427
12427
|
}
|
|
12428
|
-
|
|
12428
|
+
lit5 += { n: "\n", t: " ", r: "\r" }[n] ?? n;
|
|
12429
12429
|
i += 2;
|
|
12430
12430
|
continue;
|
|
12431
12431
|
}
|
|
12432
12432
|
if (hcl && (c === "$" || c === "%") && src[i + 1] === c && src[i + 2] === "{") {
|
|
12433
|
-
|
|
12433
|
+
lit5 += `${c}{`;
|
|
12434
12434
|
i += 3;
|
|
12435
12435
|
continue;
|
|
12436
12436
|
}
|
|
12437
12437
|
if ((c === "$" || hcl && c === "%") && src[i + 1] === "{") {
|
|
12438
12438
|
const close = scanInterp(src, i + 2, this.dialect);
|
|
12439
12439
|
template = true;
|
|
12440
|
-
if (
|
|
12441
|
-
|
|
12440
|
+
if (lit5) parts.push(lit5);
|
|
12441
|
+
lit5 = "";
|
|
12442
12442
|
if (c === "%") {
|
|
12443
12443
|
parts.push(this.node("other", i, close, { why: "a template directive" }));
|
|
12444
12444
|
i = close;
|
|
@@ -12458,10 +12458,10 @@ var Parser2 = class _Parser {
|
|
|
12458
12458
|
i = close;
|
|
12459
12459
|
continue;
|
|
12460
12460
|
}
|
|
12461
|
-
|
|
12461
|
+
lit5 += c;
|
|
12462
12462
|
i++;
|
|
12463
12463
|
}
|
|
12464
|
-
if (
|
|
12464
|
+
if (lit5) parts.push(lit5);
|
|
12465
12465
|
return this.node("str", s, e, { v: template ? null : parts.join(""), template, parts });
|
|
12466
12466
|
}
|
|
12467
12467
|
};
|
|
@@ -13290,10 +13290,10 @@ function readTerraform(src, file = "main.tf") {
|
|
|
13290
13290
|
});
|
|
13291
13291
|
} else if (b.type === "locals") {
|
|
13292
13292
|
for (const a of b.body) if (a.kind === "attr") {
|
|
13293
|
-
const
|
|
13293
|
+
const lit5 = isLiteral(a.value);
|
|
13294
13294
|
const secret = isSecretKey(a.name) && a.value.t === "str";
|
|
13295
|
-
if (secret &&
|
|
13296
|
-
settings.push({ name: a.name, source:
|
|
13295
|
+
if (secret && lit5 && a.value.v) fact("secret-in-plain-config", `The value ${a.name} looks like a secret and is written in the file.`, a.line);
|
|
13296
|
+
settings.push({ name: a.name, source: lit5 ? "literal" : "computed", secret, file, line: a.line, ...lit5 ? {} : { computed: true }, ...lit5 && !secret ? { default: valueText(a.value, refWords).text } : {} });
|
|
13297
13297
|
}
|
|
13298
13298
|
} else if (b.type === "output" && b.labels[0]) {
|
|
13299
13299
|
const sens = attrOf(b.body, "sensitive")?.value;
|
|
@@ -13955,10 +13955,10 @@ function readBicep(src, file = "main.bicep") {
|
|
|
13955
13955
|
...doc
|
|
13956
13956
|
});
|
|
13957
13957
|
} else if (d.kind === "var") {
|
|
13958
|
-
const
|
|
13958
|
+
const lit5 = isLiteral(d.value);
|
|
13959
13959
|
const secret = isSecretKey(d.name) && d.value?.t === "str";
|
|
13960
|
-
if (secret &&
|
|
13961
|
-
settings.push({ name: d.name, source:
|
|
13960
|
+
if (secret && lit5 && d.value.v) fact("secret-in-plain-config", `The value ${d.name} looks like a secret and is written in the file.`, d.line);
|
|
13961
|
+
settings.push({ name: d.name, source: lit5 ? "literal" : "computed", secret, file, line: d.line, ...lit5 ? {} : { computed: true }, ...lit5 && !secret ? { default: valueText(d.value, refWords).text } : {}, ...doc });
|
|
13962
13962
|
} else if (d.kind === "output") {
|
|
13963
13963
|
const from = valueText(d.value, refWords);
|
|
13964
13964
|
settings.push({ name: d.name, source: "computed", secret: !!deco(d, "secure") || isSecretKey(d.name) && /^string\b/.test(d.typeRaw ?? ""), computed: true, output: true, file, line: d.line, ...from.from?.length ? { from: from.from.slice(0, 3) } : {}, ...doc });
|
|
@@ -14175,12 +14175,12 @@ function secretLiteral(name, value) {
|
|
|
14175
14175
|
return !/^(true|false|yes|no|on|off|\d+|enabled|disabled|none|null|changeme|<.*>)$/i.test(v);
|
|
14176
14176
|
}
|
|
14177
14177
|
var HOST_KEY = /(host|hostname|addr|address|url|uri|server|servers|endpoint|dsn|broker|brokers|connection|conn)$/i;
|
|
14178
|
-
function servicesNamed(key, value,
|
|
14178
|
+
function servicesNamed(key, value, known2) {
|
|
14179
14179
|
const out = [];
|
|
14180
14180
|
const v = String(value ?? "").trim();
|
|
14181
14181
|
const add = (h) => {
|
|
14182
14182
|
const host = String(h).toLowerCase();
|
|
14183
|
-
if ((!
|
|
14183
|
+
if ((!known2 || known2.has(host)) && !out.includes(host) && !/^(localhost|0\.0\.0\.0|127\.0\.0\.1)$/.test(host)) out.push(host);
|
|
14184
14184
|
};
|
|
14185
14185
|
for (const part of v.split(/[,\s]+/)) {
|
|
14186
14186
|
if (!part) continue;
|
|
@@ -15891,8 +15891,8 @@ function sayCall(name, args) {
|
|
|
15891
15891
|
return null;
|
|
15892
15892
|
}
|
|
15893
15893
|
var wholeWords = (q2) => q2 && q2.endsWith("\u2026") && q2.length > 24 ? `${q2.slice(0, -1).replace(/\s+\S*$/, "").replace(/[\s,;:.-]+$/, "")}\u2026` : q2;
|
|
15894
|
-
function templateWithValues(
|
|
15895
|
-
const t = String(
|
|
15894
|
+
function templateWithValues(lit5, n = 70) {
|
|
15895
|
+
const t = String(lit5).trim();
|
|
15896
15896
|
if (!t.startsWith("`")) return null;
|
|
15897
15897
|
let out = "";
|
|
15898
15898
|
for (let i = 1; i < t.length; i++) {
|
|
@@ -16057,9 +16057,9 @@ function sayCommon(value) {
|
|
|
16057
16057
|
const t = x.trim();
|
|
16058
16058
|
return sayValue(t) ?? sayArithmetic(t) ?? (/^\$?[\w$]+(?:\.[\w$]+)*$/.test(t) ? possessiveWords(t) : null);
|
|
16059
16059
|
};
|
|
16060
|
-
const choice = (yes, cond,
|
|
16061
|
-
if (![yes, cond,
|
|
16062
|
-
const a = side2(yes), b = side2(
|
|
16060
|
+
const choice = (yes, cond, no3) => {
|
|
16061
|
+
if (![yes, cond, no3].every((x) => balancedText(x))) return null;
|
|
16062
|
+
const a = side2(yes), b = side2(no3), c = sayCodeCondition(cond);
|
|
16063
16063
|
return a != null && b != null && !isCodeWords(c) ? `${a} if ${c}, otherwise ${b}` : null;
|
|
16064
16064
|
};
|
|
16065
16065
|
if ((m = e.match(/^(.+?)\s+\?\s+([^:?]+?)\s+:\s+([^:?]+)$/)) && !/^(?:[\w$]+\??\s*:)/.test(e)) return choice(m[2], m[1], m[3]);
|
|
@@ -16600,8 +16600,8 @@ function libraryStep(head) {
|
|
|
16600
16600
|
const lib = sayLibraryCall(h);
|
|
16601
16601
|
return lib && !lib.value ? { kind: "call", says: lib.says, library: true, does: lib.does } : null;
|
|
16602
16602
|
}
|
|
16603
|
-
function quotedBody(
|
|
16604
|
-
const t = String(
|
|
16603
|
+
function quotedBody(lit5) {
|
|
16604
|
+
const t = String(lit5).trim();
|
|
16605
16605
|
if (!/^"/.test(t) || t.length < 2 || !t.endsWith('"')) return null;
|
|
16606
16606
|
for (let i = 1; i < t.length - 1; i++) {
|
|
16607
16607
|
if (t[i] === "\\") {
|
|
@@ -16613,8 +16613,8 @@ function quotedBody(lit4) {
|
|
|
16613
16613
|
return t.slice(1, -1);
|
|
16614
16614
|
}
|
|
16615
16615
|
var PLAIN_PLACEHOLDER = /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*|\[\d+\])*(?:\(\))?$/;
|
|
16616
|
-
function templateTextWithValues(
|
|
16617
|
-
const t = String(
|
|
16616
|
+
function templateTextWithValues(lit5) {
|
|
16617
|
+
const t = String(lit5).trim();
|
|
16618
16618
|
const js = t[0] === "`";
|
|
16619
16619
|
if (!js && !/^f(["'])/.test(t)) return null;
|
|
16620
16620
|
const q2 = js ? "`" : t[1];
|
|
@@ -16663,8 +16663,8 @@ function templateTextWithValues(lit4) {
|
|
|
16663
16663
|
}
|
|
16664
16664
|
return any && i === t.length - 1 ? `"${out}"` : null;
|
|
16665
16665
|
}
|
|
16666
|
-
function swiftTextWithValues(
|
|
16667
|
-
const t = String(
|
|
16666
|
+
function swiftTextWithValues(lit5) {
|
|
16667
|
+
const t = String(lit5).trim();
|
|
16668
16668
|
if (!/^"/.test(t) || /^"""/.test(t)) return null;
|
|
16669
16669
|
let out = "", i = 1;
|
|
16670
16670
|
for (; i < t.length; i++) {
|
|
@@ -16687,8 +16687,8 @@ function swiftTextWithValues(lit4) {
|
|
|
16687
16687
|
return i === t.length - 1 ? `"${out}"` : null;
|
|
16688
16688
|
}
|
|
16689
16689
|
var PLAIN_CONVERSION = /^%(?:hh|h|ll|l|j|z|t|L|q)?[diusc@]$/;
|
|
16690
|
-
function printfTextWithValues(
|
|
16691
|
-
const body2 = quotedBody(
|
|
16690
|
+
function printfTextWithValues(lit5, args) {
|
|
16691
|
+
const body2 = quotedBody(lit5);
|
|
16692
16692
|
if (body2 == null) return null;
|
|
16693
16693
|
let out = "", k = 0, last = 0;
|
|
16694
16694
|
for (const m of body2.matchAll(/%(?:%|[-+ #0']*(?:\d+|\*)?(?:\.(?:\d+|\*))?(?:hh|h|ll|l|j|z|t|L|q)?[diouxXeEfFgGaAcspn@])/g)) {
|
|
@@ -16701,8 +16701,8 @@ function printfTextWithValues(lit4, args) {
|
|
|
16701
16701
|
if (k !== args.length) return null;
|
|
16702
16702
|
return `"${out}${body2.slice(last)}"`;
|
|
16703
16703
|
}
|
|
16704
|
-
function braceTextWithValues(
|
|
16705
|
-
const body2 = quotedBody(
|
|
16704
|
+
function braceTextWithValues(lit5, args) {
|
|
16705
|
+
const body2 = quotedBody(lit5);
|
|
16706
16706
|
if (body2 == null) return null;
|
|
16707
16707
|
let out = "", next = 0, last = 0;
|
|
16708
16708
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -16771,8 +16771,8 @@ function sayExactly(first, head) {
|
|
|
16771
16771
|
if (c && (m = t.match(/^(?:std::)?(printf|fprintf|dprintf|puts|fputs|perror)\s*\(/)) && (args = wholeCallArgs(t, m[0]))) {
|
|
16772
16772
|
const fmtAt = m[1] === "fprintf" || m[1] === "dprintf" ? 1 : 0;
|
|
16773
16773
|
const to = m[1] === "fputs" ? args[1] : fmtAt ? args[0] : null;
|
|
16774
|
-
const
|
|
16775
|
-
const text2 = /^(?:puts|fputs|perror)$/.test(m[1]) ? quotedBody(
|
|
16774
|
+
const lit5 = m[1] === "fputs" ? args[0] : args[fmtAt];
|
|
16775
|
+
const text2 = /^(?:puts|fputs|perror)$/.test(m[1]) ? quotedBody(lit5) != null ? `"${quotedBody(lit5)}"` : null : lit5 && printfTextWithValues(lit5, args.slice(fmtAt + 1));
|
|
16776
16776
|
if (!text2) return { kind: "other", says: clip(t, 70) };
|
|
16777
16777
|
return { kind: "call", says: `Writes a log or message${to && !/^(?:stdout|stderr)$/.test(to.trim()) ? ` to ${words7(to.trim())}` : ""}: ${text2}`, callee: m[1] };
|
|
16778
16778
|
}
|
|
@@ -16782,9 +16782,9 @@ function sayExactly(first, head) {
|
|
|
16782
16782
|
return text2 ? { kind: "set", says: `Writes the text ${text2} into ${targetWords2(args[0].trim().replace(/^&/, ""))}` } : { kind: "other", says: clip(t, 70) };
|
|
16783
16783
|
}
|
|
16784
16784
|
if (c && (m = t.match(/^(?:fmt|std)::(print|println)\s*\(/)) && (args = wholeCallArgs(t, m[0]))) {
|
|
16785
|
-
const
|
|
16786
|
-
const text2 = args[
|
|
16787
|
-
return text2 ? { kind: "call", says: `Writes a log or message${
|
|
16785
|
+
const lit5 = /^"/.test(args[0] || "") ? 0 : 1;
|
|
16786
|
+
const text2 = args[lit5] && braceTextWithValues(args[lit5], args.slice(lit5 + 1));
|
|
16787
|
+
return text2 ? { kind: "call", says: `Writes a log or message${lit5 ? ` to ${words7(args[0].trim())}` : ""}: ${text2}`, callee: m[1] } : { kind: "other", says: clip(t, 70) };
|
|
16788
16788
|
}
|
|
16789
16789
|
if (c && /^(?:std::)?(?:cout|cerr|clog)\s*<</.test(t)) {
|
|
16790
16790
|
const parts = splitShift(t).slice(1);
|
|
@@ -17261,8 +17261,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17261
17261
|
const everyday = value ? sayPython(value) || sayCommon(value) : null;
|
|
17262
17262
|
if (everyday) return { kind: "set", says: `Sets ${target} to ${everyday}`, code: code3 };
|
|
17263
17263
|
if (c2 && wholeValueCall(value)) {
|
|
17264
|
-
const
|
|
17265
|
-
if (
|
|
17264
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
17265
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
17266
17266
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, m[1]))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
17267
17267
|
return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
|
|
17268
17268
|
}
|
|
@@ -17334,8 +17334,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17334
17334
|
if (common) return { kind: "set", says: `Sets ${target} to ${common}`, code: code3 };
|
|
17335
17335
|
const c2 = callee(value);
|
|
17336
17336
|
if (c2 && wholeValueCall(value)) {
|
|
17337
|
-
const
|
|
17338
|
-
if (
|
|
17337
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
17338
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
17339
17339
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, declType))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
17340
17340
|
return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
|
|
17341
17341
|
}
|
|
@@ -17398,8 +17398,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17398
17398
|
}
|
|
17399
17399
|
const c = callee(head);
|
|
17400
17400
|
if (c) {
|
|
17401
|
-
const
|
|
17402
|
-
if (
|
|
17401
|
+
const known2 = sayCall(c, firstArgs(head));
|
|
17402
|
+
if (known2) return { kind: "call", says: known2, code: code3, callee: c };
|
|
17403
17403
|
const o = head.indexOf("("), cl = o >= 0 ? closeOf(head, o) : -1;
|
|
17404
17404
|
const only = cl > o && /^\s*;?\s*$/.test(head.slice(cl + 1)) ? splitTopArgs(head.slice(o + 1, cl)) : [];
|
|
17405
17405
|
if ((LANG === "typescript" || LANG === "javascript" || LANG === "python") && only.length === 1 && !/^\s*(?:async\s*)?(?:\(|function\b|[A-Za-z_$][\w$]*\s*=>)/.test(only[0]) && !/^(?:exec|eval|compile|__import__|execfile|Function|setTimeout|setInterval)$/.test(c)) {
|
|
@@ -17411,9 +17411,9 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17411
17411
|
}
|
|
17412
17412
|
if ((m = head.match(/^([a-z_][\w.]*[?!]?)\s+(?![=<>!+\-*/%]|and\b|or\b|if\b|unless\b)(.+)$/)) && !/^(?:if|for|while|return|else|elsif|when|case|def|class|module|end|not|const|let|var|val|new|await|typeof|delete|void|in|of|throw|import|export|from|as|is)$/.test(m[1])) {
|
|
17413
17413
|
if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
|
|
17414
|
-
const
|
|
17414
|
+
const known2 = sayCall(m[1], m[2]);
|
|
17415
17415
|
const named2 = /^[:'"]([\w ]+)['"]?/.exec(m[2].trim())?.[1];
|
|
17416
|
-
return { kind: "call", says:
|
|
17416
|
+
return { kind: "call", says: known2 || (named2 ? `Calls ${lastWords(m[1])}: ${words7(named2)}` : `Calls ${lastWords(m[1])}`), code: code3, callee: m[1] };
|
|
17417
17417
|
}
|
|
17418
17418
|
return { kind: "other", says: clip(head, 70), code: code3 };
|
|
17419
17419
|
}
|
|
@@ -18240,8 +18240,8 @@ function braceStatements(stmts, split = null) {
|
|
|
18240
18240
|
return stmts.map((s) => {
|
|
18241
18241
|
const text2 = s.text;
|
|
18242
18242
|
const head0 = headLine(text2);
|
|
18243
|
-
const
|
|
18244
|
-
let open =
|
|
18243
|
+
const lit5 = BLOCK_HEAD.test(head0) && !/^func\s*\(/.test(head0) ? null : fnLiteral(text2);
|
|
18244
|
+
let open = lit5?.open ?? (LANG === "swift" || C_FAMILY.has(LANG) && !/^(?:if|else\s+if|for|while|switch|catch)\s*\(/.test(head0) ? blockBrace(text2) : C_FAMILY.has(LANG) ? cBlockOpen(text2, head0) : blockOpen(text2, head0));
|
|
18245
18245
|
const lineAtPos = (pos) => s.line + (text2.slice(0, pos).match(/\n/g) || []).length;
|
|
18246
18246
|
const read = (o, e) => {
|
|
18247
18247
|
let from = o + 1;
|
|
@@ -18268,18 +18268,18 @@ function braceStatements(stmts, split = null) {
|
|
|
18268
18268
|
};
|
|
18269
18269
|
let children = [], inner = 0;
|
|
18270
18270
|
const clauses = [];
|
|
18271
|
-
if (
|
|
18272
|
-
const [f, t] =
|
|
18271
|
+
if (lit5?.expr) {
|
|
18272
|
+
const [f, t] = lit5.expr;
|
|
18273
18273
|
const raw = text2.slice(f, t);
|
|
18274
18274
|
const lead = raw.length - raw.trimStart().length;
|
|
18275
18275
|
const expr = raw.trim();
|
|
18276
18276
|
if (expr) children = braceStatements([{ text: expr, line: lineAtPos(f + lead), endLine: lineAtPos(f + lead + expr.length - 1), ...s.start != null ? { start: s.start + f + lead, end: s.start + f + lead + expr.length } : {} }], split);
|
|
18277
18277
|
inner = children.length;
|
|
18278
|
-
return { text: text2, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner, children, fn: { depth:
|
|
18278
|
+
return { text: text2, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner, children, fn: { depth: lit5.depth, expr: true, after: text2.slice(t) } };
|
|
18279
18279
|
}
|
|
18280
18280
|
if (open >= 0) {
|
|
18281
18281
|
const end2 = blockEnd2(text2, open);
|
|
18282
|
-
if (!
|
|
18282
|
+
if (!lit5 && ARMS_HEAD.test(head0)) {
|
|
18283
18283
|
const arms = readArms(open, end2);
|
|
18284
18284
|
if (arms) return { text: text2, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner: arms.length, children: arms, arms: true };
|
|
18285
18285
|
}
|
|
@@ -18323,7 +18323,7 @@ function braceStatements(stmts, split = null) {
|
|
|
18323
18323
|
pos = e + 1;
|
|
18324
18324
|
}
|
|
18325
18325
|
}
|
|
18326
|
-
return { text: text2, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner, children, ...clauses.length ? { clauses } : {}, ...
|
|
18326
|
+
return { text: text2, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner, children, ...clauses.length ? { clauses } : {}, ...lit5 ? { fn: { depth: lit5.depth, after: text2.slice(lit5.close + 1), before: text2.slice(0, lit5.open) } } : {} };
|
|
18327
18327
|
});
|
|
18328
18328
|
}
|
|
18329
18329
|
function cBlockOpen(text2, head0) {
|
|
@@ -19407,7 +19407,7 @@ function notesSummary(ast) {
|
|
|
19407
19407
|
byLens
|
|
19408
19408
|
};
|
|
19409
19409
|
}
|
|
19410
|
-
var COMPILER_VERSION = "1.
|
|
19410
|
+
var COMPILER_VERSION = "1.6.1";
|
|
19411
19411
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
19412
19412
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
19413
19413
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -22194,7 +22194,7 @@ function braceWords(inner) {
|
|
|
22194
22194
|
}
|
|
22195
22195
|
function partsOf(raw) {
|
|
22196
22196
|
const out = [];
|
|
22197
|
-
const
|
|
22197
|
+
const lit5 = (s, r = s) => {
|
|
22198
22198
|
if (!s && !r) return;
|
|
22199
22199
|
const l = out[out.length - 1];
|
|
22200
22200
|
if (l && l.lit != null) {
|
|
@@ -22211,14 +22211,14 @@ function partsOf(raw) {
|
|
|
22211
22211
|
i++;
|
|
22212
22212
|
continue;
|
|
22213
22213
|
}
|
|
22214
|
-
|
|
22214
|
+
lit5(quoted && !'$`"\\'.includes(n) ? c + n : n, c + n);
|
|
22215
22215
|
i++;
|
|
22216
22216
|
continue;
|
|
22217
22217
|
}
|
|
22218
22218
|
if (c === "'" && !quoted) {
|
|
22219
22219
|
const e = skipSingle(s, i);
|
|
22220
22220
|
const t = s.slice(i + 1, e - 1);
|
|
22221
|
-
|
|
22221
|
+
lit5(t, t);
|
|
22222
22222
|
i = e - 1;
|
|
22223
22223
|
continue;
|
|
22224
22224
|
}
|
|
@@ -22258,7 +22258,7 @@ function partsOf(raw) {
|
|
|
22258
22258
|
if (n === "'" && !quoted) {
|
|
22259
22259
|
const e = skipAnsi(s, i);
|
|
22260
22260
|
const t = s.slice(i + 2, e - 1);
|
|
22261
|
-
|
|
22261
|
+
lit5(t, t);
|
|
22262
22262
|
i = e - 1;
|
|
22263
22263
|
continue;
|
|
22264
22264
|
}
|
|
@@ -22270,7 +22270,7 @@ function partsOf(raw) {
|
|
|
22270
22270
|
}
|
|
22271
22271
|
}
|
|
22272
22272
|
if (!quoted && (/[*?]/.test(c) || c === "[" && s.indexOf("]", i + 2) > i)) out.push({ glob: true });
|
|
22273
|
-
|
|
22273
|
+
lit5(c);
|
|
22274
22274
|
}
|
|
22275
22275
|
};
|
|
22276
22276
|
walk(String(raw), false);
|
|
@@ -22874,8 +22874,8 @@ function simpleSaysInner(n, ctx = null) {
|
|
|
22874
22874
|
return { kind: "fail", says: `Fails with exit code ${DIES.get(name)}${msg ? `: "${msg}"` : ""}`, error: `exit code ${DIES.get(name)}`, ...msg ? { message: msg } : {}, callee: name };
|
|
22875
22875
|
}
|
|
22876
22876
|
if (KNOWN_FNS.has(name)) return out(`Runs ${words9(name)}${args.length ? ` with ${list2(args.slice(0, 4).map(sayWord))}${args.length > 4 ? ", \u2026" : ""}` : ""}`, { callee: name });
|
|
22877
|
-
const
|
|
22878
|
-
if (
|
|
22877
|
+
const known2 = sayCommand(name, args, sayWord);
|
|
22878
|
+
if (known2) return out(known2, { callee: name });
|
|
22879
22879
|
if (/^"?\$/.test(name)) return out(`Runs the command in ${sayWord(name)}`, { callee: name });
|
|
22880
22880
|
if (scriptPath(name)) return out(`Runs the script ${sayWord(name)}`, { callee: name });
|
|
22881
22881
|
return out(`Runs ${name}${args[0] && /^[a-z][\w-]*$/.test(args[0]) ? ` ${args[0]}` : ""}`, { callee: name });
|
|
@@ -24075,8 +24075,8 @@ function commandWords(toks2, ctx = {}) {
|
|
|
24075
24075
|
return `${VERB[verb]} the ${many ? pluralNoun(noun) : noun}${object ? dup ? ` named by ${object}` : ` ${object}` : ""}${more}`;
|
|
24076
24076
|
}
|
|
24077
24077
|
const raws = argGroups(rest2).map(toksCode);
|
|
24078
|
-
const
|
|
24079
|
-
if (
|
|
24078
|
+
const known2 = sayCommand(raw.replace(/\.exe$/i, ""), raws, (w) => sayValue2(tokenize3(w)) ?? quoteText(w));
|
|
24079
|
+
if (known2) return known2;
|
|
24080
24080
|
if (/[\\/]|\.ps1$/i.test(raw)) return `Runs the script ${quoteText(raw)}${withArgs(a)}`;
|
|
24081
24081
|
return `Runs ${raw}${withArgs(a)}`;
|
|
24082
24082
|
}
|
|
@@ -24104,11 +24104,11 @@ function pipelineWords(toks2) {
|
|
|
24104
24104
|
if (opTok) a.switches.add(opTok.text.slice(1).toLowerCase());
|
|
24105
24105
|
const prop = at0(a.named.property ?? a.pos[0] ?? []);
|
|
24106
24106
|
const val = a.named.value ?? a.pos[1];
|
|
24107
|
-
const
|
|
24108
|
-
const op = [...a.switches].map((x) => String(x).toLowerCase().replace(/^c|^i(?=[a-z]{2})/, "")).find((x) =>
|
|
24107
|
+
const OPS7 = { match: "matches the pattern", notmatch: "does not match the pattern", eq: "is", ne: "is not", like: "is like", notlike: "is not like", gt: "is more than", ge: "is at least", lt: "is less than", le: "is at most", contains: "contains", in: "is one of" };
|
|
24108
|
+
const op = [...a.switches].map((x) => String(x).toLowerCase().replace(/^c|^i(?=[a-z]{2})/, "")).find((x) => OPS7[x]);
|
|
24109
24109
|
const v2 = val ? sayValue2(val) : null;
|
|
24110
24110
|
if (prop.length === 1 && prop[0].t === "word" && op && v2) {
|
|
24111
|
-
said.push(`keeps only those whose ${words9(prop[0].text)} ${
|
|
24111
|
+
said.push(`keeps only those whose ${words9(prop[0].text)} ${OPS7[op]} ${v2}`);
|
|
24112
24112
|
command = true;
|
|
24113
24113
|
continue;
|
|
24114
24114
|
}
|
|
@@ -25565,14 +25565,14 @@ function callVerb({ bare: bare2, name, args }) {
|
|
|
25565
25565
|
case "deprecate_soft": {
|
|
25566
25566
|
const p = args.filter((x) => !x.name);
|
|
25567
25567
|
const pick3 = (k, i) => args.find((x) => x.name === k) ?? p[i];
|
|
25568
|
-
const
|
|
25568
|
+
const lit5 = (a) => {
|
|
25569
25569
|
if (!a) return null;
|
|
25570
25570
|
let v = at02(a.toks);
|
|
25571
25571
|
const c = callOf(v);
|
|
25572
25572
|
if (c?.bare === "I" && c.args.length === 1) v = at02(c.args[0].toks);
|
|
25573
25573
|
return sayValue3(v);
|
|
25574
25574
|
};
|
|
25575
|
-
const when =
|
|
25575
|
+
const when = lit5(pick3("when", 0)), what = lit5(pick3("what", 1)), withx = lit5(pick3("with", 2));
|
|
25576
25576
|
return `Warns that ${what ?? "this"} is out of date (deprecated${when ? ` in ${when}` : ""})${withx ? `; use ${withx} instead` : ""}`;
|
|
25577
25577
|
}
|
|
25578
25578
|
case "signal_stage":
|
|
@@ -27069,13 +27069,13 @@ var WRAPS_FUNCTION = /^(?:React\.)?(?:useCallback|useMemo|memo|forwardRef|useEve
|
|
|
27069
27069
|
var TEST_CALLS = /^(?:describe|it|test|context|suite|specify|before|after|beforeEach|afterEach|beforeAll|afterAll|setup|teardown|x?it|f?it|xdescribe|fdescribe|xtest|bench)(?:\.\w+)*$/;
|
|
27070
27070
|
function jsMoreFunctions(src, fns) {
|
|
27071
27071
|
const clean = stripCommentsKeepLayout(src);
|
|
27072
|
-
const
|
|
27072
|
+
const known2 = new Set(fns.map((f) => f.bodyStart));
|
|
27073
27073
|
const found = [];
|
|
27074
27074
|
const add = (fnIdx, paramsOpen, paramsClose, arrowParam, bo) => {
|
|
27075
|
-
if (
|
|
27075
|
+
if (known2.has(bo + 1)) return null;
|
|
27076
27076
|
const bc = matchClose(src, bo);
|
|
27077
27077
|
if (bc < 0) return null;
|
|
27078
|
-
|
|
27078
|
+
known2.add(bo + 1);
|
|
27079
27079
|
const line = lineAt(src, fnIdx);
|
|
27080
27080
|
const params = arrowParam != null ? parseParams2(arrowParam, "typescript") : parseParams2(src.slice(paramsOpen + 1, paramsClose), "typescript");
|
|
27081
27081
|
const f = { key: `fn@${fnIdx}`, line, params, returns: null, bodyStart: bo + 1, body: src.slice(bo + 1, bc), at: fnIdx, end: bc };
|
|
@@ -27105,7 +27105,7 @@ function jsMoreFunctions(src, fns) {
|
|
|
27105
27105
|
const arrowRe = /=>\s*\{/g;
|
|
27106
27106
|
while (m = arrowRe.exec(clean)) {
|
|
27107
27107
|
const bo = m.index + m[0].length - 1;
|
|
27108
|
-
if (
|
|
27108
|
+
if (known2.has(bo + 1)) continue;
|
|
27109
27109
|
let j = m.index - 1;
|
|
27110
27110
|
while (j >= 0 && /\s/.test(clean[j])) j--;
|
|
27111
27111
|
let start, paramText = null, pOpen = -1, pClose = -1;
|
|
@@ -30099,6 +30099,13 @@ function scanSource(source, from, to, language) {
|
|
|
30099
30099
|
continue;
|
|
30100
30100
|
}
|
|
30101
30101
|
if (/[0-9]/.test(c)) {
|
|
30102
|
+
const based = source.slice(i, to).match(/^0([xXoObB])([0-9A-Fa-f_]+)/);
|
|
30103
|
+
if (based) {
|
|
30104
|
+
const radix = { x: 16, o: 8, b: 2 }[based[1].toLowerCase()];
|
|
30105
|
+
out.push({ t: "num", v: parseInt(based[2].replace(/_/g, ""), radix), start: i, end: i + based[0].length, raw: based[0], suffix: "", decimal: false, base: based[1], upper: /[A-F]/.test(based[2]) });
|
|
30106
|
+
i += based[0].length;
|
|
30107
|
+
continue;
|
|
30108
|
+
}
|
|
30102
30109
|
const m = source.slice(i, to).match(/^[0-9][0-9_]*(\.[0-9][0-9_]*)?([eE][+-]?[0-9]+)?(f64|f32|i32|i64|u32|u64|[fFdDmMlLuU]{0,2})/);
|
|
30103
30110
|
const raw = m[0];
|
|
30104
30111
|
const suffix = m[3] || "";
|
|
@@ -30134,6 +30141,10 @@ function spell(srcTok, next) {
|
|
|
30134
30141
|
return next.v;
|
|
30135
30142
|
}
|
|
30136
30143
|
if (next.t === "num") {
|
|
30144
|
+
if (srcTok.base && Number.isInteger(next.v) && next.v >= 0) {
|
|
30145
|
+
const d = next.v.toString({ x: 16, o: 8, b: 2 }[srcTok.base.toLowerCase()]);
|
|
30146
|
+
return `0${srcTok.base}${srcTok.upper ? d.toUpperCase() : d}`;
|
|
30147
|
+
}
|
|
30137
30148
|
let s = String(next.v);
|
|
30138
30149
|
if (srcTok.decimal && Number.isInteger(next.v)) s += ".0";
|
|
30139
30150
|
return s + srcTok.suffix;
|
|
@@ -30296,6 +30307,855 @@ function joinRuleParts(parts) {
|
|
|
30296
30307
|
return parts.map((p) => p.kind === "text" ? JSON.stringify(String(p.value)) : String(p.value)).join(" ").replace(/\( /g, "(").replace(/ \)/g, ")");
|
|
30297
30308
|
}
|
|
30298
30309
|
|
|
30310
|
+
// src/core/diagnostics.mjs
|
|
30311
|
+
var CoreError = class extends Error {
|
|
30312
|
+
constructor(diag2) {
|
|
30313
|
+
super(formatDiagnostic(diag2));
|
|
30314
|
+
this.diagnostic = diag2;
|
|
30315
|
+
}
|
|
30316
|
+
};
|
|
30317
|
+
function diag(code3, line, message2, hint) {
|
|
30318
|
+
return { code: code3, severity: "error", line: line ?? 1, message: message2, ...hint ? { hint } : {} };
|
|
30319
|
+
}
|
|
30320
|
+
function formatDiagnostic(d, file) {
|
|
30321
|
+
const where2 = file ? `${file}, line ${d.line}` : `Line ${d.line}`;
|
|
30322
|
+
return `${where2}: ${d.message}${d.hint ? `
|
|
30323
|
+
${d.hint}` : ""} [${d.code}]`;
|
|
30324
|
+
}
|
|
30325
|
+
|
|
30326
|
+
// src/core/lexer.mjs
|
|
30327
|
+
var SYMS = ["==", "!=", "<>", "<=", ">=", "+", "-", "*", "/", "(", ")", "[", "]", ",", ":", ".", "=", "<", ">"];
|
|
30328
|
+
var WORD_START = /[\p{L}_]/u;
|
|
30329
|
+
var WORD_CHAR = /[\p{L}\p{N}_]/u;
|
|
30330
|
+
function tokenizeLine(text2, line, colOffset = 0) {
|
|
30331
|
+
const toks2 = [];
|
|
30332
|
+
let i = 0;
|
|
30333
|
+
const at2 = (k = 0) => text2[i + k];
|
|
30334
|
+
while (i < text2.length) {
|
|
30335
|
+
const c = at2();
|
|
30336
|
+
const col = i + colOffset + 1;
|
|
30337
|
+
if (c === " " || c === " " || c === "\r") {
|
|
30338
|
+
i++;
|
|
30339
|
+
continue;
|
|
30340
|
+
}
|
|
30341
|
+
if (c === "#") break;
|
|
30342
|
+
if (c === '"' || c === "\u201C") {
|
|
30343
|
+
const [tok, end2] = readString(text2, i, line, colOffset);
|
|
30344
|
+
toks2.push({ ...tok, col });
|
|
30345
|
+
i = end2;
|
|
30346
|
+
continue;
|
|
30347
|
+
}
|
|
30348
|
+
if (c === "$" && /[0-9]/.test(at2(1) ?? "")) {
|
|
30349
|
+
const m = text2.slice(i + 1).match(/^[0-9][0-9_]*(\.[0-9]+)?/);
|
|
30350
|
+
toks2.push({ t: "money", text: m[0].replace(/_/g, ""), col, line });
|
|
30351
|
+
i += 1 + m[0].length;
|
|
30352
|
+
continue;
|
|
30353
|
+
}
|
|
30354
|
+
if (/[0-9]/.test(c)) {
|
|
30355
|
+
const m = text2.slice(i).match(/^[0-9][0-9_]*(\.[0-9]+)?/);
|
|
30356
|
+
const num3 = m[0].replace(/_/g, "");
|
|
30357
|
+
i += m[0].length;
|
|
30358
|
+
if (at2() === "%") {
|
|
30359
|
+
toks2.push({ t: "percent", text: num3, col, line });
|
|
30360
|
+
i++;
|
|
30361
|
+
continue;
|
|
30362
|
+
}
|
|
30363
|
+
toks2.push({ t: "num", text: num3, whole: !num3.includes("."), col, line });
|
|
30364
|
+
continue;
|
|
30365
|
+
}
|
|
30366
|
+
if (WORD_START.test(c)) {
|
|
30367
|
+
let j = i;
|
|
30368
|
+
while (j < text2.length && WORD_CHAR.test(text2[j])) j++;
|
|
30369
|
+
let word = text2.slice(i, j);
|
|
30370
|
+
if (word.toLowerCase() === "yes" && text2.slice(j, j + 3).toLowerCase() === "/no") {
|
|
30371
|
+
word = text2.slice(i, j + 3);
|
|
30372
|
+
j += 3;
|
|
30373
|
+
}
|
|
30374
|
+
toks2.push({ t: "word", text: word, lower: word.toLowerCase(), col, line });
|
|
30375
|
+
i = j;
|
|
30376
|
+
if ((text2[i] === "'" || text2[i] === "\u2019") && (text2[i + 1] === "s" || text2[i + 1] === "S") && !WORD_CHAR.test(text2[i + 2] ?? " ")) {
|
|
30377
|
+
toks2.push({ t: "poss", col: i + colOffset + 1, line });
|
|
30378
|
+
i += 2;
|
|
30379
|
+
}
|
|
30380
|
+
continue;
|
|
30381
|
+
}
|
|
30382
|
+
const sym = SYMS.find((s) => text2.startsWith(s, i));
|
|
30383
|
+
if (sym) {
|
|
30384
|
+
toks2.push({ t: "sym", text: sym === "<>" ? "!=" : sym, col, line });
|
|
30385
|
+
i += sym.length;
|
|
30386
|
+
continue;
|
|
30387
|
+
}
|
|
30388
|
+
throw new CoreError(diag("TC105", line, `I can't read the character "${c}" (column ${col}).`, 'Text goes inside double quotes: "like this".'));
|
|
30389
|
+
}
|
|
30390
|
+
return toks2;
|
|
30391
|
+
}
|
|
30392
|
+
function readString(text2, start, line, colOffset) {
|
|
30393
|
+
const close = text2[start] === "\u201C" ? "\u201D" : '"';
|
|
30394
|
+
const parts = [];
|
|
30395
|
+
let buf = "";
|
|
30396
|
+
let i = start + 1;
|
|
30397
|
+
while (i < text2.length) {
|
|
30398
|
+
const c = text2[i];
|
|
30399
|
+
if (c === "\\") {
|
|
30400
|
+
const n = text2[i + 1];
|
|
30401
|
+
buf += n === "n" ? "\n" : n === "t" ? " " : n === "r" ? "\r" : n ?? "";
|
|
30402
|
+
i += 2;
|
|
30403
|
+
continue;
|
|
30404
|
+
}
|
|
30405
|
+
if (c === close || close === "\u201D" && c === '"') {
|
|
30406
|
+
if (buf || !parts.length) parts.push(buf);
|
|
30407
|
+
return [{ t: "str", parts, line }, i + 1];
|
|
30408
|
+
}
|
|
30409
|
+
if (c === "{" && text2[i + 1] === "{") {
|
|
30410
|
+
buf += "{";
|
|
30411
|
+
i += 2;
|
|
30412
|
+
continue;
|
|
30413
|
+
}
|
|
30414
|
+
if (c === "}" && text2[i + 1] === "}") {
|
|
30415
|
+
buf += "}";
|
|
30416
|
+
i += 2;
|
|
30417
|
+
continue;
|
|
30418
|
+
}
|
|
30419
|
+
if (c === "{") {
|
|
30420
|
+
const end2 = text2.indexOf("}", i);
|
|
30421
|
+
if (end2 < 0) throw new CoreError(diag("TC107", line, 'A "{" inside text has no closing "}".', "Write {{ for a brace that is just text."));
|
|
30422
|
+
if (buf) parts.push(buf);
|
|
30423
|
+
buf = "";
|
|
30424
|
+
const inner = text2.slice(i + 1, end2);
|
|
30425
|
+
parts.push({ tokens: tokenizeLine(inner, line, colOffset + i + 1), source: inner.trim() });
|
|
30426
|
+
i = end2 + 1;
|
|
30427
|
+
continue;
|
|
30428
|
+
}
|
|
30429
|
+
buf += c;
|
|
30430
|
+
i++;
|
|
30431
|
+
}
|
|
30432
|
+
throw new CoreError(diag("TC106", line, 'This text is missing its closing quote (").'));
|
|
30433
|
+
}
|
|
30434
|
+
|
|
30435
|
+
// src/core/parser.mjs
|
|
30436
|
+
var RESERVED2 = /* @__PURE__ */ new Set([
|
|
30437
|
+
"is",
|
|
30438
|
+
"are",
|
|
30439
|
+
"and",
|
|
30440
|
+
"or",
|
|
30441
|
+
"not",
|
|
30442
|
+
"to",
|
|
30443
|
+
"at",
|
|
30444
|
+
"of",
|
|
30445
|
+
"with",
|
|
30446
|
+
"from",
|
|
30447
|
+
"where",
|
|
30448
|
+
"by",
|
|
30449
|
+
"in",
|
|
30450
|
+
"as",
|
|
30451
|
+
"than",
|
|
30452
|
+
"the",
|
|
30453
|
+
"a",
|
|
30454
|
+
"an",
|
|
30455
|
+
"plus",
|
|
30456
|
+
"minus",
|
|
30457
|
+
"times",
|
|
30458
|
+
"divided",
|
|
30459
|
+
"mod",
|
|
30460
|
+
"true",
|
|
30461
|
+
"false",
|
|
30462
|
+
"yes",
|
|
30463
|
+
"no",
|
|
30464
|
+
"nothing",
|
|
30465
|
+
"otherwise",
|
|
30466
|
+
"sorted",
|
|
30467
|
+
"descending",
|
|
30468
|
+
"ascending",
|
|
30469
|
+
"equals",
|
|
30470
|
+
"contains",
|
|
30471
|
+
"between",
|
|
30472
|
+
"yes/no",
|
|
30473
|
+
"joined",
|
|
30474
|
+
"split",
|
|
30475
|
+
"replacing",
|
|
30476
|
+
"starts",
|
|
30477
|
+
"ends"
|
|
30478
|
+
]);
|
|
30479
|
+
var OPS4 = {
|
|
30480
|
+
sum: "sum",
|
|
30481
|
+
total: "sum",
|
|
30482
|
+
average: "average",
|
|
30483
|
+
mean: "average",
|
|
30484
|
+
count: "count",
|
|
30485
|
+
number: "count",
|
|
30486
|
+
min: "min",
|
|
30487
|
+
minimum: "min",
|
|
30488
|
+
smallest: "min",
|
|
30489
|
+
lowest: "min",
|
|
30490
|
+
max: "max",
|
|
30491
|
+
maximum: "max",
|
|
30492
|
+
largest: "max",
|
|
30493
|
+
highest: "max",
|
|
30494
|
+
length: "length",
|
|
30495
|
+
words: "words",
|
|
30496
|
+
lines: "lines",
|
|
30497
|
+
lowercase: "lowercase",
|
|
30498
|
+
uppercase: "uppercase",
|
|
30499
|
+
trimmed: "trimmed",
|
|
30500
|
+
keys: "keys",
|
|
30501
|
+
values: "values",
|
|
30502
|
+
first: "first",
|
|
30503
|
+
last: "last",
|
|
30504
|
+
parts: "parts"
|
|
30505
|
+
};
|
|
30506
|
+
var keyOf = (words15) => words15.map((w) => w.lower).join(" ");
|
|
30507
|
+
var isWord = (t, w) => t && t.t === "word" && (w === void 0 || t.lower === w);
|
|
30508
|
+
var isSym = (t, s) => t && t.t === "sym" && t.text === s;
|
|
30509
|
+
var Stream = class {
|
|
30510
|
+
constructor(tokens, line) {
|
|
30511
|
+
this.ts = tokens;
|
|
30512
|
+
this.i = 0;
|
|
30513
|
+
this.line = line;
|
|
30514
|
+
}
|
|
30515
|
+
peek(k = 0) {
|
|
30516
|
+
return this.ts[this.i + k];
|
|
30517
|
+
}
|
|
30518
|
+
next() {
|
|
30519
|
+
return this.ts[this.i++];
|
|
30520
|
+
}
|
|
30521
|
+
done() {
|
|
30522
|
+
return this.i >= this.ts.length;
|
|
30523
|
+
}
|
|
30524
|
+
word(w) {
|
|
30525
|
+
if (isWord(this.peek(), w)) {
|
|
30526
|
+
this.i++;
|
|
30527
|
+
return true;
|
|
30528
|
+
}
|
|
30529
|
+
return false;
|
|
30530
|
+
}
|
|
30531
|
+
words(...ws) {
|
|
30532
|
+
if (ws.every((w, k) => isWord(this.peek(k), w))) {
|
|
30533
|
+
this.i += ws.length;
|
|
30534
|
+
return true;
|
|
30535
|
+
}
|
|
30536
|
+
return false;
|
|
30537
|
+
}
|
|
30538
|
+
sym(s) {
|
|
30539
|
+
if (isSym(this.peek(), s)) {
|
|
30540
|
+
this.i++;
|
|
30541
|
+
return true;
|
|
30542
|
+
}
|
|
30543
|
+
return false;
|
|
30544
|
+
}
|
|
30545
|
+
fail(msg, hint, code3 = "TC105") {
|
|
30546
|
+
throw new CoreError(diag(code3, this.line, msg, hint));
|
|
30547
|
+
}
|
|
30548
|
+
expectSym(s, what) {
|
|
30549
|
+
if (!this.sym(s)) this.fail(`I expected "${s}" ${what}${this.peek() ? `, but found "${show(this.peek())}"` : ""}.`, null, "TC108");
|
|
30550
|
+
}
|
|
30551
|
+
};
|
|
30552
|
+
var show = (t) => t.t === "word" ? t.text : t.t === "sym" ? t.text : t.t === "num" ? t.text : t.t === "money" ? `$${t.text}` : t.t === "percent" ? `${t.text}%` : t.t === "poss" ? "'s" : '"\u2026"';
|
|
30553
|
+
var ExprParser = class {
|
|
30554
|
+
constructor(names) {
|
|
30555
|
+
this.names = names;
|
|
30556
|
+
}
|
|
30557
|
+
parse(tokens, line, opts = {}) {
|
|
30558
|
+
const s = new Stream(tokens, line);
|
|
30559
|
+
if (s.done()) s.fail("A value is missing here.", null, "TC108");
|
|
30560
|
+
const e = this.expr(s, opts);
|
|
30561
|
+
if (!s.done()) s.fail(`I understood the line up to "${show(s.peek())}", but not from there on.`, opts.extraHint ?? "Check the spelling, or put parentheses around a part to group it.", "TC112");
|
|
30562
|
+
return e;
|
|
30563
|
+
}
|
|
30564
|
+
expr(s, o = {}) {
|
|
30565
|
+
return this.or(s, o);
|
|
30566
|
+
}
|
|
30567
|
+
or(s, o) {
|
|
30568
|
+
let l = this.and(s, o);
|
|
30569
|
+
while (isWord(s.peek(), "or")) {
|
|
30570
|
+
s.next();
|
|
30571
|
+
l = { k: "bin", op: "or", l, r: this.and(s, o), line: s.line };
|
|
30572
|
+
}
|
|
30573
|
+
return l;
|
|
30574
|
+
}
|
|
30575
|
+
and(s, o) {
|
|
30576
|
+
let l = this.not(s, o);
|
|
30577
|
+
while (!o.noAnd && isWord(s.peek(), "and")) {
|
|
30578
|
+
s.next();
|
|
30579
|
+
l = { k: "bin", op: "and", l, r: this.not(s, o), line: s.line };
|
|
30580
|
+
}
|
|
30581
|
+
return l;
|
|
30582
|
+
}
|
|
30583
|
+
not(s, o) {
|
|
30584
|
+
if (s.word("not")) return { k: "not", e: this.not(s, o), line: s.line };
|
|
30585
|
+
return this.cmp(s, o);
|
|
30586
|
+
}
|
|
30587
|
+
cmp(s, o) {
|
|
30588
|
+
const l = this.add(s, o);
|
|
30589
|
+
const t = s.peek();
|
|
30590
|
+
const line = s.line;
|
|
30591
|
+
if (t?.t === "sym" && ["=", "==", "!=", "<", "<=", ">", ">="].includes(t.text)) {
|
|
30592
|
+
s.next();
|
|
30593
|
+
const op = { "=": "==", "==": "==" }[t.text] ?? t.text;
|
|
30594
|
+
return { k: "cmp", op, l, r: this.add(s, o), line };
|
|
30595
|
+
}
|
|
30596
|
+
if (s.word("equals")) return { k: "cmp", op: "==", l, r: this.add(s, o), line };
|
|
30597
|
+
if (s.word("contains")) return { k: "contains", l, r: this.add(s, o), line };
|
|
30598
|
+
if (s.words("starts", "with")) return { k: "affix", end: false, l, r: this.add(s, o), line };
|
|
30599
|
+
if (s.words("ends", "with")) return { k: "affix", end: true, l, r: this.add(s, o), line };
|
|
30600
|
+
if (s.words("does", "not", "contain")) return { k: "not", e: { k: "contains", l, r: this.add(s, o), line }, line };
|
|
30601
|
+
if (isWord(t, "is") || isWord(t, "are")) {
|
|
30602
|
+
s.next();
|
|
30603
|
+
const neg = s.word("not");
|
|
30604
|
+
const wrap = (e) => neg ? { k: "not", e, line } : e;
|
|
30605
|
+
const rel2 = [
|
|
30606
|
+
[["at", "least"], ">="],
|
|
30607
|
+
[["at", "most"], "<="],
|
|
30608
|
+
[["more", "than"], ">"],
|
|
30609
|
+
[["greater", "than"], ">"],
|
|
30610
|
+
[["less", "than"], "<"],
|
|
30611
|
+
[["fewer", "than"], "<"],
|
|
30612
|
+
[["above"], ">"],
|
|
30613
|
+
[["below"], "<"],
|
|
30614
|
+
[["equal", "to"], "=="]
|
|
30615
|
+
];
|
|
30616
|
+
for (const [ws, op] of rel2) if (s.words(...ws)) return wrap({ k: "cmp", op, l, r: this.add(s, o), line });
|
|
30617
|
+
if (s.word("nothing")) return { k: "isNothing", e: l, neg, line };
|
|
30618
|
+
for (const adj of ["empty", "positive", "negative", "zero"]) {
|
|
30619
|
+
if (isWord(s.peek(), adj) && (s.i + 1 >= s.ts.length || !(s.ts[s.i + 1].t === "word" && !RESERVED2.has(s.ts[s.i + 1].lower)))) {
|
|
30620
|
+
s.next();
|
|
30621
|
+
return wrap({ k: "adj", adj, e: l, line });
|
|
30622
|
+
}
|
|
30623
|
+
}
|
|
30624
|
+
if (s.word("between")) {
|
|
30625
|
+
const lo = this.add(s, o);
|
|
30626
|
+
if (!s.word("and")) s.fail('"is between" needs "and": is between 1 and 10.', null, "TC108");
|
|
30627
|
+
const hi = this.add(s, o);
|
|
30628
|
+
return wrap({ k: "between", e: l, lo, hi, line });
|
|
30629
|
+
}
|
|
30630
|
+
if (s.word("in")) return wrap({ k: "contains", l: this.add(s, o), r: l, line });
|
|
30631
|
+
if (s.done()) s.fail('Something is missing after "is".', "For example: is 10, is at least 18, is nothing, is empty.", "TC108");
|
|
30632
|
+
return { k: "cmp", op: neg ? "!=" : "==", l, r: this.add(s, o), line };
|
|
30633
|
+
}
|
|
30634
|
+
return l;
|
|
30635
|
+
}
|
|
30636
|
+
add(s, o) {
|
|
30637
|
+
let l = this.mul(s, o);
|
|
30638
|
+
for (; ; ) {
|
|
30639
|
+
const t = s.peek();
|
|
30640
|
+
if (isSym(t, "+") || isWord(t, "plus")) {
|
|
30641
|
+
s.next();
|
|
30642
|
+
l = { k: "bin", op: "+", l, r: this.mul(s, o), line: s.line };
|
|
30643
|
+
} else if (isSym(t, "-") || isWord(t, "minus")) {
|
|
30644
|
+
s.next();
|
|
30645
|
+
l = { k: "bin", op: "-", l, r: this.mul(s, o), line: s.line };
|
|
30646
|
+
} else return l;
|
|
30647
|
+
}
|
|
30648
|
+
}
|
|
30649
|
+
mul(s, o) {
|
|
30650
|
+
let l = this.unary(s, o);
|
|
30651
|
+
for (; ; ) {
|
|
30652
|
+
const t = s.peek();
|
|
30653
|
+
if (isSym(t, "*") || isWord(t, "times")) {
|
|
30654
|
+
s.next();
|
|
30655
|
+
l = { k: "bin", op: "*", l, r: this.unary(s, o), line: s.line };
|
|
30656
|
+
} else if (isSym(t, "/")) {
|
|
30657
|
+
s.next();
|
|
30658
|
+
l = { k: "bin", op: "/", l, r: this.unary(s, o), line: s.line };
|
|
30659
|
+
} else if (isWord(t, "divided") && isWord(s.peek(1), "by")) {
|
|
30660
|
+
s.i += 2;
|
|
30661
|
+
l = { k: "bin", op: "/", l, r: this.unary(s, o), line: s.line };
|
|
30662
|
+
} else if (isWord(t, "mod")) {
|
|
30663
|
+
s.next();
|
|
30664
|
+
l = { k: "bin", op: "mod", l, r: this.unary(s, o), line: s.line };
|
|
30665
|
+
} else return l;
|
|
30666
|
+
}
|
|
30667
|
+
}
|
|
30668
|
+
unary(s, o) {
|
|
30669
|
+
if (s.sym("-")) return { k: "neg", e: this.unary(s, o), line: s.line };
|
|
30670
|
+
return this.postfix(s, o);
|
|
30671
|
+
}
|
|
30672
|
+
postfix(s, o) {
|
|
30673
|
+
let e = this.primary(s, o);
|
|
30674
|
+
for (; ; ) {
|
|
30675
|
+
const t = s.peek();
|
|
30676
|
+
if (t?.t === "poss") {
|
|
30677
|
+
s.next();
|
|
30678
|
+
const run = this.wordRun(s);
|
|
30679
|
+
if (!run.length) s.fail(`I expected a field name after "'s".`, null, "TC108");
|
|
30680
|
+
const k = this.longest(run, (key) => this.names.fields.has(key)) || run.length;
|
|
30681
|
+
s.i -= run.length - k;
|
|
30682
|
+
e = { k: "field", obj: e, name: keyOf(run.slice(0, k)), text: run.slice(0, k).map((w) => w.text).join(" "), line: s.line };
|
|
30683
|
+
} else if (isWord(t, "at") && !isWord(s.peek(1), "least") && !isWord(s.peek(1), "most")) {
|
|
30684
|
+
s.next();
|
|
30685
|
+
const key = this.unary(s, { ...o, noAnd: true });
|
|
30686
|
+
let dflt = null;
|
|
30687
|
+
if (s.word("otherwise")) dflt = this.unary(s, { ...o, noAnd: true });
|
|
30688
|
+
e = { k: "at", obj: e, key, dflt, line: s.line };
|
|
30689
|
+
} else if (isWord(t, "as")) {
|
|
30690
|
+
s.next();
|
|
30691
|
+
e = { k: "conv", e, type: this.typeRef(s), line: s.line };
|
|
30692
|
+
} else if (isWord(t, "where")) {
|
|
30693
|
+
s.next();
|
|
30694
|
+
e = { k: "where", list: e, cond: this.or(s, { ...o, stopSorted: true }), line: s.line };
|
|
30695
|
+
} else if (isWord(t, "sorted") && isWord(s.peek(1), "by")) {
|
|
30696
|
+
s.i += 2;
|
|
30697
|
+
const run = this.wordRun(s);
|
|
30698
|
+
if (!run.length) s.fail('"sorted by" needs a field: sorted by date.', null, "TC108");
|
|
30699
|
+
const desc = s.word("descending") ? true : (s.word("ascending"), false);
|
|
30700
|
+
e = { k: "sorted", list: e, by: keyOf(run), text: run.map((w) => w.text).join(" "), desc, line: s.line };
|
|
30701
|
+
} else if (isWord(t, "sorted")) {
|
|
30702
|
+
s.next();
|
|
30703
|
+
const desc = s.word("descending") ? true : (s.word("ascending"), false);
|
|
30704
|
+
e = { k: "sortedValues", list: e, desc, line: s.line };
|
|
30705
|
+
} else if (isWord(t, "joined") && isWord(s.peek(1), "with")) {
|
|
30706
|
+
s.i += 2;
|
|
30707
|
+
e = { k: "joined", list: e, sep: this.unary(s, { ...o, noAnd: true }), line: s.line };
|
|
30708
|
+
} else if (isWord(t, "split") && isWord(s.peek(1), "at")) {
|
|
30709
|
+
s.i += 2;
|
|
30710
|
+
e = { k: "splitAt", text: e, sep: this.unary(s, { ...o, noAnd: true }), line: s.line };
|
|
30711
|
+
} else if (isWord(t, "replacing")) {
|
|
30712
|
+
s.next();
|
|
30713
|
+
const from = this.unary(s, { ...o, noAnd: true });
|
|
30714
|
+
if (!s.word("with")) s.fail('"replacing" needs "with": name replacing "-" with " ".', null, "TC108");
|
|
30715
|
+
e = { k: "replacing", text: e, from, to: this.unary(s, { ...o, noAnd: true }), line: s.line };
|
|
30716
|
+
} else if (isSym(t, ".") && s.peek(1)?.t === "word") {
|
|
30717
|
+
s.next();
|
|
30718
|
+
const attr2 = s.next().text;
|
|
30719
|
+
let args = null;
|
|
30720
|
+
if (isSym(s.peek(), "(")) args = this.parenArgs(s);
|
|
30721
|
+
e = { k: "dot", obj: e, attr: attr2, args, line: s.line };
|
|
30722
|
+
} else return e;
|
|
30723
|
+
}
|
|
30724
|
+
}
|
|
30725
|
+
// words that may form a name (stops at reserved words and non-words)
|
|
30726
|
+
wordRun(s) {
|
|
30727
|
+
const run = [];
|
|
30728
|
+
while (s.peek()?.t === "word" && !RESERVED2.has(s.peek().lower)) run.push(s.next());
|
|
30729
|
+
return run;
|
|
30730
|
+
}
|
|
30731
|
+
// Does a known field name start k tokens ahead? (So "," inside a list is not read as "and the next field".)
|
|
30732
|
+
fieldAhead(s, k) {
|
|
30733
|
+
const run = [];
|
|
30734
|
+
for (let j = s.i + k; s.ts[j]?.t === "word" && !RESERVED2.has(s.ts[j].lower); j++) run.push(s.ts[j]);
|
|
30735
|
+
return this.longest(run, (key) => this.names.fields.has(key)) > 0;
|
|
30736
|
+
}
|
|
30737
|
+
longest(run, ok) {
|
|
30738
|
+
for (let k = run.length; k > 0; k--) if (ok(keyOf(run.slice(0, k)))) return k;
|
|
30739
|
+
return 0;
|
|
30740
|
+
}
|
|
30741
|
+
parenArgs(s) {
|
|
30742
|
+
s.expectSym("(", "to start the values");
|
|
30743
|
+
const args = [];
|
|
30744
|
+
if (s.sym(")")) return args;
|
|
30745
|
+
for (; ; ) {
|
|
30746
|
+
args.push(this.expr(s, {}));
|
|
30747
|
+
if (s.sym(")")) return args;
|
|
30748
|
+
s.expectSym(",", "between values");
|
|
30749
|
+
}
|
|
30750
|
+
}
|
|
30751
|
+
withArgs(s) {
|
|
30752
|
+
const args = [this.expr(s, { noAnd: true })];
|
|
30753
|
+
while (s.sym(",") || s.word("and")) args.push(this.expr(s, { noAnd: true }));
|
|
30754
|
+
return args;
|
|
30755
|
+
}
|
|
30756
|
+
typeRef(s) {
|
|
30757
|
+
s.word("a");
|
|
30758
|
+
s.word("an");
|
|
30759
|
+
const t = s.next();
|
|
30760
|
+
if (!t || t.t !== "word") s.fail("A kind of value is missing (number, whole number, text, yes/no, money, date, list, map, or a record name).", null, "TC306");
|
|
30761
|
+
const w = t.lower;
|
|
30762
|
+
if (w === "optional") return { k: "optional", of: this.typeRef(s) };
|
|
30763
|
+
if (w === "whole" && s.word("number")) return { k: "whole" };
|
|
30764
|
+
if (w === "yes" && s.word("or") && s.word("no")) return { k: "bool" };
|
|
30765
|
+
if (w === "list") {
|
|
30766
|
+
if (s.word("of")) return { k: "list", of: this.typeRef(s) };
|
|
30767
|
+
return { k: "list", of: { k: "unknown" } };
|
|
30768
|
+
}
|
|
30769
|
+
if (w === "map") {
|
|
30770
|
+
if (s.word("of")) {
|
|
30771
|
+
const key2 = this.typeRef(s);
|
|
30772
|
+
if (!s.word("to")) s.fail('"map of" needs "to": map of text to number.', null, "TC306");
|
|
30773
|
+
return { k: "map", key: key2, of: this.typeRef(s) };
|
|
30774
|
+
}
|
|
30775
|
+
return { k: "map", key: { k: "unknown" }, of: { k: "unknown" } };
|
|
30776
|
+
}
|
|
30777
|
+
const simple = { number: "number", numbers: "number", text: "text", texts: "text", "yes/no": "bool", money: "money", date: "date", integer: "whole" }[w];
|
|
30778
|
+
if (simple) return { k: simple };
|
|
30779
|
+
const run = [t, ...this.wordRun(s)];
|
|
30780
|
+
const k = this.longest(run, (key2) => this.names.records.has(key2)) || this.longest(run, (key2) => this.names.records.has(key2.replace(/s$/, "")));
|
|
30781
|
+
if (!k) s.fail(`I don't know the kind of value "${run.map((x) => x.text).join(" ")}".`, 'Kinds: number, whole number, text, yes/no, money, date, list of \u2026, map of \u2026 to \u2026, optional \u2026, or a record you defined with "A \u2026 has:".', "TC306");
|
|
30782
|
+
s.i -= run.length - k;
|
|
30783
|
+
const key = keyOf(run.slice(0, k));
|
|
30784
|
+
return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, "") };
|
|
30785
|
+
}
|
|
30786
|
+
primary(s, o) {
|
|
30787
|
+
const t = s.peek();
|
|
30788
|
+
const line = s.line;
|
|
30789
|
+
if (!t) s.fail("A value is missing at the end of this line.", null, "TC108");
|
|
30790
|
+
if (t.t === "num") {
|
|
30791
|
+
s.next();
|
|
30792
|
+
return { k: "num", text: t.text, whole: t.whole, line };
|
|
30793
|
+
}
|
|
30794
|
+
if (t.t === "money") {
|
|
30795
|
+
s.next();
|
|
30796
|
+
return { k: "money", text: t.text, line };
|
|
30797
|
+
}
|
|
30798
|
+
if (t.t === "percent") {
|
|
30799
|
+
s.next();
|
|
30800
|
+
const p = { k: "percent", text: t.text, line };
|
|
30801
|
+
if (s.word("of")) return { k: "bin", op: "*", l: p, r: this.unary(s, o), line, percentOf: true };
|
|
30802
|
+
return p;
|
|
30803
|
+
}
|
|
30804
|
+
if (t.t === "str") {
|
|
30805
|
+
s.next();
|
|
30806
|
+
return { k: "str", parts: t.parts.map((p) => typeof p === "string" ? p : { e: this.parse(p.tokens, line), source: p.source }), line };
|
|
30807
|
+
}
|
|
30808
|
+
if (isSym(t, "(")) {
|
|
30809
|
+
s.next();
|
|
30810
|
+
const e = this.expr(s, {});
|
|
30811
|
+
s.expectSym(")", "to close the parenthesis");
|
|
30812
|
+
return { k: "paren", e, line };
|
|
30813
|
+
}
|
|
30814
|
+
if (isSym(t, "[")) {
|
|
30815
|
+
s.next();
|
|
30816
|
+
const items = [];
|
|
30817
|
+
if (!s.sym("]")) for (; ; ) {
|
|
30818
|
+
items.push(this.expr(s, {}));
|
|
30819
|
+
if (s.sym("]")) break;
|
|
30820
|
+
s.expectSym(",", "between list items");
|
|
30821
|
+
}
|
|
30822
|
+
return { k: "list", items, line };
|
|
30823
|
+
}
|
|
30824
|
+
if (t.t !== "word") s.fail(`I didn't expect "${show(t)}" here.`, null, "TC105");
|
|
30825
|
+
const w = t.lower;
|
|
30826
|
+
if (w === "true" || w === "yes") {
|
|
30827
|
+
s.next();
|
|
30828
|
+
return { k: "bool", v: true, line };
|
|
30829
|
+
}
|
|
30830
|
+
if (w === "false" || w === "no") {
|
|
30831
|
+
s.next();
|
|
30832
|
+
return { k: "bool", v: false, line };
|
|
30833
|
+
}
|
|
30834
|
+
if (w === "nothing") {
|
|
30835
|
+
s.next();
|
|
30836
|
+
return { k: "nothing", line };
|
|
30837
|
+
}
|
|
30838
|
+
if ((w === "an" || w === "a") && isWord(s.peek(1), "empty") && (isWord(s.peek(2), "list") || isWord(s.peek(2), "map"))) {
|
|
30839
|
+
s.i += 3;
|
|
30840
|
+
const kind = s.ts[s.i - 1].lower === "list" ? "list" : "map";
|
|
30841
|
+
if (kind === "list" && isWord(s.peek(), "of")) {
|
|
30842
|
+
s.next();
|
|
30843
|
+
return { k: "list", items: [], of: this.typeRef(s), line };
|
|
30844
|
+
}
|
|
30845
|
+
return { k: kind, items: [], line };
|
|
30846
|
+
}
|
|
30847
|
+
if (w === "the" || w === "a" || w === "an") {
|
|
30848
|
+
s.next();
|
|
30849
|
+
return this.primary(s, { ...o, article: w !== "the" });
|
|
30850
|
+
}
|
|
30851
|
+
if (w === "absolute" && isWord(s.peek(1), "value") && isWord(s.peek(2), "of")) {
|
|
30852
|
+
s.i += 3;
|
|
30853
|
+
return { k: "op", op: "abs", word: "absolute value", arg: this.unary(s, o), line };
|
|
30854
|
+
}
|
|
30855
|
+
if (w === "json" && isWord(s.peek(1), "text") && isWord(s.peek(2), "of")) {
|
|
30856
|
+
s.i += 3;
|
|
30857
|
+
return { k: "op", op: "jsonText", word: "JSON text", arg: this.unary(s, o), line };
|
|
30858
|
+
}
|
|
30859
|
+
if (w === "json" && isWord(s.peek(1), "data") && isWord(s.peek(2), "in")) {
|
|
30860
|
+
s.i += 3;
|
|
30861
|
+
return { k: "op", op: "jsonData", word: "JSON data", arg: this.unary(s, o), line };
|
|
30862
|
+
}
|
|
30863
|
+
if (OPS4[w] && isWord(s.peek(1), "of")) {
|
|
30864
|
+
s.i += 2;
|
|
30865
|
+
return { k: "op", op: OPS4[w], word: t.text, arg: this.unary(s, o), line };
|
|
30866
|
+
}
|
|
30867
|
+
if (w === "round") {
|
|
30868
|
+
s.next();
|
|
30869
|
+
const e = this.unary(s, { ...o, noAnd: true });
|
|
30870
|
+
let places = null;
|
|
30871
|
+
if (s.word("to")) {
|
|
30872
|
+
places = this.unary(s, o);
|
|
30873
|
+
s.word("decimal");
|
|
30874
|
+
if (!s.word("places") && !s.word("place")) s.fail('Write "round X to 2 places" (or "to 2 decimal places").', null, "TC108");
|
|
30875
|
+
}
|
|
30876
|
+
return { k: "round", e, places, line };
|
|
30877
|
+
}
|
|
30878
|
+
if (w === "read" && isWord(s.peek(1), "file")) {
|
|
30879
|
+
s.i += 2;
|
|
30880
|
+
return { k: "readFile", path: this.unary(s, o), line };
|
|
30881
|
+
}
|
|
30882
|
+
if (w === "today" && !this.names.known.has("today")) {
|
|
30883
|
+
s.next();
|
|
30884
|
+
return { k: "today", line };
|
|
30885
|
+
}
|
|
30886
|
+
if (w === "date" && s.peek(1)?.t === "str") {
|
|
30887
|
+
s.next();
|
|
30888
|
+
const str3 = s.next();
|
|
30889
|
+
return { k: "date", text: str3.parts.join(""), line };
|
|
30890
|
+
}
|
|
30891
|
+
if (RESERVED2.has(w)) s.fail(`"${t.text}" is a Thunder word and can't start a value here.`, null, "TC105");
|
|
30892
|
+
const run = this.wordRun(s);
|
|
30893
|
+
let off = run[0]?.lower === "new" && run.length > 1 ? 1 : 0;
|
|
30894
|
+
const recK = this.longest(run.slice(off), (key) => this.names.records.has(key));
|
|
30895
|
+
const wantsRecord = o.article || off || isWord(s.peek(), "with") || !this.longest(run, (key) => this.names.known.has(key));
|
|
30896
|
+
if (recK && wantsRecord && recK + off === run.length) {
|
|
30897
|
+
s.i -= run.length - off - recK;
|
|
30898
|
+
const name = keyOf(run.slice(off, off + recK));
|
|
30899
|
+
const fields = [];
|
|
30900
|
+
if (s.word("with")) {
|
|
30901
|
+
do {
|
|
30902
|
+
const fr = this.wordRun(s);
|
|
30903
|
+
if (!fr.length) s.fail(`I expected a field name after "with" (for example: with name "Ann").`, null, "TC108");
|
|
30904
|
+
const fk2 = this.longest(fr, (key) => this.names.fields.has(key)) || fr.length;
|
|
30905
|
+
s.i -= fr.length - fk2;
|
|
30906
|
+
fields.push({ name: keyOf(fr.slice(0, fk2)), text: fr.slice(0, fk2).map((x) => x.text).join(" "), e: this.expr(s, { noAnd: true }), line });
|
|
30907
|
+
} while ((isSym(s.peek(), ",") || isWord(s.peek(), "and")) && this.fieldAhead(s, 1) && s.next());
|
|
30908
|
+
}
|
|
30909
|
+
const node2 = { k: "new", record: name, fields, line };
|
|
30910
|
+
if (!fields.length && this.open) this.open.push(node2);
|
|
30911
|
+
return node2;
|
|
30912
|
+
}
|
|
30913
|
+
off = 0;
|
|
30914
|
+
if (isWord(s.peek(), "from")) {
|
|
30915
|
+
s.next();
|
|
30916
|
+
return { k: "from", name: keyOf(run), text: run.map((x) => x.text).join(" "), list: this.unary(s, o), line };
|
|
30917
|
+
}
|
|
30918
|
+
const k = this.longest(run, (key) => this.names.known.has(key));
|
|
30919
|
+
if (k) {
|
|
30920
|
+
s.i -= run.length - k;
|
|
30921
|
+
const key = keyOf(run.slice(0, k));
|
|
30922
|
+
const text2 = run.slice(0, k).map((x) => x.text).join(" ");
|
|
30923
|
+
if (this.names.known.get(key) === "func") {
|
|
30924
|
+
if (isSym(s.peek(), "(")) return { k: "call", name: key, text: text2, args: this.parenArgs(s), line };
|
|
30925
|
+
if (s.word("with")) return { k: "call", name: key, text: text2, args: this.withArgs(s), line };
|
|
30926
|
+
const node2 = { k: "call", name: key, text: text2, args: [], line, bare: true };
|
|
30927
|
+
if (this.open) this.open.push(node2);
|
|
30928
|
+
return node2;
|
|
30929
|
+
}
|
|
30930
|
+
return { k: "name", name: key, text: text2, line };
|
|
30931
|
+
}
|
|
30932
|
+
const fk = this.longest(run, (key) => this.names.fields.has(key));
|
|
30933
|
+
if (fk) {
|
|
30934
|
+
s.i -= run.length - fk;
|
|
30935
|
+
return { k: "name", name: keyOf(run.slice(0, fk)), text: run.slice(0, fk).map((x) => x.text).join(" "), line, unknown: true };
|
|
30936
|
+
}
|
|
30937
|
+
return { k: "name", name: keyOf(run), text: run.map((x) => x.text).join(" "), line, unknown: true };
|
|
30938
|
+
}
|
|
30939
|
+
};
|
|
30940
|
+
|
|
30941
|
+
// src/write-words.mjs
|
|
30942
|
+
var nameWords2 = (id2) => id2.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/_+/g, " ").trim().toLowerCase();
|
|
30943
|
+
var KEYWORDS = /* @__PURE__ */ new Set(["def", "return", "if", "elif", "else", "for", "while", "in", "is", "not", "and", "or", "None", "True", "False", "class", "import", "from", "as", "with", "try", "except", "finally", "raise", "lambda", "pass", "break", "continue", "yield", "function", "const", "let", "var", "new", "this", "null", "undefined", "true", "false", "typeof", "instanceof", "throw", "catch", "switch", "case", "default", "func", "package", "nil", "type", "struct", "interface", "go", "defer", "chan", "map", "range", "export", "async", "await", "self", "cls"]);
|
|
30944
|
+
var codeOnly = (src) => String(src ?? "").replace(/"""[\s\S]*?"""|'''[\s\S]*?'''/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ").replace(/`(?:\\[\s\S]|[^`\\])*`|"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'/g, " ").replace(/(#|\/\/)[^\n]*/g, " ");
|
|
30945
|
+
function namesOf(source, scope) {
|
|
30946
|
+
const byWords = /* @__PURE__ */ new Map(), exact = /* @__PURE__ */ new Set();
|
|
30947
|
+
for (const text2 of [scope, source]) {
|
|
30948
|
+
for (const m of codeOnly(text2).matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) {
|
|
30949
|
+
const id2 = m[0];
|
|
30950
|
+
if (KEYWORDS.has(id2)) continue;
|
|
30951
|
+
exact.add(id2);
|
|
30952
|
+
const w = nameWords2(id2);
|
|
30953
|
+
if (w && !byWords.has(w)) byWords.set(w, id2);
|
|
30954
|
+
}
|
|
30955
|
+
}
|
|
30956
|
+
for (const id2 of exact) byWords.set(id2, id2);
|
|
30957
|
+
for (const [w, id2] of byWords) if (exact.has(w)) byWords.set(w, w);
|
|
30958
|
+
return byWords;
|
|
30959
|
+
}
|
|
30960
|
+
var THUNDER_MARKERS = /\b(is (not )?(at least|at most|more than|less than|greater than|fewer than|below|above|under|over|nothing|missing|between|true|false|empty)|the (length|number|count|lowercase|uppercase|first|last|sum|total|trimmed) of|contains|starts with|ends with|plus|minus|times|divided by|equals)\b|'s\b/i;
|
|
30961
|
+
var lit4 = (type, value, raw) => ({ kind: "literal", type, value, raw });
|
|
30962
|
+
var NULL_RAW = { python: "None", go: "nil", typescript: "null", javascript: "null" };
|
|
30963
|
+
var Unsaid = class extends Error {
|
|
30964
|
+
};
|
|
30965
|
+
var Unknown = class extends Error {
|
|
30966
|
+
constructor(word) {
|
|
30967
|
+
super(word);
|
|
30968
|
+
this.word = word;
|
|
30969
|
+
}
|
|
30970
|
+
};
|
|
30971
|
+
function inputsOf2(scope) {
|
|
30972
|
+
const code3 = codeOnly(scope || ""), open = code3.indexOf("(");
|
|
30973
|
+
if (open < 0) return [];
|
|
30974
|
+
let depth = 0, end2 = open;
|
|
30975
|
+
for (; end2 < code3.length; end2++) {
|
|
30976
|
+
if (code3[end2] === "(") depth++;
|
|
30977
|
+
else if (code3[end2] === ")" && --depth === 0) break;
|
|
30978
|
+
}
|
|
30979
|
+
const out = [];
|
|
30980
|
+
for (const part of code3.slice(open + 1, end2).split(",")) {
|
|
30981
|
+
const id2 = part.replace(/^\s*[*&.]*\s*/, "").match(/^[A-Za-z_]\w*/)?.[0];
|
|
30982
|
+
if (id2 && !KEYWORDS.has(id2) && id2 !== "self" && id2 !== "cls" && !out.includes(id2)) out.push(id2);
|
|
30983
|
+
}
|
|
30984
|
+
return out;
|
|
30985
|
+
}
|
|
30986
|
+
var unknownWord = (word, scope) => {
|
|
30987
|
+
const inputs = inputsOf2(scope);
|
|
30988
|
+
return `"${word}" is not a name in this function or file${inputs.length ? `; its inputs are ${inputs.map((i) => `"${nameWords2(i) || i}"`).join(", ")}` : ""}. Use one of its names, or add an input first (addInput).`;
|
|
30989
|
+
};
|
|
30990
|
+
var no2 = (why) => {
|
|
30991
|
+
throw new Unsaid(why);
|
|
30992
|
+
};
|
|
30993
|
+
function toTree(n, language, names) {
|
|
30994
|
+
const T = (x) => toTree(x, language, names);
|
|
30995
|
+
const py = language === "python", go = language === "go", js = language === "typescript" || language === "javascript";
|
|
30996
|
+
const call2 = (callee2, args) => ({ kind: "call", callee: callee2, args });
|
|
30997
|
+
const member = (object, property) => ({ kind: "member", object, property });
|
|
30998
|
+
const nm = (name) => ({ kind: "name", name });
|
|
30999
|
+
switch (n.k) {
|
|
31000
|
+
case "paren":
|
|
31001
|
+
return T(n.e);
|
|
31002
|
+
case "num":
|
|
31003
|
+
return lit4("number", Number(n.text), n.text);
|
|
31004
|
+
case "str":
|
|
31005
|
+
if (n.parts.some((p) => typeof p !== "string")) no2("a text with values inside it ({\u2026})");
|
|
31006
|
+
return lit4("text", n.parts.join(""), JSON.stringify(n.parts.join("")));
|
|
31007
|
+
case "bool":
|
|
31008
|
+
return lit4("bool", n.v, py ? n.v ? "True" : "False" : String(n.v));
|
|
31009
|
+
case "nothing":
|
|
31010
|
+
return lit4("null", null, NULL_RAW[language]);
|
|
31011
|
+
case "name": {
|
|
31012
|
+
const id2 = names.get(n.name);
|
|
31013
|
+
if (!id2) throw new Unknown(n.name);
|
|
31014
|
+
return nm(id2);
|
|
31015
|
+
}
|
|
31016
|
+
case "field":
|
|
31017
|
+
case "dot": {
|
|
31018
|
+
if (n.args) no2("a call written with a dot");
|
|
31019
|
+
const prop = n.k === "field" ? n.name : n.attr;
|
|
31020
|
+
return member(T(n.obj), names.get(prop) ?? prop.replace(/ /g, "_"));
|
|
31021
|
+
}
|
|
31022
|
+
case "neg":
|
|
31023
|
+
return { kind: "unary", op: "-", value: T(n.e) };
|
|
31024
|
+
case "not":
|
|
31025
|
+
return { kind: "not", value: T(n.e) };
|
|
31026
|
+
case "bin": {
|
|
31027
|
+
if (n.op === "and" || n.op === "or") {
|
|
31028
|
+
const operands = [];
|
|
31029
|
+
for (const side2 of [n.l, n.r]) {
|
|
31030
|
+
const t = T(side2);
|
|
31031
|
+
if (t.kind === "logic" && t.op === n.op) operands.push(...t.operands);
|
|
31032
|
+
else operands.push(t);
|
|
31033
|
+
}
|
|
31034
|
+
return { kind: "logic", op: n.op, operands };
|
|
31035
|
+
}
|
|
31036
|
+
const op = { "+": "+", "-": "-", "*": "*", "/": "/", mod: "%", "%": "%" }[n.op];
|
|
31037
|
+
if (!op) no2(`"${n.op}"`);
|
|
31038
|
+
return { kind: "binary", op, left: T(n.l), right: T(n.r) };
|
|
31039
|
+
}
|
|
31040
|
+
case "cmp": {
|
|
31041
|
+
if (py && (n.op === "==" || n.op === "!=") && n.r.k === "bool") return { kind: "compare", op: n.op === "==" ? "is" : "is not", left: T(n.l), right: T(n.r) };
|
|
31042
|
+
const op = n.op === "==" ? js ? "===" : "==" : n.op === "!=" ? js ? "!==" : "!=" : n.op;
|
|
31043
|
+
return { kind: "compare", op, left: T(n.l), right: T(n.r) };
|
|
31044
|
+
}
|
|
31045
|
+
case "isNothing": {
|
|
31046
|
+
const op = py ? n.neg ? "is not" : "is" : n.neg ? "!=" : "==";
|
|
31047
|
+
return { kind: "compare", op, left: T(n.e), right: lit4("null", null, NULL_RAW[language]) };
|
|
31048
|
+
}
|
|
31049
|
+
case "between": {
|
|
31050
|
+
const e = T(n.e);
|
|
31051
|
+
return { kind: "logic", op: "and", operands: [{ kind: "compare", op: ">=", left: e, right: T(n.lo) }, { kind: "compare", op: "<=", left: e, right: T(n.hi) }] };
|
|
31052
|
+
}
|
|
31053
|
+
case "contains": {
|
|
31054
|
+
if (py) return { kind: "compare", op: "in", left: T(n.r), right: T(n.l) };
|
|
31055
|
+
if (js) return call2(member(T(n.l), "includes"), [T(n.r)]);
|
|
31056
|
+
no2('"contains" in Go (strings.Contains or slices.Contains depends on the value)');
|
|
31057
|
+
break;
|
|
31058
|
+
}
|
|
31059
|
+
case "affix": {
|
|
31060
|
+
const l = T(n.l), r = T(n.r);
|
|
31061
|
+
if (py) return call2(member(l, n.end ? "endswith" : "startswith"), [r]);
|
|
31062
|
+
if (js) return call2(member(l, n.end ? "endsWith" : "startsWith"), [r]);
|
|
31063
|
+
return call2(member(nm("strings"), n.end ? "HasSuffix" : "HasPrefix"), [l, r]);
|
|
31064
|
+
}
|
|
31065
|
+
case "op": {
|
|
31066
|
+
const a = T(n.arg);
|
|
31067
|
+
if (n.op === "length" || n.op === "count") return js ? member(a, "length") : call2(nm("len"), [a]);
|
|
31068
|
+
if (n.op === "lowercase") return py ? call2(member(a, "lower"), []) : js ? call2(member(a, "toLowerCase"), []) : call2(member(nm("strings"), "ToLower"), [a]);
|
|
31069
|
+
if (n.op === "uppercase") return py ? call2(member(a, "upper"), []) : js ? call2(member(a, "toUpperCase"), []) : call2(member(nm("strings"), "ToUpper"), [a]);
|
|
31070
|
+
if (n.op === "trimmed") return py ? call2(member(a, "strip"), []) : js ? call2(member(a, "trim"), []) : call2(member(nm("strings"), "TrimSpace"), [a]);
|
|
31071
|
+
if (n.op === "first") return { kind: "index", object: a, index: lit4("number", 0, "0") };
|
|
31072
|
+
if (n.op === "last") return py ? { kind: "index", object: a, index: { kind: "unary", op: "-", value: lit4("number", 1, "1") } } : { kind: "index", object: a, index: { kind: "binary", op: "-", left: js ? member(a, "length") : call2(nm("len"), [a]), right: lit4("number", 1, "1") } };
|
|
31073
|
+
no2(`"the ${n.word} of"`);
|
|
31074
|
+
break;
|
|
31075
|
+
}
|
|
31076
|
+
default:
|
|
31077
|
+
no2(`"${n.k}"`);
|
|
31078
|
+
}
|
|
31079
|
+
return null;
|
|
31080
|
+
}
|
|
31081
|
+
function parseThunder(text2, source, scope) {
|
|
31082
|
+
const names = namesOf(source, scope);
|
|
31083
|
+
const known2 = new Map([...names.keys()].map((k) => [k, "var"]));
|
|
31084
|
+
const ep = new ExprParser({ known: known2, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
31085
|
+
const lexed = tokenizeLine(String(text2), 1);
|
|
31086
|
+
const tokens = Array.isArray(lexed) ? lexed : lexed.tokens;
|
|
31087
|
+
return { node: ep.parse(tokens, 1), names };
|
|
31088
|
+
}
|
|
31089
|
+
function thunderTree(text2, language, source, scope = "") {
|
|
31090
|
+
let parsed;
|
|
31091
|
+
try {
|
|
31092
|
+
parsed = parseThunder(text2, source, scope);
|
|
31093
|
+
} catch (e) {
|
|
31094
|
+
return { error: String(e.message).replace(/^Line 1: /, "").split("\n")[0] };
|
|
31095
|
+
}
|
|
31096
|
+
try {
|
|
31097
|
+
return { tree: toTree(parsed.node, language, parsed.names) };
|
|
31098
|
+
} catch (e) {
|
|
31099
|
+
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
31100
|
+
if (e instanceof Unknown) return { error: unknownWord(e.word, scope), unknown: e.word };
|
|
31101
|
+
throw e;
|
|
31102
|
+
}
|
|
31103
|
+
}
|
|
31104
|
+
var looksThunder = (text2) => typeof text2 === "string" && THUNDER_MARKERS.test(text2);
|
|
31105
|
+
function thunderStep(text2, language, source, scope = "") {
|
|
31106
|
+
const t = String(text2).trim();
|
|
31107
|
+
let m;
|
|
31108
|
+
if (m = t.match(/^stop with\s+(["'])(.*)\1\s*$/i)) return { stop: m[2] };
|
|
31109
|
+
if (m = t.match(/^give(?: back)?\s+(.+)$/i)) {
|
|
31110
|
+
const v = thunderTree(m[1], language, source, scope);
|
|
31111
|
+
return v.tree ? { tree: { kind: "return", value: v.tree } } : { error: v.error };
|
|
31112
|
+
}
|
|
31113
|
+
if (m = t.match(/^set\s+(.+?)\s+to\s+(.+)$/i)) {
|
|
31114
|
+
const target = thunderTree(m[1], language, source, scope), value = thunderTree(m[2], language, source, scope);
|
|
31115
|
+
if (!target.tree) return { error: target.error };
|
|
31116
|
+
if (!value.tree) return { error: value.error };
|
|
31117
|
+
if (target.tree.kind !== "name" && target.tree.kind !== "member") return { error: `"${m[1]}" is not a name to set.` };
|
|
31118
|
+
return { tree: { kind: "assign", op: "=", target: target.tree, value: value.tree } };
|
|
31119
|
+
}
|
|
31120
|
+
return null;
|
|
31121
|
+
}
|
|
31122
|
+
var BUILTINS = {
|
|
31123
|
+
python: "abs all any ascii bin bool bytearray bytes callable chr dict dir divmod enumerate filter float format frozenset getattr globals hasattr hash hex id int isinstance issubclass iter len list locals map max min next object oct open ord pow print range repr reversed round set setattr slice sorted str sum super tuple type vars zip Exception ValueError TypeError KeyError IndexError RuntimeError AttributeError NotImplementedError StopIteration LookupError ArithmeticError ZeroDivisionError OSError NotImplemented Ellipsis __name__ __file__",
|
|
31124
|
+
typescript: "Math JSON Object Array String Number Boolean Date Error TypeError RangeError Promise Map Set WeakMap Symbol BigInt RegExp console parseInt parseFloat isNaN isFinite undefined NaN Infinity globalThis window document process require module exports",
|
|
31125
|
+
go: "len cap append make new copy delete panic recover print println close complex real imag min max clear error string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 bool byte rune any iota fmt errors strings strconv"
|
|
31126
|
+
};
|
|
31127
|
+
BUILTINS.javascript = BUILTINS.typescript;
|
|
31128
|
+
function unknownName(tree, language, source, scope = "") {
|
|
31129
|
+
const known2 = new Set(BUILTINS[language]?.split(" ") ?? []);
|
|
31130
|
+
for (const text2 of [codeOnly(source), codeOnly(scope)]) for (const m of text2.matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) known2.add(m[0]);
|
|
31131
|
+
for (const k of KEYWORDS) known2.add(k);
|
|
31132
|
+
const bound = /* @__PURE__ */ new Set();
|
|
31133
|
+
const all = [];
|
|
31134
|
+
const walk = (n) => {
|
|
31135
|
+
if (Array.isArray(n)) {
|
|
31136
|
+
n.forEach(walk);
|
|
31137
|
+
return;
|
|
31138
|
+
}
|
|
31139
|
+
if (!n || typeof n !== "object") return;
|
|
31140
|
+
if (n.kind === "lambda" || n.kind === "code") {
|
|
31141
|
+
bound.add("*");
|
|
31142
|
+
return;
|
|
31143
|
+
}
|
|
31144
|
+
if (n.kind === "name") all.push(n.name);
|
|
31145
|
+
if ((n.kind === "assign" || n.kind === "declare") && n.target?.kind === "name") bound.add(n.target.name);
|
|
31146
|
+
if (n.kind === "declare" && typeof n.name === "string") bound.add(n.name);
|
|
31147
|
+
if (n.kind === "loop") for (const v of [n.variable, n.var, n.name, n.target]) {
|
|
31148
|
+
if (typeof v === "string") bound.add(v);
|
|
31149
|
+
else if (v?.kind === "name") bound.add(v.name);
|
|
31150
|
+
}
|
|
31151
|
+
for (const [k, v] of Object.entries(n)) if (k !== "raw" && v && typeof v === "object") walk(v);
|
|
31152
|
+
};
|
|
31153
|
+
walk(tree);
|
|
31154
|
+
if (bound.has("*")) return null;
|
|
31155
|
+
return all.find((id2) => !known2.has(id2) && !bound.has(id2)) ?? null;
|
|
31156
|
+
}
|
|
31157
|
+
var unknownNameReason = (word, scope) => unknownWord(word, scope);
|
|
31158
|
+
|
|
30299
31159
|
// src/read-repo.mjs
|
|
30300
31160
|
var READ_REPO_SCHEMA = "thunder-repo-reading-v1";
|
|
30301
31161
|
var EXT_LANG = [
|
|
@@ -30495,7 +31355,7 @@ var NAME_TEXT = /^[A-Za-z0-9 $.,'_-]+$/;
|
|
|
30495
31355
|
var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
30496
31356
|
var pascal3 = (s) => s.replace(/[^A-Za-z0-9 ]/g, " ").trim().split(/\s+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join("");
|
|
30497
31357
|
var camel = (s) => lowerFirst(pascal3(s));
|
|
30498
|
-
var
|
|
31358
|
+
var RESERVED3 = /* @__PURE__ */ new Set(["and", "or", "not", "in", "true", "false", "case", "expect"]);
|
|
30499
31359
|
function formatValue(input, value) {
|
|
30500
31360
|
if (input.kind === "yesno") return value ? input.yes : input.no;
|
|
30501
31361
|
if (input.kind === "text") return value === "" ? "empty" : JSON.stringify(String(value));
|
|
@@ -30532,9 +31392,9 @@ function parseNumber(text2, input, line) {
|
|
|
30532
31392
|
function parseInputLine(text2, line) {
|
|
30533
31393
|
let m;
|
|
30534
31394
|
if (m = text2.match(/^whether it is (.+?) or (.+?)\.?$/)) {
|
|
30535
|
-
const [yes,
|
|
30536
|
-
if (yes ===
|
|
30537
|
-
return { id: camel(yes), kind: "yesno", label: `it is ${yes}`, yes, no:
|
|
31395
|
+
const [yes, no3] = [m[1].trim(), m[2].trim()];
|
|
31396
|
+
if (yes === no3) fail3(line, 'Use two different words, such as "whether it is on time or late".');
|
|
31397
|
+
return { id: camel(yes), kind: "yesno", label: `it is ${yes}`, yes, no: no3 };
|
|
30538
31398
|
}
|
|
30539
31399
|
if (m = text2.match(/^(the .+?), (in dollars|a number)\.?$/)) {
|
|
30540
31400
|
const label = m[1].trim();
|
|
@@ -30558,8 +31418,8 @@ function parseCondition(text2, inputs, line) {
|
|
|
30558
31418
|
}
|
|
30559
31419
|
fail3(line, `Compare ${input.label} with at least, at most, under, over, or exactly. For example: "${input.label} is at most ${formatValue(input, 100)}".`);
|
|
30560
31420
|
}
|
|
30561
|
-
const
|
|
30562
|
-
fail3(line, `This condition does not name an input. Start with one of: ${
|
|
31421
|
+
const known2 = inputs.map((i) => i.kind === "yesno" ? `"it is ${i.yes}"` : `"${i.label} is \u2026"`).join(", ");
|
|
31422
|
+
fail3(line, `This condition does not name an input. Start with one of: ${known2}.`);
|
|
30563
31423
|
}
|
|
30564
31424
|
function parsePlainContract(source) {
|
|
30565
31425
|
if (typeof source !== "string" || source.length > 1e5) throw new Error("A plain contract must be text of at most 100 KB.");
|
|
@@ -30600,7 +31460,7 @@ function parsePlainContract(source) {
|
|
|
30600
31460
|
}
|
|
30601
31461
|
if (section === "inputs") {
|
|
30602
31462
|
const input = parseInputLine(text2, line);
|
|
30603
|
-
if (
|
|
31463
|
+
if (RESERVED3.has(input.id) || !input.id) fail3(line, "Choose a different name for this input.");
|
|
30604
31464
|
if (model.inputs.some((i) => i.id === input.id)) fail3(line, `${input.label} is listed twice.`);
|
|
30605
31465
|
const words15 = model.inputs.flatMap((i) => i.kind === "yesno" ? [i.yes, i.no] : []);
|
|
30606
31466
|
if (input.kind === "yesno" && (words15.includes(input.yes) || words15.includes(input.no))) fail3(line, "Each yes/no word must be unique across inputs.");
|
|
@@ -30699,7 +31559,7 @@ function conditionExpr(model, c) {
|
|
|
30699
31559
|
}
|
|
30700
31560
|
function plainToThunder(model) {
|
|
30701
31561
|
const name = pascal3(model.title);
|
|
30702
|
-
const
|
|
31562
|
+
const lit5 = (v) => typeof v === "boolean" ? String(v) : String(v);
|
|
30703
31563
|
const out = [
|
|
30704
31564
|
`# Compiled from plain ThunderLang (${PLAIN_SCHEMA}). Edit the plain file, not this one.`,
|
|
30705
31565
|
`mission ${name}`,
|
|
@@ -30723,7 +31583,7 @@ function plainToThunder(model) {
|
|
|
30723
31583
|
}
|
|
30724
31584
|
out.push(" default", ` return ${model.otherwise}`, "", `test ${name}`);
|
|
30725
31585
|
for (const e of model.examples) {
|
|
30726
|
-
out.push(` case ${e.name}`, ` given ${model.inputs.map((i) => `${i.id} ${
|
|
31586
|
+
out.push(` case ${e.name}`, ` given ${model.inputs.map((i) => `${i.id} ${lit5(e.values[i.id])}`).join(", ")}`, ` expect ${e.expected}`);
|
|
30727
31587
|
}
|
|
30728
31588
|
return out.join("\n") + "\n";
|
|
30729
31589
|
}
|
|
@@ -31226,11 +32086,11 @@ function comparePlainRules(a, b) {
|
|
|
31226
32086
|
return { same: true, tried };
|
|
31227
32087
|
}
|
|
31228
32088
|
var SYNTAX = new Set("const let var val final auto def fn func function return await async new public private protected static self this my local export mut ref out in of for foreach if elif elsif while do then end each as range".split(" "));
|
|
31229
|
-
var
|
|
32089
|
+
var OPS5 = { "&&": "and", "||": "or", "!": "not", "===": "==", "!==": "!=", "<>": "!=", "**": "^", and: "and", or: "or", not: "not", is: "==", None: "null", nil: "null", undefined: "null", NULL: "null", nullptr: "null", True: "true", False: "false" };
|
|
31230
32090
|
function stepSignature(code3) {
|
|
31231
32091
|
const t = String(code3 || "").replace(/(\/\/|#)[^\n]*$/gm, "");
|
|
31232
32092
|
const toks2 = t.match(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|-?\d+(?:\.\d+)?|[A-Za-z_$][\w$]*|===|!==|==|!=|<=|>=|&&|\|\||\*\*|<>|[-+*\/%<>=!]/g) || [];
|
|
31233
|
-
return toks2.filter((x) => !SYNTAX.has(x)).map((x) =>
|
|
32093
|
+
return toks2.filter((x) => !SYNTAX.has(x)).map((x) => OPS5[x] ?? (/^["'`]/.test(x) ? `"${x.slice(1, -1)}"` : /^[A-Za-z_$]/.test(x) ? x.replace(/[_$]/g, "").toLowerCase() : x)).join(" ");
|
|
31234
32094
|
}
|
|
31235
32095
|
var flatSteps = (steps, depth = 0) => (steps || []).flatMap((s) => [
|
|
31236
32096
|
{ sig: `${depth}:${s.restates ? "code" : s.kind}:${s.restates || s.kind === "other" ? "" : norm4(s.says)}`, code: stepSignature(s.code), raw: String(s.code ?? ""), text: s.restates || s.kind === "other" ? `\`${s.code ?? s.says}\`` : s.says },
|
|
@@ -38035,9 +38895,9 @@ function pathsOf(flow) {
|
|
|
38035
38895
|
if (n && (n.kind === "stop" || n.kind === "end")) (out.ended ||= /* @__PURE__ */ new Set()).add(blocks2);
|
|
38036
38896
|
const q2 = n?.text ?? "";
|
|
38037
38897
|
const yes = { question: q2, answer: "Yes", ...n?.holds ? { says: n.holds.yes } : {} };
|
|
38038
|
-
const
|
|
38898
|
+
const no3 = { question: q2, answer: "No", ...n?.holds ? { says: n.holds.no } : {} };
|
|
38039
38899
|
walk(b.yes, [...when, yes]);
|
|
38040
|
-
walk(b.no, [...when,
|
|
38900
|
+
walk(b.no, [...when, no3]);
|
|
38041
38901
|
walk(b.each, [...when, { question: q2, answer: "For each" }]);
|
|
38042
38902
|
for (const c of b.cases || []) walk(c.blocks, [...when, { question: q2, answer: c.label }]);
|
|
38043
38903
|
if (!b.nested) walk(b.body, when);
|
|
@@ -38048,7 +38908,7 @@ function pathsOf(flow) {
|
|
|
38048
38908
|
if (b.always) walk(b.always.blocks, when);
|
|
38049
38909
|
if (n?.kind === "decision" && (b.yes || b.no)) {
|
|
38050
38910
|
const yesEnds = ends(b.yes), noEnds = ends(b.no);
|
|
38051
|
-
if (yesEnds && !noEnds) when = [...when,
|
|
38911
|
+
if (yesEnds && !noEnds) when = [...when, no3];
|
|
38052
38912
|
else if (noEnds && !yesEnds) when = [...when, yes];
|
|
38053
38913
|
}
|
|
38054
38914
|
}
|
|
@@ -38400,6 +39260,8 @@ function locateStep(steps, sel, { flowSteps } = {}) {
|
|
|
38400
39260
|
all.push({ step: s, list: list3, index: i, path: [...path, i], parent });
|
|
38401
39261
|
if (s.children) walk(s.children, [...path, i], s);
|
|
38402
39262
|
if (s.otherwise) walk(s.otherwise, [...path, i, "else"], s);
|
|
39263
|
+
(s.handlers || []).forEach((h, k) => walk(h.steps || [], [...path, i, `h:${k}`], s));
|
|
39264
|
+
if (s.always?.steps) walk(s.always.steps, [...path, i, "always"], s);
|
|
38403
39265
|
});
|
|
38404
39266
|
walk(steps || [], [], null);
|
|
38405
39267
|
if (Array.isArray(sel)) return all.find((x) => x.path.join(".") === sel.join(".")) ?? null;
|
|
@@ -38413,23 +39275,25 @@ function locateStep(steps, sel, { flowSteps } = {}) {
|
|
|
38413
39275
|
if (/^\d+$/.test(String(sel))) return all.find((x) => x.path.join(".") === String(sel)) ?? null;
|
|
38414
39276
|
return null;
|
|
38415
39277
|
}
|
|
39278
|
+
var isSide = (p) => p === "else" || p === "always" || typeof p === "string" && p.startsWith("h:");
|
|
39279
|
+
var sideOf = (node2, p) => p === "else" ? node2.o ?? (node2.o = []) : p === "always" ? node2.a ?? (node2.a = []) : node2.h[Number(p.slice(2))].c;
|
|
38416
39280
|
var pathIn = (shape, path) => {
|
|
38417
39281
|
let list3 = shape, node2 = null;
|
|
38418
39282
|
for (let i = 0; i < path.length; i++) {
|
|
38419
39283
|
const p = path[i];
|
|
38420
|
-
if (p
|
|
38421
|
-
list3 =
|
|
39284
|
+
if (isSide(p)) {
|
|
39285
|
+
list3 = sideOf(node2, p);
|
|
38422
39286
|
continue;
|
|
38423
39287
|
}
|
|
38424
39288
|
node2 = list3[p];
|
|
38425
|
-
if (i < path.length - 1 && path[i + 1]
|
|
39289
|
+
if (i < path.length - 1 && !isSide(path[i + 1])) list3 = node2.c;
|
|
38426
39290
|
}
|
|
38427
39291
|
return { list: list3, node: node2, index: path[path.length - 1] };
|
|
38428
39292
|
};
|
|
38429
39293
|
var listAt = (shape, path) => {
|
|
38430
39294
|
if (path.length === 1) return shape;
|
|
38431
39295
|
const parentPath = path.slice(0, -1);
|
|
38432
|
-
if (parentPath[parentPath.length - 1]
|
|
39296
|
+
if (isSide(parentPath[parentPath.length - 1])) return sideOf(pathIn(shape, parentPath.slice(0, -1)).node, parentPath[parentPath.length - 1]);
|
|
38433
39297
|
return pathIn(shape, parentPath).node.c;
|
|
38434
39298
|
};
|
|
38435
39299
|
function parseMemberRef(ref) {
|
|
@@ -38469,9 +39333,17 @@ function literalOf(value, language, like = null) {
|
|
|
38469
39333
|
if (typeof value === "number") {
|
|
38470
39334
|
if (!Number.isFinite(value)) refuse(`${value} is not a number that can be written.`);
|
|
38471
39335
|
let raw = String(value);
|
|
38472
|
-
|
|
38473
|
-
const
|
|
38474
|
-
if (
|
|
39336
|
+
const was = like?.type === "number" ? String(like.raw) : "";
|
|
39337
|
+
const base2 = was.match(/^0([xXoObB])/);
|
|
39338
|
+
if (base2) {
|
|
39339
|
+
if (!Number.isInteger(value) || value < 0) refuse(`${value} cannot be written as a ${{ x: "hex", o: "octal", b: "binary" }[base2[1].toLowerCase()]} number like ${was}.`);
|
|
39340
|
+
const digits = value.toString({ x: 16, o: 8, b: 2 }[base2[1].toLowerCase()]);
|
|
39341
|
+
return { kind: "literal", type: "number", value, raw: `0${base2[1]}${/[A-F]/.test(was.slice(2)) ? digits.toUpperCase() : digits}` };
|
|
39342
|
+
}
|
|
39343
|
+
if (was.includes("_") && Number.isInteger(value)) raw = String(value).replace(/\B(?=(\d{3})+(?!\d))/g, "_");
|
|
39344
|
+
if (/\.\d/.test(was) && Number.isInteger(value)) raw += ".0";
|
|
39345
|
+
const suffix = was.match(/\d([mMfFdDlLnuU]|ul|UL|lu|LU)$/)?.[1] ?? "";
|
|
39346
|
+
if (suffix) raw += suffix;
|
|
38475
39347
|
return { kind: "literal", type: "number", value, raw };
|
|
38476
39348
|
}
|
|
38477
39349
|
if (typeof value === "string") {
|
|
@@ -38483,14 +39355,27 @@ function literalOf(value, language, like = null) {
|
|
|
38483
39355
|
refuse(`${JSON.stringify(value)} is not a value (use a number, text, true/false, or null).`);
|
|
38484
39356
|
}
|
|
38485
39357
|
var PARSE_ORDER = (lang) => [lang, ...WRITE_STEPS_LANGUAGES.filter((l) => l !== lang)];
|
|
39358
|
+
var wordsSource = "";
|
|
39359
|
+
var wordsScope = "";
|
|
39360
|
+
var misreadIs = (t) => t?.kind === "compare" && (t.op === "is" || t.op === "is not") && !(t.right?.kind === "literal" && t.right.type === "null");
|
|
38486
39361
|
function exprFrom(input, language, what = "expression") {
|
|
38487
39362
|
if (input && typeof input === "object" && input.kind) return input;
|
|
38488
39363
|
if (typeof input !== "string") return literalOf(input, language);
|
|
39364
|
+
let said = null;
|
|
39365
|
+
const words15 = () => said ??= thunderTree(input, language, wordsSource, wordsScope);
|
|
39366
|
+
if (looksThunder(input) && words15().tree) return words15().tree;
|
|
38489
39367
|
for (const l of PARSE_ORDER(language)) {
|
|
38490
39368
|
const t = parseExpr(input, l);
|
|
38491
|
-
if (t && t.kind !== "code") return adapt(t, language);
|
|
39369
|
+
if (t && t.kind !== "code" && !misreadIs(t)) return known(adapt(t, language), language);
|
|
38492
39370
|
}
|
|
38493
|
-
|
|
39371
|
+
if (words15().tree) return words15().tree;
|
|
39372
|
+
if (said?.unknown) refuse(`The ${what} "${input}" could not be read: ${said.error}`);
|
|
39373
|
+
refuse(`The ${what} "${input}" could not be read${said?.error ? ` (${said.error})` : ""}. Write it in Thunder's words, for example "days is more than 10 and not member's vip", or as code.`);
|
|
39374
|
+
}
|
|
39375
|
+
function known(tree, language) {
|
|
39376
|
+
const word = unknownName(tree, language, wordsSource, wordsScope);
|
|
39377
|
+
if (word) refuse(`It cannot be written: ${unknownNameReason(word, wordsScope)}`);
|
|
39378
|
+
return tree;
|
|
38494
39379
|
}
|
|
38495
39380
|
function adapt(tree, language) {
|
|
38496
39381
|
const t = cloneShape(tree);
|
|
@@ -38512,15 +39397,19 @@ function adapt(tree, language) {
|
|
|
38512
39397
|
function statementFrom(input, language) {
|
|
38513
39398
|
if (input && typeof input === "object" && input.kind) return input;
|
|
38514
39399
|
if (typeof input !== "string" || !input.trim()) refuse("Say the new step as code, for example notify(order.customer).");
|
|
39400
|
+
const said = thunderStep(input, language, wordsSource, wordsScope);
|
|
39401
|
+
if (said?.tree) return said.tree;
|
|
39402
|
+
if (said?.error) refuse(`The step "${input}" could not be read: ${said.error}`);
|
|
38515
39403
|
for (const l of PARSE_ORDER(language)) {
|
|
38516
39404
|
const t = parseStatement(input, l);
|
|
38517
39405
|
if (t && t.kind !== "code") {
|
|
38518
39406
|
const a = adapt(t, language);
|
|
38519
39407
|
try {
|
|
38520
39408
|
renderStatement(a, language);
|
|
38521
|
-
return a;
|
|
38522
39409
|
} catch {
|
|
39410
|
+
continue;
|
|
38523
39411
|
}
|
|
39412
|
+
return known(a, language);
|
|
38524
39413
|
}
|
|
38525
39414
|
}
|
|
38526
39415
|
refuse(`The step "${input}" could not be read as one statement.`);
|
|
@@ -38615,6 +39504,7 @@ function rewriteCode(code3, oldTree, newTree, language) {
|
|
|
38615
39504
|
const trimmed = code3.trim();
|
|
38616
39505
|
if (trimmed.endsWith("{") && !head.endsWith("{")) head = `${head} {`;
|
|
38617
39506
|
if (!trimmed.endsWith(";") && head.endsWith(";") && !/[{:]$/.test(trimmed)) head = head.replace(/;$/, "");
|
|
39507
|
+
if (language === "python" && head.endsWith(":") && !trimmed.endsWith(":")) head = head.slice(0, -1);
|
|
38618
39508
|
attempts.push(head);
|
|
38619
39509
|
} catch {
|
|
38620
39510
|
}
|
|
@@ -38632,7 +39522,10 @@ function headLines(step) {
|
|
|
38632
39522
|
return [first, last];
|
|
38633
39523
|
}
|
|
38634
39524
|
function writeStepTree(source, step, newTree, language) {
|
|
38635
|
-
|
|
39525
|
+
let [a, b] = headLines(step);
|
|
39526
|
+
const SL = linesOf(source);
|
|
39527
|
+
const comment = language === "python" ? /^\s*(#.*)?$/ : /^\s*(\/\/.*)?$/;
|
|
39528
|
+
while (b > a && comment.test(SL[b - 1] ?? "")) b--;
|
|
38636
39529
|
const starts = lineStarts3(source);
|
|
38637
39530
|
const from = starts[a - 1], to = b < starts.length ? starts[b] - 1 : source.length;
|
|
38638
39531
|
const region = source.slice(from, to);
|
|
@@ -38701,6 +39594,10 @@ function renderBlock(steps, language, indent, unit) {
|
|
|
38701
39594
|
}
|
|
38702
39595
|
function stepSpec(spec, ctx) {
|
|
38703
39596
|
const { language } = ctx;
|
|
39597
|
+
if (typeof spec === "string") {
|
|
39598
|
+
const said = thunderStep(spec, language, wordsSource, wordsScope);
|
|
39599
|
+
if (said?.stop != null) return { e: stopTree(ctx, null, said.stop), c: [] };
|
|
39600
|
+
}
|
|
38704
39601
|
if (typeof spec === "string" || spec?.kind) return { e: statementFrom(spec, language), c: [] };
|
|
38705
39602
|
if (spec && typeof spec === "object" && "if" in spec) {
|
|
38706
39603
|
const test = exprFrom(spec.if, language, "condition");
|
|
@@ -39045,17 +39942,23 @@ function opSetValue(ctx, edit) {
|
|
|
39045
39942
|
const { step } = ctx.at(edit.step);
|
|
39046
39943
|
if (!step.expr || step.expr.kind === "code") needsAi(`The step at line ${step.line} is shown as code; Thunder has no tree for it to change exactly.`);
|
|
39047
39944
|
const tree = cloneShape(step.expr);
|
|
39048
|
-
let
|
|
39945
|
+
let lit5;
|
|
39049
39946
|
if (edit.at != null) {
|
|
39050
39947
|
const lits = [...nodesOf(tree)].filter((n) => n.kind === "literal" && (edit.from === void 0 || n.value === edit.from || n.raw === String(edit.from)));
|
|
39051
|
-
|
|
39052
|
-
if (!
|
|
39053
|
-
} else
|
|
39054
|
-
const next = literalOf(edit.to, ctx.language,
|
|
39055
|
-
if (next.type ===
|
|
39056
|
-
const old =
|
|
39057
|
-
|
|
39058
|
-
|
|
39948
|
+
lit5 = lits[edit.at];
|
|
39949
|
+
if (!lit5) refuse(`There is no value number ${edit.at} like that in this step.`);
|
|
39950
|
+
} else lit5 = findLiteral(tree, edit.from);
|
|
39951
|
+
const next = edit.toValue != null ? exprFrom(edit.toValue, ctx.language, "value") : literalOf(edit.to, ctx.language, lit5);
|
|
39952
|
+
if (next.kind === "literal" && next.type === lit5.type && next.value === lit5.value) refuse(`The value is already ${lit5.raw}.`);
|
|
39953
|
+
const old = lit5.raw;
|
|
39954
|
+
if (next.kind !== "literal") {
|
|
39955
|
+
Object.keys(lit5).forEach((k) => delete lit5[k]);
|
|
39956
|
+
Object.assign(lit5, cloneShape(next));
|
|
39957
|
+
ctx.setTree(step, tree);
|
|
39958
|
+
return `Changed ${old} to ${sayFull(next)} in ${q(sayStep(step))}`;
|
|
39959
|
+
}
|
|
39960
|
+
Object.keys(lit5).forEach((k) => delete lit5[k]);
|
|
39961
|
+
Object.assign(lit5, next);
|
|
39059
39962
|
ctx.setTree(step, tree);
|
|
39060
39963
|
return `Changed ${old} to ${next.raw} in ${q(sayStep(step))}`;
|
|
39061
39964
|
}
|
|
@@ -39181,6 +40084,13 @@ function opSetGivesBack(ctx, edit) {
|
|
|
39181
40084
|
ctx.setTree(target, tree);
|
|
39182
40085
|
return `Changed ${q(sayStep(target))} to give back ${renderExpr2(tree.value, ctx.language)}`;
|
|
39183
40086
|
}
|
|
40087
|
+
function withDecorators(source, a) {
|
|
40088
|
+
const L = linesOf(source);
|
|
40089
|
+
const ind = indentOf2(L[a - 1] ?? "");
|
|
40090
|
+
let first = a;
|
|
40091
|
+
while (first > 1 && /^\s*@/.test(L[first - 2]) && indentOf2(L[first - 2]) === ind) first--;
|
|
40092
|
+
return first;
|
|
40093
|
+
}
|
|
39184
40094
|
function placeFor(ctx, edit) {
|
|
39185
40095
|
const pos = ["before", "after", "into"].find((k) => edit[k] != null);
|
|
39186
40096
|
if (!pos) refuse('Say where the new step goes: before, after, or into ({ step, side: "yes" | "no", at: "start" | "end" }).');
|
|
@@ -39204,15 +40114,12 @@ function placeFor(ctx, edit) {
|
|
|
39204
40114
|
if (!ownsLines(ctx.source, loc.step)) needsAi(`The step at line ${loc.step.line} shares its lines with other code, so the writer cannot place a step ${pos} it.`);
|
|
39205
40115
|
const path = [...loc.path];
|
|
39206
40116
|
if (pos === "after") path[path.length - 1] += 1;
|
|
39207
|
-
return { pos, line: pos === "after" ? b + 1 : a, indent: indentOf2(linesOf(ctx.source)[a - 1]), shapePath: path, loc };
|
|
40117
|
+
return { pos, line: pos === "after" ? b + 1 : withDecorators(ctx.source, a), indent: indentOf2(linesOf(ctx.source)[a - 1]), shapePath: path, loc };
|
|
39208
40118
|
}
|
|
39209
40119
|
function insertShape(shape, path, nodes2) {
|
|
39210
40120
|
const list3 = path.length === 1 ? shape : (() => {
|
|
39211
40121
|
const parentPath = path.slice(0, -1);
|
|
39212
|
-
if (parentPath[parentPath.length - 1]
|
|
39213
|
-
const n = pathIn(shape, parentPath.slice(0, -1)).node;
|
|
39214
|
-
return n.o ?? (n.o = []);
|
|
39215
|
-
}
|
|
40122
|
+
if (isSide(parentPath[parentPath.length - 1])) return sideOf(pathIn(shape, parentPath.slice(0, -1)).node, parentPath[parentPath.length - 1]);
|
|
39216
40123
|
return pathIn(shape, parentPath).node.c;
|
|
39217
40124
|
})();
|
|
39218
40125
|
list3.splice(path[path.length - 1], 0, ...nodes2);
|
|
@@ -39238,12 +40145,21 @@ function insertSteps(ctx, edit, nodes2) {
|
|
|
39238
40145
|
ctx.lines(place.line, 0, renderBlock(nodes2, ctx.language, place.indent, unit));
|
|
39239
40146
|
insertShape(ctx.shape, place.shapePath, nodes2);
|
|
39240
40147
|
}
|
|
40148
|
+
function docstringBefore(L, a) {
|
|
40149
|
+
for (let i = a - 2; i >= 0; i--) {
|
|
40150
|
+
const t = L[i].trim();
|
|
40151
|
+
if (!t || t.startsWith("#")) continue;
|
|
40152
|
+
return /['"]$/.test(t);
|
|
40153
|
+
}
|
|
40154
|
+
return false;
|
|
40155
|
+
}
|
|
39241
40156
|
function removeAt(ctx, loc, { replaceWithPass = true } = {}) {
|
|
39242
|
-
const [
|
|
40157
|
+
const [a0, b] = stepLines(loc.step);
|
|
40158
|
+
const a = withDecorators(ctx.source, a0);
|
|
39243
40159
|
if (!ownsLines(ctx.source, loc.step)) needsAi(`The step at line ${loc.step.line} shares its lines with other code, so the writer cannot remove it alone.`);
|
|
39244
40160
|
const L = linesOf(ctx.source);
|
|
39245
40161
|
const siblings = loc.list.filter((s) => s.expr?.kind !== "pass");
|
|
39246
|
-
if (ctx.language === "python" && siblings.length === 1 && loc.parent
|
|
40162
|
+
if (ctx.language === "python" && siblings.length === 1 && replaceWithPass && (loc.parent || !docstringBefore(L, a))) ctx.lines(a, b - a + 1, [`${indentOf2(L[a - 1])}pass`]);
|
|
39247
40163
|
else ctx.lines(a, b - a + 1, []);
|
|
39248
40164
|
listAt(ctx.shape, loc.path).splice(loc.path[loc.path.length - 1], 1);
|
|
39249
40165
|
}
|
|
@@ -39265,8 +40181,10 @@ function opMoveStep(ctx, edit) {
|
|
|
39265
40181
|
if (dest.step === loc.step) refuse("A step cannot move next to itself.");
|
|
39266
40182
|
if (dest.path.join(".").startsWith(`${loc.path.join(".")}.`)) refuse("A step cannot move inside itself.");
|
|
39267
40183
|
if (!ownsLines(ctx.source, loc.step) || !ownsLines(ctx.source, dest.step)) needsAi("One of the steps shares its lines with other code, so the writer cannot move it alone.");
|
|
39268
|
-
const [
|
|
39269
|
-
const
|
|
40184
|
+
const [a0, b] = stepLines(loc.step);
|
|
40185
|
+
const a = withDecorators(ctx.source, a0);
|
|
40186
|
+
const [da0, db] = stepLines(dest.step);
|
|
40187
|
+
const da = withDecorators(ctx.source, da0);
|
|
39270
40188
|
const L = linesOf(ctx.source);
|
|
39271
40189
|
const moved = L.slice(a - 1, b);
|
|
39272
40190
|
const fromIndent = indentOf2(moved[0]), toIndent = indentOf2(L[da - 1]);
|
|
@@ -39488,6 +40406,9 @@ function opAddFunction(state, edit) {
|
|
|
39488
40406
|
if (language === "go" && inputs.some((p) => !p.type)) refuse("Go needs a type for every input.");
|
|
39489
40407
|
const ctx = { language, source, item: { name, line: 1 } };
|
|
39490
40408
|
if (language === "go" && edit.returns) ctx.goResults = edit.returns;
|
|
40409
|
+
wordsScope = `${name}(${inputs.map((p) => p.name).join(", ")})`;
|
|
40410
|
+
wordsSource = `${wordsScope}
|
|
40411
|
+
${source}`;
|
|
39491
40412
|
const nodes2 = (edit.steps || []).map((s) => stepSpec(s, { ...ctx, source: `${source}
|
|
39492
40413
|
func ${name}() (${edit.returns || ""}) {}` }));
|
|
39493
40414
|
if (!nodes2.length) refuse("A new function needs at least one step.");
|
|
@@ -39511,7 +40432,7 @@ func ${name}() (${edit.returns || ""}) {}` }));
|
|
|
39511
40432
|
const next = L.join("\n");
|
|
39512
40433
|
return { path, source: next, name, nodes: nodes2, inputs: inputs.map((p) => p.name), says: `Added ${name}(${inputs.map((p) => p.name).join(", ")}) with ${nodes2.length} step${nodes2.length === 1 ? "" : "s"}` };
|
|
39513
40434
|
}
|
|
39514
|
-
var
|
|
40435
|
+
var OPS6 = { setValue: opSetValue, setCondition: opSetCondition, setGivesBack: opSetGivesBack, addStep: opAddStep, removeStep: opRemoveStep, moveStep: opMoveStep, addStop: opAddStop, removeStop: opRemoveStop, addInput: opAddInput, removeInput: opRemoveInput, rename: opRename };
|
|
39515
40436
|
function applyEdit(state, edit) {
|
|
39516
40437
|
if (!edit || typeof edit !== "object") refuse('An edit is an object such as { op: "setValue", member, step, to }.');
|
|
39517
40438
|
if (!EDIT_OPS.includes(edit.op)) refuse(`"${edit.op}" is not a Thunder edit. The edits are: ${EDIT_OPS.join(", ")}.`);
|
|
@@ -39520,6 +40441,8 @@ function applyEdit(state, edit) {
|
|
|
39520
40441
|
return { files: new Map([...state.files, [r.path, r.source]]), plan: { added: { path: r.path, name: r.name, shape: r.nodes, inputs: r.inputs } }, says: r.says };
|
|
39521
40442
|
}
|
|
39522
40443
|
const m = findMember(state, edit.member);
|
|
40444
|
+
wordsSource = m.source;
|
|
40445
|
+
wordsScope = m.source.split("\n").slice(Math.max(0, m.item.line - 1), memberEnd(m.item)).join("\n");
|
|
39523
40446
|
if (!m.item.steps) needsAi(`Thunder has no steps for ${m.item.name} (line ${m.item.line}), so the edit cannot be placed exactly.`);
|
|
39524
40447
|
let source = m.source;
|
|
39525
40448
|
const ctx = {
|
|
@@ -39568,7 +40491,7 @@ function applyEdit(state, edit) {
|
|
|
39568
40491
|
return s;
|
|
39569
40492
|
}
|
|
39570
40493
|
};
|
|
39571
|
-
const says =
|
|
40494
|
+
const says = OPS6[edit.op](ctx, edit);
|
|
39572
40495
|
if (!WRITE_STEPS_LANGUAGES.includes(m.language)) needsAi(`The deterministic writers cover TypeScript, JavaScript, Python, and Go; ${m.path} is ${langName(m.language)}.`);
|
|
39573
40496
|
for (const t of ctx.treeEdits) source = writeStepTree(source, t.step, t.tree, m.language);
|
|
39574
40497
|
if (ctx.goImport) source = addGoImport(source, ctx.goImport);
|
|
@@ -39627,6 +40550,8 @@ function stepPathOf(steps, step) {
|
|
|
39627
40550
|
}
|
|
39628
40551
|
if (s.children) walk(s.children, [...path, i]);
|
|
39629
40552
|
if (s.otherwise) walk(s.otherwise, [...path, i, "else"]);
|
|
40553
|
+
(s.handlers || []).forEach((h, k) => walk(h.steps || [], [...path, i, `h:${k}`]));
|
|
40554
|
+
if (s.always?.steps) walk(s.always.steps, [...path, i, "always"]);
|
|
39630
40555
|
});
|
|
39631
40556
|
walk(steps, []);
|
|
39632
40557
|
return found;
|
|
@@ -39682,6 +40607,14 @@ function proveChange(before, after, plans) {
|
|
|
39682
40607
|
const editedKeys = /* @__PURE__ */ new Set();
|
|
39683
40608
|
const ranges = /* @__PURE__ */ new Map();
|
|
39684
40609
|
const renamed = plans.find((p) => p.renameFunction)?.renameFunction;
|
|
40610
|
+
const last = /* @__PURE__ */ new Map();
|
|
40611
|
+
for (const p of plans) {
|
|
40612
|
+
if (p.added) continue;
|
|
40613
|
+
const k = `${p.member.path}|${p.member.key}`;
|
|
40614
|
+
const prev = last.get(k)?.member;
|
|
40615
|
+
last.set(k, { ...p, member: { ...p.member, inputs: p.member.inputs ?? prev?.inputs, returns: p.member.returns ?? prev?.returns } });
|
|
40616
|
+
}
|
|
40617
|
+
plans = [...plans.filter((p) => p.added), ...last.values()];
|
|
39685
40618
|
for (const p of plans) {
|
|
39686
40619
|
if (p.added) {
|
|
39687
40620
|
const r2 = readOf(after, p.added.path);
|
|
@@ -39885,7 +40818,7 @@ function describeEdit(e) {
|
|
|
39885
40818
|
const who = e.member ? ` in ${parseMemberRef(e.member).name}` : "";
|
|
39886
40819
|
switch (e.op) {
|
|
39887
40820
|
case "setValue":
|
|
39888
|
-
return `Change the value ${e.from !== void 0 ? JSON.stringify(e.from) : ""} to ${JSON.stringify(e.to)}${at2(e.step)}${who}.`.replace("value to", "value to");
|
|
40821
|
+
return `Change the value ${e.from !== void 0 ? JSON.stringify(e.from) : ""} to ${e.toValue != null ? e.toValue : JSON.stringify(e.to)}${at2(e.step)}${who}.`.replace("value to", "value to");
|
|
39889
40822
|
case "setCondition":
|
|
39890
40823
|
return `Change the question${at2(e.step)}${who}: ${[e.when != null && `ask "${e.when}"`, e.compare != null && `compare with ${e.compare}`, e.operand && `make the ${e.operand.side || "right"} side ${JSON.stringify(e.operand.to)}`, e.negate && "turn it around (not)", e.addClause && `add "${e.addClause.join || "and"} ${e.addClause.when}"`, e.removeClause != null && `remove part ${e.removeClause}`].filter(Boolean).join(", ")}.`;
|
|
39891
40824
|
case "addStep":
|
|
@@ -39992,8 +40925,9 @@ function thunderWrite(files, edits, options = {}) {
|
|
|
39992
40925
|
}
|
|
39993
40926
|
let state = makeState(original);
|
|
39994
40927
|
const plans = [], said = [];
|
|
39995
|
-
for (const
|
|
40928
|
+
for (const raw of list3) {
|
|
39996
40929
|
try {
|
|
40930
|
+
const e = followLines(raw, original, state.files);
|
|
39997
40931
|
const r = applyEdit(state, e);
|
|
39998
40932
|
state = makeState(r.files, original);
|
|
39999
40933
|
plans.push(r.plan);
|
|
@@ -40030,13 +40964,53 @@ function thunderWrite(files, edits, options = {}) {
|
|
|
40030
40964
|
function planOnly(original, list3) {
|
|
40031
40965
|
let state = makeState(original);
|
|
40032
40966
|
const plans = [];
|
|
40033
|
-
for (const
|
|
40034
|
-
const r = applyEdit(state,
|
|
40967
|
+
for (const raw of list3) {
|
|
40968
|
+
const r = applyEdit(state, followLines(raw, original, state.files));
|
|
40035
40969
|
state = makeState(r.files, original);
|
|
40036
40970
|
plans.push(r.plan);
|
|
40037
40971
|
}
|
|
40038
40972
|
return plans;
|
|
40039
40973
|
}
|
|
40974
|
+
function followLine(before, after, n, { start = false } = {}) {
|
|
40975
|
+
if (before === after) return n;
|
|
40976
|
+
const a = before.split("\n"), b = after.split("\n");
|
|
40977
|
+
let p = 0;
|
|
40978
|
+
while (p < a.length && p < b.length && a[p] === b[p]) p++;
|
|
40979
|
+
let q2 = 0;
|
|
40980
|
+
while (q2 < a.length - p && q2 < b.length - p && a[a.length - 1 - q2] === b[b.length - 1 - q2]) q2++;
|
|
40981
|
+
if (n <= p) return n;
|
|
40982
|
+
if (start && n === p + 1) return n;
|
|
40983
|
+
if (n > a.length - q2) return n + (b.length - a.length);
|
|
40984
|
+
const text2 = a[n - 1];
|
|
40985
|
+
if (!text2.trim()) return null;
|
|
40986
|
+
const inA = a.slice(p, a.length - q2).filter((l) => l === text2).length;
|
|
40987
|
+
const hits = [];
|
|
40988
|
+
for (let i = p; i < b.length - q2; i++) if (b[i] === text2) hits.push(i + 1);
|
|
40989
|
+
return inA === 1 && hits.length === 1 ? hits[0] : null;
|
|
40990
|
+
}
|
|
40991
|
+
function followLines(edit, original, current) {
|
|
40992
|
+
if (!edit || typeof edit !== "object" || original === current) return edit;
|
|
40993
|
+
let path = typeof edit.member === "object" ? edit.member?.file : typeof edit.member === "string" && edit.member.includes("#") ? edit.member.split("#")[0] : null;
|
|
40994
|
+
if (!path || !original.has(path)) {
|
|
40995
|
+
const changed = [...original.keys()].filter((p) => original.get(p) !== current.get(p));
|
|
40996
|
+
if (original.size === 1) path = [...original.keys()][0];
|
|
40997
|
+
else if (changed.length === 1) path = changed[0];
|
|
40998
|
+
else if (changed.length > 1 && ["step", "before", "after"].some((k) => /^line:\d+$/.test(String(edit[k] ?? "")))) refuse("Several files changed in this list and this edit does not name its file; give its member as { file, name } so its lines can be followed.");
|
|
40999
|
+
}
|
|
41000
|
+
if (!path || !original.has(path) || !current.has(path) || original.get(path) === current.get(path)) return edit;
|
|
41001
|
+
const move = (n, opts) => {
|
|
41002
|
+
const to = followLine(original.get(path), current.get(path), n, opts);
|
|
41003
|
+
if (to == null) refuse(`Line ${n} was rewritten by an earlier edit in this list, so it cannot be found again; give that edit after this one, or address the step by its new line.`);
|
|
41004
|
+
return to;
|
|
41005
|
+
};
|
|
41006
|
+
const out = { ...edit };
|
|
41007
|
+
for (const k of ["step", "before", "after"]) {
|
|
41008
|
+
const m = typeof out[k] === "string" && out[k].match(/^line:(\d+)$/);
|
|
41009
|
+
if (m) out[k] = `line:${move(Number(m[1]))}`;
|
|
41010
|
+
}
|
|
41011
|
+
if (typeof out.member === "object" && out.member?.line) out.member = { ...out.member, line: move(out.member.line, { start: true }) };
|
|
41012
|
+
return out;
|
|
41013
|
+
}
|
|
40040
41014
|
|
|
40041
41015
|
// src/trace-data.mjs
|
|
40042
41016
|
var lineAt4 = (text2, index) => {
|
|
@@ -40382,14 +41356,14 @@ var methodOk = (route, req) => route === req || route === "ANY" || route === "AL
|
|
|
40382
41356
|
var WRITE_ACROSS_SCHEMA = "thunder-write-across-v1";
|
|
40383
41357
|
var words13 = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[_\-.\s]+/g, " ").trim().toLowerCase();
|
|
40384
41358
|
var editable2 = (t) => t.t === "num" || t.t === "str" || t.t === "op" && ["<", "<=", ">", ">=", "==", "!="].includes(t.v);
|
|
40385
|
-
var
|
|
41359
|
+
var keyOf2 = (t) => t.t === "id" ? `id:${words13(t.v)}` : t.t === "str" ? `str:${JSON.stringify(t.v)}` : `${t.t}:${t.v}`;
|
|
40386
41360
|
var shapeOf = (t) => t.t === "id" ? "id" : editable2(t) ? t.t === "op" ? "cmp" : t.t : `${t.t}:${t.v}`;
|
|
40387
41361
|
var join3 = (toks2) => toks2.map((t) => t.t === "str" ? JSON.stringify(t.v) : String(t.v)).join(" ");
|
|
40388
41362
|
var FILLER = /* @__PURE__ */ new Set(["get", "is", "has", "can", "should", "calc", "calculate", "compute", "check", "find", "the", "a", "an", "of", "for", "to", "by"]);
|
|
40389
|
-
var
|
|
41363
|
+
var nameWords3 = (name) => new Set(words13(name).split(" ").filter((w) => w && !FILLER.has(w)));
|
|
40390
41364
|
var sharesWord = (a, b) => {
|
|
40391
|
-
const A =
|
|
40392
|
-
return [...
|
|
41365
|
+
const A = nameWords3(a);
|
|
41366
|
+
return [...nameWords3(b)].some((w) => A.has(w));
|
|
40393
41367
|
};
|
|
40394
41368
|
var toks = (when) => {
|
|
40395
41369
|
try {
|
|
@@ -40430,14 +41404,14 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40430
41404
|
}
|
|
40431
41405
|
if (anchors.length > 1) return { ok: false, problems: [`${anchors.length} decisions are called ${name}: ${anchors.map(where).join(", ")}. Name one as "part/file:${name}".`] };
|
|
40432
41406
|
const anchor = anchors[0];
|
|
40433
|
-
const key = anchor.toks.map(
|
|
41407
|
+
const key = anchor.toks.map(keyOf2).join(" ");
|
|
40434
41408
|
const shape = anchor.toks.map(shapeOf).join(" ");
|
|
40435
|
-
const names = anchor.toks.filter((t) => t.t === "id").map(
|
|
40436
|
-
const values = anchor.toks.filter((t) => t.t !== "id").map(
|
|
41409
|
+
const names = anchor.toks.filter((t) => t.t === "id").map(keyOf2).join(" ");
|
|
41410
|
+
const values = anchor.toks.filter((t) => t.t !== "id").map(keyOf2).join(" ");
|
|
40437
41411
|
const same = [], notIncluded = [];
|
|
40438
41412
|
for (const x of all) {
|
|
40439
41413
|
if (x === anchor) continue;
|
|
40440
|
-
const k = x.toks.map(
|
|
41414
|
+
const k = x.toks.map(keyOf2).join(" ");
|
|
40441
41415
|
const said = sayCondition(x.when);
|
|
40442
41416
|
if (k === key) {
|
|
40443
41417
|
if (sharesWord(x.decision, anchor.decision)) same.push({ ...x, why: `the same condition: ${said} (names compared as words)` });
|
|
@@ -40445,8 +41419,8 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40445
41419
|
continue;
|
|
40446
41420
|
}
|
|
40447
41421
|
if (x.toks.map(shapeOf).join(" ") !== shape) continue;
|
|
40448
|
-
const xNames = x.toks.filter((t) => t.t === "id").map(
|
|
40449
|
-
const xValues = x.toks.filter((t) => t.t !== "id").map(
|
|
41422
|
+
const xNames = x.toks.filter((t) => t.t === "id").map(keyOf2).join(" ");
|
|
41423
|
+
const xValues = x.toks.filter((t) => t.t !== "id").map(keyOf2).join(" ");
|
|
40450
41424
|
if (xNames === names) notIncluded.push({ ...x, why: `the same names but a different limit (${said}); it may be another rule, or one that has already drifted` });
|
|
40451
41425
|
else if (xValues === values) notIncluded.push({ ...x, why: `the same limit but different names (${said}); Thunder cannot tell that these are the same values` });
|
|
40452
41426
|
}
|
|
@@ -40454,7 +41428,7 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40454
41428
|
return { ok: true, anchor: strip(anchor), same: [anchor, ...same].map(strip), notIncluded: notIncluded.map(strip), problems: [] };
|
|
40455
41429
|
}
|
|
40456
41430
|
function testsMentioning(files, oldToks, newToks, functions) {
|
|
40457
|
-
const changed = oldToks.filter((t, i) => editable2(t) && t.t !== "op" &&
|
|
41431
|
+
const changed = oldToks.filter((t, i) => editable2(t) && t.t !== "op" && keyOf2(t) !== keyOf2(newToks[i]));
|
|
40458
41432
|
if (!changed.length) return [];
|
|
40459
41433
|
const callsRule = (src) => (src.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? []).some((w) => functions.has(words13(w)));
|
|
40460
41434
|
const out = [];
|
|
@@ -40473,7 +41447,7 @@ function writeRuleAcross(files, { decision, rule, when }) {
|
|
|
40473
41447
|
if (!found.ok) return { ...base2, problems: found.problems };
|
|
40474
41448
|
const oldT = toks(found.anchor.when), newT = toks(when);
|
|
40475
41449
|
if (!newT) return { ...base2, problems: [`The new condition "${when}" could not be read.`] };
|
|
40476
|
-
if (oldT.length !== newT.length || oldT.some((t, i) => editable2(t) ? !(editable2(newT[i]) && shapeOf(t) === shapeOf(newT[i])) :
|
|
41450
|
+
if (oldT.length !== newT.length || oldT.some((t, i) => editable2(t) ? !(editable2(newT[i]) && shapeOf(t) === shapeOf(newT[i])) : keyOf2(t) !== keyOf2(newT[i]))) {
|
|
40477
41451
|
return { ...base2, problems: [`Thunder write can change a number, a comparison, or a text value in a rule. "${when}" also changes the rule's shape (names, and/or, or parentheses), so it is not one change Thunder can write into every implementation.`] };
|
|
40478
41452
|
}
|
|
40479
41453
|
const result = { ...base2, plan: [], files: {}, rule: { before: sayCondition(found.anchor.when), after: sayCondition(join3(newT)) }, notIncluded: found.notIncluded, tests: testsMentioning(files, oldT, newT, new Set(found.same.map((x) => words13(x.decision)))) };
|
|
@@ -40918,7 +41892,7 @@ function nodeAt(member, line, want) {
|
|
|
40918
41892
|
}
|
|
40919
41893
|
return null;
|
|
40920
41894
|
}
|
|
40921
|
-
function
|
|
41895
|
+
function sideOf2(node2, block, ev) {
|
|
40922
41896
|
if (node2.kind === "loop") return ev.side === "each" || ev.side === "held" ? { key: "each", label: "For each" } : { key: "done", label: "Done" };
|
|
40923
41897
|
if (node2.cases) {
|
|
40924
41898
|
const P = String(ev.side).startsWith("case:") ? Number(String(ev.side).slice(5)) : null;
|
|
@@ -41093,7 +42067,7 @@ function runtimeOverlay(model, evidence2 = []) {
|
|
|
41093
42067
|
nr.ran = (nr.ran || 0) + c;
|
|
41094
42068
|
continue;
|
|
41095
42069
|
}
|
|
41096
|
-
side2 ??=
|
|
42070
|
+
side2 ??= sideOf2(n, blockOf(member, n.id), ev);
|
|
41097
42071
|
if (!side2) {
|
|
41098
42072
|
unplaced(ev, `the case at line ${String(ev.side).slice(5)} is not one Thunder draws for "${n.text}"`);
|
|
41099
42073
|
continue;
|
|
@@ -44675,19 +45649,19 @@ function universalPack() {
|
|
|
44675
45649
|
};
|
|
44676
45650
|
}
|
|
44677
45651
|
var confidenceFor = (rule) => rule.detection === "deterministic" ? "Observed" : "Inferred";
|
|
44678
|
-
function toFinding(
|
|
44679
|
-
const rule = fableRuleFor(
|
|
44680
|
-
const isBlocker =
|
|
45652
|
+
function toFinding(diag2, { file = null, index = 0, affectedNodes = [] } = {}) {
|
|
45653
|
+
const rule = fableRuleFor(diag2.code);
|
|
45654
|
+
const isBlocker = diag2.severity === "blocker";
|
|
44681
45655
|
return {
|
|
44682
|
-
findingId: `${(
|
|
45656
|
+
findingId: `${(diag2.code || "FINDING").toLowerCase()}-${file ? file.replace(/[^a-z0-9]+/gi, "-") : "x"}-${index}`,
|
|
44683
45657
|
ruleId: rule.ruleId,
|
|
44684
45658
|
ruleVersion: rule.ruleVersion,
|
|
44685
45659
|
category: rule.category,
|
|
44686
|
-
detected:
|
|
44687
|
-
why:
|
|
44688
|
-
evidence: [{ file, line:
|
|
45660
|
+
detected: diag2.message,
|
|
45661
|
+
why: diag2.why || rule.title,
|
|
45662
|
+
evidence: [{ file, line: diag2.line ?? null, kind: "diagnostic", detail: diag2.message }],
|
|
44689
45663
|
affectedNodes,
|
|
44690
|
-
severity: isBlocker ? "blocker" :
|
|
45664
|
+
severity: isBlocker ? "blocker" : diag2.level || "warning",
|
|
44691
45665
|
confidence: confidenceFor(rule),
|
|
44692
45666
|
detectionType: rule.detection,
|
|
44693
45667
|
potentialImpact: isBlocker ? "Blocks a phase (e.g. release) until resolved." : "Weakens the intent; not blocking.",
|