@skillstech/thunderlang 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/core.cjs +1036 -134
- package/dist/index.cjs +5543 -4624
- 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 +152 -23
- package/src/write-words.mjs +182 -0
- package/src/write.mjs +12 -0
package/dist/core.cjs
CHANGED
|
@@ -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"}`;
|
|
@@ -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 });
|
|
@@ -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);
|
|
@@ -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.0";
|
|
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);
|
|
@@ -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":
|
|
@@ -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,793 @@ 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 no2 = (why) => {
|
|
30966
|
+
throw new Unsaid(why);
|
|
30967
|
+
};
|
|
30968
|
+
function toTree(n, language, names) {
|
|
30969
|
+
const T = (x) => toTree(x, language, names);
|
|
30970
|
+
const py = language === "python", go = language === "go", js = language === "typescript" || language === "javascript";
|
|
30971
|
+
const call2 = (callee2, args) => ({ kind: "call", callee: callee2, args });
|
|
30972
|
+
const member = (object, property) => ({ kind: "member", object, property });
|
|
30973
|
+
const nm = (name) => ({ kind: "name", name });
|
|
30974
|
+
switch (n.k) {
|
|
30975
|
+
case "paren":
|
|
30976
|
+
return T(n.e);
|
|
30977
|
+
case "num":
|
|
30978
|
+
return lit4("number", Number(n.text), n.text);
|
|
30979
|
+
case "str":
|
|
30980
|
+
if (n.parts.some((p) => typeof p !== "string")) no2("a text with values inside it ({\u2026})");
|
|
30981
|
+
return lit4("text", n.parts.join(""), JSON.stringify(n.parts.join("")));
|
|
30982
|
+
case "bool":
|
|
30983
|
+
return lit4("bool", n.v, py ? n.v ? "True" : "False" : String(n.v));
|
|
30984
|
+
case "nothing":
|
|
30985
|
+
return lit4("null", null, NULL_RAW[language]);
|
|
30986
|
+
case "name": {
|
|
30987
|
+
const id2 = names.get(n.name) ?? (/^[A-Za-z_]\w*$/.test(n.name) ? n.name : null);
|
|
30988
|
+
if (!id2) no2(`"${n.name}" (no name in the file is said that way)`);
|
|
30989
|
+
return nm(id2);
|
|
30990
|
+
}
|
|
30991
|
+
case "field":
|
|
30992
|
+
case "dot": {
|
|
30993
|
+
if (n.args) no2("a call written with a dot");
|
|
30994
|
+
const prop = n.k === "field" ? n.name : n.attr;
|
|
30995
|
+
return member(T(n.obj), names.get(prop) ?? prop.replace(/ /g, "_"));
|
|
30996
|
+
}
|
|
30997
|
+
case "neg":
|
|
30998
|
+
return { kind: "unary", op: "-", value: T(n.e) };
|
|
30999
|
+
case "not":
|
|
31000
|
+
return { kind: "not", value: T(n.e) };
|
|
31001
|
+
case "bin": {
|
|
31002
|
+
if (n.op === "and" || n.op === "or") {
|
|
31003
|
+
const operands = [];
|
|
31004
|
+
for (const side2 of [n.l, n.r]) {
|
|
31005
|
+
const t = T(side2);
|
|
31006
|
+
if (t.kind === "logic" && t.op === n.op) operands.push(...t.operands);
|
|
31007
|
+
else operands.push(t);
|
|
31008
|
+
}
|
|
31009
|
+
return { kind: "logic", op: n.op, operands };
|
|
31010
|
+
}
|
|
31011
|
+
const op = { "+": "+", "-": "-", "*": "*", "/": "/", mod: "%", "%": "%" }[n.op];
|
|
31012
|
+
if (!op) no2(`"${n.op}"`);
|
|
31013
|
+
return { kind: "binary", op, left: T(n.l), right: T(n.r) };
|
|
31014
|
+
}
|
|
31015
|
+
case "cmp": {
|
|
31016
|
+
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) };
|
|
31017
|
+
const op = n.op === "==" ? js ? "===" : "==" : n.op === "!=" ? js ? "!==" : "!=" : n.op;
|
|
31018
|
+
return { kind: "compare", op, left: T(n.l), right: T(n.r) };
|
|
31019
|
+
}
|
|
31020
|
+
case "isNothing": {
|
|
31021
|
+
const op = py ? n.neg ? "is not" : "is" : n.neg ? "!=" : "==";
|
|
31022
|
+
return { kind: "compare", op, left: T(n.e), right: lit4("null", null, NULL_RAW[language]) };
|
|
31023
|
+
}
|
|
31024
|
+
case "between": {
|
|
31025
|
+
const e = T(n.e);
|
|
31026
|
+
return { kind: "logic", op: "and", operands: [{ kind: "compare", op: ">=", left: e, right: T(n.lo) }, { kind: "compare", op: "<=", left: e, right: T(n.hi) }] };
|
|
31027
|
+
}
|
|
31028
|
+
case "contains": {
|
|
31029
|
+
if (py) return { kind: "compare", op: "in", left: T(n.r), right: T(n.l) };
|
|
31030
|
+
if (js) return call2(member(T(n.l), "includes"), [T(n.r)]);
|
|
31031
|
+
no2('"contains" in Go (strings.Contains or slices.Contains depends on the value)');
|
|
31032
|
+
break;
|
|
31033
|
+
}
|
|
31034
|
+
case "affix": {
|
|
31035
|
+
const l = T(n.l), r = T(n.r);
|
|
31036
|
+
if (py) return call2(member(l, n.end ? "endswith" : "startswith"), [r]);
|
|
31037
|
+
if (js) return call2(member(l, n.end ? "endsWith" : "startsWith"), [r]);
|
|
31038
|
+
return call2(member(nm("strings"), n.end ? "HasSuffix" : "HasPrefix"), [l, r]);
|
|
31039
|
+
}
|
|
31040
|
+
case "op": {
|
|
31041
|
+
const a = T(n.arg);
|
|
31042
|
+
if (n.op === "length" || n.op === "count") return js ? member(a, "length") : call2(nm("len"), [a]);
|
|
31043
|
+
if (n.op === "lowercase") return py ? call2(member(a, "lower"), []) : js ? call2(member(a, "toLowerCase"), []) : call2(member(nm("strings"), "ToLower"), [a]);
|
|
31044
|
+
if (n.op === "uppercase") return py ? call2(member(a, "upper"), []) : js ? call2(member(a, "toUpperCase"), []) : call2(member(nm("strings"), "ToUpper"), [a]);
|
|
31045
|
+
if (n.op === "trimmed") return py ? call2(member(a, "strip"), []) : js ? call2(member(a, "trim"), []) : call2(member(nm("strings"), "TrimSpace"), [a]);
|
|
31046
|
+
if (n.op === "first") return { kind: "index", object: a, index: lit4("number", 0, "0") };
|
|
31047
|
+
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") } };
|
|
31048
|
+
no2(`"the ${n.word} of"`);
|
|
31049
|
+
break;
|
|
31050
|
+
}
|
|
31051
|
+
default:
|
|
31052
|
+
no2(`"${n.k}"`);
|
|
31053
|
+
}
|
|
31054
|
+
return null;
|
|
31055
|
+
}
|
|
31056
|
+
function parseThunder(text2, source, scope) {
|
|
31057
|
+
const names = namesOf(source, scope);
|
|
31058
|
+
const known = new Map([...names.keys()].map((k) => [k, "var"]));
|
|
31059
|
+
const ep = new ExprParser({ known, 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() });
|
|
31060
|
+
const lexed = tokenizeLine(String(text2), 1);
|
|
31061
|
+
const tokens = Array.isArray(lexed) ? lexed : lexed.tokens;
|
|
31062
|
+
return { node: ep.parse(tokens, 1), names };
|
|
31063
|
+
}
|
|
31064
|
+
function thunderTree(text2, language, source, scope = "") {
|
|
31065
|
+
let parsed;
|
|
31066
|
+
try {
|
|
31067
|
+
parsed = parseThunder(text2, source, scope);
|
|
31068
|
+
} catch (e) {
|
|
31069
|
+
return { error: String(e.message).replace(/^Line 1: /, "").split("\n")[0] };
|
|
31070
|
+
}
|
|
31071
|
+
try {
|
|
31072
|
+
return { tree: toTree(parsed.node, language, parsed.names) };
|
|
31073
|
+
} catch (e) {
|
|
31074
|
+
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
31075
|
+
throw e;
|
|
31076
|
+
}
|
|
31077
|
+
}
|
|
31078
|
+
var looksThunder = (text2) => typeof text2 === "string" && THUNDER_MARKERS.test(text2);
|
|
31079
|
+
function thunderStep(text2, language, source, scope = "") {
|
|
31080
|
+
const t = String(text2).trim();
|
|
31081
|
+
let m;
|
|
31082
|
+
if (m = t.match(/^stop with\s+(["'])(.*)\1\s*$/i)) return { stop: m[2] };
|
|
31083
|
+
if (m = t.match(/^give(?: back)?\s+(.+)$/i)) {
|
|
31084
|
+
const v = thunderTree(m[1], language, source, scope);
|
|
31085
|
+
return v.tree ? { tree: { kind: "return", value: v.tree } } : { error: v.error };
|
|
31086
|
+
}
|
|
31087
|
+
if (m = t.match(/^set\s+(.+?)\s+to\s+(.+)$/i)) {
|
|
31088
|
+
const target = thunderTree(m[1], language, source, scope), value = thunderTree(m[2], language, source, scope);
|
|
31089
|
+
if (!target.tree) return { error: target.error };
|
|
31090
|
+
if (!value.tree) return { error: value.error };
|
|
31091
|
+
if (target.tree.kind !== "name" && target.tree.kind !== "member") return { error: `"${m[1]}" is not a name to set.` };
|
|
31092
|
+
return { tree: { kind: "assign", op: "=", target: target.tree, value: value.tree } };
|
|
31093
|
+
}
|
|
31094
|
+
return null;
|
|
31095
|
+
}
|
|
31096
|
+
|
|
30299
31097
|
// src/read-repo.mjs
|
|
30300
31098
|
var READ_REPO_SCHEMA = "thunder-repo-reading-v1";
|
|
30301
31099
|
var EXT_LANG = [
|
|
@@ -30495,7 +31293,7 @@ var NAME_TEXT = /^[A-Za-z0-9 $.,'_-]+$/;
|
|
|
30495
31293
|
var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
30496
31294
|
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
31295
|
var camel = (s) => lowerFirst(pascal3(s));
|
|
30498
|
-
var
|
|
31296
|
+
var RESERVED3 = /* @__PURE__ */ new Set(["and", "or", "not", "in", "true", "false", "case", "expect"]);
|
|
30499
31297
|
function formatValue(input, value) {
|
|
30500
31298
|
if (input.kind === "yesno") return value ? input.yes : input.no;
|
|
30501
31299
|
if (input.kind === "text") return value === "" ? "empty" : JSON.stringify(String(value));
|
|
@@ -30532,9 +31330,9 @@ function parseNumber(text2, input, line) {
|
|
|
30532
31330
|
function parseInputLine(text2, line) {
|
|
30533
31331
|
let m;
|
|
30534
31332
|
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:
|
|
31333
|
+
const [yes, no3] = [m[1].trim(), m[2].trim()];
|
|
31334
|
+
if (yes === no3) fail3(line, 'Use two different words, such as "whether it is on time or late".');
|
|
31335
|
+
return { id: camel(yes), kind: "yesno", label: `it is ${yes}`, yes, no: no3 };
|
|
30538
31336
|
}
|
|
30539
31337
|
if (m = text2.match(/^(the .+?), (in dollars|a number)\.?$/)) {
|
|
30540
31338
|
const label = m[1].trim();
|
|
@@ -30600,7 +31398,7 @@ function parsePlainContract(source) {
|
|
|
30600
31398
|
}
|
|
30601
31399
|
if (section === "inputs") {
|
|
30602
31400
|
const input = parseInputLine(text2, line);
|
|
30603
|
-
if (
|
|
31401
|
+
if (RESERVED3.has(input.id) || !input.id) fail3(line, "Choose a different name for this input.");
|
|
30604
31402
|
if (model.inputs.some((i) => i.id === input.id)) fail3(line, `${input.label} is listed twice.`);
|
|
30605
31403
|
const words15 = model.inputs.flatMap((i) => i.kind === "yesno" ? [i.yes, i.no] : []);
|
|
30606
31404
|
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 +31497,7 @@ function conditionExpr(model, c) {
|
|
|
30699
31497
|
}
|
|
30700
31498
|
function plainToThunder(model) {
|
|
30701
31499
|
const name = pascal3(model.title);
|
|
30702
|
-
const
|
|
31500
|
+
const lit5 = (v) => typeof v === "boolean" ? String(v) : String(v);
|
|
30703
31501
|
const out = [
|
|
30704
31502
|
`# Compiled from plain ThunderLang (${PLAIN_SCHEMA}). Edit the plain file, not this one.`,
|
|
30705
31503
|
`mission ${name}`,
|
|
@@ -30723,7 +31521,7 @@ function plainToThunder(model) {
|
|
|
30723
31521
|
}
|
|
30724
31522
|
out.push(" default", ` return ${model.otherwise}`, "", `test ${name}`);
|
|
30725
31523
|
for (const e of model.examples) {
|
|
30726
|
-
out.push(` case ${e.name}`, ` given ${model.inputs.map((i) => `${i.id} ${
|
|
31524
|
+
out.push(` case ${e.name}`, ` given ${model.inputs.map((i) => `${i.id} ${lit5(e.values[i.id])}`).join(", ")}`, ` expect ${e.expected}`);
|
|
30727
31525
|
}
|
|
30728
31526
|
return out.join("\n") + "\n";
|
|
30729
31527
|
}
|
|
@@ -31226,11 +32024,11 @@ function comparePlainRules(a, b) {
|
|
|
31226
32024
|
return { same: true, tried };
|
|
31227
32025
|
}
|
|
31228
32026
|
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
|
|
32027
|
+
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
32028
|
function stepSignature(code3) {
|
|
31231
32029
|
const t = String(code3 || "").replace(/(\/\/|#)[^\n]*$/gm, "");
|
|
31232
32030
|
const toks2 = t.match(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|-?\d+(?:\.\d+)?|[A-Za-z_$][\w$]*|===|!==|==|!=|<=|>=|&&|\|\||\*\*|<>|[-+*\/%<>=!]/g) || [];
|
|
31233
|
-
return toks2.filter((x) => !SYNTAX.has(x)).map((x) =>
|
|
32031
|
+
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
32032
|
}
|
|
31235
32033
|
var flatSteps = (steps, depth = 0) => (steps || []).flatMap((s) => [
|
|
31236
32034
|
{ 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 +38833,9 @@ function pathsOf(flow) {
|
|
|
38035
38833
|
if (n && (n.kind === "stop" || n.kind === "end")) (out.ended ||= /* @__PURE__ */ new Set()).add(blocks2);
|
|
38036
38834
|
const q2 = n?.text ?? "";
|
|
38037
38835
|
const yes = { question: q2, answer: "Yes", ...n?.holds ? { says: n.holds.yes } : {} };
|
|
38038
|
-
const
|
|
38836
|
+
const no3 = { question: q2, answer: "No", ...n?.holds ? { says: n.holds.no } : {} };
|
|
38039
38837
|
walk(b.yes, [...when, yes]);
|
|
38040
|
-
walk(b.no, [...when,
|
|
38838
|
+
walk(b.no, [...when, no3]);
|
|
38041
38839
|
walk(b.each, [...when, { question: q2, answer: "For each" }]);
|
|
38042
38840
|
for (const c of b.cases || []) walk(c.blocks, [...when, { question: q2, answer: c.label }]);
|
|
38043
38841
|
if (!b.nested) walk(b.body, when);
|
|
@@ -38048,7 +38846,7 @@ function pathsOf(flow) {
|
|
|
38048
38846
|
if (b.always) walk(b.always.blocks, when);
|
|
38049
38847
|
if (n?.kind === "decision" && (b.yes || b.no)) {
|
|
38050
38848
|
const yesEnds = ends(b.yes), noEnds = ends(b.no);
|
|
38051
|
-
if (yesEnds && !noEnds) when = [...when,
|
|
38849
|
+
if (yesEnds && !noEnds) when = [...when, no3];
|
|
38052
38850
|
else if (noEnds && !yesEnds) when = [...when, yes];
|
|
38053
38851
|
}
|
|
38054
38852
|
}
|
|
@@ -38400,6 +39198,8 @@ function locateStep(steps, sel, { flowSteps } = {}) {
|
|
|
38400
39198
|
all.push({ step: s, list: list3, index: i, path: [...path, i], parent });
|
|
38401
39199
|
if (s.children) walk(s.children, [...path, i], s);
|
|
38402
39200
|
if (s.otherwise) walk(s.otherwise, [...path, i, "else"], s);
|
|
39201
|
+
(s.handlers || []).forEach((h, k) => walk(h.steps || [], [...path, i, `h:${k}`], s));
|
|
39202
|
+
if (s.always?.steps) walk(s.always.steps, [...path, i, "always"], s);
|
|
38403
39203
|
});
|
|
38404
39204
|
walk(steps || [], [], null);
|
|
38405
39205
|
if (Array.isArray(sel)) return all.find((x) => x.path.join(".") === sel.join(".")) ?? null;
|
|
@@ -38413,23 +39213,25 @@ function locateStep(steps, sel, { flowSteps } = {}) {
|
|
|
38413
39213
|
if (/^\d+$/.test(String(sel))) return all.find((x) => x.path.join(".") === String(sel)) ?? null;
|
|
38414
39214
|
return null;
|
|
38415
39215
|
}
|
|
39216
|
+
var isSide = (p) => p === "else" || p === "always" || typeof p === "string" && p.startsWith("h:");
|
|
39217
|
+
var sideOf = (node2, p) => p === "else" ? node2.o ?? (node2.o = []) : p === "always" ? node2.a ?? (node2.a = []) : node2.h[Number(p.slice(2))].c;
|
|
38416
39218
|
var pathIn = (shape, path) => {
|
|
38417
39219
|
let list3 = shape, node2 = null;
|
|
38418
39220
|
for (let i = 0; i < path.length; i++) {
|
|
38419
39221
|
const p = path[i];
|
|
38420
|
-
if (p
|
|
38421
|
-
list3 =
|
|
39222
|
+
if (isSide(p)) {
|
|
39223
|
+
list3 = sideOf(node2, p);
|
|
38422
39224
|
continue;
|
|
38423
39225
|
}
|
|
38424
39226
|
node2 = list3[p];
|
|
38425
|
-
if (i < path.length - 1 && path[i + 1]
|
|
39227
|
+
if (i < path.length - 1 && !isSide(path[i + 1])) list3 = node2.c;
|
|
38426
39228
|
}
|
|
38427
39229
|
return { list: list3, node: node2, index: path[path.length - 1] };
|
|
38428
39230
|
};
|
|
38429
39231
|
var listAt = (shape, path) => {
|
|
38430
39232
|
if (path.length === 1) return shape;
|
|
38431
39233
|
const parentPath = path.slice(0, -1);
|
|
38432
|
-
if (parentPath[parentPath.length - 1]
|
|
39234
|
+
if (isSide(parentPath[parentPath.length - 1])) return sideOf(pathIn(shape, parentPath.slice(0, -1)).node, parentPath[parentPath.length - 1]);
|
|
38433
39235
|
return pathIn(shape, parentPath).node.c;
|
|
38434
39236
|
};
|
|
38435
39237
|
function parseMemberRef(ref) {
|
|
@@ -38469,9 +39271,17 @@ function literalOf(value, language, like = null) {
|
|
|
38469
39271
|
if (typeof value === "number") {
|
|
38470
39272
|
if (!Number.isFinite(value)) refuse(`${value} is not a number that can be written.`);
|
|
38471
39273
|
let raw = String(value);
|
|
38472
|
-
|
|
38473
|
-
const
|
|
38474
|
-
if (
|
|
39274
|
+
const was = like?.type === "number" ? String(like.raw) : "";
|
|
39275
|
+
const base2 = was.match(/^0([xXoObB])/);
|
|
39276
|
+
if (base2) {
|
|
39277
|
+
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}.`);
|
|
39278
|
+
const digits = value.toString({ x: 16, o: 8, b: 2 }[base2[1].toLowerCase()]);
|
|
39279
|
+
return { kind: "literal", type: "number", value, raw: `0${base2[1]}${/[A-F]/.test(was.slice(2)) ? digits.toUpperCase() : digits}` };
|
|
39280
|
+
}
|
|
39281
|
+
if (was.includes("_") && Number.isInteger(value)) raw = String(value).replace(/\B(?=(\d{3})+(?!\d))/g, "_");
|
|
39282
|
+
if (/\.\d/.test(was) && Number.isInteger(value)) raw += ".0";
|
|
39283
|
+
const suffix = was.match(/\d([mMfFdDlLnuU]|ul|UL|lu|LU)$/)?.[1] ?? "";
|
|
39284
|
+
if (suffix) raw += suffix;
|
|
38475
39285
|
return { kind: "literal", type: "number", value, raw };
|
|
38476
39286
|
}
|
|
38477
39287
|
if (typeof value === "string") {
|
|
@@ -38483,14 +39293,21 @@ function literalOf(value, language, like = null) {
|
|
|
38483
39293
|
refuse(`${JSON.stringify(value)} is not a value (use a number, text, true/false, or null).`);
|
|
38484
39294
|
}
|
|
38485
39295
|
var PARSE_ORDER = (lang) => [lang, ...WRITE_STEPS_LANGUAGES.filter((l) => l !== lang)];
|
|
39296
|
+
var wordsSource = "";
|
|
39297
|
+
var wordsScope = "";
|
|
39298
|
+
var misreadIs = (t) => t?.kind === "compare" && (t.op === "is" || t.op === "is not") && !(t.right?.kind === "literal" && t.right.type === "null");
|
|
38486
39299
|
function exprFrom(input, language, what = "expression") {
|
|
38487
39300
|
if (input && typeof input === "object" && input.kind) return input;
|
|
38488
39301
|
if (typeof input !== "string") return literalOf(input, language);
|
|
39302
|
+
let said = null;
|
|
39303
|
+
const words15 = () => said ??= thunderTree(input, language, wordsSource, wordsScope);
|
|
39304
|
+
if (looksThunder(input) && words15().tree) return words15().tree;
|
|
38489
39305
|
for (const l of PARSE_ORDER(language)) {
|
|
38490
39306
|
const t = parseExpr(input, l);
|
|
38491
|
-
if (t && t.kind !== "code") return adapt(t, language);
|
|
39307
|
+
if (t && t.kind !== "code" && !misreadIs(t)) return adapt(t, language);
|
|
38492
39308
|
}
|
|
38493
|
-
|
|
39309
|
+
if (words15().tree) return words15().tree;
|
|
39310
|
+
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.`);
|
|
38494
39311
|
}
|
|
38495
39312
|
function adapt(tree, language) {
|
|
38496
39313
|
const t = cloneShape(tree);
|
|
@@ -38512,6 +39329,9 @@ function adapt(tree, language) {
|
|
|
38512
39329
|
function statementFrom(input, language) {
|
|
38513
39330
|
if (input && typeof input === "object" && input.kind) return input;
|
|
38514
39331
|
if (typeof input !== "string" || !input.trim()) refuse("Say the new step as code, for example notify(order.customer).");
|
|
39332
|
+
const said = thunderStep(input, language, wordsSource, wordsScope);
|
|
39333
|
+
if (said?.tree) return said.tree;
|
|
39334
|
+
if (said?.error) refuse(`The step "${input}" could not be read: ${said.error}`);
|
|
38515
39335
|
for (const l of PARSE_ORDER(language)) {
|
|
38516
39336
|
const t = parseStatement(input, l);
|
|
38517
39337
|
if (t && t.kind !== "code") {
|
|
@@ -38615,6 +39435,7 @@ function rewriteCode(code3, oldTree, newTree, language) {
|
|
|
38615
39435
|
const trimmed = code3.trim();
|
|
38616
39436
|
if (trimmed.endsWith("{") && !head.endsWith("{")) head = `${head} {`;
|
|
38617
39437
|
if (!trimmed.endsWith(";") && head.endsWith(";") && !/[{:]$/.test(trimmed)) head = head.replace(/;$/, "");
|
|
39438
|
+
if (language === "python" && head.endsWith(":") && !trimmed.endsWith(":")) head = head.slice(0, -1);
|
|
38618
39439
|
attempts.push(head);
|
|
38619
39440
|
} catch {
|
|
38620
39441
|
}
|
|
@@ -38632,7 +39453,10 @@ function headLines(step) {
|
|
|
38632
39453
|
return [first, last];
|
|
38633
39454
|
}
|
|
38634
39455
|
function writeStepTree(source, step, newTree, language) {
|
|
38635
|
-
|
|
39456
|
+
let [a, b] = headLines(step);
|
|
39457
|
+
const SL = linesOf(source);
|
|
39458
|
+
const comment = language === "python" ? /^\s*(#.*)?$/ : /^\s*(\/\/.*)?$/;
|
|
39459
|
+
while (b > a && comment.test(SL[b - 1] ?? "")) b--;
|
|
38636
39460
|
const starts = lineStarts3(source);
|
|
38637
39461
|
const from = starts[a - 1], to = b < starts.length ? starts[b] - 1 : source.length;
|
|
38638
39462
|
const region = source.slice(from, to);
|
|
@@ -38701,6 +39525,10 @@ function renderBlock(steps, language, indent, unit) {
|
|
|
38701
39525
|
}
|
|
38702
39526
|
function stepSpec(spec, ctx) {
|
|
38703
39527
|
const { language } = ctx;
|
|
39528
|
+
if (typeof spec === "string") {
|
|
39529
|
+
const said = thunderStep(spec, language, wordsSource, wordsScope);
|
|
39530
|
+
if (said?.stop != null) return { e: stopTree(ctx, null, said.stop), c: [] };
|
|
39531
|
+
}
|
|
38704
39532
|
if (typeof spec === "string" || spec?.kind) return { e: statementFrom(spec, language), c: [] };
|
|
38705
39533
|
if (spec && typeof spec === "object" && "if" in spec) {
|
|
38706
39534
|
const test = exprFrom(spec.if, language, "condition");
|
|
@@ -39045,17 +39873,23 @@ function opSetValue(ctx, edit) {
|
|
|
39045
39873
|
const { step } = ctx.at(edit.step);
|
|
39046
39874
|
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
39875
|
const tree = cloneShape(step.expr);
|
|
39048
|
-
let
|
|
39876
|
+
let lit5;
|
|
39049
39877
|
if (edit.at != null) {
|
|
39050
39878
|
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
|
-
|
|
39879
|
+
lit5 = lits[edit.at];
|
|
39880
|
+
if (!lit5) refuse(`There is no value number ${edit.at} like that in this step.`);
|
|
39881
|
+
} else lit5 = findLiteral(tree, edit.from);
|
|
39882
|
+
const next = edit.toValue != null ? exprFrom(edit.toValue, ctx.language, "value") : literalOf(edit.to, ctx.language, lit5);
|
|
39883
|
+
if (next.kind === "literal" && next.type === lit5.type && next.value === lit5.value) refuse(`The value is already ${lit5.raw}.`);
|
|
39884
|
+
const old = lit5.raw;
|
|
39885
|
+
if (next.kind !== "literal") {
|
|
39886
|
+
Object.keys(lit5).forEach((k) => delete lit5[k]);
|
|
39887
|
+
Object.assign(lit5, cloneShape(next));
|
|
39888
|
+
ctx.setTree(step, tree);
|
|
39889
|
+
return `Changed ${old} to ${sayFull(next)} in ${q(sayStep(step))}`;
|
|
39890
|
+
}
|
|
39891
|
+
Object.keys(lit5).forEach((k) => delete lit5[k]);
|
|
39892
|
+
Object.assign(lit5, next);
|
|
39059
39893
|
ctx.setTree(step, tree);
|
|
39060
39894
|
return `Changed ${old} to ${next.raw} in ${q(sayStep(step))}`;
|
|
39061
39895
|
}
|
|
@@ -39181,6 +40015,13 @@ function opSetGivesBack(ctx, edit) {
|
|
|
39181
40015
|
ctx.setTree(target, tree);
|
|
39182
40016
|
return `Changed ${q(sayStep(target))} to give back ${renderExpr2(tree.value, ctx.language)}`;
|
|
39183
40017
|
}
|
|
40018
|
+
function withDecorators(source, a) {
|
|
40019
|
+
const L = linesOf(source);
|
|
40020
|
+
const ind = indentOf2(L[a - 1] ?? "");
|
|
40021
|
+
let first = a;
|
|
40022
|
+
while (first > 1 && /^\s*@/.test(L[first - 2]) && indentOf2(L[first - 2]) === ind) first--;
|
|
40023
|
+
return first;
|
|
40024
|
+
}
|
|
39184
40025
|
function placeFor(ctx, edit) {
|
|
39185
40026
|
const pos = ["before", "after", "into"].find((k) => edit[k] != null);
|
|
39186
40027
|
if (!pos) refuse('Say where the new step goes: before, after, or into ({ step, side: "yes" | "no", at: "start" | "end" }).');
|
|
@@ -39204,15 +40045,12 @@ function placeFor(ctx, edit) {
|
|
|
39204
40045
|
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
40046
|
const path = [...loc.path];
|
|
39206
40047
|
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 };
|
|
40048
|
+
return { pos, line: pos === "after" ? b + 1 : withDecorators(ctx.source, a), indent: indentOf2(linesOf(ctx.source)[a - 1]), shapePath: path, loc };
|
|
39208
40049
|
}
|
|
39209
40050
|
function insertShape(shape, path, nodes2) {
|
|
39210
40051
|
const list3 = path.length === 1 ? shape : (() => {
|
|
39211
40052
|
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
|
-
}
|
|
40053
|
+
if (isSide(parentPath[parentPath.length - 1])) return sideOf(pathIn(shape, parentPath.slice(0, -1)).node, parentPath[parentPath.length - 1]);
|
|
39216
40054
|
return pathIn(shape, parentPath).node.c;
|
|
39217
40055
|
})();
|
|
39218
40056
|
list3.splice(path[path.length - 1], 0, ...nodes2);
|
|
@@ -39238,12 +40076,21 @@ function insertSteps(ctx, edit, nodes2) {
|
|
|
39238
40076
|
ctx.lines(place.line, 0, renderBlock(nodes2, ctx.language, place.indent, unit));
|
|
39239
40077
|
insertShape(ctx.shape, place.shapePath, nodes2);
|
|
39240
40078
|
}
|
|
40079
|
+
function docstringBefore(L, a) {
|
|
40080
|
+
for (let i = a - 2; i >= 0; i--) {
|
|
40081
|
+
const t = L[i].trim();
|
|
40082
|
+
if (!t || t.startsWith("#")) continue;
|
|
40083
|
+
return /['"]$/.test(t);
|
|
40084
|
+
}
|
|
40085
|
+
return false;
|
|
40086
|
+
}
|
|
39241
40087
|
function removeAt(ctx, loc, { replaceWithPass = true } = {}) {
|
|
39242
|
-
const [
|
|
40088
|
+
const [a0, b] = stepLines(loc.step);
|
|
40089
|
+
const a = withDecorators(ctx.source, a0);
|
|
39243
40090
|
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
40091
|
const L = linesOf(ctx.source);
|
|
39245
40092
|
const siblings = loc.list.filter((s) => s.expr?.kind !== "pass");
|
|
39246
|
-
if (ctx.language === "python" && siblings.length === 1 && loc.parent
|
|
40093
|
+
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
40094
|
else ctx.lines(a, b - a + 1, []);
|
|
39248
40095
|
listAt(ctx.shape, loc.path).splice(loc.path[loc.path.length - 1], 1);
|
|
39249
40096
|
}
|
|
@@ -39265,8 +40112,10 @@ function opMoveStep(ctx, edit) {
|
|
|
39265
40112
|
if (dest.step === loc.step) refuse("A step cannot move next to itself.");
|
|
39266
40113
|
if (dest.path.join(".").startsWith(`${loc.path.join(".")}.`)) refuse("A step cannot move inside itself.");
|
|
39267
40114
|
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
|
|
40115
|
+
const [a0, b] = stepLines(loc.step);
|
|
40116
|
+
const a = withDecorators(ctx.source, a0);
|
|
40117
|
+
const [da0, db] = stepLines(dest.step);
|
|
40118
|
+
const da = withDecorators(ctx.source, da0);
|
|
39270
40119
|
const L = linesOf(ctx.source);
|
|
39271
40120
|
const moved = L.slice(a - 1, b);
|
|
39272
40121
|
const fromIndent = indentOf2(moved[0]), toIndent = indentOf2(L[da - 1]);
|
|
@@ -39511,7 +40360,7 @@ func ${name}() (${edit.returns || ""}) {}` }));
|
|
|
39511
40360
|
const next = L.join("\n");
|
|
39512
40361
|
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
40362
|
}
|
|
39514
|
-
var
|
|
40363
|
+
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
40364
|
function applyEdit(state, edit) {
|
|
39516
40365
|
if (!edit || typeof edit !== "object") refuse('An edit is an object such as { op: "setValue", member, step, to }.');
|
|
39517
40366
|
if (!EDIT_OPS.includes(edit.op)) refuse(`"${edit.op}" is not a Thunder edit. The edits are: ${EDIT_OPS.join(", ")}.`);
|
|
@@ -39520,6 +40369,8 @@ function applyEdit(state, edit) {
|
|
|
39520
40369
|
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
40370
|
}
|
|
39522
40371
|
const m = findMember(state, edit.member);
|
|
40372
|
+
wordsSource = m.source;
|
|
40373
|
+
wordsScope = m.source.split("\n").slice(Math.max(0, m.item.line - 1), memberEnd(m.item)).join("\n");
|
|
39523
40374
|
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
40375
|
let source = m.source;
|
|
39525
40376
|
const ctx = {
|
|
@@ -39568,7 +40419,7 @@ function applyEdit(state, edit) {
|
|
|
39568
40419
|
return s;
|
|
39569
40420
|
}
|
|
39570
40421
|
};
|
|
39571
|
-
const says =
|
|
40422
|
+
const says = OPS6[edit.op](ctx, edit);
|
|
39572
40423
|
if (!WRITE_STEPS_LANGUAGES.includes(m.language)) needsAi(`The deterministic writers cover TypeScript, JavaScript, Python, and Go; ${m.path} is ${langName(m.language)}.`);
|
|
39573
40424
|
for (const t of ctx.treeEdits) source = writeStepTree(source, t.step, t.tree, m.language);
|
|
39574
40425
|
if (ctx.goImport) source = addGoImport(source, ctx.goImport);
|
|
@@ -39627,6 +40478,8 @@ function stepPathOf(steps, step) {
|
|
|
39627
40478
|
}
|
|
39628
40479
|
if (s.children) walk(s.children, [...path, i]);
|
|
39629
40480
|
if (s.otherwise) walk(s.otherwise, [...path, i, "else"]);
|
|
40481
|
+
(s.handlers || []).forEach((h, k) => walk(h.steps || [], [...path, i, `h:${k}`]));
|
|
40482
|
+
if (s.always?.steps) walk(s.always.steps, [...path, i, "always"]);
|
|
39630
40483
|
});
|
|
39631
40484
|
walk(steps, []);
|
|
39632
40485
|
return found;
|
|
@@ -39682,6 +40535,14 @@ function proveChange(before, after, plans) {
|
|
|
39682
40535
|
const editedKeys = /* @__PURE__ */ new Set();
|
|
39683
40536
|
const ranges = /* @__PURE__ */ new Map();
|
|
39684
40537
|
const renamed = plans.find((p) => p.renameFunction)?.renameFunction;
|
|
40538
|
+
const last = /* @__PURE__ */ new Map();
|
|
40539
|
+
for (const p of plans) {
|
|
40540
|
+
if (p.added) continue;
|
|
40541
|
+
const k = `${p.member.path}|${p.member.key}`;
|
|
40542
|
+
const prev = last.get(k)?.member;
|
|
40543
|
+
last.set(k, { ...p, member: { ...p.member, inputs: p.member.inputs ?? prev?.inputs, returns: p.member.returns ?? prev?.returns } });
|
|
40544
|
+
}
|
|
40545
|
+
plans = [...plans.filter((p) => p.added), ...last.values()];
|
|
39685
40546
|
for (const p of plans) {
|
|
39686
40547
|
if (p.added) {
|
|
39687
40548
|
const r2 = readOf(after, p.added.path);
|
|
@@ -39885,7 +40746,7 @@ function describeEdit(e) {
|
|
|
39885
40746
|
const who = e.member ? ` in ${parseMemberRef(e.member).name}` : "";
|
|
39886
40747
|
switch (e.op) {
|
|
39887
40748
|
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");
|
|
40749
|
+
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
40750
|
case "setCondition":
|
|
39890
40751
|
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
40752
|
case "addStep":
|
|
@@ -39992,8 +40853,9 @@ function thunderWrite(files, edits, options = {}) {
|
|
|
39992
40853
|
}
|
|
39993
40854
|
let state = makeState(original);
|
|
39994
40855
|
const plans = [], said = [];
|
|
39995
|
-
for (const
|
|
40856
|
+
for (const raw of list3) {
|
|
39996
40857
|
try {
|
|
40858
|
+
const e = followLines(raw, original, state.files);
|
|
39997
40859
|
const r = applyEdit(state, e);
|
|
39998
40860
|
state = makeState(r.files, original);
|
|
39999
40861
|
plans.push(r.plan);
|
|
@@ -40030,13 +40892,53 @@ function thunderWrite(files, edits, options = {}) {
|
|
|
40030
40892
|
function planOnly(original, list3) {
|
|
40031
40893
|
let state = makeState(original);
|
|
40032
40894
|
const plans = [];
|
|
40033
|
-
for (const
|
|
40034
|
-
const r = applyEdit(state,
|
|
40895
|
+
for (const raw of list3) {
|
|
40896
|
+
const r = applyEdit(state, followLines(raw, original, state.files));
|
|
40035
40897
|
state = makeState(r.files, original);
|
|
40036
40898
|
plans.push(r.plan);
|
|
40037
40899
|
}
|
|
40038
40900
|
return plans;
|
|
40039
40901
|
}
|
|
40902
|
+
function followLine(before, after, n, { start = false } = {}) {
|
|
40903
|
+
if (before === after) return n;
|
|
40904
|
+
const a = before.split("\n"), b = after.split("\n");
|
|
40905
|
+
let p = 0;
|
|
40906
|
+
while (p < a.length && p < b.length && a[p] === b[p]) p++;
|
|
40907
|
+
let q2 = 0;
|
|
40908
|
+
while (q2 < a.length - p && q2 < b.length - p && a[a.length - 1 - q2] === b[b.length - 1 - q2]) q2++;
|
|
40909
|
+
if (n <= p) return n;
|
|
40910
|
+
if (start && n === p + 1) return n;
|
|
40911
|
+
if (n > a.length - q2) return n + (b.length - a.length);
|
|
40912
|
+
const text2 = a[n - 1];
|
|
40913
|
+
if (!text2.trim()) return null;
|
|
40914
|
+
const inA = a.slice(p, a.length - q2).filter((l) => l === text2).length;
|
|
40915
|
+
const hits = [];
|
|
40916
|
+
for (let i = p; i < b.length - q2; i++) if (b[i] === text2) hits.push(i + 1);
|
|
40917
|
+
return inA === 1 && hits.length === 1 ? hits[0] : null;
|
|
40918
|
+
}
|
|
40919
|
+
function followLines(edit, original, current) {
|
|
40920
|
+
if (!edit || typeof edit !== "object" || original === current) return edit;
|
|
40921
|
+
let path = typeof edit.member === "object" ? edit.member?.file : typeof edit.member === "string" && edit.member.includes("#") ? edit.member.split("#")[0] : null;
|
|
40922
|
+
if (!path || !original.has(path)) {
|
|
40923
|
+
const changed = [...original.keys()].filter((p) => original.get(p) !== current.get(p));
|
|
40924
|
+
if (original.size === 1) path = [...original.keys()][0];
|
|
40925
|
+
else if (changed.length === 1) path = changed[0];
|
|
40926
|
+
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.");
|
|
40927
|
+
}
|
|
40928
|
+
if (!path || !original.has(path) || !current.has(path) || original.get(path) === current.get(path)) return edit;
|
|
40929
|
+
const move = (n, opts) => {
|
|
40930
|
+
const to = followLine(original.get(path), current.get(path), n, opts);
|
|
40931
|
+
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.`);
|
|
40932
|
+
return to;
|
|
40933
|
+
};
|
|
40934
|
+
const out = { ...edit };
|
|
40935
|
+
for (const k of ["step", "before", "after"]) {
|
|
40936
|
+
const m = typeof out[k] === "string" && out[k].match(/^line:(\d+)$/);
|
|
40937
|
+
if (m) out[k] = `line:${move(Number(m[1]))}`;
|
|
40938
|
+
}
|
|
40939
|
+
if (typeof out.member === "object" && out.member?.line) out.member = { ...out.member, line: move(out.member.line, { start: true }) };
|
|
40940
|
+
return out;
|
|
40941
|
+
}
|
|
40040
40942
|
|
|
40041
40943
|
// src/trace-data.mjs
|
|
40042
40944
|
var lineAt4 = (text2, index) => {
|
|
@@ -40382,14 +41284,14 @@ var methodOk = (route, req) => route === req || route === "ANY" || route === "AL
|
|
|
40382
41284
|
var WRITE_ACROSS_SCHEMA = "thunder-write-across-v1";
|
|
40383
41285
|
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
41286
|
var editable2 = (t) => t.t === "num" || t.t === "str" || t.t === "op" && ["<", "<=", ">", ">=", "==", "!="].includes(t.v);
|
|
40385
|
-
var
|
|
41287
|
+
var keyOf2 = (t) => t.t === "id" ? `id:${words13(t.v)}` : t.t === "str" ? `str:${JSON.stringify(t.v)}` : `${t.t}:${t.v}`;
|
|
40386
41288
|
var shapeOf = (t) => t.t === "id" ? "id" : editable2(t) ? t.t === "op" ? "cmp" : t.t : `${t.t}:${t.v}`;
|
|
40387
41289
|
var join3 = (toks2) => toks2.map((t) => t.t === "str" ? JSON.stringify(t.v) : String(t.v)).join(" ");
|
|
40388
41290
|
var FILLER = /* @__PURE__ */ new Set(["get", "is", "has", "can", "should", "calc", "calculate", "compute", "check", "find", "the", "a", "an", "of", "for", "to", "by"]);
|
|
40389
|
-
var
|
|
41291
|
+
var nameWords3 = (name) => new Set(words13(name).split(" ").filter((w) => w && !FILLER.has(w)));
|
|
40390
41292
|
var sharesWord = (a, b) => {
|
|
40391
|
-
const A =
|
|
40392
|
-
return [...
|
|
41293
|
+
const A = nameWords3(a);
|
|
41294
|
+
return [...nameWords3(b)].some((w) => A.has(w));
|
|
40393
41295
|
};
|
|
40394
41296
|
var toks = (when) => {
|
|
40395
41297
|
try {
|
|
@@ -40430,14 +41332,14 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40430
41332
|
}
|
|
40431
41333
|
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
41334
|
const anchor = anchors[0];
|
|
40433
|
-
const key = anchor.toks.map(
|
|
41335
|
+
const key = anchor.toks.map(keyOf2).join(" ");
|
|
40434
41336
|
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(
|
|
41337
|
+
const names = anchor.toks.filter((t) => t.t === "id").map(keyOf2).join(" ");
|
|
41338
|
+
const values = anchor.toks.filter((t) => t.t !== "id").map(keyOf2).join(" ");
|
|
40437
41339
|
const same = [], notIncluded = [];
|
|
40438
41340
|
for (const x of all) {
|
|
40439
41341
|
if (x === anchor) continue;
|
|
40440
|
-
const k = x.toks.map(
|
|
41342
|
+
const k = x.toks.map(keyOf2).join(" ");
|
|
40441
41343
|
const said = sayCondition(x.when);
|
|
40442
41344
|
if (k === key) {
|
|
40443
41345
|
if (sharesWord(x.decision, anchor.decision)) same.push({ ...x, why: `the same condition: ${said} (names compared as words)` });
|
|
@@ -40445,8 +41347,8 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40445
41347
|
continue;
|
|
40446
41348
|
}
|
|
40447
41349
|
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(
|
|
41350
|
+
const xNames = x.toks.filter((t) => t.t === "id").map(keyOf2).join(" ");
|
|
41351
|
+
const xValues = x.toks.filter((t) => t.t !== "id").map(keyOf2).join(" ");
|
|
40450
41352
|
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
41353
|
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
41354
|
}
|
|
@@ -40454,7 +41356,7 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40454
41356
|
return { ok: true, anchor: strip(anchor), same: [anchor, ...same].map(strip), notIncluded: notIncluded.map(strip), problems: [] };
|
|
40455
41357
|
}
|
|
40456
41358
|
function testsMentioning(files, oldToks, newToks, functions) {
|
|
40457
|
-
const changed = oldToks.filter((t, i) => editable2(t) && t.t !== "op" &&
|
|
41359
|
+
const changed = oldToks.filter((t, i) => editable2(t) && t.t !== "op" && keyOf2(t) !== keyOf2(newToks[i]));
|
|
40458
41360
|
if (!changed.length) return [];
|
|
40459
41361
|
const callsRule = (src) => (src.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? []).some((w) => functions.has(words13(w)));
|
|
40460
41362
|
const out = [];
|
|
@@ -40473,7 +41375,7 @@ function writeRuleAcross(files, { decision, rule, when }) {
|
|
|
40473
41375
|
if (!found.ok) return { ...base2, problems: found.problems };
|
|
40474
41376
|
const oldT = toks(found.anchor.when), newT = toks(when);
|
|
40475
41377
|
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])) :
|
|
41378
|
+
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
41379
|
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
41380
|
}
|
|
40479
41381
|
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 +41820,7 @@ function nodeAt(member, line, want) {
|
|
|
40918
41820
|
}
|
|
40919
41821
|
return null;
|
|
40920
41822
|
}
|
|
40921
|
-
function
|
|
41823
|
+
function sideOf2(node2, block, ev) {
|
|
40922
41824
|
if (node2.kind === "loop") return ev.side === "each" || ev.side === "held" ? { key: "each", label: "For each" } : { key: "done", label: "Done" };
|
|
40923
41825
|
if (node2.cases) {
|
|
40924
41826
|
const P = String(ev.side).startsWith("case:") ? Number(String(ev.side).slice(5)) : null;
|
|
@@ -41093,7 +41995,7 @@ function runtimeOverlay(model, evidence2 = []) {
|
|
|
41093
41995
|
nr.ran = (nr.ran || 0) + c;
|
|
41094
41996
|
continue;
|
|
41095
41997
|
}
|
|
41096
|
-
side2 ??=
|
|
41998
|
+
side2 ??= sideOf2(n, blockOf(member, n.id), ev);
|
|
41097
41999
|
if (!side2) {
|
|
41098
42000
|
unplaced(ev, `the case at line ${String(ev.side).slice(5)} is not one Thunder draws for "${n.text}"`);
|
|
41099
42001
|
continue;
|
|
@@ -44675,19 +45577,19 @@ function universalPack() {
|
|
|
44675
45577
|
};
|
|
44676
45578
|
}
|
|
44677
45579
|
var confidenceFor = (rule) => rule.detection === "deterministic" ? "Observed" : "Inferred";
|
|
44678
|
-
function toFinding(
|
|
44679
|
-
const rule = fableRuleFor(
|
|
44680
|
-
const isBlocker =
|
|
45580
|
+
function toFinding(diag2, { file = null, index = 0, affectedNodes = [] } = {}) {
|
|
45581
|
+
const rule = fableRuleFor(diag2.code);
|
|
45582
|
+
const isBlocker = diag2.severity === "blocker";
|
|
44681
45583
|
return {
|
|
44682
|
-
findingId: `${(
|
|
45584
|
+
findingId: `${(diag2.code || "FINDING").toLowerCase()}-${file ? file.replace(/[^a-z0-9]+/gi, "-") : "x"}-${index}`,
|
|
44683
45585
|
ruleId: rule.ruleId,
|
|
44684
45586
|
ruleVersion: rule.ruleVersion,
|
|
44685
45587
|
category: rule.category,
|
|
44686
|
-
detected:
|
|
44687
|
-
why:
|
|
44688
|
-
evidence: [{ file, line:
|
|
45588
|
+
detected: diag2.message,
|
|
45589
|
+
why: diag2.why || rule.title,
|
|
45590
|
+
evidence: [{ file, line: diag2.line ?? null, kind: "diagnostic", detail: diag2.message }],
|
|
44689
45591
|
affectedNodes,
|
|
44690
|
-
severity: isBlocker ? "blocker" :
|
|
45592
|
+
severity: isBlocker ? "blocker" : diag2.level || "warning",
|
|
44691
45593
|
confidence: confidenceFor(rule),
|
|
44692
45594
|
detectionType: rule.detection,
|
|
44693
45595
|
potentialImpact: isBlocker ? "Blocks a phase (e.g. release) until resolved." : "Weakens the intent; not blocking.",
|