@skillstech/thunderlang 1.4.3 → 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 +51 -0
- package/dist/core.cjs +1437 -292
- package/dist/index.cjs +6013 -4774
- package/dist/learn.cjs +409 -155
- package/package.json +1 -1
- package/src/cli.mjs +8 -5
- package/src/emit.mjs +1 -1
- package/src/mcp.mjs +20 -3
- package/src/passport.mjs +9 -2
- package/src/read-repo-fs.mjs +3 -2
- package/src/trace-cli.mjs +3 -3
- package/src/trace-data.mjs +219 -0
- package/src/trace-fs.mjs +10 -3
- package/src/trace.mjs +207 -16
- 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
|
}
|
|
@@ -6529,8 +6529,8 @@ function exactText(inner, code3) {
|
|
|
6529
6529
|
function exactIn(inner, code3, open) {
|
|
6530
6530
|
if (!/«|…/.test(inner) && inner.length && [`'${inner}'`, `"${inner}"`, `\`${inner}\``].some((q2) => String(code3).includes(q2))) return true;
|
|
6531
6531
|
if (!/«|…/.test(inner) && inner.trim().length) {
|
|
6532
|
-
const
|
|
6533
|
-
if (new RegExp(`(?:^|[\\s#%/:+=(\\-{"'])${
|
|
6532
|
+
const esc3 = inner.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6533
|
+
if (new RegExp(`(?:^|[\\s#%/:+=(\\-{"'])${esc3}(?=$|[\\s}/)"';|])`).test(String(code3))) return true;
|
|
6534
6534
|
}
|
|
6535
6535
|
const cut = /…$/.test(inner);
|
|
6536
6536
|
const w = textSkeleton(inner.replace(/…$/, ""), true);
|
|
@@ -6546,10 +6546,10 @@ function exactIn(inner, code3, open) {
|
|
|
6546
6546
|
for (let i = 0; i < parts.length; i++) {
|
|
6547
6547
|
const f = parts[i].trim();
|
|
6548
6548
|
if (!f) continue;
|
|
6549
|
-
const
|
|
6549
|
+
const esc3 = f.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6550
6550
|
const lead = i === 0 ? B : "[\"'`\\s,|]";
|
|
6551
6551
|
const tail = i === parts.length - 1 ? cut ? "" : E : "[\"'`\\s,]";
|
|
6552
|
-
const src = `${lead}${
|
|
6552
|
+
const src = `${lead}${esc3}${tail ? `(?=${tail})` : ""}`;
|
|
6553
6553
|
let re = FRAG_RE.get(src);
|
|
6554
6554
|
if (!re) {
|
|
6555
6555
|
if (FRAG_RE.size > 5e3) FRAG_RE.clear();
|
|
@@ -7889,10 +7889,10 @@ function lexSql(src, from = 0, to = src.length, dialect = "pg") {
|
|
|
7889
7889
|
}
|
|
7890
7890
|
const pre = /[EeNnBbXx]/.test(c) && src[i + 1] === "'" && !/[\w$]/.test(src[i - 1] || "");
|
|
7891
7891
|
if (c === "'" || pre) {
|
|
7892
|
-
const
|
|
7892
|
+
const esc3 = dialect === "mysql" || pre && /[Ee]/.test(c);
|
|
7893
7893
|
let j = i + (pre ? 2 : 1);
|
|
7894
7894
|
for (; j < to; j++) {
|
|
7895
|
-
if (
|
|
7895
|
+
if (esc3 && src[j] === "\\") {
|
|
7896
7896
|
j++;
|
|
7897
7897
|
continue;
|
|
7898
7898
|
}
|
|
@@ -8434,12 +8434,12 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8434
8434
|
const n = toks2.length;
|
|
8435
8435
|
const labels = [];
|
|
8436
8436
|
const peek = (k = 0) => toks2[i + k];
|
|
8437
|
-
const
|
|
8438
|
-
const baseOf = (a, b) => ({ line:
|
|
8437
|
+
const lineOf7 = (tok) => ctx.lineAt(tok.s);
|
|
8438
|
+
const baseOf = (a, b) => ({ line: lineOf7(toks2[a]), span: { startLine: lineOf7(toks2[a]), endLine: lineOf7(toks2[Math.max(a, b - 1)]) } });
|
|
8439
8439
|
const textOf3 = (a, b) => ctx.src.slice(toks2[a].s, toks2[b - 1].e);
|
|
8440
8440
|
const semi = ctx.dialect !== "tsql";
|
|
8441
8441
|
const expect = (cond, what) => {
|
|
8442
|
-
if (!cond) throw new Unmatched(`${what} (line ${peek() ?
|
|
8442
|
+
if (!cond) throw new Unmatched(`${what} (line ${peek() ? lineOf7(peek()) : "end"})`);
|
|
8443
8443
|
};
|
|
8444
8444
|
const skipSemis = () => {
|
|
8445
8445
|
while (isP(peek(), ";")) i++;
|
|
@@ -8635,19 +8635,19 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8635
8635
|
const [c0, c1] = condUntil((x) => isW(x, "THEN"));
|
|
8636
8636
|
i++;
|
|
8637
8637
|
const step2 = branch(c0, c1, block(endsWith("ELSIF", "ELSEIF", "ELSE", "END")));
|
|
8638
|
-
step2.line =
|
|
8638
|
+
step2.line = lineOf7(toks2[a]);
|
|
8639
8639
|
let tail = step2;
|
|
8640
8640
|
while (isW(peek(), "ELSIF", "ELSEIF")) {
|
|
8641
8641
|
const at2 = i;
|
|
8642
8642
|
i++;
|
|
8643
8643
|
const [e0, e1] = condUntil((x) => isW(x, "THEN"));
|
|
8644
8644
|
i++;
|
|
8645
|
-
const next = branch(e0, e1, block(endsWith("ELSIF", "ELSEIF", "ELSE", "END")), null,
|
|
8645
|
+
const next = branch(e0, e1, block(endsWith("ELSIF", "ELSEIF", "ELSE", "END")), null, lineOf7(toks2[at2]));
|
|
8646
8646
|
tail.otherwise = [next];
|
|
8647
8647
|
tail = next;
|
|
8648
8648
|
}
|
|
8649
8649
|
if (isW(peek(), "ELSE")) {
|
|
8650
|
-
tail.otherwiseLine =
|
|
8650
|
+
tail.otherwiseLine = lineOf7(peek());
|
|
8651
8651
|
i++;
|
|
8652
8652
|
tail.otherwise = block(endsWith("END"));
|
|
8653
8653
|
}
|
|
@@ -8660,9 +8660,9 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8660
8660
|
const kids2 = tsqlBody();
|
|
8661
8661
|
skipSemis();
|
|
8662
8662
|
const step2 = branch(c0, c1, kids2);
|
|
8663
|
-
step2.line =
|
|
8663
|
+
step2.line = lineOf7(toks2[a]);
|
|
8664
8664
|
if (isW(peek(), "ELSE")) {
|
|
8665
|
-
step2.otherwiseLine =
|
|
8665
|
+
step2.otherwiseLine = lineOf7(peek());
|
|
8666
8666
|
i++;
|
|
8667
8667
|
step2.otherwise = tsqlBody();
|
|
8668
8668
|
}
|
|
@@ -8686,7 +8686,7 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8686
8686
|
expect(arms.length, "CASE without WHEN");
|
|
8687
8687
|
let elseKids = null, elseLine = null;
|
|
8688
8688
|
if (isW(peek(), "ELSE")) {
|
|
8689
|
-
elseLine =
|
|
8689
|
+
elseLine = lineOf7(peek());
|
|
8690
8690
|
i++;
|
|
8691
8691
|
elseKids = block(endsWith("END"));
|
|
8692
8692
|
}
|
|
@@ -8699,14 +8699,14 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8699
8699
|
text2 = vals.length === 1 ? `${subj} = ${vals[0]}` : `${subj} IN (${vals.join(", ")})`;
|
|
8700
8700
|
} else text2 = code2(textOf3(arm.w0, arm.w1));
|
|
8701
8701
|
const w = condWords(text2, ctx);
|
|
8702
|
-
return { kind: "branch", says: `If ${w ?? asCodeWords(text2, 400)}`, code: text2, cond: text2, line:
|
|
8702
|
+
return { kind: "branch", says: `If ${w ?? asCodeWords(text2, 400)}`, code: text2, cond: text2, line: lineOf7(toks2[arm.at]), span: { startLine: lineOf7(toks2[arm.at]), endLine: lineOf7(toks2[arm.w1 - 1]) }, children: arm.kids };
|
|
8703
8703
|
});
|
|
8704
8704
|
for (let k = 0; k < steps.length - 1; k++) steps[k].otherwise = [steps[k + 1]];
|
|
8705
8705
|
const last = steps.at(-1);
|
|
8706
8706
|
if (elseKids) {
|
|
8707
8707
|
last.otherwise = elseKids;
|
|
8708
8708
|
last.otherwiseLine = elseLine;
|
|
8709
|
-
} else last.otherwise = [{ kind: "fail", says: "Fails with an error: no WHEN matched and there is no ELSE (case not found)", error: "case not found", code: code2(textOf3(a, i)), line:
|
|
8709
|
+
} else last.otherwise = [{ kind: "fail", says: "Fails with an error: no WHEN matched and there is no ELSE (case not found)", error: "case not found", code: code2(textOf3(a, i)), line: lineOf7(toks2[a]) }];
|
|
8710
8710
|
return [steps[0]];
|
|
8711
8711
|
}
|
|
8712
8712
|
if (up === "LOOP" && semi) {
|
|
@@ -8802,7 +8802,7 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8802
8802
|
closeWith("TRY", "BEGIN TRY");
|
|
8803
8803
|
skipSemis();
|
|
8804
8804
|
expect(isW(peek(), "BEGIN") && isW(peek(1), "CATCH"), "BEGIN TRY without BEGIN CATCH");
|
|
8805
|
-
const hLine =
|
|
8805
|
+
const hLine = lineOf7(peek());
|
|
8806
8806
|
i += 2;
|
|
8807
8807
|
const handler = block(endsWith("END"));
|
|
8808
8808
|
closeWith("CATCH", "BEGIN CATCH");
|
|
@@ -8825,7 +8825,7 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8825
8825
|
i++;
|
|
8826
8826
|
const names = toks2.slice(c0, c1).filter((x) => !isW(x, "OR", "SQLSTATE")).map((x) => x.t === "str" ? `error ${strText(x)}` : words2(x.v));
|
|
8827
8827
|
const any = toks2.slice(c0, c1).some((x) => isW(x, "OTHERS"));
|
|
8828
|
-
handlers.push({ says: any ? "If anything goes wrong" : `If ${names.join(" or ")} goes wrong`, line:
|
|
8828
|
+
handlers.push({ says: any ? "If anything goes wrong" : `If ${names.join(" or ")} goes wrong`, line: lineOf7(toks2[hAt]), steps: block(endsWith("WHEN", "END")) });
|
|
8829
8829
|
}
|
|
8830
8830
|
}
|
|
8831
8831
|
ctx.depth--;
|
|
@@ -8943,9 +8943,9 @@ function bodySteps(toks2, ctx, opts = {}) {
|
|
|
8943
8943
|
if (isP(peek(), ";")) i++;
|
|
8944
8944
|
return [{ kind: "call", says: `Jumps to ${toks2[a + 1]?.v ?? "a label"}`, code: code2(textOf3(a, e2)), jump: "break", ...baseOf(a, e2) }];
|
|
8945
8945
|
}
|
|
8946
|
-
if (!semi && (up === "ELSE" || up === "END")) throw new Unmatched(`${up} without its IF or BEGIN (line ${
|
|
8947
|
-
if (semi && (up === "ELSE" || up === "ELSIF" || up === "ELSEIF" || up === "WHEN" || up === "UNTIL" || up === "EXCEPTION")) throw new Unmatched(`${up} outside its block (line ${
|
|
8948
|
-
if (semi && up === "END" && !ctx.allowEnd) throw new Unmatched(`END without its BEGIN (line ${
|
|
8946
|
+
if (!semi && (up === "ELSE" || up === "END")) throw new Unmatched(`${up} without its IF or BEGIN (line ${lineOf7(t)})`);
|
|
8947
|
+
if (semi && (up === "ELSE" || up === "ELSIF" || up === "ELSEIF" || up === "WHEN" || up === "UNTIL" || up === "EXCEPTION")) throw new Unmatched(`${up} outside its block (line ${lineOf7(t)})`);
|
|
8948
|
+
if (semi && up === "END" && !ctx.allowEnd) throw new Unmatched(`END without its BEGIN (line ${lineOf7(t)})`);
|
|
8949
8949
|
const e = Math.max(simpleEnd(a), a + 1);
|
|
8950
8950
|
i = e;
|
|
8951
8951
|
if (isP(peek(), ";")) i++;
|
|
@@ -8967,10 +8967,10 @@ function sqlDialect(src) {
|
|
|
8967
8967
|
return "pg";
|
|
8968
8968
|
}
|
|
8969
8969
|
var ROUTINE_WORDS = ["FUNCTION", "PROCEDURE", "PROC"];
|
|
8970
|
-
function sqlRoutines(src,
|
|
8970
|
+
function sqlRoutines(src, lineAt5, dialect = sqlDialect(src)) {
|
|
8971
8971
|
const toks2 = lexSql(src, 0, src.length, dialect);
|
|
8972
8972
|
const out = [];
|
|
8973
|
-
const
|
|
8973
|
+
const lineOf7 = (k) => lineAt5(toks2[Math.min(k, toks2.length - 1)].s);
|
|
8974
8974
|
for (let k = 0; k < toks2.length; k++) {
|
|
8975
8975
|
const start = k;
|
|
8976
8976
|
let j = k;
|
|
@@ -9116,7 +9116,7 @@ function sqlRoutines(src, lineAt4, dialect = sqlDialect(src)) {
|
|
|
9116
9116
|
}
|
|
9117
9117
|
}
|
|
9118
9118
|
let steps = [], bodyEnd3 = end2;
|
|
9119
|
-
const ctx = { src, lineAt:
|
|
9119
|
+
const ctx = { src, lineAt: lineAt5, dialect: bodyDialect, routine, setof, trigger, depth: 0 };
|
|
9120
9120
|
try {
|
|
9121
9121
|
if (dialect === "pg") {
|
|
9122
9122
|
if (bodyToks && language !== "c" && language !== "internal") {
|
|
@@ -9155,8 +9155,8 @@ function sqlRoutines(src, lineAt4, dialect = sqlDialect(src)) {
|
|
|
9155
9155
|
steps = [];
|
|
9156
9156
|
}
|
|
9157
9157
|
if (dialect === "tsql" || dialect === "mysql") end2 = bodyEnd3;
|
|
9158
|
-
const endLine =
|
|
9159
|
-
out.push({ name, line:
|
|
9158
|
+
const endLine = lineOf7(Math.max(end2, start));
|
|
9159
|
+
out.push({ name, line: lineOf7(start), endLine, kind: routine, inputs, outs, returns, setof, trigger, steps, ...unreadWhy ? { unreadWhy } : {}, headerEnd: lineOf7(Math.max(start, j - 1)) });
|
|
9160
9160
|
k = Math.max(k, Math.min(end2, toks2.length - 1));
|
|
9161
9161
|
}
|
|
9162
9162
|
return out;
|
|
@@ -9322,7 +9322,7 @@ function sqlCondition(cond, { aliases = {}, vars = false, keepAt = true, raw = f
|
|
|
9322
9322
|
}
|
|
9323
9323
|
function readSchema(src) {
|
|
9324
9324
|
const m = mask(src);
|
|
9325
|
-
const
|
|
9325
|
+
const lineAt5 = lineFinder(src);
|
|
9326
9326
|
const tables = [], choices = [], rules = [];
|
|
9327
9327
|
const docs = /* @__PURE__ */ new Map();
|
|
9328
9328
|
for (const c of src.matchAll(/COMMENT\s+ON\s+TABLE\s+([\w."]+)\s+IS\s+'((?:[^']|'')*)'/gi)) docs.set(bare(c[1]).toLowerCase(), c[2].replace(/''/g, "'"));
|
|
@@ -9331,10 +9331,10 @@ function readSchema(src) {
|
|
|
9331
9331
|
const close = parenEnd(m, open);
|
|
9332
9332
|
if (close < 0) continue;
|
|
9333
9333
|
const name = bare(src.slice(t.index, open).match(/([\w."[\]`]+)\s*$/)[1]);
|
|
9334
|
-
const table = { name, lines: [
|
|
9334
|
+
const table = { name, lines: [lineAt5(t.index), lineAt5(close)], doc: docs.get(name.toLowerCase()) ?? docAbove(src, t.index), columns: [], checks: [], uniques: [], refs: [] };
|
|
9335
9335
|
for (const part of splitTop(src.slice(open + 1, close), m.slice(open + 1, close))) {
|
|
9336
9336
|
const text2 = part.text.trim().replace(/\s+/g, " ");
|
|
9337
|
-
const line =
|
|
9337
|
+
const line = lineAt5(open + 1 + part.at + (part.text.length - part.text.trimStart().length));
|
|
9338
9338
|
let x;
|
|
9339
9339
|
if (x = text2.match(/^(?:CONSTRAINT\s+([\w"]+)\s+)?CHECK\s*\((.*)\)$/i)) {
|
|
9340
9340
|
table.checks.push({ name: x[1] && unquote(x[1]), cond: x[2], line });
|
|
@@ -9367,7 +9367,7 @@ function readSchema(src) {
|
|
|
9367
9367
|
const close = parenEnd(m, open);
|
|
9368
9368
|
if (close < 0) continue;
|
|
9369
9369
|
const values = [...src.slice(open + 1, close).matchAll(/'((?:[^']|'')*)'/g)].map((v) => v[1].replace(/''/g, "'").replace(/_/g, " "));
|
|
9370
|
-
choices.push({ name: bare(e[1]), lines: [
|
|
9370
|
+
choices.push({ name: bare(e[1]), lines: [lineAt5(e.index), lineAt5(close)], doc: docAbove(src, e.index), values });
|
|
9371
9371
|
}
|
|
9372
9372
|
for (const t of tables) {
|
|
9373
9373
|
for (const c of t.checks) rules.push({ table: t.name, kind: "check", ...c });
|
|
@@ -9470,7 +9470,7 @@ function sqlTemplateReason(src) {
|
|
|
9470
9470
|
}
|
|
9471
9471
|
function sqlItems(src) {
|
|
9472
9472
|
const m = mask(src);
|
|
9473
|
-
const
|
|
9473
|
+
const lineAt5 = lineFinder(src);
|
|
9474
9474
|
const items = [];
|
|
9475
9475
|
const push = (name, line, steps, extra = {}) => {
|
|
9476
9476
|
const code3 = steps.filter((s) => s.kind === "other").length;
|
|
@@ -9500,9 +9500,9 @@ function sqlItems(src) {
|
|
|
9500
9500
|
const end2 = m.indexOf(";", v.index);
|
|
9501
9501
|
const query = src.slice(v.index + v[0].length, end2 < 0 ? src.length : end2);
|
|
9502
9502
|
const name = bare(v[1]);
|
|
9503
|
-
push(name,
|
|
9503
|
+
push(name, lineAt5(v.index), selectSteps(query, lineAt5(v.index + v[0].length)), { doc: docAbove(src, v.index), endLine: lineAt5(end2 < 0 ? src.length : end2), says: `${words2(name)} is a saved query.`, headline: `${words2(name)}: a saved query.` });
|
|
9504
9504
|
}
|
|
9505
|
-
for (const r of sqlRoutines(src,
|
|
9505
|
+
for (const r of sqlRoutines(src, lineAt5)) {
|
|
9506
9506
|
const inputs = r.inputs.map(({ name, type }) => ({ name, type }));
|
|
9507
9507
|
const returns = r.returns ?? (r.outs.length ? listWords(r.outs.map((o) => words2(o.name))) : null);
|
|
9508
9508
|
const steps = r.unreadWhy ? [] : r.steps;
|
|
@@ -9520,7 +9520,7 @@ function sqlItems(src) {
|
|
|
9520
9520
|
const events = t[3].split(/\s+OR\s+/i).map((e) => ({ INSERT: "added", UPDATE: "changed", DELETE: "removed", TRUNCATE: "emptied" })[e.trim().split(/\s+/)[0].toUpperCase()] || words2(e)).filter(Boolean);
|
|
9521
9521
|
const what = article(singular(words2(bare(t[4]))));
|
|
9522
9522
|
const when = `${t[2].toUpperCase() === "BEFORE" ? "Before" : t[2].toUpperCase() === "AFTER" ? "After" : "Instead of when"} ${what} is ${events.join(" or ")}`;
|
|
9523
|
-
push(bare(t[1]),
|
|
9523
|
+
push(bare(t[1]), lineAt5(t.index), [{ kind: "call", says: `${when}, runs ${words2(bare(t[5]))}`, code: t[0].replace(/\s+/g, " "), line: lineAt5(t.index) }], { says: `${when}, the database runs ${words2(bare(t[5]))}.`, headline: `${when}.`, doc: docAbove(src, t.index) });
|
|
9524
9524
|
}
|
|
9525
9525
|
for (const r of readSchema(src).rules) {
|
|
9526
9526
|
const table = words2(r.table);
|
|
@@ -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"}`;
|
|
@@ -11954,7 +11954,7 @@ function scanInterp(src, j, dialect) {
|
|
|
11954
11954
|
}
|
|
11955
11955
|
return j;
|
|
11956
11956
|
}
|
|
11957
|
-
function tokenize2(src, dialect, from = 0, to = src.length,
|
|
11957
|
+
function tokenize2(src, dialect, from = 0, to = src.length, lineAt5 = lineIndex(src)) {
|
|
11958
11958
|
const hcl = dialect === "hcl";
|
|
11959
11959
|
const toks2 = [], comments = [];
|
|
11960
11960
|
let i = from;
|
|
@@ -11972,14 +11972,14 @@ function tokenize2(src, dialect, from = 0, to = src.length, lineAt4 = lineIndex(
|
|
|
11972
11972
|
if (c === "#" || c === "/" && src[i + 1] === "/") {
|
|
11973
11973
|
let j = i;
|
|
11974
11974
|
while (j < to && src[j] !== "\n") j++;
|
|
11975
|
-
comments.push({ line:
|
|
11975
|
+
comments.push({ line: lineAt5(i), endLine: lineAt5(i), text: src.slice(i, j).replace(/^(#|\/\/)\s?/, "").trim(), s: i });
|
|
11976
11976
|
i = j;
|
|
11977
11977
|
continue;
|
|
11978
11978
|
}
|
|
11979
11979
|
if (c === "/" && src[i + 1] === "*") {
|
|
11980
11980
|
let j = src.indexOf("*/", i + 2);
|
|
11981
11981
|
if (j < 0 || j > to) j = to - 2;
|
|
11982
|
-
comments.push({ line:
|
|
11982
|
+
comments.push({ line: lineAt5(i), endLine: lineAt5(j), text: src.slice(i + 2, j).replace(/^\s*\*+/gm, "").trim(), s: i });
|
|
11983
11983
|
i = j + 2;
|
|
11984
11984
|
continue;
|
|
11985
11985
|
}
|
|
@@ -12054,12 +12054,12 @@ function tokenize2(src, dialect, from = 0, to = src.length, lineAt4 = lineIndex(
|
|
|
12054
12054
|
}
|
|
12055
12055
|
var BIN = { "??": 1, "||": 2, "&&": 3, "==": 4, "!=": 4, "=~": 4, "!~": 4, "<": 5, ">": 5, "<=": 5, ">=": 5, "+": 6, "-": 6, "*": 7, "/": 7, "%": 7 };
|
|
12056
12056
|
var Parser2 = class _Parser {
|
|
12057
|
-
constructor(src, toks2, dialect,
|
|
12057
|
+
constructor(src, toks2, dialect, lineAt5, hooks = {}) {
|
|
12058
12058
|
this.src = src;
|
|
12059
12059
|
this.toks = toks2;
|
|
12060
12060
|
this.i = 0;
|
|
12061
12061
|
this.dialect = dialect;
|
|
12062
|
-
this.lineAt =
|
|
12062
|
+
this.lineAt = lineAt5;
|
|
12063
12063
|
this.hooks = hooks;
|
|
12064
12064
|
this.skipNl = [false];
|
|
12065
12065
|
}
|
|
@@ -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
|
};
|
|
@@ -12572,9 +12572,9 @@ function docAbove2(comments, line) {
|
|
|
12572
12572
|
}
|
|
12573
12573
|
function parseHcl(src) {
|
|
12574
12574
|
const text2 = String(src ?? "").replace(/^/, "");
|
|
12575
|
-
const
|
|
12576
|
-
const { toks: toks2, comments } = tokenize2(text2, "hcl", 0, text2.length,
|
|
12577
|
-
const p = new Parser2(text2, toks2, "hcl",
|
|
12575
|
+
const lineAt5 = lineIndex(text2);
|
|
12576
|
+
const { toks: toks2, comments } = tokenize2(text2, "hcl", 0, text2.length, lineAt5);
|
|
12577
|
+
const p = new Parser2(text2, toks2, "hcl", lineAt5);
|
|
12578
12578
|
const errors = [];
|
|
12579
12579
|
const body2 = [];
|
|
12580
12580
|
for (; ; ) {
|
|
@@ -12589,7 +12589,7 @@ function parseHcl(src) {
|
|
|
12589
12589
|
p.i = resync(toks2, start);
|
|
12590
12590
|
}
|
|
12591
12591
|
}
|
|
12592
|
-
return { body: body2, comments, errors, lineAt:
|
|
12592
|
+
return { body: body2, comments, errors, lineAt: lineAt5, src: text2 };
|
|
12593
12593
|
}
|
|
12594
12594
|
function resync(toks2, i) {
|
|
12595
12595
|
let depth = 0, seen = false;
|
|
@@ -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;
|
|
@@ -13584,9 +13584,9 @@ function ingressFacts(d, fact) {
|
|
|
13584
13584
|
// src/bicep.mjs
|
|
13585
13585
|
function parseBicep(src) {
|
|
13586
13586
|
const text2 = String(src ?? "").replace(/^/, "");
|
|
13587
|
-
const
|
|
13588
|
-
const { toks: toks2, comments } = tokenize2(text2, "bicep", 0, text2.length,
|
|
13589
|
-
const p = new Parser2(text2, toks2, "bicep",
|
|
13587
|
+
const lineAt5 = lineIndex(text2);
|
|
13588
|
+
const { toks: toks2, comments } = tokenize2(text2, "bicep", 0, text2.length, lineAt5);
|
|
13589
|
+
const p = new Parser2(text2, toks2, "bicep", lineAt5, { objectKey: nestedResource });
|
|
13590
13590
|
const decls = [], errors = [];
|
|
13591
13591
|
let decorators = [];
|
|
13592
13592
|
for (; ; ) {
|
|
@@ -13615,7 +13615,7 @@ function parseBicep(src) {
|
|
|
13615
13615
|
decorators = [];
|
|
13616
13616
|
}
|
|
13617
13617
|
}
|
|
13618
|
-
return { decls, comments, errors, lineAt:
|
|
13618
|
+
return { decls, comments, errors, lineAt: lineAt5, src: text2 };
|
|
13619
13619
|
}
|
|
13620
13620
|
function resync2(toks2, i) {
|
|
13621
13621
|
let depth = 0;
|
|
@@ -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);
|
|
@@ -22902,7 +22902,7 @@ function sayNode(n) {
|
|
|
22902
22902
|
}
|
|
22903
22903
|
var CODE_MAX = 160;
|
|
22904
22904
|
function makeStepper(src) {
|
|
22905
|
-
const
|
|
22905
|
+
const lineAt5 = lineFinder2(src);
|
|
22906
22906
|
const codeOf = (n) => {
|
|
22907
22907
|
const t = src.slice(n.at, n.end).replace(/\s+/g, " ").trim();
|
|
22908
22908
|
return t.length > CODE_MAX ? `${t.slice(0, CODE_MAX - 1)}\u2026` : t;
|
|
@@ -22911,8 +22911,8 @@ function makeStepper(src) {
|
|
|
22911
22911
|
const t = src.slice(n.at, n.end).split("\n")[0].trim();
|
|
22912
22912
|
return t.length > CODE_MAX ? `${t.slice(0, CODE_MAX - 1)}\u2026` : t;
|
|
22913
22913
|
};
|
|
22914
|
-
const span = (n) => ({ startLine:
|
|
22915
|
-
const base2 = (n, code3 = codeOf(n)) => ({ code: code3, line:
|
|
22914
|
+
const span = (n) => ({ startLine: lineAt5(n.at), endLine: lineAt5(Math.max(n.at, n.end - 1)) });
|
|
22915
|
+
const base2 = (n, code3 = codeOf(n)) => ({ code: code3, line: lineAt5(n.at), span: span(n) });
|
|
22916
22916
|
function steps(nodes2) {
|
|
22917
22917
|
const out = [];
|
|
22918
22918
|
for (let k = 0; k < nodes2.length; k++) {
|
|
@@ -22924,7 +22924,7 @@ function makeStepper(src) {
|
|
|
22924
22924
|
if (ex && (ex.kind === "fail" || ex.failCode) && !ex.message) {
|
|
22925
22925
|
const code3 = ex.exitCode ?? ex.failCode;
|
|
22926
22926
|
const what = ex.exitCode ? `exit code ${code3}` : `return code ${code3}`;
|
|
22927
|
-
out.push({ kind: "fail", says: `Fails with ${what}: "${got[0].stderr}"`, error: what, message: got[0].stderr, code: `${codeOf(n)}; ${codeOf(next)}`, line:
|
|
22927
|
+
out.push({ kind: "fail", says: `Fails with ${what}: "${got[0].stderr}"`, error: what, message: got[0].stderr, code: `${codeOf(n)}; ${codeOf(next)}`, line: lineAt5(n.at), span: { startLine: lineAt5(n.at), endLine: lineAt5(next.end - 1) } });
|
|
22928
22928
|
k++;
|
|
22929
22929
|
continue;
|
|
22930
22930
|
}
|
|
@@ -22977,7 +22977,7 @@ function makeStepper(src) {
|
|
|
22977
22977
|
case "if": {
|
|
22978
22978
|
let first = null, tail = null;
|
|
22979
22979
|
for (const c of n.clauses) {
|
|
22980
|
-
const b = { kind: "branch", says: `If ${condWords2(c.cond)}`, code: src.slice(c.at, src.indexOf("\n", c.at) < 0 ? void 0 : src.indexOf("\n", c.at)).trim().slice(0, CODE_MAX), line:
|
|
22980
|
+
const b = { kind: "branch", says: `If ${condWords2(c.cond)}`, code: src.slice(c.at, src.indexOf("\n", c.at) < 0 ? void 0 : src.indexOf("\n", c.at)).trim().slice(0, CODE_MAX), line: lineAt5(c.at), span: first ? { startLine: lineAt5(c.at), endLine: lineAt5(n.end - 1) } : span(n) };
|
|
22981
22981
|
const kids2 = steps(c.body);
|
|
22982
22982
|
if (kids2.length) b.children = kids2;
|
|
22983
22983
|
if (!first) first = b;
|
|
@@ -22990,7 +22990,7 @@ function makeStepper(src) {
|
|
|
22990
22990
|
if (n.otherwise) {
|
|
22991
22991
|
const kids2 = steps(n.otherwise);
|
|
22992
22992
|
tail.otherwise = kids2;
|
|
22993
|
-
tail.otherwiseLine =
|
|
22993
|
+
tail.otherwiseLine = lineAt5(n.elseAt);
|
|
22994
22994
|
}
|
|
22995
22995
|
return [first];
|
|
22996
22996
|
}
|
|
@@ -23039,7 +23039,7 @@ function makeStepper(src) {
|
|
|
23039
23039
|
says = `When it is ${ws.length > 1 ? `${ws.slice(0, -1).join(", ")} or ${ws.at(-1)}` : ws[0]}`;
|
|
23040
23040
|
} else says = `When it matches ${pats.map((p) => asCode3(p)).join(" or ")}`;
|
|
23041
23041
|
const kids2 = steps(a.body);
|
|
23042
|
-
return { kind: "check", says, caseLabel: true, code: src.slice(a.at, src.indexOf(")", a.at) + 1).trim().slice(0, 90), line:
|
|
23042
|
+
return { kind: "check", says, caseLabel: true, code: src.slice(a.at, src.indexOf(")", a.at) + 1).trim().slice(0, 90), line: lineAt5(a.at), span: { startLine: lineAt5(a.at), endLine: lineAt5(Math.max(a.at, a.end - 1)) }, ...kids2.length ? { children: kids2 } : {} };
|
|
23043
23043
|
});
|
|
23044
23044
|
return [{ kind: "branch", says: `Chooses by ${sayWord(n.word)}`, ...base2(n, headOf2(n)), ...arms.length ? { children: arms } : {} }];
|
|
23045
23045
|
}
|
|
@@ -23098,7 +23098,7 @@ function makeStepper(src) {
|
|
|
23098
23098
|
};
|
|
23099
23099
|
return build(0);
|
|
23100
23100
|
}
|
|
23101
|
-
return { steps, lineAt:
|
|
23101
|
+
return { steps, lineAt: lineAt5, codeOf, headOf: headOf2 };
|
|
23102
23102
|
}
|
|
23103
23103
|
function docAbove3(lines, line) {
|
|
23104
23104
|
const run = [];
|
|
@@ -23219,7 +23219,7 @@ function shellReading(src, file = "") {
|
|
|
23219
23219
|
const last = f.body[f.body.length - 1];
|
|
23220
23220
|
if (last?.type === "simple" && last.words[0] === "exit" && /^[1-9]\d*$/.test(last.words[1] ?? "")) DIES.set(f.name, last.words[1]);
|
|
23221
23221
|
}
|
|
23222
|
-
const { steps, lineAt:
|
|
23222
|
+
const { steps, lineAt: lineAt5 } = makeStepper(src);
|
|
23223
23223
|
const errors = /* @__PURE__ */ new Map();
|
|
23224
23224
|
const noteErrors = (list3) => {
|
|
23225
23225
|
for (const s of list3 || []) {
|
|
@@ -23229,19 +23229,19 @@ function shellReading(src, file = "") {
|
|
|
23229
23229
|
}
|
|
23230
23230
|
};
|
|
23231
23231
|
for (const f of all) {
|
|
23232
|
-
const line =
|
|
23232
|
+
const line = lineAt5(f.at);
|
|
23233
23233
|
const st = steps(f.body);
|
|
23234
|
-
if (!st.length) st.push({ kind: "return", says: "Does nothing", code: src.slice(f.at, f.end).replace(/\s+/g, " ").trim().slice(0, 160), line, span: { startLine: line, endLine:
|
|
23234
|
+
if (!st.length) st.push({ kind: "return", says: "Does nothing", code: src.slice(f.at, f.end).replace(/\s+/g, " ").trim().slice(0, 160), line, span: { startLine: line, endLine: lineAt5(f.end - 1) } });
|
|
23235
23235
|
noteErrors(st);
|
|
23236
23236
|
const first = f.body[0], lastN = f.body[f.body.length - 1];
|
|
23237
|
-
fns.push({ name: f.name, line, params: inputsOf(f.body, src), doc: docAbove3(lines, line), steps: st, body: first ? [
|
|
23237
|
+
fns.push({ name: f.name, line, params: inputsOf(f.body, src), doc: docAbove3(lines, line), steps: st, body: first ? [lineAt5(first.at), lineAt5(lastN.end - 1)] : null });
|
|
23238
23238
|
}
|
|
23239
23239
|
const top = nodes2.filter((n) => n.type !== "function");
|
|
23240
23240
|
if (top.length) {
|
|
23241
23241
|
const st = steps(top);
|
|
23242
23242
|
noteErrors(st);
|
|
23243
23243
|
const name = file ? String(file).split(/[\\/]/).pop() : "script";
|
|
23244
|
-
fns.push({ name, line:
|
|
23244
|
+
fns.push({ name, line: lineAt5(top[0].at), params: inputsOf(top, src), doc: headerDoc(lines), steps: st, body: [lineAt5(top[0].at), lineAt5(top[top.length - 1].end - 1)], topLevel: true, headline: `Runs ${name}, from top to bottom.` });
|
|
23245
23245
|
}
|
|
23246
23246
|
fns.sort((a, b) => a.line - b.line);
|
|
23247
23247
|
KNOWN_FNS = /* @__PURE__ */ new Set();
|
|
@@ -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
|
}
|
|
@@ -24293,7 +24293,7 @@ function docBefore(toks2, idx) {
|
|
|
24293
24293
|
}
|
|
24294
24294
|
function makeReader(src) {
|
|
24295
24295
|
const toks2 = tokenize3(src);
|
|
24296
|
-
const
|
|
24296
|
+
const lineAt5 = lineFinder3(src);
|
|
24297
24297
|
const fns = [], things = [], errors = /* @__PURE__ */ new Map(), tests = [];
|
|
24298
24298
|
const code3 = (s, e) => {
|
|
24299
24299
|
const t = src.slice(toks2[s].at, toks2[e - 1].end).replace(/\s+/g, " ").trim();
|
|
@@ -24303,8 +24303,8 @@ function makeReader(src) {
|
|
|
24303
24303
|
const t = src.slice(toks2[s].at, toks2[e - 1].end).split("\n")[0].trim();
|
|
24304
24304
|
return t.length > 160 ? `${t.slice(0, 159)}\u2026` : t;
|
|
24305
24305
|
};
|
|
24306
|
-
const spanOf2 = (s, e) => ({ startLine:
|
|
24307
|
-
const base2 = (s, e, c = code3(s, e)) => ({ code: c, line:
|
|
24306
|
+
const spanOf2 = (s, e) => ({ startLine: lineAt5(toks2[s].at), endLine: lineAt5(toks2[e - 1].end - 1) });
|
|
24307
|
+
const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt5(toks2[s].at), span: spanOf2(s, e) });
|
|
24308
24308
|
const nextTok = (i, to) => {
|
|
24309
24309
|
while (i < to && (toks2[i].t === "nl" || toks2[i].t === "comment")) i++;
|
|
24310
24310
|
return i;
|
|
@@ -24343,7 +24343,7 @@ function makeReader(src) {
|
|
|
24343
24343
|
const blk = blockAt(toks2[p].match + 1, e);
|
|
24344
24344
|
if (!blk) break;
|
|
24345
24345
|
const cond = toks2.slice(p + 1, toks2[p].match);
|
|
24346
|
-
const b = { kind: "branch", says: `If ${gated(cond, condWords3(cond, false)) ?? asCodeWords(code3(p + 1, toks2[p].match))}`, cond: condJs(cond), code: head(i, blk[1] + 1), line:
|
|
24346
|
+
const b = { kind: "branch", says: `If ${gated(cond, condWords3(cond, false)) ?? asCodeWords(code3(p + 1, toks2[p].match))}`, cond: condJs(cond), code: head(i, blk[1] + 1), line: lineAt5(toks2[i].at), span: first ? spanOf2(i, e) : spanOf2(s, e) };
|
|
24347
24347
|
const kids2 = stepsIn(blk[0], blk[1], ctx);
|
|
24348
24348
|
if (kids2.length) b.children = kids2;
|
|
24349
24349
|
if (!first) first = b;
|
|
@@ -24359,7 +24359,7 @@ function makeReader(src) {
|
|
|
24359
24359
|
const blk = blockAt(i + 1, e);
|
|
24360
24360
|
if (!blk) break;
|
|
24361
24361
|
tail.otherwise = stepsIn(blk[0], blk[1], ctx);
|
|
24362
|
-
tail.otherwiseLine =
|
|
24362
|
+
tail.otherwiseLine = lineAt5(toks2[i].at);
|
|
24363
24363
|
i = blk[1] + 1;
|
|
24364
24364
|
continue;
|
|
24365
24365
|
}
|
|
@@ -24440,7 +24440,7 @@ function makeReader(src) {
|
|
|
24440
24440
|
if (!body2) break;
|
|
24441
24441
|
const kids2 = stepsIn(body2[0], body2[1], ctx);
|
|
24442
24442
|
const label = /^default$/i.test(pat.text) ? "Otherwise" : pat.text === "{" ? `When ${gated(toks2.slice(patStart + 1, pat.match), condWords3(toks2.slice(patStart + 1, pat.match), false)) ?? asCodeWords(code3(patStart + 1, pat.match))}` : flags2.includes("-regex") ? `When it matches the pattern ${sayValue2([pat])}` : flags2.includes("-wildcard") ? `When it matches ${sayValue2([pat])}` : `When it is ${sayValue2(toks2.slice(patStart, k)) ?? pat.text}`;
|
|
24443
|
-
arms.push({ kind: "check", says: label, caseLabel: true, code: head(patStart, body2[1] + 1).slice(0, 90), line:
|
|
24443
|
+
arms.push({ kind: "check", says: label, caseLabel: true, code: head(patStart, body2[1] + 1).slice(0, 90), line: lineAt5(pat.at), span: spanOf2(patStart, body2[1] + 1), ...kids2.length ? { children: kids2 } : {}, _pat: pat });
|
|
24444
24444
|
k = body2[1] + 1;
|
|
24445
24445
|
}
|
|
24446
24446
|
for (const a of arms) delete a._pat;
|
|
@@ -24471,14 +24471,14 @@ function makeReader(src) {
|
|
|
24471
24471
|
} finally {
|
|
24472
24472
|
IN_CATCH--;
|
|
24473
24473
|
}
|
|
24474
|
-
(step.handlers ||= []).push({ says: types.length ? `If ${types.join(" or ")} goes wrong` : "If anything goes wrong", line:
|
|
24474
|
+
(step.handlers ||= []).push({ says: types.length ? `If ${types.join(" or ")} goes wrong` : "If anything goes wrong", line: lineAt5(toks2[i].at), steps: hs });
|
|
24475
24475
|
i = nextTok(b[1] + 1, e);
|
|
24476
24476
|
continue;
|
|
24477
24477
|
}
|
|
24478
24478
|
if (w === "finally") {
|
|
24479
24479
|
const b = blockAt(i + 1, e);
|
|
24480
24480
|
if (!b) break;
|
|
24481
|
-
step.always = { line:
|
|
24481
|
+
step.always = { line: lineAt5(toks2[i].at), steps: stepsIn(b[0], b[1], ctx) };
|
|
24482
24482
|
i = nextTok(b[1] + 1, e);
|
|
24483
24483
|
continue;
|
|
24484
24484
|
}
|
|
@@ -24514,8 +24514,8 @@ function makeReader(src) {
|
|
|
24514
24514
|
msg = null;
|
|
24515
24515
|
name = varWords2(rest2[0].name);
|
|
24516
24516
|
} else if (!rest2.length) return [{ kind: "fail", says: "Fails again with the same error", error: "the same error", ...base2(s, e) }];
|
|
24517
|
-
if (msg) errors.set(msg, errors.get(msg) ??
|
|
24518
|
-
else if (name !== "an error") errors.set(name, errors.get(name) ??
|
|
24517
|
+
if (msg) errors.set(msg, errors.get(msg) ?? lineAt5(t.at));
|
|
24518
|
+
else if (name !== "an error") errors.set(name, errors.get(name) ?? lineAt5(t.at));
|
|
24519
24519
|
return [{ kind: "fail", says: `Fails with ${name}${msg ? `: "${msg}"` : ""}`, error: name, ...msg ? { message: msg } : {}, ...base2(s, e) }];
|
|
24520
24520
|
}
|
|
24521
24521
|
case "return": {
|
|
@@ -24575,7 +24575,7 @@ function makeReader(src) {
|
|
|
24575
24575
|
if (/^(describe|context|it)$/i.test(t.text) && toks2[nextTok(s + 1, e)]?.t === "str") {
|
|
24576
24576
|
const name = stringText(toks2[nextTok(s + 1, e)]);
|
|
24577
24577
|
const blk = toks2.slice(s, e).find((x) => x.text === "{" && x.match != null);
|
|
24578
|
-
if (/^it$/i.test(t.text)) tests.push({ name, line:
|
|
24578
|
+
if (/^it$/i.test(t.text)) tests.push({ name, line: lineAt5(t.at) });
|
|
24579
24579
|
else if (blk) stepsIn(blk.i + 1, blk.match, ctx);
|
|
24580
24580
|
return [];
|
|
24581
24581
|
}
|
|
@@ -24640,7 +24640,7 @@ function makeReader(src) {
|
|
|
24640
24640
|
const msg = a.named.message ? sayValue2(a.named.message) : a.pos[0] ? sayValue2(a.pos[0]) : null;
|
|
24641
24641
|
const text2 = msg ? msg.replace(/^"|"$/g, "") : null;
|
|
24642
24642
|
const stops = STOP_ON_ERROR || /stop/i.test(a.named.erroraction?.map((x) => x.text).join("") ?? "");
|
|
24643
|
-
if (text2) errors.set(text2, errors.get(text2) ??
|
|
24643
|
+
if (text2) errors.set(text2, errors.get(text2) ?? lineAt5(head0.at));
|
|
24644
24644
|
return [stops ? { kind: "fail", says: `Fails with an error${text2 ? `: "${text2}"` : ""}`, error: "an error", ...text2 ? { message: text2 } : {}, ...base2(s, e) } : { kind: "call", says: `Reports an error${text2 ? `: "${text2}"` : ""} and carries on`, ...base2(s, e) }];
|
|
24645
24645
|
}
|
|
24646
24646
|
const lg = groups(list3);
|
|
@@ -24728,7 +24728,7 @@ function makeReader(src) {
|
|
|
24728
24728
|
if (!steps.length) steps.push({ kind: "return", says: "Does nothing", ...base2(s, e, head(s, e)) });
|
|
24729
24729
|
lastValueToReturn(steps);
|
|
24730
24730
|
const first = nextTok(parts.from, blk[1]);
|
|
24731
|
-
fns.push({ name, line:
|
|
24731
|
+
fns.push({ name, line: lineAt5(nameTok.at), params, doc, steps, body: first < blk[1] ? [lineAt5(toks2[first].at), lineAt5(toks2[blk[1]].at)] : null, _range: [parts.from, blk[1]] });
|
|
24732
24732
|
}
|
|
24733
24733
|
function podeRoute(s, e) {
|
|
24734
24734
|
const a = argsOf(toks2.slice(s + 1, e));
|
|
@@ -24738,14 +24738,14 @@ function makeReader(src) {
|
|
|
24738
24738
|
const sb = a.named.scriptblock;
|
|
24739
24739
|
if (!sb || sb[0].text !== "{") return;
|
|
24740
24740
|
const open = sb[0].i;
|
|
24741
|
-
fns.push({ name: `${method} ${path}`, line:
|
|
24741
|
+
fns.push({ name: `${method} ${path}`, line: lineAt5(toks2[s].at), params: [], route: { method, path }, steps: stepsIn(open + 1, sb[0].match), body: [lineAt5(toks2[nextTok(open + 1, sb[0].match)]?.at ?? toks2[open].at), lineAt5(toks2[sb[0].match].at)] });
|
|
24742
24742
|
}
|
|
24743
24743
|
function defineType(s, e, kw) {
|
|
24744
24744
|
const nameTok = toks2[nextTok(s + 1, e)];
|
|
24745
24745
|
const blk = toks2.slice(s, e).find((x) => x.text === "{" && x.match != null);
|
|
24746
24746
|
if (!nameTok || !blk) return;
|
|
24747
24747
|
const open = blk.i, close = blk.match;
|
|
24748
|
-
const lines = [
|
|
24748
|
+
const lines = [lineAt5(toks2[s].at), lineAt5(toks2[close].at)];
|
|
24749
24749
|
const doc = docBefore(toks2, s);
|
|
24750
24750
|
if (kw === "enum") {
|
|
24751
24751
|
const choices = [];
|
|
@@ -24762,7 +24762,7 @@ function makeReader(src) {
|
|
|
24762
24762
|
const type = st.slice(0, v).reverse().find((x) => x.t === "type");
|
|
24763
24763
|
const eq2 = st.findIndex((x, i) => i > v && x.text === "=");
|
|
24764
24764
|
const def = eq2 > 0 ? st.slice(eq2 + 1) : null;
|
|
24765
|
-
thing.knows.push({ name: st[v].name, type: type?.name ?? null, start: def ? def.map((x) => x.text).join(" ") : null, line:
|
|
24765
|
+
thing.knows.push({ name: st[v].name, type: type?.name ?? null, start: def ? def.map((x) => x.text).join(" ") : null, line: lineAt5(st[v].at) });
|
|
24766
24766
|
continue;
|
|
24767
24767
|
}
|
|
24768
24768
|
const nameAt = st.findIndex((x, i) => x.t === "word" && st[i + 1]?.text === "(");
|
|
@@ -24778,7 +24778,7 @@ function makeReader(src) {
|
|
|
24778
24778
|
const first = nextTok(bOpen + 1, body2.match);
|
|
24779
24779
|
const ret = st.slice(0, nameAt).reverse().find((x) => x.t === "type");
|
|
24780
24780
|
if (mTok.text !== nameTok.text) thing.methods++;
|
|
24781
|
-
fns.push({ name: mTok.text, line:
|
|
24781
|
+
fns.push({ name: mTok.text, line: lineAt5(mTok.at), params, returns: ret && !/^void$/i.test(ret.name) ? ret.name : null, doc: docBefore(toks2, st[0].i), steps, body: first < body2.match ? [lineAt5(toks2[first].at), lineAt5(toks2[body2.match].at)] : null, _range: [bOpen + 1, body2.match] });
|
|
24782
24782
|
if (mTok.text === nameTok.text) {
|
|
24783
24783
|
for (const [x, y] of splitStatements(toks2, bOpen + 1, body2.match)) {
|
|
24784
24784
|
const st2 = at0(toks2.slice(x, y));
|
|
@@ -24789,7 +24789,7 @@ function makeReader(src) {
|
|
|
24789
24789
|
const start = param ? param.default ? { param: param.default } : { given: true } : val.map((q2) => q2.text).join(" ");
|
|
24790
24790
|
if (k2) {
|
|
24791
24791
|
if (k2.start == null || param) k2.start = start;
|
|
24792
|
-
} else thing.knows.push({ name: st2[2].text, type: null, start, line:
|
|
24792
|
+
} else thing.knows.push({ name: st2[2].text, type: null, start, line: lineAt5(st2[0].at) });
|
|
24793
24793
|
}
|
|
24794
24794
|
}
|
|
24795
24795
|
}
|
|
@@ -24797,7 +24797,7 @@ function makeReader(src) {
|
|
|
24797
24797
|
delete thing.methods;
|
|
24798
24798
|
things.push(thing);
|
|
24799
24799
|
}
|
|
24800
|
-
return { toks: toks2, fns, things, errors, tests, stepsIn, lineAt:
|
|
24800
|
+
return { toks: toks2, fns, things, errors, tests, stepsIn, lineAt: lineAt5, splitStatements: () => splitStatements(toks2, 0, toks2.length), statement: statement2, nextTok, code: code3, cleanSteps };
|
|
24801
24801
|
}
|
|
24802
24802
|
var fixedOf = (toks2) => {
|
|
24803
24803
|
const v = at0(toks2 || []);
|
|
@@ -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":
|
|
@@ -25876,7 +25876,7 @@ var KNOWN_FNS3 = /* @__PURE__ */ new Set();
|
|
|
25876
25876
|
function makeReader2(src) {
|
|
25877
25877
|
SRC = src;
|
|
25878
25878
|
const toks2 = tokenize4(src);
|
|
25879
|
-
const
|
|
25879
|
+
const lineAt5 = lineFinder4(src);
|
|
25880
25880
|
const fns = [], things = [], errors = /* @__PURE__ */ new Map(), tests = [], defs = [];
|
|
25881
25881
|
const code3 = (s, e) => {
|
|
25882
25882
|
const t = src.slice(toks2[s].at, toks2[e - 1].end).replace(/\s+/g, " ").trim();
|
|
@@ -25886,8 +25886,8 @@ function makeReader2(src) {
|
|
|
25886
25886
|
const t = src.slice(toks2[s].at, toks2[e - 1].end).split("\n")[0].trim();
|
|
25887
25887
|
return t.length > 160 ? `${t.slice(0, 159)}\u2026` : t;
|
|
25888
25888
|
};
|
|
25889
|
-
const spanOf2 = (s, e) => ({ startLine:
|
|
25890
|
-
const base2 = (s, e, c = code3(s, e)) => ({ code: c, line:
|
|
25889
|
+
const spanOf2 = (s, e) => ({ startLine: lineAt5(toks2[s].at), endLine: lineAt5(toks2[e - 1].end - 1) });
|
|
25890
|
+
const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt5(toks2[s].at), span: spanOf2(s, e) });
|
|
25891
25891
|
const next = (i, to) => {
|
|
25892
25892
|
while (i < to && (toks2[i].t === "nl" || toks2[i].t === "comment")) i++;
|
|
25893
25893
|
return i;
|
|
@@ -25939,7 +25939,7 @@ function makeReader2(src) {
|
|
|
25939
25939
|
thenTo = elseAt >= 0 ? elseAt : e;
|
|
25940
25940
|
}
|
|
25941
25941
|
const c = condSaid(condT);
|
|
25942
|
-
const step = { kind: "branch", says: `If ${c ?? `\`${code3(open + 1, close)}\``}`, cond: condJs2(condT), code: head(s, e), line:
|
|
25942
|
+
const step = { kind: "branch", says: `If ${c ?? `\`${code3(open + 1, close)}\``}`, cond: condJs2(condT), code: head(s, e), line: lineAt5(toks2[s].at), span: spanOf2(s, e) };
|
|
25943
25943
|
const kids2 = stepsOfBody(close + 1, thenTo, ctx);
|
|
25944
25944
|
if (kids2.length) step.children = kids2;
|
|
25945
25945
|
if (elseAt >= 0) {
|
|
@@ -25953,7 +25953,7 @@ function makeReader2(src) {
|
|
|
25953
25953
|
}
|
|
25954
25954
|
} else {
|
|
25955
25955
|
step.otherwise = stepsOfBody(elseAt + 1, e, ctx);
|
|
25956
|
-
step.otherwiseLine =
|
|
25956
|
+
step.otherwiseLine = lineAt5(toks2[elseAt].at);
|
|
25957
25957
|
}
|
|
25958
25958
|
}
|
|
25959
25959
|
return step;
|
|
@@ -26046,7 +26046,7 @@ function makeReader2(src) {
|
|
|
26046
26046
|
const fnSteps = stepsOfBody(fv.from, fv.to, { last: true, fn: true });
|
|
26047
26047
|
if (!fnSteps.length) fnSteps.push({ kind: "return", says: "Does nothing", ...base2(nameTok.i, fv.to, head(nameTok.i, fv.to)) });
|
|
26048
26048
|
const [a, b] = bodyRange2(fv.from, fv.to);
|
|
26049
|
-
const f = { name: route && !name ? `${route.method} ${route.path}` : name, line:
|
|
26049
|
+
const f = { name: route && !name ? `${route.method} ${route.path}` : name, line: lineAt5(nameTok.at), params, doc, steps: fnSteps, body: a < b && next(a, b) < b ? [lineAt5(toks2[next(a, b)].at), lineAt5(toks2[b - 1].end - 1)] : null, ...route ? { route } : {}, _fv: fv, ...owner ? { owner } : {} };
|
|
26050
26050
|
fns.push(f);
|
|
26051
26051
|
return f;
|
|
26052
26052
|
}
|
|
@@ -26202,11 +26202,11 @@ function makeReader2(src) {
|
|
|
26202
26202
|
const fv = fnValue(a.toks);
|
|
26203
26203
|
const r = at02(a.toks).length ? range(at02(a.toks)) : null;
|
|
26204
26204
|
if (a.name === "finally") {
|
|
26205
|
-
step.always = { line:
|
|
26205
|
+
step.always = { line: lineAt5(at02(a.toks)[0]?.at ?? toks2[s].at), steps: r ? stepsOfBody(r[0], r[1], { ...ctx, last: false }) : [] };
|
|
26206
26206
|
continue;
|
|
26207
26207
|
}
|
|
26208
26208
|
const says = a.name === "error" ? "If anything goes wrong" : a.name === "warning" ? "If there is a warning" : a.name === "message" ? "If a message is written" : a.name === "interrupt" ? "If it is stopped" : `If ${a.name} goes wrong`;
|
|
26209
|
-
(step.handlers ||= []).push({ says, line:
|
|
26209
|
+
(step.handlers ||= []).push({ says, line: lineAt5(at02(a.toks)[0]?.at ?? toks2[s].at), steps: fv ? stepsOfBody(fv.from, fv.to, { ...ctx, last: !!target || ctx.last, fn: true }) : [] });
|
|
26210
26210
|
}
|
|
26211
26211
|
if (target) {
|
|
26212
26212
|
for (const list3 of [step.children, ...(step.handlers || []).map((h) => h.steps)]) if (list3?.length) giveValue2({ kind: "branch", children: list3 }, target);
|
|
@@ -26227,7 +26227,7 @@ function makeReader2(src) {
|
|
|
26227
26227
|
pending = [];
|
|
26228
26228
|
const r = vtoks.length ? range(vtoks) : null;
|
|
26229
26229
|
const kids2 = r ? stepsOfBody(r[0], r[1], ctx) : [];
|
|
26230
|
-
arms.push({ kind: "check", says: names ? `When it is ${list2(names.map((n) => `"${n}"`)).replace(/,? and ([^,]*)$/, " or $1")}` : "Otherwise", caseLabel: true, code: names ? `${names.join(", ")} =` : "(default)", line:
|
|
26230
|
+
arms.push({ kind: "check", says: names ? `When it is ${list2(names.map((n) => `"${n}"`)).replace(/,? and ([^,]*)$/, " or $1")}` : "Otherwise", caseLabel: true, code: names ? `${names.join(", ")} =` : "(default)", line: lineAt5(vtoks[0]?.at ?? toks2[s].at), span: r ? spanOf2(r[0], r[1]) : spanOf2(s, e), ...kids2.length ? { children: kids2 } : {} });
|
|
26231
26231
|
}
|
|
26232
26232
|
return { kind: "branch", says: `Chooses by ${sayValue3(subject?.toks ?? []) ?? "value"}`, ...base2(s, e, head(s, e)), ...arms.length ? { children: arms } : {} };
|
|
26233
26233
|
}
|
|
@@ -26253,7 +26253,7 @@ function makeReader2(src) {
|
|
|
26253
26253
|
const isVar = parts.length === 1 && one.length === 1 && one[0].t === "id";
|
|
26254
26254
|
const single = !isVar && oneValue(parts) ? sayValue3(parts[0].toks) : null;
|
|
26255
26255
|
const msg = isVar || single || !parts.length ? null : textOf2(parts, "", bare2 === "cli_abort" || bare2 === "ui_abort");
|
|
26256
|
-
if (msg) errors.set(msg, errors.get(msg) ??
|
|
26256
|
+
if (msg) errors.set(msg, errors.get(msg) ?? lineAt5(toks2[s].at));
|
|
26257
26257
|
const cls = args.find((a) => a.name === "class");
|
|
26258
26258
|
const name = cls ? at02(cls.toks)[0]?.value ?? "an error" : "an error";
|
|
26259
26259
|
const says = isVar ? `Fails with the error in ${rWords(one[0].text)}` : single ? `Fails with the error ${/^the result of /.test(single) ? single.replace(/^the result of /, "made by ") : `in ${single}`}` : `Fails with ${name}${msg ? `: "${msg}"` : ""}`;
|
|
@@ -26281,7 +26281,7 @@ function makeReader2(src) {
|
|
|
26281
26281
|
if (bare2 === "try") {
|
|
26282
26282
|
const r = args[0] && at02(args[0].toks).length ? range(at02(args[0].toks)) : null;
|
|
26283
26283
|
const kids2 = r ? stepsOfBody(r[0], r[1], { ...ctx, last: false }) : [];
|
|
26284
|
-
return [{ kind: "try", says: "Tries these steps, and carries on if they fail", ...base2(s, e, head(s, e)), ...kids2.length ? { children: kids2 } : {}, handlers: [{ says: "If anything goes wrong", line:
|
|
26284
|
+
return [{ kind: "try", says: "Tries these steps, and carries on if they fail", ...base2(s, e, head(s, e)), ...kids2.length ? { children: kids2 } : {}, handlers: [{ says: "If anything goes wrong", line: lineAt5(toks2[s].at), steps: [] }] }];
|
|
26285
26285
|
}
|
|
26286
26286
|
if (bare2 === "on.exit") {
|
|
26287
26287
|
const r = args[0] && at02(args[0].toks).length ? range(at02(args[0].toks)) : null;
|
|
@@ -26295,7 +26295,7 @@ function makeReader2(src) {
|
|
|
26295
26295
|
}
|
|
26296
26296
|
if (bare2 === "test_that") {
|
|
26297
26297
|
const name = at02(args[0]?.toks ?? [])[0]?.value;
|
|
26298
|
-
if (name) tests.push({ name, line:
|
|
26298
|
+
if (name) tests.push({ name, line: lineAt5(toks2[s].at) });
|
|
26299
26299
|
return [];
|
|
26300
26300
|
}
|
|
26301
26301
|
if (bare2 === "return" || bare2 === "invisible") {
|
|
@@ -26332,7 +26332,7 @@ function makeReader2(src) {
|
|
|
26332
26332
|
return [val ? { kind: "call", says: `Works out ${val}`, ...base2(s, e) } : { kind: "other", says: code3(s, e), ...base2(s, e) }];
|
|
26333
26333
|
}
|
|
26334
26334
|
function defineThing(name, call2, s, e) {
|
|
26335
|
-
const lines = [
|
|
26335
|
+
const lines = [lineAt5(toks2[s].at), lineAt5(toks2[e - 1].end - 1)];
|
|
26336
26336
|
const className = at02(call2.args[0]?.toks ?? [])[0]?.value ?? at02(call2.args.find((a) => a.name === "Classname")?.toks ?? [])[0]?.value ?? name;
|
|
26337
26337
|
const { doc } = docAbove5(s);
|
|
26338
26338
|
const thing = { kind: "record", name: className || name, lines, ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
|
|
@@ -26345,13 +26345,13 @@ function makeReader2(src) {
|
|
|
26345
26345
|
for (const a of args || []) {
|
|
26346
26346
|
if (!a.name) {
|
|
26347
26347
|
const sv = at02(a.toks)[0];
|
|
26348
|
-
if (sv?.t === "str") thing.knows.push({ name: sv.value, type: null, start: null, line:
|
|
26348
|
+
if (sv?.t === "str") thing.knows.push({ name: sv.value, type: null, start: null, line: lineAt5(sv.at) });
|
|
26349
26349
|
continue;
|
|
26350
26350
|
}
|
|
26351
26351
|
const vt = at02(a.toks);
|
|
26352
26352
|
if (fnValue(vt)) continue;
|
|
26353
26353
|
const tv = typed && vt.length === 1 && vt[0].t === "str" ? vt[0].value : null;
|
|
26354
|
-
thing.knows.push({ name: a.name, type: tv ? R_TYPE[tv] ?? tv : null, start: typed ? null : vt.map((x) => x.text).join(""), line:
|
|
26354
|
+
thing.knows.push({ name: a.name, type: tv ? R_TYPE[tv] ?? tv : null, start: typed ? null : vt.map((x) => x.text).join(""), line: lineAt5(vt[0]?.at ?? toks2[s].at) });
|
|
26355
26355
|
}
|
|
26356
26356
|
};
|
|
26357
26357
|
let methods = 0;
|
|
@@ -26360,7 +26360,7 @@ function makeReader2(src) {
|
|
|
26360
26360
|
const fv = a.name ? fnValue(a.toks) : null;
|
|
26361
26361
|
if (!fv) continue;
|
|
26362
26362
|
const f = defineFunction(a.name, fv, at02(a.toks)[0].i, toks2[at02(a.toks)[0].i - 2] ?? toks2[s]);
|
|
26363
|
-
f.line =
|
|
26363
|
+
f.line = lineAt5(toks2[at02(a.toks)[0].i - 2]?.at ?? toks2[s].at);
|
|
26364
26364
|
if (a.name !== "initialize") methods++;
|
|
26365
26365
|
if (a.name === "initialize") {
|
|
26366
26366
|
const byName = new Map(fv.params.map((p) => [p.name, p.default ? at02(p.default).map((x) => x.text).join("") : null]));
|
|
@@ -26374,7 +26374,7 @@ function makeReader2(src) {
|
|
|
26374
26374
|
const start = val.length === 1 && byName.has(val[0].text) ? { param: byName.get(val[0].text) } : val.map((q2) => q2.text).join("");
|
|
26375
26375
|
if (k) {
|
|
26376
26376
|
if (k.start == null || typeof start === "object") k.start = start;
|
|
26377
|
-
} else thing.knows.push({ name: field, type: null, start, line:
|
|
26377
|
+
} else thing.knows.push({ name: field, type: null, start, line: lineAt5(st[0].at) });
|
|
26378
26378
|
}
|
|
26379
26379
|
}
|
|
26380
26380
|
}
|
|
@@ -26399,7 +26399,7 @@ function makeReader2(src) {
|
|
|
26399
26399
|
thing._methods = methods;
|
|
26400
26400
|
things.push(thing);
|
|
26401
26401
|
}
|
|
26402
|
-
return { toks: toks2, fns, things, errors, tests, stepsIn, lineAt:
|
|
26402
|
+
return { toks: toks2, fns, things, errors, tests, stepsIn, lineAt: lineAt5, next, statement: statement2, code: code3, base: base2 };
|
|
26403
26403
|
}
|
|
26404
26404
|
function decisionOf2(r, fv) {
|
|
26405
26405
|
const { toks: toks2 } = r;
|
|
@@ -28292,7 +28292,7 @@ function swiftImplicitResult(text2, returns) {
|
|
|
28292
28292
|
var rebind = (guard, name, subject) => guard.replace(new RegExp(`\\b${name}\\b`, "g"), subject);
|
|
28293
28293
|
function switchArms(body2, language, baseLine) {
|
|
28294
28294
|
const arms = [];
|
|
28295
|
-
const
|
|
28295
|
+
const lineOf7 = (idx) => baseLine + lineAt(body2, idx) - 1;
|
|
28296
28296
|
if (language === "rust" || language === "csharp-expr") {
|
|
28297
28297
|
let i = 0;
|
|
28298
28298
|
while (i < body2.length) {
|
|
@@ -28315,7 +28315,7 @@ function switchArms(body2, language, baseLine) {
|
|
|
28315
28315
|
value = body2.slice(j, end2).trim();
|
|
28316
28316
|
}
|
|
28317
28317
|
const g = head.match(/^(.*?)\s+(?:if|when)\s+(.+)$/s);
|
|
28318
|
-
arms.push({ pattern: (g ? g[1] : head).trim(), guard: g ? g[2].trim() : null, value, line:
|
|
28318
|
+
arms.push({ pattern: (g ? g[1] : head).trim(), guard: g ? g[2].trim() : null, value, line: lineOf7(i) });
|
|
28319
28319
|
i = end2 + 1;
|
|
28320
28320
|
}
|
|
28321
28321
|
return arms;
|
|
@@ -28354,8 +28354,8 @@ function switchArms(body2, language, baseLine) {
|
|
|
28354
28354
|
}
|
|
28355
28355
|
const patterns = [...pending, pattern2];
|
|
28356
28356
|
pending = [];
|
|
28357
|
-
if (patterns.includes(null)) arms.push({ pattern: null, guard: null, value, line:
|
|
28358
|
-
else arms.push({ pattern: patterns.join(language === "go" && patterns.length === 1 ? "" : ", ") || patterns[0], guard: g ? g[2].trim() : null, value, line:
|
|
28357
|
+
if (patterns.includes(null)) arms.push({ pattern: null, guard: null, value, line: lineOf7(starts[k]) });
|
|
28358
|
+
else arms.push({ pattern: patterns.join(language === "go" && patterns.length === 1 ? "" : ", ") || patterns[0], guard: g ? g[2].trim() : null, value, line: lineOf7(starts[k]) });
|
|
28359
28359
|
}
|
|
28360
28360
|
return arms;
|
|
28361
28361
|
}
|
|
@@ -28648,12 +28648,12 @@ function readBraceStatements(stmts, language, inputs) {
|
|
|
28648
28648
|
}
|
|
28649
28649
|
let rest2 = t;
|
|
28650
28650
|
let ok = true;
|
|
28651
|
-
const
|
|
28651
|
+
const lineOf7 = (part) => {
|
|
28652
28652
|
const at2 = t.lastIndexOf(part);
|
|
28653
28653
|
return st.line + (at2 > 0 ? (t.slice(0, at2).match(/\n/g) || []).length : 0);
|
|
28654
28654
|
};
|
|
28655
28655
|
while (rest2) {
|
|
28656
|
-
const here =
|
|
28656
|
+
const here = lineOf7(rest2);
|
|
28657
28657
|
const head2 = rest2.match(/^(?:else\s+)?if\b\s*/);
|
|
28658
28658
|
if (!head2) break;
|
|
28659
28659
|
rest2 = rest2.slice(head2[0].length);
|
|
@@ -28706,9 +28706,9 @@ function readBraceStatements(stmts, language, inputs) {
|
|
|
28706
28706
|
const elseBody = remaining.replace(/^else\s*/, "");
|
|
28707
28707
|
const v = elseBody.startsWith("{") ? blockValue(elseBody) : elseBody.startsWith("return ") ? elseBody.slice(7).replace(/;$/, "") : null;
|
|
28708
28708
|
if (v == null) {
|
|
28709
|
-
unread.push({ line:
|
|
28709
|
+
unread.push({ line: lineOf7(remaining), text: "else", reason: "The fallback branch does more than choose an answer." });
|
|
28710
28710
|
ok = false;
|
|
28711
|
-
} else take(null, v,
|
|
28711
|
+
} else take(null, v, lineOf7(remaining));
|
|
28712
28712
|
}
|
|
28713
28713
|
rest2 = "";
|
|
28714
28714
|
}
|
|
@@ -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;
|
|
@@ -30253,7 +30264,7 @@ function writeRule({ source, language, file = "", decision: name, line = null, r
|
|
|
30253
30264
|
});
|
|
30254
30265
|
if (problems.length) return fail4(...problems);
|
|
30255
30266
|
const starts = lineStartsOf(source);
|
|
30256
|
-
const
|
|
30267
|
+
const lineOf7 = (off) => {
|
|
30257
30268
|
let lo = 0, hi = starts.length - 1;
|
|
30258
30269
|
while (lo < hi) {
|
|
30259
30270
|
const m = lo + hi + 1 >> 1;
|
|
@@ -30262,7 +30273,7 @@ function writeRule({ source, language, file = "", decision: name, line = null, r
|
|
|
30262
30273
|
}
|
|
30263
30274
|
return lo + 1;
|
|
30264
30275
|
};
|
|
30265
|
-
const change = real.slice().reverse().map((e) => ({ line:
|
|
30276
|
+
const change = real.slice().reverse().map((e) => ({ line: lineOf7(e.start), column: e.start - starts[lineOf7(e.start) - 1] + 1, before: e.was, after: e.text }));
|
|
30266
30277
|
const label = (r) => r === "otherwise" ? "Otherwise" : `If ${sayCondition(r.when)}`;
|
|
30267
30278
|
const beforeRule = index === "otherwise" ? `Otherwise, the answer is ${target.result}` : `${label(target)}, the answer is ${target.result}`;
|
|
30268
30279
|
const afterRule = index === "otherwise" ? `Otherwise, the answer is ${wantResult}` : `If ${sayCondition(newWhen)}, the answer is ${wantResult}`;
|
|
@@ -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
|
}
|
|
@@ -30768,12 +31566,12 @@ function plainFromReading(item4) {
|
|
|
30768
31566
|
const whens = (item4.rules ?? []).map((r) => r.when ?? "").join(" and ");
|
|
30769
31567
|
const typed = (item4.inputs ?? []).map((i) => {
|
|
30770
31568
|
if (i.type) return i;
|
|
30771
|
-
const
|
|
30772
|
-
if (new RegExp(`\\b${
|
|
31569
|
+
const esc3 = i.name.replace(/[$]/g, "\\$");
|
|
31570
|
+
if (new RegExp(`\\b${esc3}\\s*(>=|<=|<|>|==)\\s*-?\\d`).test(whens)) {
|
|
30773
31571
|
inferred.push(i.name);
|
|
30774
31572
|
return { ...i, type: "number" };
|
|
30775
31573
|
}
|
|
30776
|
-
if (new RegExp(`(^|\\s|not\\s+|!)${
|
|
31574
|
+
if (new RegExp(`(^|\\s|not\\s+|!)${esc3}(\\s|$)`).test(whens)) {
|
|
30777
31575
|
inferred.push(i.name);
|
|
30778
31576
|
return { ...i, type: "boolean" };
|
|
30779
31577
|
}
|
|
@@ -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 },
|
|
@@ -31471,11 +32269,11 @@ function jsxChildren(src, j, tag) {
|
|
|
31471
32269
|
}
|
|
31472
32270
|
var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
|
|
31473
32271
|
function parseTemplate(html, fileSrc = null, offset = 0) {
|
|
31474
|
-
const
|
|
32272
|
+
const lineOf7 = (i2) => fileSrc ? lineAt2(fileSrc, offset + i2) : lineAt2(html, i2);
|
|
31475
32273
|
let i = 0;
|
|
31476
32274
|
const parseNodes = (stopTag, stopBrace) => {
|
|
31477
32275
|
const out = [];
|
|
31478
|
-
let text2 = "", tl =
|
|
32276
|
+
let text2 = "", tl = lineOf7(i);
|
|
31479
32277
|
const flush = () => {
|
|
31480
32278
|
if (text2.trim()) out.push(textNode(text2, tl));
|
|
31481
32279
|
text2 = "";
|
|
@@ -31502,17 +32300,17 @@ function parseTemplate(html, fileSrc = null, offset = 0) {
|
|
|
31502
32300
|
flush();
|
|
31503
32301
|
const b = parseBlock();
|
|
31504
32302
|
if (b) out.push(b);
|
|
31505
|
-
tl =
|
|
32303
|
+
tl = lineOf7(i);
|
|
31506
32304
|
continue;
|
|
31507
32305
|
}
|
|
31508
32306
|
if (html[i] === "<" && /[A-Za-z]/.test(html[i + 1] ?? "")) {
|
|
31509
32307
|
flush();
|
|
31510
32308
|
const el = parseElement();
|
|
31511
32309
|
if (el) out.push(el);
|
|
31512
|
-
tl =
|
|
32310
|
+
tl = lineOf7(i);
|
|
31513
32311
|
continue;
|
|
31514
32312
|
}
|
|
31515
|
-
if (!text2) tl =
|
|
32313
|
+
if (!text2) tl = lineOf7(i);
|
|
31516
32314
|
text2 += html[i];
|
|
31517
32315
|
i++;
|
|
31518
32316
|
}
|
|
@@ -31531,7 +32329,7 @@ function parseTemplate(html, fileSrc = null, offset = 0) {
|
|
|
31531
32329
|
return { type: "text", parts, line };
|
|
31532
32330
|
};
|
|
31533
32331
|
const parseElement = () => {
|
|
31534
|
-
const line =
|
|
32332
|
+
const line = lineOf7(i);
|
|
31535
32333
|
const tm = /^<([A-Za-z][\w:-]*)/.exec(html.slice(i));
|
|
31536
32334
|
const tag = tm[1];
|
|
31537
32335
|
i += tm[0].length;
|
|
@@ -31577,7 +32375,7 @@ function parseTemplate(html, fileSrc = null, offset = 0) {
|
|
|
31577
32375
|
return { type: "el", tag, attrs, kids: kids2, line };
|
|
31578
32376
|
};
|
|
31579
32377
|
const parseBlock = () => {
|
|
31580
|
-
const line =
|
|
32378
|
+
const line = lineOf7(i);
|
|
31581
32379
|
const m = /^@(\w+)\s*(?:\(([^)]*(?:\([^)]*\)[^)]*)*)\))?\s*\{/.exec(html.slice(i));
|
|
31582
32380
|
if (!m) {
|
|
31583
32381
|
const e = html.indexOf("\n", i);
|
|
@@ -32555,7 +33353,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32555
33353
|
return { name, label: words15(name.replace(/^[_$]+|_$/g, "")), kind, start: said, line };
|
|
32556
33354
|
};
|
|
32557
33355
|
function curlyThings(src, file, language) {
|
|
32558
|
-
const
|
|
33356
|
+
const lineAt5 = lineFinder5(src);
|
|
32559
33357
|
const out = [];
|
|
32560
33358
|
const kw = {
|
|
32561
33359
|
java: /(?:^|\n)[ \t]*(?:@\w+(?:\([^)]*\))?\s*)*(?:(?:public|private|protected|static|final|abstract|sealed|non-sealed)\s+)*(class|enum|record)\s+(\w+)\s*(?:<[^>{]*>)?\s*(\([^)]*\))?[^{;]*\{/g,
|
|
@@ -32582,7 +33380,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32582
33380
|
kind: isEnum ? "choices" : isRecord ? "record" : "thing",
|
|
32583
33381
|
name,
|
|
32584
33382
|
file,
|
|
32585
|
-
lines: [
|
|
33383
|
+
lines: [lineAt5(declAt), lineAt5(close >= 0 ? close : m.index + head.length)],
|
|
32586
33384
|
...docAbove4(src, declAt) ? { doc: docAbove4(src, declAt) } : {},
|
|
32587
33385
|
knows: [],
|
|
32588
33386
|
choices: []
|
|
@@ -32650,7 +33448,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32650
33448
|
return out;
|
|
32651
33449
|
}
|
|
32652
33450
|
function goThings(src, file) {
|
|
32653
|
-
const
|
|
33451
|
+
const lineAt5 = lineFinder5(src);
|
|
32654
33452
|
const out = [];
|
|
32655
33453
|
const byName = /* @__PURE__ */ new Map();
|
|
32656
33454
|
for (const m of src.matchAll(/(?:^|\n)type\s+(\w+)\s+struct\s*\{/g)) {
|
|
@@ -32658,7 +33456,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32658
33456
|
const open = m.index + m[0].length - 1;
|
|
32659
33457
|
const close = braceEnd(src, open);
|
|
32660
33458
|
if (close < 0) continue;
|
|
32661
|
-
const t = { kind: "record", name: m[1], file, lines: [
|
|
33459
|
+
const t = { kind: "record", name: m[1], file, lines: [lineAt5(at2), lineAt5(close)], ...goDoc(src, at2, m[1]) ? { doc: goDoc(src, at2, m[1]) } : {}, knows: [], choices: [], memberRanges: [] };
|
|
32662
33460
|
for (const raw of src.slice(open + 1, close).split("\n")) {
|
|
32663
33461
|
const f = raw.replace(/\/\/.*$/, "").replace(/`[^`]*`/g, "").trim().match(/^([A-Za-z_]\w*(?:\s*,\s*[A-Za-z_]\w*)*)\s+(\S.*)$/);
|
|
32664
33462
|
if (f) for (const n of f[1].split(",")) t.knows.push(know(n.trim(), f[2].trim(), null, {}));
|
|
@@ -32673,7 +33471,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32673
33471
|
const open = src.indexOf("{", at2);
|
|
32674
33472
|
const close = open >= 0 ? braceEnd(src, open) : -1;
|
|
32675
33473
|
t.kind = "thing";
|
|
32676
|
-
t.memberRanges.push([
|
|
33474
|
+
t.memberRanges.push([lineAt5(at2), lineAt5(close >= 0 ? close : at2)]);
|
|
32677
33475
|
}
|
|
32678
33476
|
for (const m of src.matchAll(/func\s+New(\w+)\s*\(([^)]*)\)[^{]*\{/g)) {
|
|
32679
33477
|
const t = byName.get(m[1]);
|
|
@@ -32707,19 +33505,19 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32707
33505
|
const label = f[3] && /^"/.test(f[3].trim()) ? f[3].trim().slice(1, -1) : words15(f[1].replace(new RegExp(`^${name}`), "") || f[1]);
|
|
32708
33506
|
choices.push(label);
|
|
32709
33507
|
}
|
|
32710
|
-
if (choices.length) out.push({ kind: "choices", name, file, lines: [
|
|
33508
|
+
if (choices.length) out.push({ kind: "choices", name, file, lines: [lineAt5(at2), lineAt5(at2)], ...goDoc(src, at2, name) ? { doc: goDoc(src, at2, name) } : {}, knows: [], choices });
|
|
32711
33509
|
}
|
|
32712
33510
|
return out;
|
|
32713
33511
|
}
|
|
32714
33512
|
function rustThings(src, file) {
|
|
32715
|
-
const
|
|
33513
|
+
const lineAt5 = lineFinder5(src);
|
|
32716
33514
|
const out = [];
|
|
32717
33515
|
const byName = /* @__PURE__ */ new Map();
|
|
32718
33516
|
for (const m of src.matchAll(/(?:^|\n)[ \t]*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?(struct|enum)\s+(\w+)\s*(?:<[^>{]*>)?\s*(?:where[^{]*)?(\{|\(|;)/g)) {
|
|
32719
33517
|
const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
|
|
32720
33518
|
const doc = docAbove4(src, at2);
|
|
32721
33519
|
if (m[3] !== "{") {
|
|
32722
|
-
const t2 = { kind: "record", name: m[2], file, lines: [
|
|
33520
|
+
const t2 = { kind: "record", name: m[2], file, lines: [lineAt5(at2), lineAt5(at2)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
|
|
32723
33521
|
out.push(t2);
|
|
32724
33522
|
byName.set(m[2], t2);
|
|
32725
33523
|
continue;
|
|
@@ -32728,7 +33526,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32728
33526
|
const close = braceEnd(src, open);
|
|
32729
33527
|
if (close < 0) continue;
|
|
32730
33528
|
const body2 = ownLevel(src.slice(open + 1, close));
|
|
32731
|
-
const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [
|
|
33529
|
+
const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt5(at2), lineAt5(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
|
|
32732
33530
|
if (m[1] === "enum") {
|
|
32733
33531
|
for (const v of splitParams2(body2.replace(/\/\/[^\n]*/g, "").replace(/#\[[^\]]*\]/g, ""))) {
|
|
32734
33532
|
const n = v.trim().match(/^(\w+)/);
|
|
@@ -32752,7 +33550,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32752
33550
|
if (/\bfn\s+\w+\s*(?:<[^>]*>)?\s*\(\s*&?(?:mut\s+)?self\b/.test(src.slice(at2, close))) {
|
|
32753
33551
|
if (t.kind === "record") t.kind = "thing";
|
|
32754
33552
|
}
|
|
32755
|
-
t.memberRanges.push([
|
|
33553
|
+
t.memberRanges.push([lineAt5(at2), lineAt5(close)]);
|
|
32756
33554
|
const block = src.slice(at2, close);
|
|
32757
33555
|
const fnNew = block.match(/fn\s+new\s*\(([^)]*)\)[^{;]*\{/);
|
|
32758
33556
|
const fnOpen = fnNew ? fnNew.index + fnNew[0].length - 1 : -1;
|
|
@@ -32904,7 +33702,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32904
33702
|
}
|
|
32905
33703
|
function cThings(src, file) {
|
|
32906
33704
|
const code3 = src.replace(/^[ \t]*#.*(?:\\\r?\n.*)*$/gm, (m) => m.replace(/[^\n]/g, " "));
|
|
32907
|
-
const
|
|
33705
|
+
const lineAt5 = lineFinder5(code3);
|
|
32908
33706
|
const out = [];
|
|
32909
33707
|
for (const m of code3.matchAll(/(?:^|\n)[ \t]*(typedef\s+)?(struct|union|enum)\b\s*(\w+)?\s*\{/g)) {
|
|
32910
33708
|
const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
|
|
@@ -32915,7 +33713,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32915
33713
|
const name = alias || m[3];
|
|
32916
33714
|
if (!name) continue;
|
|
32917
33715
|
const doc = cDocAbove(code3, at2);
|
|
32918
|
-
const t = { kind: m[2] === "enum" ? "choices" : "record", name, ...m[3] && m[3] !== name ? { tag: m[3] } : {}, file, lines: [
|
|
33716
|
+
const t = { kind: m[2] === "enum" ? "choices" : "record", name, ...m[3] && m[3] !== name ? { tag: m[3] } : {}, file, lines: [lineAt5(at2), lineAt5(close)], ...doc ? { doc } : {}, knows: [], choices: [] };
|
|
32919
33717
|
const body2 = code3.slice(open + 1, close);
|
|
32920
33718
|
if (m[2] === "enum") {
|
|
32921
33719
|
t.choices = enumNames(splitParams2(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "")).map((x) => (x.trim().match(/^(\w+)/) || [])[1]).filter(Boolean)).map((n) => words15(n));
|
|
@@ -32965,7 +33763,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32965
33763
|
}
|
|
32966
33764
|
function cppThings(src, file) {
|
|
32967
33765
|
const code3 = src.replace(/^[ \t]*#.*(?:\\\r?\n.*)*$/gm, (m) => m.replace(/[^\n]/g, " "));
|
|
32968
|
-
const
|
|
33766
|
+
const lineAt5 = lineFinder5(code3);
|
|
32969
33767
|
const out = [];
|
|
32970
33768
|
const byName = /* @__PURE__ */ new Map();
|
|
32971
33769
|
for (const m of code3.matchAll(/(?:^|\n)[ \t]*(?:template\s*<[^>{;]*>\s*)?(?:(class|struct|union)\s+(?:alignas\([^)]*\)\s*)?(?:[A-Z_][A-Z0-9_]*\s+)*(\w+)(?:\s+final)?\s*(?::[^{;]*)?|enum(?:\s+(?:class|struct))?\s+(\w+)(?:\s*:\s*[\w:]+)?\s*)\{/g)) {
|
|
@@ -32978,10 +33776,10 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
32978
33776
|
const body2 = code3.slice(open + 1, close);
|
|
32979
33777
|
if (m[3]) {
|
|
32980
33778
|
const vals = splitParams2(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "")).map((x) => (x.trim().match(/^(\w+)/) || [])[1]).filter(Boolean);
|
|
32981
|
-
out.push({ kind: "choices", name, file, lines: [
|
|
33779
|
+
out.push({ kind: "choices", name, file, lines: [lineAt5(at2), lineAt5(close)], ...doc ? { doc } : {}, knows: [], choices: enumNames(vals).map((n) => words15(n)) });
|
|
32982
33780
|
continue;
|
|
32983
33781
|
}
|
|
32984
|
-
const t = { kind: "record", name, file, lines: [
|
|
33782
|
+
const t = { kind: "record", name, file, lines: [lineAt5(at2), lineAt5(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
|
|
32985
33783
|
let methods = false;
|
|
32986
33784
|
const inits = {}, params = {};
|
|
32987
33785
|
for (const mem of members(body2)) {
|
|
@@ -33020,7 +33818,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
33020
33818
|
if (brace < 0 || semi >= 0 && semi < brace || /[()]/.test(code3.slice(pClose + 1, brace).replace(/:\s*[\s\S]*$/, ""))) continue;
|
|
33021
33819
|
methods = true;
|
|
33022
33820
|
const bClose = braceEnd(code3, brace);
|
|
33023
|
-
t.memberRanges.push([
|
|
33821
|
+
t.memberRanges.push([lineAt5(d.index), lineAt5(bClose >= 0 ? bClose : brace)]);
|
|
33024
33822
|
if (d[1] === name) cppCtor(code3.slice(pOpen + 1, pClose), (code3.slice(pClose + 1, brace).match(/^\s*(?:noexcept\s*)?:\s*([\s\S]+)$/) || [])[1], bClose > 0 ? code3.slice(brace + 1, bClose) : "", params, inits);
|
|
33025
33823
|
}
|
|
33026
33824
|
for (const k of t.knows) {
|
|
@@ -33051,7 +33849,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
33051
33849
|
for (const a of String(bodyText || "").matchAll(/(?:this->)?(\w+)\s*=\s*([^;\n]+);/g)) if (inits[a[1]] == null) inits[a[1]] = a[2];
|
|
33052
33850
|
}
|
|
33053
33851
|
function swiftThings(src, file) {
|
|
33054
|
-
const
|
|
33852
|
+
const lineAt5 = lineFinder5(src);
|
|
33055
33853
|
const out = [];
|
|
33056
33854
|
const byName = /* @__PURE__ */ new Map();
|
|
33057
33855
|
for (const m of src.matchAll(/(?:^|\n)[ \t]*(?:@\w+(?:\([^)\n]*\))?\s+)*(?:(?:public|private|internal|fileprivate|open|final|indirect|nonisolated)\s+)*(class|struct|enum|actor|protocol)\s+(\w+)(?:<[^>{\n]*>)?[ \t]*(?::[ \t]*([^{\n]+?))?[ \t]*\{/g)) {
|
|
@@ -33062,7 +33860,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
33062
33860
|
if (close < 0) continue;
|
|
33063
33861
|
const doc = docAbove4(src, at2);
|
|
33064
33862
|
const body2 = src.slice(open + 1, close);
|
|
33065
|
-
const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [
|
|
33863
|
+
const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt5(at2), lineAt5(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
|
|
33066
33864
|
const mems = members(body2, { newlines: true });
|
|
33067
33865
|
if (m[1] === "enum") {
|
|
33068
33866
|
for (const { head } of mems) {
|
|
@@ -33111,7 +33909,7 @@ function makeThingReaders({ words: words15, kindWords: kindWords3, startValue: s
|
|
|
33111
33909
|
const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
|
|
33112
33910
|
const close = braceEnd(src, m.index + m[0].length - 1);
|
|
33113
33911
|
if (close < 0) continue;
|
|
33114
|
-
t.memberRanges.push([
|
|
33912
|
+
t.memberRanges.push([lineAt5(at2), lineAt5(close)]);
|
|
33115
33913
|
if (t.kind === "record" && /(?:^|\s)func\s/.test(src.slice(at2, close))) t.kind = "thing";
|
|
33116
33914
|
}
|
|
33117
33915
|
return out;
|
|
@@ -36397,13 +37195,13 @@ var Analyzer = class {
|
|
|
36397
37195
|
const sawRecord = data.some((a) => a.recs?.length || a.recFields?.length);
|
|
36398
37196
|
const sawCaller = data.some((a) => a.ident?.length);
|
|
36399
37197
|
const sawInput = data.some((a) => a.input?.length || a.unknown?.length);
|
|
36400
|
-
const
|
|
36401
|
-
if ((sawRecord || sawCaller) && (GUARDISH.test(
|
|
37198
|
+
const baseName2 = String(name).split(".").pop();
|
|
37199
|
+
if ((sawRecord || sawCaller) && (GUARDISH.test(baseName2) || sawRecord && sawCaller)) st.unresolved = uniq(st.unresolved, [{ ...ev, says: `${name}(\u2026) might check who may see it` }]);
|
|
36402
37200
|
const out = joinAll(data.map(dataOf));
|
|
36403
|
-
if (sawCaller && !GUARDISH.test(
|
|
37201
|
+
if (sawCaller && !GUARDISH.test(baseName2)) out.clientFor = { says: `${name}(\u2026)`, file: ctx.file, line };
|
|
36404
37202
|
const parts = String(name).split(".");
|
|
36405
37203
|
const ownerName = parts.length > 1 ? parts[parts.length - 2] : "";
|
|
36406
|
-
const dataLike = name !== "fetch" && !NOT_DATA_PACKAGE.test(calleeVal?.pkg ?? "") && !["path", "fs", "os", "url", "crypto", "util", "process", "console", "JSON", "Math", "Date", BUF].includes(parts[0]) && (LOOKUP_NAME.test(
|
|
37204
|
+
const dataLike = name !== "fetch" && !NOT_DATA_PACKAGE.test(calleeVal?.pkg ?? "") && !["path", "fs", "os", "url", "crypto", "util", "process", "console", "JSON", "Math", "Date", BUF].includes(parts[0]) && (LOOKUP_NAME.test(baseName2) || parts.length > 1 && LOOKUP_OWNER.test(ownerName) && !/^(set|add|log|emit|send|push|on|use)$/.test(baseName2));
|
|
36407
37205
|
if ((sawInput || calleeVal?.recs?.length) && dataLike) out.unknown = uniq(out.unknown, [{ ...ev, says: `${name}(\u2026)` }]);
|
|
36408
37206
|
if (calleeVal && hasData(calleeVal)) return join2(out, dataOf(calleeVal));
|
|
36409
37207
|
return out;
|
|
@@ -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,17 +40892,229 @@ 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
|
+
}
|
|
40942
|
+
|
|
40943
|
+
// src/trace-data.mjs
|
|
40944
|
+
var lineAt4 = (text2, index) => {
|
|
40945
|
+
let n = 1;
|
|
40946
|
+
for (let i = 0; i < index && i < text2.length; i++) if (text2.charCodeAt(i) === 10) n++;
|
|
40947
|
+
return n;
|
|
40948
|
+
};
|
|
40949
|
+
var lineOf6 = (text2, re) => {
|
|
40950
|
+
const lines = text2.split("\n");
|
|
40951
|
+
for (let i = 0; i < lines.length; i++) if (re.test(lines[i])) return i + 1;
|
|
40952
|
+
return null;
|
|
40953
|
+
};
|
|
40954
|
+
var esc = (s) => s.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
40955
|
+
var baseName = (path) => path.split("/").pop();
|
|
40956
|
+
var dirOf4 = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
40957
|
+
function isManifest(path) {
|
|
40958
|
+
const n = baseName(path);
|
|
40959
|
+
return n === "package.json" || n === "go.mod" || n === "requirements.txt" || /\.csproj$/i.test(n);
|
|
40960
|
+
}
|
|
40961
|
+
function packagesIn(files) {
|
|
40962
|
+
const publishes = [], depends = [];
|
|
40963
|
+
for (const f of files) {
|
|
40964
|
+
if (!isManifest(f.path)) continue;
|
|
40965
|
+
const text2 = String(f.source ?? "");
|
|
40966
|
+
const n = baseName(f.path);
|
|
40967
|
+
try {
|
|
40968
|
+
if (n === "package.json") {
|
|
40969
|
+
const j = JSON.parse(text2);
|
|
40970
|
+
if (typeof j.name === "string" && j.name.trim()) publishes.push({ package: j.name, ...j.version ? { version: String(j.version) } : {}, file: f.path, line: lineOf6(text2, /^\s*"name"\s*:/), root: dirOf4(f.path) });
|
|
40971
|
+
for (const k of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
40972
|
+
for (const [name, version] of Object.entries(j[k] ?? {})) {
|
|
40973
|
+
depends.push({ package: name, version: String(version), ...k === "devDependencies" ? { dev: true } : {}, ...k === "peerDependencies" ? { peer: true } : {}, file: f.path, line: lineOf6(text2, new RegExp(`^\\s*"${esc(name)}"\\s*:`)) });
|
|
40974
|
+
}
|
|
40975
|
+
}
|
|
40976
|
+
} else if (n === "go.mod") {
|
|
40977
|
+
const lines = text2.split("\n");
|
|
40978
|
+
let inRequire = false;
|
|
40979
|
+
lines.forEach((raw, i) => {
|
|
40980
|
+
const line = raw.replace(/\/\/.*$/, "").trim();
|
|
40981
|
+
let m;
|
|
40982
|
+
if (m = line.match(/^module\s+(\S+)/)) publishes.push({ package: m[1], file: f.path, line: i + 1, root: dirOf4(f.path) });
|
|
40983
|
+
else if (/^require\s*\($/.test(line)) inRequire = true;
|
|
40984
|
+
else if (inRequire && line === ")") inRequire = false;
|
|
40985
|
+
else if (m = inRequire ? line.match(/^(\S+)\s+(v\S+)/) : line.match(/^require\s+(\S+)\s+(v\S+)/)) depends.push({ package: m[1], version: m[2], file: f.path, line: i + 1 });
|
|
40986
|
+
});
|
|
40987
|
+
} else if (n === "requirements.txt") {
|
|
40988
|
+
text2.split("\n").forEach((raw, i) => {
|
|
40989
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
40990
|
+
if (!line || line.startsWith("-")) return;
|
|
40991
|
+
const m = line.match(/^([A-Za-z0-9][A-Za-z0-9_.-]*)(?:\[[^\]]*\])?\s*(.*)$/);
|
|
40992
|
+
if (m) depends.push({ package: m[1].toLowerCase().replace(/_/g, "-"), ...m[2] ? { version: m[2].replace(/\s*;.*$/, "").trim() } : {}, file: f.path, line: i + 1 });
|
|
40993
|
+
});
|
|
40994
|
+
} else {
|
|
40995
|
+
for (const m of text2.matchAll(/<PackageReference\s+Include="([^"]+)"(?:\s+Version="([^"]+)")?/g)) depends.push({ package: m[1], ...m[2] ? { version: m[2] } : {}, file: f.path, line: lineAt4(text2, m.index) });
|
|
40996
|
+
const id2 = text2.match(/<PackageId>\s*([^<\s]+)\s*<\/PackageId>/);
|
|
40997
|
+
if (id2) publishes.push({ package: id2[1], file: f.path, line: lineAt4(text2, id2.index), root: dirOf4(f.path) });
|
|
40998
|
+
}
|
|
40999
|
+
} catch {
|
|
41000
|
+
}
|
|
41001
|
+
}
|
|
41002
|
+
return { publishes, depends };
|
|
41003
|
+
}
|
|
41004
|
+
var LOCAL_VERSION = /^(workspace:|file:|link:|portal:|\.{0,2}\/|git\+|github:|https?:)/;
|
|
41005
|
+
var KEY = "([A-Za-z_][A-Za-z0-9_]*)";
|
|
41006
|
+
var Q = `["'\`]`;
|
|
41007
|
+
var SETTING_READS = [
|
|
41008
|
+
new RegExp(`\\bprocess\\.env\\.${KEY}`, "g"),
|
|
41009
|
+
new RegExp(`\\bprocess\\.env\\[\\s*${Q}${KEY}${Q}\\s*\\]`, "g"),
|
|
41010
|
+
new RegExp(`\\bimport\\.meta\\.env\\.${KEY}`, "g"),
|
|
41011
|
+
new RegExp(`\\bDeno\\.env\\.get\\(\\s*${Q}${KEY}${Q}`, "g"),
|
|
41012
|
+
new RegExp(`\\b(?:os\\.)?environ(?:\\.get)?\\s*[\\[(]\\s*${Q}${KEY}${Q}`, "g"),
|
|
41013
|
+
new RegExp(`\\bos\\.getenv\\(\\s*${Q}${KEY}${Q}`, "g"),
|
|
41014
|
+
new RegExp(`\\bos\\.(?:Getenv|LookupEnv)\\(\\s*"${KEY}"`, "g"),
|
|
41015
|
+
new RegExp(`\\bSystem\\.getenv\\(\\s*"${KEY}"`, "g"),
|
|
41016
|
+
new RegExp(`\\bEnvironment\\.GetEnvironmentVariable\\(\\s*"${KEY}"`, "g"),
|
|
41017
|
+
new RegExp(`\\bENV(?:\\.fetch\\(\\s*|\\[\\s*)${Q}${KEY}${Q}`, "g"),
|
|
41018
|
+
new RegExp(`\\benv::var(?:_os)?\\(\\s*"${KEY}"`, "g"),
|
|
41019
|
+
new RegExp(`\\bgetenv\\(\\s*${Q}${KEY}${Q}`, "g"),
|
|
41020
|
+
new RegExp(`\\$_ENV\\[\\s*${Q}${KEY}${Q}`, "g")
|
|
41021
|
+
];
|
|
41022
|
+
var isGenericSetting = (key) => GENERIC_SETTINGS.has(key) || /^(VERCEL_|EAS_BUILD|GITHUB_|RUNNER_|npm_|NETLIFY|RENDER_|RAILWAY_|FLY_|HEROKU_|AWS_LAMBDA_|K_SERVICE|KUBERNETES_)/.test(key);
|
|
41023
|
+
var GENERIC_SETTINGS = /* @__PURE__ */ new Set(["NODE_ENV", "PORT", "HOST", "HOSTNAME", "HOME", "PATH", "PWD", "USER", "SHELL", "TMPDIR", "TEMP", "TMP", "TZ", "LANG", "CI", "DEBUG", "ENV", "ENVIRONMENT", "APP_ENV", "LOG_LEVEL", "LOGLEVEL", "VERBOSE", "GITHUB_ACTIONS", "npm_package_version", "ASPNETCORE_ENVIRONMENT", "DOTNET_ENVIRONMENT", "PYTHONPATH", "GOPATH", "JAVA_HOME", "NODE_OPTIONS", "CI_COMMIT_SHA"]);
|
|
41024
|
+
function settingsIn(files) {
|
|
41025
|
+
const out = [];
|
|
41026
|
+
for (const f of files) {
|
|
41027
|
+
if (isManifest(f.path) || /\.sql$/i.test(f.path)) continue;
|
|
41028
|
+
const text2 = String(f.source ?? "");
|
|
41029
|
+
if (!/env/i.test(text2)) continue;
|
|
41030
|
+
const seen = /* @__PURE__ */ new Set();
|
|
41031
|
+
for (const re of SETTING_READS) {
|
|
41032
|
+
for (const m of text2.matchAll(re)) {
|
|
41033
|
+
const line = lineAt4(text2, m.index);
|
|
41034
|
+
const k = `${m[1]}|${line}`;
|
|
41035
|
+
if (seen.has(k)) continue;
|
|
41036
|
+
seen.add(k);
|
|
41037
|
+
out.push({ key: m[1], file: f.path, line });
|
|
41038
|
+
}
|
|
41039
|
+
}
|
|
41040
|
+
}
|
|
41041
|
+
return out.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.key.localeCompare(b.key));
|
|
41042
|
+
}
|
|
41043
|
+
var NAME = '((?:[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?\\.){0,2}[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?)';
|
|
41044
|
+
var NOT_TABLES = /* @__PURE__ */ new Set(["select", "set", "where", "values", "dual", "lateral", "unnest", "only", "table", "if", "exists", "not", "the", "a", "an", "my", "your", "this", "that", "each", "all", "json_table", "information_schema", "pg_catalog", "sys"]);
|
|
41045
|
+
function tableName(raw) {
|
|
41046
|
+
const name = raw.replace(/[`"[\]]/g, "");
|
|
41047
|
+
return { table: name.split(".").pop().toLowerCase(), name };
|
|
41048
|
+
}
|
|
41049
|
+
function usesIn(sql, offsetOf, push) {
|
|
41050
|
+
const re = new RegExp(`\\b(DELETE\\s+FROM|INSERT\\s+(?:OR\\s+\\w+\\s+)?INTO|MERGE\\s+INTO|UPDATE|FROM|JOIN)\\s+${NAME}(\\s*\\()?`, "gi");
|
|
41051
|
+
for (const m of sql.matchAll(re)) {
|
|
41052
|
+
const kw = m[1].toUpperCase().replace(/\s+/g, " ");
|
|
41053
|
+
if (m[3] && (kw === "FROM" || kw === "JOIN")) continue;
|
|
41054
|
+
const { table, name } = tableName(m[2]);
|
|
41055
|
+
if (NOT_TABLES.has(table) || NOT_TABLES.has(name.toLowerCase())) continue;
|
|
41056
|
+
if (kw === "UPDATE" && (/\b(DO|FOR|KEY)\s*$/i.test(sql.slice(Math.max(0, m.index - 12), m.index)) || !/^\s*(?:(?:AS\s+)?\w+\s+)?SET\b/i.test(sql.slice(m.index + m[0].length)))) continue;
|
|
41057
|
+
push({ table, name, access: kw === "FROM" || kw === "JOIN" ? "reads" : "writes", at: offsetOf(m.index) });
|
|
41058
|
+
}
|
|
41059
|
+
}
|
|
41060
|
+
var SQL_SHAPES = [
|
|
41061
|
+
/^\s*SELECT\b[\s\S]*?\bFROM\s/i,
|
|
41062
|
+
/^\s*INSERT\s+(?:OR\s+\w+\s+)?INTO\s/i,
|
|
41063
|
+
/^\s*UPDATE\s+[\w."`[\]]+\s+(?:(?:AS\s+)?\w+\s+)?SET\s/i,
|
|
41064
|
+
/^\s*DELETE\s+FROM\s/i,
|
|
41065
|
+
/^\s*WITH\s+(?:RECURSIVE\s+)?\w+\s+AS\s*\(/i,
|
|
41066
|
+
/^\s*MERGE\s+INTO\s/i
|
|
41067
|
+
];
|
|
41068
|
+
var isSql = (text2) => SQL_SHAPES.some((re) => re.test(text2));
|
|
41069
|
+
var CODE_STRINGS = /"""([\s\S]*?)"""|'''([\s\S]*?)'''|`((?:\\[\s\S]|[^`\\])*)`|"((?:\\.|[^"\\\n])*)"|'((?:\\.|[^'\\\n])*)'/g;
|
|
41070
|
+
function tablesIn(files) {
|
|
41071
|
+
const out = [];
|
|
41072
|
+
for (const f of files) {
|
|
41073
|
+
if (isManifest(f.path)) continue;
|
|
41074
|
+
const text2 = String(f.source ?? "");
|
|
41075
|
+
const push = (u) => out.push({ table: u.table, name: u.name, access: u.access, file: f.path, line: lineAt4(text2, u.at), ...u.end != null ? { lines: [lineAt4(text2, u.at), lineAt4(text2, u.end)] } : {} });
|
|
41076
|
+
if (/\.sql$/i.test(f.path)) {
|
|
41077
|
+
const clean = text2.replace(/--[^\n]*/g, (s) => " ".repeat(s.length)).replace(/\/\*[\s\S]*?\*\//g, (s) => s.replace(/[^\n]/g, " "));
|
|
41078
|
+
const ddl = new RegExp(`\\b(CREATE(?:\\s+OR\\s+REPLACE)?(?:\\s+(?:TEMP|TEMPORARY|UNLOGGED|GLOBAL|LOCAL))*\\s+TABLE|ALTER\\s+TABLE|DROP\\s+TABLE)(?:\\s+IF\\s+(?:NOT\\s+)?EXISTS)?(?:\\s+ONLY)?\\s+${NAME}`, "gi");
|
|
41079
|
+
const ddlSpans = [];
|
|
41080
|
+
for (const m of clean.matchAll(ddl)) {
|
|
41081
|
+
const { table, name } = tableName(m[2]);
|
|
41082
|
+
if (NOT_TABLES.has(table)) continue;
|
|
41083
|
+
const kw = m[1].toUpperCase();
|
|
41084
|
+
if (/TEMP/.test(kw)) continue;
|
|
41085
|
+
const end2 = clean.indexOf(";", m.index);
|
|
41086
|
+
const stop = end2 < 0 ? clean.length : end2;
|
|
41087
|
+
ddlSpans.push([m.index, stop]);
|
|
41088
|
+
push({ table, name, access: kw.startsWith("CREATE") ? "creates" : kw.startsWith("ALTER") ? "alters" : "drops", at: m.index, end: stop });
|
|
41089
|
+
}
|
|
41090
|
+
const roles = [...clean.matchAll(/\b(?:GRANT|REVOKE)\b[^;]*/gi)].map((m) => [m.index, m.index + m[0].length]);
|
|
41091
|
+
const skip = [...ddlSpans, ...roles];
|
|
41092
|
+
usesIn(clean, (i) => i, (u) => {
|
|
41093
|
+
if (!skip.some(([a, b]) => u.at >= a && u.at <= b)) push(u);
|
|
41094
|
+
});
|
|
41095
|
+
continue;
|
|
41096
|
+
}
|
|
41097
|
+
if (!/\b(SELECT|INSERT|UPDATE|DELETE|MERGE)\b/i.test(text2)) continue;
|
|
41098
|
+
for (const m of text2.matchAll(CODE_STRINGS)) {
|
|
41099
|
+
const body2 = m[1] ?? m[2] ?? m[3] ?? m[4] ?? m[5] ?? "";
|
|
41100
|
+
if (!isSql(body2)) continue;
|
|
41101
|
+
const start = m.index + m[0].indexOf(body2);
|
|
41102
|
+
usesIn(body2, (i) => start + i, push);
|
|
41103
|
+
}
|
|
41104
|
+
}
|
|
41105
|
+
const seen = /* @__PURE__ */ new Set();
|
|
41106
|
+
return out.filter((t) => {
|
|
41107
|
+
const k = `${t.file}|${t.line}|${t.table}|${t.access}`;
|
|
41108
|
+
if (seen.has(k)) return false;
|
|
41109
|
+
seen.add(k);
|
|
41110
|
+
return true;
|
|
41111
|
+
}).sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.table.localeCompare(b.table));
|
|
41112
|
+
}
|
|
41113
|
+
var DEFINES = /* @__PURE__ */ new Set(["creates", "alters", "drops"]);
|
|
40040
41114
|
|
|
40041
41115
|
// src/trace.mjs
|
|
40042
41116
|
var TRACE_SCHEMA = "thunder-trace-v1";
|
|
40043
|
-
var TRACE_RULES_VERSION = "
|
|
41117
|
+
var TRACE_RULES_VERSION = "2";
|
|
40044
41118
|
function isTestFile(file) {
|
|
40045
41119
|
return /(^|\/)(tests?|__tests__|specs?|__mocks__|mocks?|fixtures?|__fixtures__|e2e|testdata|test-data)\//i.test(file) || /\.(test|spec|e2e)\.[a-z0-9]+$/i.test(file) || /(^|\/)test_[^/]+\.py$/.test(file) || /_test\.(go|py|rb|exs?)$/.test(file) || /(Tests?|Spec|IT)\.(cs|java|kt|scala)$/.test(file);
|
|
40046
41120
|
}
|
|
@@ -40060,7 +41134,8 @@ function buildTrace(repos) {
|
|
|
40060
41134
|
const model = thunderModel(r.files, { name: r.name });
|
|
40061
41135
|
const facts = serviceFacts(model, r.files);
|
|
40062
41136
|
const real = (x) => !isTestFile(x.file);
|
|
40063
|
-
const
|
|
41137
|
+
const data = dataFacts(r.files, model);
|
|
41138
|
+
const testItems = ["routes", "listeners", "requests", "publishes"].reduce((n, k) => n + facts[k].filter((x) => !real(x)).length, 0) + data.testItems;
|
|
40064
41139
|
return {
|
|
40065
41140
|
name: r.name,
|
|
40066
41141
|
sha: r.sha ?? null,
|
|
@@ -40072,11 +41147,35 @@ function buildTrace(repos) {
|
|
|
40072
41147
|
requests: facts.requests.filter(real),
|
|
40073
41148
|
publishes: facts.publishes.filter(real),
|
|
40074
41149
|
unknown: facts.unknown.filter(real),
|
|
41150
|
+
packages: data.packages,
|
|
41151
|
+
settings: data.settings,
|
|
41152
|
+
tables: data.tables,
|
|
40075
41153
|
testItems
|
|
40076
41154
|
};
|
|
40077
41155
|
});
|
|
40078
41156
|
return linkRepos(read);
|
|
40079
41157
|
}
|
|
41158
|
+
function memberAt(model, file, line) {
|
|
41159
|
+
let best = null;
|
|
41160
|
+
for (const m of model.members) {
|
|
41161
|
+
if (m.file !== file || !m.lines || line < m.lines[0] || line > m.lines[1]) continue;
|
|
41162
|
+
if (!best || m.lines[1] - m.lines[0] < best.lines[1] - best.lines[0]) best = m;
|
|
41163
|
+
}
|
|
41164
|
+
return best ? { member: best.id, label: best.label } : { member: null, label: file.split("/").pop() };
|
|
41165
|
+
}
|
|
41166
|
+
function dataFacts(files, model) {
|
|
41167
|
+
const real = (x) => !isTestFile(x.file);
|
|
41168
|
+
const pk = packagesIn(files), settings = settingsIn(files), tables = tablesIn(files);
|
|
41169
|
+
const place = (x) => ({ ...x, ...memberAt(model, x.file, x.line) });
|
|
41170
|
+
const manifest = (x) => ({ ...x, member: null, label: x.file });
|
|
41171
|
+
const testItems = [...pk.publishes, ...pk.depends, ...settings, ...tables].filter((x) => !real(x)).length;
|
|
41172
|
+
return {
|
|
41173
|
+
packages: { publishes: pk.publishes.filter(real).map(manifest), depends: pk.depends.filter(real).map(manifest) },
|
|
41174
|
+
settings: settings.filter(real).map(place),
|
|
41175
|
+
tables: tables.filter(real).map((t) => /\.sql$/i.test(t.file) ? { ...t, member: null, label: t.file } : place(t)),
|
|
41176
|
+
testItems
|
|
41177
|
+
};
|
|
41178
|
+
}
|
|
40080
41179
|
function linkRepos(read) {
|
|
40081
41180
|
const links = [], notLinked = [];
|
|
40082
41181
|
for (const repo of read) {
|
|
@@ -40118,7 +41217,33 @@ function linkRepos(read) {
|
|
|
40118
41217
|
if (!found) notLinked.push({ kind: "event", call: `event ${p.event}`, from, why: `no listener Thunder read in the traced repositories waits for ${p.event}` });
|
|
40119
41218
|
}
|
|
40120
41219
|
}
|
|
40121
|
-
const
|
|
41220
|
+
const pk = (r) => r.packages ?? { publishes: [], depends: [] };
|
|
41221
|
+
const publishers = /* @__PURE__ */ new Map();
|
|
41222
|
+
for (const repo of read) for (const p of pk(repo).publishes) (publishers.get(p.package) ?? publishers.set(p.package, []).get(p.package)).push({ repo, p });
|
|
41223
|
+
for (const repo of read) {
|
|
41224
|
+
const own = new Set(pk(repo).publishes.map((p) => p.package));
|
|
41225
|
+
for (const d of pk(repo).depends) {
|
|
41226
|
+
if (own.has(d.package)) continue;
|
|
41227
|
+
const pubs = (publishers.get(d.package) ?? []).filter((x) => x.repo !== repo);
|
|
41228
|
+
const byRepo = [...new Map(pubs.map((x) => [x.repo.name, x])).values()];
|
|
41229
|
+
if (byRepo.length === 1) links.push({ kind: "package", package: d.package, version: d.version ?? null, ...d.dev ? { dev: true } : {}, from: end(repo, d), to: end(byRepo[0].repo, byRepo[0].p) });
|
|
41230
|
+
else if (byRepo.length > 1) notLinked.push({ kind: "package", call: `package ${d.package}`, from: end(repo, d), why: `${byRepo.length} repositories publish ${d.package} (${byRepo.map((x) => x.repo.name).join(", ")}), so none is chosen` });
|
|
41231
|
+
}
|
|
41232
|
+
}
|
|
41233
|
+
const tb = (r) => r.tables ?? [];
|
|
41234
|
+
const creators = /* @__PURE__ */ new Map();
|
|
41235
|
+
for (const repo of read) for (const t of tb(repo)) if (t.access === "creates") (creators.get(t.table) ?? creators.set(t.table, []).get(t.table)).push({ repo, t });
|
|
41236
|
+
for (const repo of read) {
|
|
41237
|
+
const own = new Set(tb(repo).filter((t) => t.access === "creates").map((t) => t.table));
|
|
41238
|
+
for (const t of tb(repo)) {
|
|
41239
|
+
if (DEFINES.has(t.access) || own.has(t.table)) continue;
|
|
41240
|
+
const owners = [...new Map((creators.get(t.table) ?? []).filter((x) => x.repo !== repo).map((x) => [x.repo.name, x])).values()];
|
|
41241
|
+
if (owners.length === 1) links.push({ kind: "data", table: t.table, access: t.access, from: end(repo, t), to: end(owners[0].repo, owners[0].t) });
|
|
41242
|
+
else if (owners.length > 1) notLinked.push({ kind: "data", call: `table ${t.name}`, from: end(repo, t), why: `${owners.length} repositories create a table named ${t.table} (${owners.map((x) => x.repo.name).join(", ")}), so none is chosen` });
|
|
41243
|
+
}
|
|
41244
|
+
}
|
|
41245
|
+
const shared = sharedFacts(read);
|
|
41246
|
+
const sortKey = (l) => `${l.from.cite}|${l.to?.cite ?? ""}|${l.kind}|${l.call ?? l.event ?? l.path ?? l.package ?? l.table ?? ""}`;
|
|
40122
41247
|
const once = (xs) => {
|
|
40123
41248
|
const seen = /* @__PURE__ */ new Set();
|
|
40124
41249
|
return xs.filter((x) => {
|
|
@@ -40130,24 +41255,43 @@ function linkRepos(read) {
|
|
|
40130
41255
|
};
|
|
40131
41256
|
links.splice(0, links.length, ...once(links).sort((a, b) => sortKey(a).localeCompare(sortKey(b))));
|
|
40132
41257
|
notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => sortKey(a).localeCompare(sortKey(b))));
|
|
40133
|
-
const repos = read.map(({ unknown, ...r }) => ({ ...r, unknown: unknown ?? [] }));
|
|
40134
|
-
const body2 = { schema: TRACE_SCHEMA, rulesVersion: TRACE_RULES_VERSION, repos, links, notLinked };
|
|
41258
|
+
const repos = read.map(({ unknown, ...r }) => ({ ...r, unknown: unknown ?? [], packages: pk(r), settings: r.settings ?? [], tables: tb(r) }));
|
|
41259
|
+
const body2 = { schema: TRACE_SCHEMA, rulesVersion: TRACE_RULES_VERSION, repos, links, notLinked, shared };
|
|
40135
41260
|
return { ...body2, fingerprint: sha256(JSON.stringify(body2)) };
|
|
40136
41261
|
}
|
|
41262
|
+
function sharedFacts(read) {
|
|
41263
|
+
const group = (items) => {
|
|
41264
|
+
const m = /* @__PURE__ */ new Map();
|
|
41265
|
+
for (const [k, repo, x] of items) (m.get(k) ?? m.set(k, []).get(k)).push({ repo, x });
|
|
41266
|
+
return m;
|
|
41267
|
+
};
|
|
41268
|
+
const manyRepos = (xs) => new Set(xs.map((y) => y.repo.name)).size > 1;
|
|
41269
|
+
const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
41270
|
+
const settings = [...group(read.flatMap((r) => (r.settings ?? []).filter((x) => !isGenericSetting(x.key)).map((x) => [x.key, r, x]))).entries()].filter(([, xs]) => manyRepos(xs)).sort(byKey).map(([key, xs]) => ({ key, readers: xs.map(({ repo, x }) => end(repo, x)) }));
|
|
41271
|
+
const tables = [...group(read.flatMap((r) => (r.tables ?? []).map((x) => [x.table, r, x]))).entries()].filter(([, xs]) => manyRepos(xs)).sort(byKey).map(([table, xs]) => ({ table, users: xs.map(({ repo, x }) => ({ ...end(repo, x), access: x.access })) }));
|
|
41272
|
+
const drift = [];
|
|
41273
|
+
for (const [name, xs] of [...group(read.flatMap((r) => (r.packages?.depends ?? []).filter((d) => d.version && !d.peer && !LOCAL_VERSION.test(d.version)).map((d) => [d.package, r, d]))).entries()].sort(byKey)) {
|
|
41274
|
+
const versions = group(xs.map(({ repo, x }) => [x.version, repo, x]));
|
|
41275
|
+
const perRepo = new Set([...group(xs.map(({ repo, x }) => [repo.name, repo, x])).values()].map((ys) => [...new Set(ys.map((y) => y.x.version))].sort().join("|")));
|
|
41276
|
+
if (!manyRepos(xs) || versions.size < 2 || perRepo.size < 2) continue;
|
|
41277
|
+
drift.push({ package: name, versions: [...versions.entries()].sort(byKey).map(([version, ys]) => ({ version, at: ys.map(({ repo, x }) => end(repo, x)) })) });
|
|
41278
|
+
}
|
|
41279
|
+
return { settings, tables, drift };
|
|
41280
|
+
}
|
|
40137
41281
|
var methodOk = (route, req) => route === req || route === "ANY" || route === "ALL";
|
|
40138
41282
|
|
|
40139
41283
|
// src/write-across.mjs
|
|
40140
41284
|
var WRITE_ACROSS_SCHEMA = "thunder-write-across-v1";
|
|
40141
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();
|
|
40142
41286
|
var editable2 = (t) => t.t === "num" || t.t === "str" || t.t === "op" && ["<", "<=", ">", ">=", "==", "!="].includes(t.v);
|
|
40143
|
-
var
|
|
41287
|
+
var keyOf2 = (t) => t.t === "id" ? `id:${words13(t.v)}` : t.t === "str" ? `str:${JSON.stringify(t.v)}` : `${t.t}:${t.v}`;
|
|
40144
41288
|
var shapeOf = (t) => t.t === "id" ? "id" : editable2(t) ? t.t === "op" ? "cmp" : t.t : `${t.t}:${t.v}`;
|
|
40145
41289
|
var join3 = (toks2) => toks2.map((t) => t.t === "str" ? JSON.stringify(t.v) : String(t.v)).join(" ");
|
|
40146
41290
|
var FILLER = /* @__PURE__ */ new Set(["get", "is", "has", "can", "should", "calc", "calculate", "compute", "check", "find", "the", "a", "an", "of", "for", "to", "by"]);
|
|
40147
|
-
var
|
|
41291
|
+
var nameWords3 = (name) => new Set(words13(name).split(" ").filter((w) => w && !FILLER.has(w)));
|
|
40148
41292
|
var sharesWord = (a, b) => {
|
|
40149
|
-
const A =
|
|
40150
|
-
return [...
|
|
41293
|
+
const A = nameWords3(a);
|
|
41294
|
+
return [...nameWords3(b)].some((w) => A.has(w));
|
|
40151
41295
|
};
|
|
40152
41296
|
var toks = (when) => {
|
|
40153
41297
|
try {
|
|
@@ -40188,14 +41332,14 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40188
41332
|
}
|
|
40189
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}".`] };
|
|
40190
41334
|
const anchor = anchors[0];
|
|
40191
|
-
const key = anchor.toks.map(
|
|
41335
|
+
const key = anchor.toks.map(keyOf2).join(" ");
|
|
40192
41336
|
const shape = anchor.toks.map(shapeOf).join(" ");
|
|
40193
|
-
const names = anchor.toks.filter((t) => t.t === "id").map(
|
|
40194
|
-
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(" ");
|
|
40195
41339
|
const same = [], notIncluded = [];
|
|
40196
41340
|
for (const x of all) {
|
|
40197
41341
|
if (x === anchor) continue;
|
|
40198
|
-
const k = x.toks.map(
|
|
41342
|
+
const k = x.toks.map(keyOf2).join(" ");
|
|
40199
41343
|
const said = sayCondition(x.when);
|
|
40200
41344
|
if (k === key) {
|
|
40201
41345
|
if (sharesWord(x.decision, anchor.decision)) same.push({ ...x, why: `the same condition: ${said} (names compared as words)` });
|
|
@@ -40203,8 +41347,8 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40203
41347
|
continue;
|
|
40204
41348
|
}
|
|
40205
41349
|
if (x.toks.map(shapeOf).join(" ") !== shape) continue;
|
|
40206
|
-
const xNames = x.toks.filter((t) => t.t === "id").map(
|
|
40207
|
-
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(" ");
|
|
40208
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` });
|
|
40209
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` });
|
|
40210
41354
|
}
|
|
@@ -40212,7 +41356,7 @@ function findSameRule(files, { decision, rule }) {
|
|
|
40212
41356
|
return { ok: true, anchor: strip(anchor), same: [anchor, ...same].map(strip), notIncluded: notIncluded.map(strip), problems: [] };
|
|
40213
41357
|
}
|
|
40214
41358
|
function testsMentioning(files, oldToks, newToks, functions) {
|
|
40215
|
-
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]));
|
|
40216
41360
|
if (!changed.length) return [];
|
|
40217
41361
|
const callsRule = (src) => (src.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? []).some((w) => functions.has(words13(w)));
|
|
40218
41362
|
const out = [];
|
|
@@ -40231,7 +41375,7 @@ function writeRuleAcross(files, { decision, rule, when }) {
|
|
|
40231
41375
|
if (!found.ok) return { ...base2, problems: found.problems };
|
|
40232
41376
|
const oldT = toks(found.anchor.when), newT = toks(when);
|
|
40233
41377
|
if (!newT) return { ...base2, problems: [`The new condition "${when}" could not be read.`] };
|
|
40234
|
-
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]))) {
|
|
40235
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.`] };
|
|
40236
41380
|
}
|
|
40237
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)))) };
|
|
@@ -40650,7 +41794,7 @@ function fileMatcher(model) {
|
|
|
40650
41794
|
return { file: found[0] };
|
|
40651
41795
|
};
|
|
40652
41796
|
}
|
|
40653
|
-
function
|
|
41797
|
+
function memberAt2(model, file, line) {
|
|
40654
41798
|
const hits = model.members.filter((m) => m.file === file && line >= m.lines[0] && line <= m.lines[1]);
|
|
40655
41799
|
return hits.sort((a, b) => a.lines[1] - a.lines[0] - (b.lines[1] - b.lines[0]))[0] ?? null;
|
|
40656
41800
|
}
|
|
@@ -40676,7 +41820,7 @@ function nodeAt(member, line, want) {
|
|
|
40676
41820
|
}
|
|
40677
41821
|
return null;
|
|
40678
41822
|
}
|
|
40679
|
-
function
|
|
41823
|
+
function sideOf2(node2, block, ev) {
|
|
40680
41824
|
if (node2.kind === "loop") return ev.side === "each" || ev.side === "held" ? { key: "each", label: "For each" } : { key: "done", label: "Done" };
|
|
40681
41825
|
if (node2.cases) {
|
|
40682
41826
|
const P = String(ev.side).startsWith("case:") ? Number(String(ev.side).slice(5)) : null;
|
|
@@ -40769,7 +41913,7 @@ function runtimeOverlay(model, evidence2 = []) {
|
|
|
40769
41913
|
file = got.file;
|
|
40770
41914
|
line = f.line ?? null;
|
|
40771
41915
|
if (ev.fnLine != null) member = model.members.filter((m) => m.file === file && m.lines[0] <= ev.fnLine && ev.fnLine <= Math.min(m.lines[1], m.lines[0] + 3) && (m.lines[0] === ev.fnLine || !fnStarts.has(`${file}|${m.lines[0]}`))).sort((a, b) => b.lines[0] - a.lines[0])[0] ?? null;
|
|
40772
|
-
else if (line != null && ev.kind !== "call") member =
|
|
41916
|
+
else if (line != null && ev.kind !== "call") member = memberAt2(model, file, line);
|
|
40773
41917
|
else if (ev.kind === "call" && ev.fnLine == null) {
|
|
40774
41918
|
if (line != null) {
|
|
40775
41919
|
const starts = model.members.filter((m) => m.file === file && m.lines[0] <= line && line <= m.lines[0] + 3).sort((a, b) => a.lines[0] - b.lines[0]);
|
|
@@ -40778,7 +41922,7 @@ function runtimeOverlay(model, evidence2 = []) {
|
|
|
40778
41922
|
const named2 = membersNamed(model, f.function, { file, namespace: ev.namespace });
|
|
40779
41923
|
if (named2.length === 1) member = named2[0];
|
|
40780
41924
|
}
|
|
40781
|
-
if (!member) member =
|
|
41925
|
+
if (!member) member = memberAt2(model, file, line);
|
|
40782
41926
|
} else if (f.function) {
|
|
40783
41927
|
const named2 = membersNamed(model, f.function, { file, namespace: ev.namespace });
|
|
40784
41928
|
if (named2.length === 1) member = named2[0];
|
|
@@ -40851,7 +41995,7 @@ function runtimeOverlay(model, evidence2 = []) {
|
|
|
40851
41995
|
nr.ran = (nr.ran || 0) + c;
|
|
40852
41996
|
continue;
|
|
40853
41997
|
}
|
|
40854
|
-
side2 ??=
|
|
41998
|
+
side2 ??= sideOf2(n, blockOf(member, n.id), ev);
|
|
40855
41999
|
if (!side2) {
|
|
40856
42000
|
unplaced(ev, `the case at line ${String(ev.side).slice(5)} is not one Thunder draws for "${n.text}"`);
|
|
40857
42001
|
continue;
|
|
@@ -41024,7 +42168,7 @@ function explainError(model, stack) {
|
|
|
41024
42168
|
placed.push({ frame: f });
|
|
41025
42169
|
continue;
|
|
41026
42170
|
}
|
|
41027
|
-
const m3 =
|
|
42171
|
+
const m3 = memberAt2(model, got.file, f.line);
|
|
41028
42172
|
if (!m3) {
|
|
41029
42173
|
reason ??= `line ${f.line} of ${got.file} is not inside any action or rule Thunder read`;
|
|
41030
42174
|
placed.push({ frame: f, file: got.file });
|
|
@@ -42025,7 +43169,7 @@ function countsLine(c) {
|
|
|
42025
43169
|
if (c.notRead) parts.push(`${plural5(c.notRead, "file")} Thunder does not read`);
|
|
42026
43170
|
return `${parts.join(" \xB7 ")}.`;
|
|
42027
43171
|
}
|
|
42028
|
-
var
|
|
43172
|
+
var esc2 = (s) => String(s).replace(/[<>]/g, (ch) => ch === "<" ? "<" : ">");
|
|
42029
43173
|
var fence2 = (lines) => ["```", ...lines.map((l) => l.replace(/```/g, "'''")), "```"];
|
|
42030
43174
|
var cutLines = (lines, max) => lines.length > max ? [...lines.slice(0, max), `\u2026 ${lines.length - max} more lines`] : lines;
|
|
42031
43175
|
function evidence(ev, maxLines) {
|
|
@@ -42043,7 +43187,7 @@ var HEADINGS = {
|
|
|
42043
43187
|
};
|
|
42044
43188
|
function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], footer = "", evidenceLines = 40 } = {}) {
|
|
42045
43189
|
const where2 = (w) => {
|
|
42046
|
-
const label = `\`${
|
|
43190
|
+
const label = `\`${esc2(w.file)}:${w.line}\``;
|
|
42047
43191
|
const url = fileUrl?.(w.file, w.line);
|
|
42048
43192
|
return url ? `[${label}](${url})` : label;
|
|
42049
43193
|
};
|
|
@@ -42064,12 +43208,12 @@ function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], fo
|
|
|
42064
43208
|
const close = sev === "form" ? ["</details>", ""] : [];
|
|
42065
43209
|
const memberBlocks = [...members.values()].map((xs) => {
|
|
42066
43210
|
const render = (compact2) => {
|
|
42067
|
-
const lines = [`- **${
|
|
43211
|
+
const lines = [`- **${esc2(xs[0].subject)}** \xB7 ${where2(xs[0].where)}`];
|
|
42068
43212
|
const list4 = compact2 ? xs.slice(0, COMPACT_SENTENCES) : xs;
|
|
42069
43213
|
for (const x of list4) {
|
|
42070
43214
|
const ev = sev === "form" ? [] : evidence(x.evidence, evidenceLines);
|
|
42071
43215
|
const at2 = x.where.line !== xs[0].where.line || x.where.file !== xs[0].where.file ? ` (${where2(x.where)})` : "";
|
|
42072
|
-
lines.push(` - ${
|
|
43216
|
+
lines.push(` - ${esc2(x.says)}${at2}${compact2 && (ev.length || x.also?.length) ? " _(Before and after, and other places: in the job summary.)_" : ""}`);
|
|
42073
43217
|
if (compact2) continue;
|
|
42074
43218
|
if (ev.length) lines.push("", ` <details><summary>Before and after</summary>`, "", ...ev.map((l) => l ? ` ${l}` : ""), "", " </details>", "");
|
|
42075
43219
|
if (x.also?.length) {
|
|
@@ -42077,7 +43221,7 @@ function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], fo
|
|
|
42077
43221
|
"",
|
|
42078
43222
|
` <details><summary>The same in ${x.also.length} more</summary>`,
|
|
42079
43223
|
"",
|
|
42080
|
-
...x.also.slice(0, 50).map((a) => ` - **${
|
|
43224
|
+
...x.also.slice(0, 50).map((a) => ` - **${esc2(a.subject)}** \xB7 ${where2(a.where)}`),
|
|
42081
43225
|
...x.also.length > 50 ? [` - and ${x.also.length - 50} more`] : [],
|
|
42082
43226
|
"",
|
|
42083
43227
|
" </details>",
|
|
@@ -42093,7 +43237,7 @@ function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], fo
|
|
|
42093
43237
|
blocks2.push({ open, close, members: memberBlocks });
|
|
42094
43238
|
}
|
|
42095
43239
|
const tail = [];
|
|
42096
|
-
if (r.notRead?.length) tail.push(`Also changed, not read by Thunder (check ${r.notRead.length === 1 ? "it" : "them"} yourself if ${r.notRead.length === 1 ? "it matters" : "they matter"}): ${r.notRead.slice(0, 20).map((f) => `\`${
|
|
43240
|
+
if (r.notRead?.length) tail.push(`Also changed, not read by Thunder (check ${r.notRead.length === 1 ? "it" : "them"} yourself if ${r.notRead.length === 1 ? "it matters" : "they matter"}): ${r.notRead.slice(0, 20).map((f) => `\`${esc2(f.path)}\``).join(", ")}${r.notRead.length > 20 ? `, and ${r.notRead.length - 20} more` : ""}.`, "");
|
|
42097
43241
|
const foot = ["---", `<sub>Read from the code by the Thunder compiler, with no AI and without running the code. "Only the form changed" is said only when it is shown. Thunder describes the change; a person still decides whether it is right. [How this works](${DOCS_URL}) \xB7 [thunderlang.dev](${SITE_URL})${footer ? ` \xB7 ${footer}` : ""}</sub>`, ""];
|
|
42098
43242
|
const size = (lines) => lines.join("\n").length + 1;
|
|
42099
43243
|
const total = r.items.length;
|
|
@@ -44433,19 +45577,19 @@ function universalPack() {
|
|
|
44433
45577
|
};
|
|
44434
45578
|
}
|
|
44435
45579
|
var confidenceFor = (rule) => rule.detection === "deterministic" ? "Observed" : "Inferred";
|
|
44436
|
-
function toFinding(
|
|
44437
|
-
const rule = fableRuleFor(
|
|
44438
|
-
const isBlocker =
|
|
45580
|
+
function toFinding(diag2, { file = null, index = 0, affectedNodes = [] } = {}) {
|
|
45581
|
+
const rule = fableRuleFor(diag2.code);
|
|
45582
|
+
const isBlocker = diag2.severity === "blocker";
|
|
44439
45583
|
return {
|
|
44440
|
-
findingId: `${(
|
|
45584
|
+
findingId: `${(diag2.code || "FINDING").toLowerCase()}-${file ? file.replace(/[^a-z0-9]+/gi, "-") : "x"}-${index}`,
|
|
44441
45585
|
ruleId: rule.ruleId,
|
|
44442
45586
|
ruleVersion: rule.ruleVersion,
|
|
44443
45587
|
category: rule.category,
|
|
44444
|
-
detected:
|
|
44445
|
-
why:
|
|
44446
|
-
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 }],
|
|
44447
45591
|
affectedNodes,
|
|
44448
|
-
severity: isBlocker ? "blocker" :
|
|
45592
|
+
severity: isBlocker ? "blocker" : diag2.level || "warning",
|
|
44449
45593
|
confidence: confidenceFor(rule),
|
|
44450
45594
|
detectionType: rule.detection,
|
|
44451
45595
|
potentialImpact: isBlocker ? "Blocks a phase (e.g. release) until resolved." : "Weakens the intent; not blocking.",
|
|
@@ -46016,7 +47160,8 @@ function assemblePassport({ parts, change = null, runs = [], purpose = null, ext
|
|
|
46016
47160
|
}
|
|
46017
47161
|
const shownBehavior = behavior.slice(0, MAX_BEHAVIOR);
|
|
46018
47162
|
const trace = buildTrace(parts.map((p) => ({ name: p.name, sha: p.sha ?? null, dirty: !!p.dirty, files: p.files.filter((f) => !f.manifest) })));
|
|
46019
|
-
const
|
|
47163
|
+
const linkSays = (l) => l.kind === "http" ? `${l.from.repo} calls ${l.to.repo}: ${l.method} ${l.path} (handled by ${l.to.label ?? l.route})` : l.kind === "event" ? `${l.from.repo} publishes ${l.event}, and ${l.to.repo} listens` : l.kind === "data" ? `${l.from.repo} ${l.access} the ${l.table} table, which ${l.to.repo} creates` : `${l.from.repo} depends on the package ${l.package}, which ${l.to.repo} publishes`;
|
|
47164
|
+
const links = trace.links.map((l) => ({ kind: l.kind, says: linkSays(l), from: l.from.cite, to: l.to.cite }));
|
|
46020
47165
|
const services = [];
|
|
46021
47166
|
for (const r of trace.repos) for (const q2 of r.requests ?? []) if (q2.base && q2.base !== "this app") services.push({ part: r.name, calls: `${q2.method} ${q2.base}${q2.path}`, at: `${r.name}:${q2.file}:${q2.line}` });
|
|
46022
47167
|
const evidence2 = [];
|
|
@@ -46037,7 +47182,7 @@ function assemblePassport({ parts, change = null, runs = [], purpose = null, ext
|
|
|
46037
47182
|
add({
|
|
46038
47183
|
kind: "trace-link",
|
|
46039
47184
|
status: "read",
|
|
46040
|
-
claim: l.kind === "http" ? `${l.from.repo} calls ${l.to.repo} with ${l.method} ${l.path}, and ${l.to.repo} handles it.` : `${l.from.repo} publishes "${l.event}", and ${l.to.repo} listens for it.`,
|
|
47185
|
+
claim: l.kind === "http" ? `${l.from.repo} calls ${l.to.repo} with ${l.method} ${l.path}, and ${l.to.repo} handles it.` : l.kind === "event" ? `${l.from.repo} publishes "${l.event}", and ${l.to.repo} listens for it.` : l.kind === "data" ? `${l.from.repo} ${l.access} the ${l.table} table, and ${l.to.repo} creates it.` : `${l.from.repo} depends on the package ${l.package}, and ${l.to.repo} publishes it.`,
|
|
46041
47186
|
basis: { from: l.from.cite, to: l.to.cite, rules: `thunder-trace rules v${trace.rulesVersion}` },
|
|
46042
47187
|
scope: "Read from code; nothing was run. It does not show that the call succeeds or what it answers.",
|
|
46043
47188
|
inputs: [inputOf(l.from.repo, l.from.file), inputOf(l.to.repo, l.to.file)]
|