@skillstech/thunderlang 0.5.4 → 0.5.6
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 +112 -0
- package/README.md +3 -0
- package/dist/core.cjs +2240 -424
- package/dist/index.cjs +1247 -113
- package/dist/learn.cjs +6066 -0
- package/package.json +10 -1
- package/src/cli.mjs +45 -2
- package/src/core.d.ts +14 -0
- package/src/core.mjs +8 -1
- package/src/emit.mjs +1 -1
- package/src/index.d.ts +3 -0
- package/src/index.mjs +3 -0
- package/src/learn-lessons.mjs +458 -0
- package/src/learn.d.mts +34 -0
- package/src/learn.mjs +77 -0
- package/src/model.d.mts +18 -0
- package/src/model.mjs +456 -0
- package/src/read.d.mts +25 -1
- package/src/read.mjs +280 -23
- package/src/same.d.mts +10 -0
- package/src/same.mjs +160 -0
- package/src/steps.mjs +351 -49
- package/src/thunder-repo.mjs +1 -1
- package/src/thunderize.d.mts +14 -0
- package/src/thunderize.mjs +82 -0
- package/src/visual.d.mts +40 -0
- package/src/visual.mjs +304 -0
package/dist/index.cjs
CHANGED
|
@@ -119,6 +119,8 @@ __export(index_exports, {
|
|
|
119
119
|
SUPPORTED_LANGUAGES: () => SUPPORTED_LANGUAGES,
|
|
120
120
|
SYNC_SCHEMA: () => SYNC_SCHEMA,
|
|
121
121
|
TEST_SCHEMA: () => TEST_SCHEMA,
|
|
122
|
+
THUNDER_TEXT_EXT: () => THUNDER_TEXT_EXT,
|
|
123
|
+
THUNDER_VISUAL: () => THUNDER_VISUAL,
|
|
122
124
|
TOKEN_PATHS: () => TOKEN_PATHS,
|
|
123
125
|
TWELVE_FACTOR_SCHEMA: () => TWELVE_FACTOR_SCHEMA,
|
|
124
126
|
UNSETTLED: () => UNSETTLED,
|
|
@@ -126,6 +128,7 @@ __export(index_exports, {
|
|
|
126
128
|
VERIFY_DIFF_SCHEMA: () => VERIFY_DIFF_SCHEMA,
|
|
127
129
|
VIEWS: () => VIEWS,
|
|
128
130
|
VIEW_SCHEMA: () => VIEW_SCHEMA,
|
|
131
|
+
VISUAL_SCHEMA: () => VISUAL_SCHEMA,
|
|
129
132
|
WRITE_SCHEMA: () => WRITE_SCHEMA,
|
|
130
133
|
acceptedRisks: () => acceptedRisks,
|
|
131
134
|
adoptRegion: () => adoptRegion,
|
|
@@ -279,6 +282,7 @@ __export(index_exports, {
|
|
|
279
282
|
renderMarker: () => renderMarker,
|
|
280
283
|
renderMermaid: () => renderMermaid,
|
|
281
284
|
renderReviewBrief: () => renderReviewBrief,
|
|
285
|
+
renderSame: () => renderSame,
|
|
282
286
|
renderTestplan: () => renderTestplan,
|
|
283
287
|
resolveObligations: () => resolveObligations,
|
|
284
288
|
resolveState: () => resolveState,
|
|
@@ -287,6 +291,7 @@ __export(index_exports, {
|
|
|
287
291
|
ruleNamespace: () => ruleNamespace,
|
|
288
292
|
ruleParts: () => ruleParts,
|
|
289
293
|
runTests: () => runTests,
|
|
294
|
+
sameMeaning: () => sameMeaning,
|
|
290
295
|
sarifLevel: () => sarifLevel,
|
|
291
296
|
scanIntent: () => scanIntent,
|
|
292
297
|
scanProject: () => scanProject,
|
|
@@ -308,6 +313,8 @@ __export(index_exports, {
|
|
|
308
313
|
startMcpServer: () => startMcpServer,
|
|
309
314
|
styleDiagnostics: () => styleDiagnostics,
|
|
310
315
|
subjectName: () => subjectName,
|
|
316
|
+
thunderText: () => thunderText,
|
|
317
|
+
thunderizeFiles: () => thunderizeFiles,
|
|
311
318
|
timeline: () => timeline,
|
|
312
319
|
toBPMN: () => toBPMN,
|
|
313
320
|
toCSharp: () => toCSharp,
|
|
@@ -339,6 +346,8 @@ __export(index_exports, {
|
|
|
339
346
|
verifyDiffToEvidence: () => verifyDiffToEvidence,
|
|
340
347
|
verifyLedger: () => verifyLedger,
|
|
341
348
|
violatesArchitecture: () => violatesArchitecture,
|
|
349
|
+
visualFor: () => visualFor,
|
|
350
|
+
visualForStep: () => visualForStep,
|
|
342
351
|
whyBuilt: () => whyBuilt,
|
|
343
352
|
writeRule: () => writeRule
|
|
344
353
|
});
|
|
@@ -2414,7 +2423,7 @@ function notesSummary(ast) {
|
|
|
2414
2423
|
byLens
|
|
2415
2424
|
};
|
|
2416
2425
|
}
|
|
2417
|
-
var COMPILER_VERSION = "0.5.
|
|
2426
|
+
var COMPILER_VERSION = "0.5.6";
|
|
2418
2427
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
2419
2428
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
2420
2429
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -4278,7 +4287,7 @@ function liftSource(source, { language = "typescript", file = "", seeds = void 0
|
|
|
4278
4287
|
}
|
|
4279
4288
|
const intentText = renderLiftedIntent(lifted);
|
|
4280
4289
|
const diagnostics = liftDiagnostics(lifted, codeFacts);
|
|
4281
|
-
const
|
|
4290
|
+
const summary2 = {
|
|
4282
4291
|
schemaVersion: IR_SCHEMA_VERSION,
|
|
4283
4292
|
sourceLanguage: codeFacts.sourceLanguage,
|
|
4284
4293
|
mission: lifted.mission,
|
|
@@ -4290,7 +4299,7 @@ function liftSource(source, { language = "typescript", file = "", seeds = void 0
|
|
|
4290
4299
|
tests: codeFacts.tests.length,
|
|
4291
4300
|
seeds: normSeeds.map((s) => s.nodeId)
|
|
4292
4301
|
};
|
|
4293
|
-
return { ok: true, codeFacts, lifted, intentText, diagnostics, summary, seeds: normSeeds };
|
|
4302
|
+
return { ok: true, codeFacts, lifted, intentText, diagnostics, summary: summary2, seeds: normSeeds };
|
|
4294
4303
|
}
|
|
4295
4304
|
|
|
4296
4305
|
// src/drift.mjs
|
|
@@ -4409,28 +4418,28 @@ function checkDrift(intentText, codeSource, { language = "typescript" } = {}) {
|
|
|
4409
4418
|
return verdict(findings2);
|
|
4410
4419
|
}
|
|
4411
4420
|
const li = lift.lifted;
|
|
4412
|
-
const
|
|
4413
|
-
const codeGuar = new Set(li.guarantees.map((g) =>
|
|
4414
|
-
const codeNever = new Set(li.neverRules.map((n) =>
|
|
4415
|
-
const codeInputs = new Set(li.inputs.map((i) =>
|
|
4416
|
-
const intentGuar = new Set(ast.guarantees.map((g) =>
|
|
4421
|
+
const norm5 = (s) => slug(s);
|
|
4422
|
+
const codeGuar = new Set(li.guarantees.map((g) => norm5(g.statement)));
|
|
4423
|
+
const codeNever = new Set(li.neverRules.map((n) => norm5(n.statement)));
|
|
4424
|
+
const codeInputs = new Set(li.inputs.map((i) => norm5(i.name)));
|
|
4425
|
+
const intentGuar = new Set(ast.guarantees.map((g) => norm5(g.statement)));
|
|
4417
4426
|
for (const g of ast.guarantees) {
|
|
4418
|
-
if (!codeGuar.has(
|
|
4427
|
+
if (!codeGuar.has(norm5(g.statement))) {
|
|
4419
4428
|
add("warning", "INTENT_DRIFT_GUARANTEE_UNSUPPORTED", `Guarantee "${g.statement}" has no matching evidence in the code (test removed or renamed?).`);
|
|
4420
4429
|
}
|
|
4421
4430
|
}
|
|
4422
4431
|
for (const n of ast.neverRules) {
|
|
4423
|
-
if (!codeNever.has(
|
|
4432
|
+
if (!codeNever.has(norm5(n.statement))) {
|
|
4424
4433
|
add("warning", "INTENT_DRIFT_NEVER_RULE_UNSUPPORTED", `Never rule "${n.statement}" has no matching error or guard in the code.`);
|
|
4425
4434
|
}
|
|
4426
4435
|
}
|
|
4427
4436
|
for (const f of ast.inputs) {
|
|
4428
|
-
if (!codeInputs.has(
|
|
4437
|
+
if (!codeInputs.has(norm5(f.name))) {
|
|
4429
4438
|
add("warning", "INTENT_DRIFT_INPUT_REMOVED", `Input "${f.name}" is declared in the intent but not found in the code signature.`);
|
|
4430
4439
|
}
|
|
4431
4440
|
}
|
|
4432
4441
|
for (const g of li.guarantees) {
|
|
4433
|
-
if (!intentGuar.has(
|
|
4442
|
+
if (!intentGuar.has(norm5(g.statement))) {
|
|
4434
4443
|
add("info", "INTENT_DRIFT_NEW_BEHAVIOR", `The code has behavior "${g.statement}" that the approved intent does not declare.`);
|
|
4435
4444
|
}
|
|
4436
4445
|
}
|
|
@@ -4539,9 +4548,9 @@ function parseSelection(lines) {
|
|
|
4539
4548
|
if (/^require\b/.test(t)) {
|
|
4540
4549
|
require2.push(t.replace(/^require\s+/, ""));
|
|
4541
4550
|
} else if (/^prefer\b/.test(t)) {
|
|
4542
|
-
const
|
|
4543
|
-
const direction = MAX_WORDS.has(
|
|
4544
|
-
prefer.push({ metric: normalizeMetric(
|
|
4551
|
+
const words5 = t.replace(/^prefer\s+/, "").split(/\s+/);
|
|
4552
|
+
const direction = MAX_WORDS.has(words5[0]) ? "max" : MIN_WORDS.has(words5[0]) ? "min" : "min";
|
|
4553
|
+
prefer.push({ metric: normalizeMetric(words5.slice(1).join(" ")), direction });
|
|
4545
4554
|
}
|
|
4546
4555
|
}
|
|
4547
4556
|
return { require: require2, prefer, requireAllChecks: require2.some((r) => /verification|all/.test(r)) };
|
|
@@ -7088,9 +7097,9 @@ function removeRule(lines, keyword, pluralKeyword, match) {
|
|
|
7088
7097
|
if (s > 0 && out[s - 1] !== void 0 && out[s - 1].trim() === "" && (out[s] === void 0 || out[s].trim() === "")) out.splice(s - 1, 1);
|
|
7089
7098
|
return { ok: true, lines: out };
|
|
7090
7099
|
}
|
|
7091
|
-
const
|
|
7092
|
-
if (
|
|
7093
|
-
for (let i =
|
|
7100
|
+
const plural2 = bs.find((b) => b.keyword === pluralKeyword);
|
|
7101
|
+
if (plural2) {
|
|
7102
|
+
for (let i = plural2.start + 1; i <= plural2.end; i++) {
|
|
7094
7103
|
if (lines[i].trim() && !lines[i].trim().startsWith("#") && lines[i].toLowerCase().includes(needle)) {
|
|
7095
7104
|
return { ok: true, lines: [...lines.slice(0, i), ...lines.slice(i + 1)] };
|
|
7096
7105
|
}
|
|
@@ -9012,8 +9021,8 @@ function identifierWords(text) {
|
|
|
9012
9021
|
return String(text).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^A-Za-z0-9]+/g, " ").toLowerCase().split(/\s+/).filter(Boolean);
|
|
9013
9022
|
}
|
|
9014
9023
|
var lineHitsTerm = (text, terms) => {
|
|
9015
|
-
const
|
|
9016
|
-
return terms.some((term) =>
|
|
9024
|
+
const words5 = identifierWords(text);
|
|
9025
|
+
return terms.some((term) => words5.some((w) => w === term || w.endsWith(term)));
|
|
9017
9026
|
};
|
|
9018
9027
|
function addedLines(before, after) {
|
|
9019
9028
|
const afterLines = String(after ?? "").split(/\r?\n/);
|
|
@@ -9117,9 +9126,9 @@ var SECRET_TYPES2 = /* @__PURE__ */ new Set(["secret", "password", "passwd", "jw
|
|
|
9117
9126
|
var SECRET_NAME = /pass(word|wd)?|secret|token|jwt|ssn|api[-_]?key|apikey|credential|cvv|private[-_]?key|card/i;
|
|
9118
9127
|
var isSecretField = (f) => f && (SECRET_TYPES2.has(String(f.type || "").toLowerCase()) || SECRET_NAME.test(f.name || ""));
|
|
9119
9128
|
function pascalish(text) {
|
|
9120
|
-
const
|
|
9121
|
-
if (
|
|
9122
|
-
return
|
|
9129
|
+
const words5 = String(text || "Mission").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/);
|
|
9130
|
+
if (words5.length === 1) return words5[0].charAt(0).toUpperCase() + words5[0].slice(1);
|
|
9131
|
+
return words5.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
9123
9132
|
}
|
|
9124
9133
|
var normRules = (list) => (Array.isArray(list) ? list : []).map((r) => typeof r === "string" ? { statement: r } : { ...r }).filter((r) => r.statement);
|
|
9125
9134
|
function draftIntent(brief = {}) {
|
|
@@ -9215,10 +9224,45 @@ var KNOWN_CALLS = [
|
|
|
9215
9224
|
{ re: /^(?:events?|bus|publisher|emitter|queue)\.(?:publish|emit|send|enqueue|push)$/i, say: () => "Announces an event" },
|
|
9216
9225
|
{ re: /^(?:log|logger|console|logging|fmt|Log|System\.out|println|print|puts|echo|printf)\b/i, say: () => "Writes a log or message" }
|
|
9217
9226
|
];
|
|
9227
|
+
var possessiveWords = (path) => {
|
|
9228
|
+
const parts = String(path).replace(/^\$/, "").replace(/\[\s*['"]?([\w$]+)['"]?\s*\]/g, ".$1").split(/\.|->/).filter((x) => x && !/^(self|this)$/.test(x));
|
|
9229
|
+
return parts.length > 1 ? `the ${words2(parts[parts.length - 2])}'s ${words2(parts[parts.length - 1])}` : words2(parts[0] || path);
|
|
9230
|
+
};
|
|
9231
|
+
var plainEnums = (text) => String(text).replace(/\b[A-Z][A-Za-z0-9]*\.([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*)\b(?!\s*\()/g, (m, v) => v.length > 1 && v === v.toUpperCase() ? words2(v) : m);
|
|
9218
9232
|
function sayCodeCondition(cond) {
|
|
9219
|
-
let c = String(cond).trim().replace(/\s*(\{|:|then|do)\s*$/, "").trim();
|
|
9233
|
+
let c = plainEnums(String(cond)).trim().replace(/\s*(\{|:|then|do)\s*$/, "").trim();
|
|
9220
9234
|
while (c.startsWith("(") && matchingClose(c, 0) === c.length - 1) c = c.slice(1, -1).trim();
|
|
9221
|
-
|
|
9235
|
+
const prop = c.match(/^(not\s+|!)?(?:self\.|this\.)?([A-Za-z_]\w*)\.([A-Za-z_]\w*)(\(\))?$/);
|
|
9236
|
+
const plural2 = (w, call2) => !call2 && !/ /.test(w) && /[^sui]s$/.test(w) && w.length > 3;
|
|
9237
|
+
if (prop && plural2(words2(prop[3]), !!prop[4])) return `${words2(prop[2])} ${prop[1] ? "has no" : "has"} ${words2(prop[3])}`;
|
|
9238
|
+
const yesNo = (w, call2) => /^(is|has|can|should|was) /.test(w) || !call2 && (/ed$/.test(w) || /^(active|valid|open|empty|ready|visible|available|enabled|required|admin|public|private|paid|due|overdue|eligible|blocked)$/.test(w));
|
|
9239
|
+
if (prop && yesNo(words2(prop[3]), !!prop[4])) {
|
|
9240
|
+
const neg = !!prop[1];
|
|
9241
|
+
const w = words2(prop[3]).replace(/^(is|has|can|should|was) /, (m) => m);
|
|
9242
|
+
const verb = /^(is|was) /.test(w) ? w.replace(/^(is|was) /, neg ? "$1 not " : "$1 ") : /^(has|can|should) /.test(w) ? (neg ? `does not ${w.replace(/^has /, "have ")}` : w).replace(/^does not can /, "cannot ").replace(/^does not should /, "should not ") : `is ${neg ? "not " : ""}${w}`;
|
|
9243
|
+
return `${words2(prop[2])} ${verb}`;
|
|
9244
|
+
}
|
|
9245
|
+
let pred;
|
|
9246
|
+
if (pred = c.match(/^(!|not\s+)?(?:([\w$]+)\.)?([a-z_]\w*)\?$/)) return `${pred[2] ? words2(pred[2]) : "it"} is ${pred[1] ? "not " : ""}${words2(pred[3])}`;
|
|
9247
|
+
c = c.replace(/\\?\b(?:count|len|sizeof)\(\s*\$?([\w$.\[\]'">-]+)\s*\)/g, (m0, x) => `how many ${possessiveWords(x)}`).replace(/\b([\w$]+(?:\.[\w$]+)*)\.(?:length|Length|Count|count\(\)|size\(\)|len\(\))(?![\w(])/g, (m0, x) => `how many ${possessiveWords(x)}`);
|
|
9248
|
+
c = c.replace(/\\(?=[a-z_]\w*\()/g, "");
|
|
9249
|
+
let call;
|
|
9250
|
+
if (call = c.match(/^(!|not\s+)?(empty|isset|is_null)\(\s*\$?([\w$.\[\]'">-]+)\s*\)$/)) {
|
|
9251
|
+
const neg = !!call[1] !== (call[2] === "isset");
|
|
9252
|
+
const what = possessiveWords(call[3]);
|
|
9253
|
+
return call[2] === "isset" || call[2] === "is_null" ? `${what} is ${call[2] === "isset" === !call[1] ? "" : "not "}set` : `${what} is ${neg ? "not " : ""}empty`;
|
|
9254
|
+
}
|
|
9255
|
+
if (call = c.match(/^(!|not\s+)?(?:(?:self|this)\.)?((?:is|has|can|should|was|are|does)[A-Z_]\w*)\s*\([^()]*\)$/)) {
|
|
9256
|
+
const w = words2(call[2]);
|
|
9257
|
+
return call[1] ? `not: ${w}` : w;
|
|
9258
|
+
}
|
|
9259
|
+
const bare = c.match(/^(not\s+|!)?(?:self\.|this\.)?([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)?)$/);
|
|
9260
|
+
if (bare && !/^(true|false|True|False|None|null|nil)$/.test(bare[2])) {
|
|
9261
|
+
const parts = bare[2].split(".");
|
|
9262
|
+
const what = parts.length > 1 ? `the ${words2(parts[0])}'s ${words2(parts[1])}` : words2(parts[0]);
|
|
9263
|
+
return `${what} is ${bare[1] ? "not " : ""}set`;
|
|
9264
|
+
}
|
|
9265
|
+
return clip(c.replace(/\s*(===|==)\s*(nil|null|None|undefined|""|'')(?=\s|\)|$)/g, " is empty").replace(/\s*(!==|!=)\s*(""|'')(?=\s|\)|$)/g, " is not empty").replace(/\s*(!==|!=)\s*(nil|null|None|undefined)\b/g, " is set").replace(/\bis not None\b/g, "is set").replace(/\bis None\b/g, "is empty").replace(/\s*(===|==)\s*/g, " is ").replace(/\s*(!==|!=)\s*/g, " is not ").replace(/\s*&&\s*/g, " and ").replace(/\s*\|\|\s*/g, " or ").replace(/\s+not\s+in\s+/g, " is not in ").replace(/(?<!\bis(?: not)?)\s+in\s+(?=[\w$])/g, " is in ").replace(/\s+<=\s+/g, " is at most ").replace(/\s+>=\s+/g, " is at least ").replace(/\s+<\s+/g, " is less than ").replace(/(?<![-=])\s+>\s+/g, " is more than ").replace(/(^|[\s(])!(?=[\w(])/g, "$1not ").replace(/\s+/g, " "), 70);
|
|
9222
9266
|
}
|
|
9223
9267
|
function matchingClose(str2, open) {
|
|
9224
9268
|
let depth = 0;
|
|
@@ -9230,12 +9274,12 @@ function matchingClose(str2, open) {
|
|
|
9230
9274
|
}
|
|
9231
9275
|
var lastWords = (path) => words2(String(path).split(".").pop());
|
|
9232
9276
|
function targetWords(path) {
|
|
9233
|
-
const parts = String(path).replace(
|
|
9277
|
+
const parts = String(path).replace(/^[@$]+/, "").replace(/#/g, "").replace(/\[.*$/, "").split(".").filter((p) => !/^(this|self)$/.test(p));
|
|
9234
9278
|
if (parts.length <= 1) return words2(parts[0] || path);
|
|
9235
|
-
return
|
|
9279
|
+
return `the ${words2(parts[parts.length - 2])}'s ${words2(parts[parts.length - 1])}`;
|
|
9236
9280
|
}
|
|
9237
9281
|
function callee(text) {
|
|
9238
|
-
const m = String(text).match(/^(?:await\s+|try\s+|yield\s+|void\s+)?(?:new\s+)?([A-Za-z_$#@][\w$#]*(?:<[^()]*?>)?(?:(?:\.|::|->)[A-Za-z_$#][\w$#]*(?:<[^()]*?>)?(?:\(\))?)*)!?\s*\(/);
|
|
9282
|
+
const m = String(text).replace(/\[[^\]]*\]/g, "").match(/^(?:await\s+|try\s+|yield\s+|void\s+)?(?:new\s+)?([A-Za-z_$#@][\w$#]*(?:<[^()]*?>)?(?:(?:\.|::|->)[A-Za-z_$#][\w$#]*(?:<[^()]*?>)?(?:\(\))?)*)!?\s*\(/);
|
|
9239
9283
|
return m ? m[1].replace(/<[^()]*?>/g, "").replace(/\(\)/g, "").replace(/::|->/g, ".").replace(/#/g, "") : null;
|
|
9240
9284
|
}
|
|
9241
9285
|
function sayCall(name, args) {
|
|
@@ -9251,7 +9295,12 @@ function firstArgs(text) {
|
|
|
9251
9295
|
return open >= 0 ? text.slice(open + 1, open + 120) : "";
|
|
9252
9296
|
}
|
|
9253
9297
|
function sayValue(expr) {
|
|
9254
|
-
|
|
9298
|
+
if (/^[A-Z][A-Za-z0-9]*\.[A-Z][A-Z0-9_]+$/.test(stripTail(expr))) return plainEnums(stripTail(expr));
|
|
9299
|
+
const e = stripTail(expr).replace(/\s+as\s+[\w.<>\[\]|, ]+$/, "");
|
|
9300
|
+
const py = sayPython(e);
|
|
9301
|
+
if (py) return py;
|
|
9302
|
+
const common = sayCommon(e);
|
|
9303
|
+
if (common) return common;
|
|
9255
9304
|
if (/^["'`].*["'`]$/.test(e)) return `"${clip(e.slice(1, -1), 40)}"`;
|
|
9256
9305
|
if (/^-?\d+(\.\d+)?$/.test(e) || /^(true|false|True|False|nil|null|None|undefined)$/.test(e)) return e;
|
|
9257
9306
|
const c = callee(e);
|
|
@@ -9259,9 +9308,77 @@ function sayValue(expr) {
|
|
|
9259
9308
|
if (/^new\s/.test(e)) return `a new ${c.split(".").pop()}`;
|
|
9260
9309
|
return `the result of ${lastWords(c)}`;
|
|
9261
9310
|
}
|
|
9262
|
-
if (/^[A-Za-z_$][\w$.]*$/.test(e)) return words2(e.split(".").pop());
|
|
9311
|
+
if (/^[A-Za-z_$][\w$.]*$/.test(e)) return words2(e.replace(/^\$/, "").split(".").pop());
|
|
9312
|
+
if (/^\$?[A-Za-z_][\w$]*(?:\[\s*['"]?\w+['"]?\s*\]|->\w+|\.\w+)+$/.test(e)) return possessiveWords(e);
|
|
9313
|
+
return null;
|
|
9314
|
+
}
|
|
9315
|
+
var PY_SUMMARY = [
|
|
9316
|
+
{ re: /^any$/, say: (src, cond) => `whether any item in ${src}${cond ? ` where ${cond}` : ""} matches` },
|
|
9317
|
+
{ re: /^all$/, say: (src, cond) => `whether every item in ${src}${cond ? ` where ${cond}` : ""} matches` },
|
|
9318
|
+
{ re: /^sum$/, say: (src) => `a total over ${src}` },
|
|
9319
|
+
{ re: /^min$/, say: (src) => `the smallest in ${src}` },
|
|
9320
|
+
{ re: /^max$/, say: (src) => `the largest in ${src}` },
|
|
9321
|
+
{ re: /^(?:sorted)$/, say: (src) => `${src}, sorted` }
|
|
9322
|
+
];
|
|
9323
|
+
var lastSeg = (x) => words2(String(x).trim().replace(/\(\)$/, "").split(".").pop());
|
|
9324
|
+
function sayPython(value) {
|
|
9325
|
+
const e = String(value).trim();
|
|
9326
|
+
let m = e.match(/^\[\s*(.+?)\s+for\s+([\w, ()]+?)\s+in\s+(.+?)(?:\s+if\s+(.+?))?\s*\]$/);
|
|
9327
|
+
if (m) {
|
|
9328
|
+
const [, expr, v, src, cond] = m;
|
|
9329
|
+
const vars = v.replace(/[()]/g, "").split(/\s*,\s*/);
|
|
9330
|
+
const bareCond = cond && cond.replace(new RegExp(`\\b(?:${vars.join("|")})\\.`, "g"), "");
|
|
9331
|
+
const condSaid = cond ? /^\w+$/.test(bareCond) ? words2(bareCond) : sayCodeCondition(bareCond) : null;
|
|
9332
|
+
if (vars.includes(expr.trim())) return condSaid ? `the items in ${lastSeg(src)} where ${condSaid}` : `the items in ${lastSeg(src)}`;
|
|
9333
|
+
return `one ${lastSeg(expr.replace(/\(.*$/, ""))} for each item in ${lastSeg(src)}${condSaid ? ` where ${condSaid}` : ""}`;
|
|
9334
|
+
}
|
|
9335
|
+
if (m = e.match(/^\{\s*(.+?)\s*:\s*.+?\s+for\s+[\w, ()]+?\s+in\s+(.+?)(?:\s+if\s+.+?)?\s*\}$/)) return `a lookup by ${lastSeg(m[1])} built from ${lastSeg(m[2])}`;
|
|
9336
|
+
if (m = e.match(/^len\(\s*([\w.]+)\s*\)$/)) return `how many ${lastSeg(m[1])}`;
|
|
9337
|
+
if (m = e.match(/^(\w+)\(\s*(.+?)\s+for\s+([\w, ()]+?)\s+in\s+(.+?)(?:\s+if\s+(.+?))?\s*\)$/)) {
|
|
9338
|
+
const hit = PY_SUMMARY.find((k) => k.re.test(m[1]));
|
|
9339
|
+
if (hit) {
|
|
9340
|
+
const vars = m[3].replace(/[()]/g, "").split(/\s*,\s*/);
|
|
9341
|
+
const condSaid = m[5] ? sayCodeCondition(m[5].replace(new RegExp(`\\b(?:${vars.join("|")})\\.`, "g"), "")) : null;
|
|
9342
|
+
return hit.say(lastSeg(m[4]), condSaid);
|
|
9343
|
+
}
|
|
9344
|
+
}
|
|
9345
|
+
if (m = e.match(/^(any|all|sum|min|max|sorted)\(\s*([\w.]+)\s*\)$/)) return PY_SUMMARY.find((k) => k.re.test(m[1])).say(lastSeg(m[2]));
|
|
9346
|
+
return null;
|
|
9347
|
+
}
|
|
9348
|
+
function sayCommon(value) {
|
|
9349
|
+
const e = String(value).trim().replace(/\s+as\s+[\w.<>\[\]|, ]+$/, "");
|
|
9350
|
+
let m;
|
|
9351
|
+
const side = (x) => sayValue(x) ?? possessiveWords(x.trim());
|
|
9352
|
+
if ((m = e.match(/^(.+?)\s+\?\s+([^:?]+?)\s+:\s+([^:?]+)$/)) && !/^(?:[\w$]+\??\s*:)/.test(e)) return `${side(m[2])} if ${sayCodeCondition(m[1])}, otherwise ${side(m[3])}`;
|
|
9353
|
+
if (m = e.match(/^(.+?)\s+if\s+(.+?)\s+else\s+(.+)$/)) return `${side(m[1])} if ${sayCodeCondition(m[2])}, otherwise ${side(m[3])}`;
|
|
9354
|
+
if ((m = e.match(/^&?([A-Z]\w*)(?:::new\s*\(|\s*\{)/)) || (m = e.match(/^(?:[\w.]+\.)?([A-Z]\w*)\{/))) return `a new ${m[1]}`;
|
|
9355
|
+
if (m = e.match(/^new\s*\(\s*(?:[\w]+\.)?([A-Z]\w*)\s*\)$/)) return `a new ${m[1]}`;
|
|
9356
|
+
if (m = e.match(/^&([A-Z]\w*)$/)) return `a new ${m[1]}`;
|
|
9357
|
+
if (m = e.match(/^[\w.]+\.(?:get|get_or_404|find|Find|findById|find_by_id)\(\s*([A-Z]\w*)\s*,\s*([\w.]+)\s*\)$/)) return `the ${m[1]} with ${lastSeg(m[2])}`;
|
|
9358
|
+
if ((m = e.match(/^([\w.]+)\.get\(\s*([A-Za-z_][\w.]*)\s*[,)]/)) || (m = e.match(/^([\w.]+)\[\s*([A-Za-z_][\w.]*)\s*\]$/))) return `the ${lastSeg(m[2])} entry in ${lastSeg(m[1])}`;
|
|
9359
|
+
if (/["'`]\s*\+|\+\s*["'`]/.test(e) && !/[<>=!&|]/.test(e)) return "text built from its parts";
|
|
9360
|
+
if (m = e.match(/^[A-Za-z_][\w.]*(\s*,\s*[A-Za-z_][\w.]*)+$/)) return e.split(/\s*,\s*/).map(lastSeg).join(" and ");
|
|
9361
|
+
if (m = e.match(/^make\(\s*(\[\]|map\[)/)) return m[1] === "[]" ? "an empty list" : "an empty lookup table";
|
|
9362
|
+
if (/^(?:f|rf|fr)["']/.test(e) || /^`[^`]*\$\{/.test(e) || /^\$"/.test(e) || /^(?:fmt\.Sprintf|String\.format|format!)\(/.test(e)) return "text built from its parts";
|
|
9363
|
+
if (m = e.match(/^([\w.]+)\.get\(\s*["'`]([\w.\-: ]{1,40})["'`]/)) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
|
|
9364
|
+
if (m = e.match(/^([\w.]+)\[\s*["'`]([\w.\-: ]{1,40})["'`]\s*\]$/)) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
|
|
9365
|
+
if (m = e.match(/^([\w.]+)\.split\(\s*["'`]([^"'`]{0,10})["'`]/)) return `${lastSeg(m[1])} split at "${m[2]}"`;
|
|
9366
|
+
if (m = e.match(/^@?([\w.]+?)(?:\.copy|\.clone|\.Clone|\.dup)(?:\(\))?$/)) return `a copy of ${lastSeg(m[1])}`;
|
|
9367
|
+
if ((m = e.match(/^(?:str|String|string)\(\s*([\w.]+)\s*\)$/)) || (m = e.match(/^([\w.]+)\.(?:toString|to_s|ToString)\(\)$/))) return `${lastSeg(m[1])} as text`;
|
|
9368
|
+
if (m = e.match(/^(?:int|float|Number|parseInt|parseFloat|strconv\.Atoi|Integer\.parseInt|int\.Parse)\(\s*([\w.]+)/)) return `${lastSeg(m[1])} as a number`;
|
|
9369
|
+
if (m = e.match(/^(?:JSON\.parse|json\.loads|json\.load|JsonSerializer\.Deserialize\w*)\(\s*([\w.]+)/)) return `${lastSeg(m[1])} read as JSON`;
|
|
9370
|
+
if (m = e.match(/^(?:JSON\.stringify|json\.dumps|JsonSerializer\.Serialize)\(\s*([\w.]+)/)) return `${lastSeg(m[1])} written as JSON`;
|
|
9371
|
+
if (/^(?:dict|Map|HashMap|map)\(\s*\)$|^\{\s*\}$|^new (?:Map|HashMap|Dictionary)\b/.test(e)) return "an empty lookup table";
|
|
9372
|
+
if (/^(?:list|Array|ArrayList|vec!?)\(?\s*\)?$|^\[\s*\]$|^new (?:ArrayList|List)\b/.test(e)) return "an empty list";
|
|
9373
|
+
if ((m = e.match(/^len\(\s*([\w.]+)\s*\)$/)) || (m = e.match(/^([\w.]+)\.(?:length|size\(\)|Count|count\(\)|len\(\))$/))) return `how many ${lastSeg(m[1])}`;
|
|
9263
9374
|
return null;
|
|
9264
9375
|
}
|
|
9376
|
+
var LOGIC = /(&&|\|\||[<>]=?|[!=]==?|\band\b|\bor\b|\bnot\b|\bis\b|^\s*!)/;
|
|
9377
|
+
function sayWhether(expr) {
|
|
9378
|
+
const e = String(expr).trim();
|
|
9379
|
+
if (!LOGIC.test(e) || /=>|\blambda\b|\?.*:/.test(e) || e.length > 90) return null;
|
|
9380
|
+
return `whether ${sayCodeCondition(e)}`;
|
|
9381
|
+
}
|
|
9265
9382
|
var CHAIN = [
|
|
9266
9383
|
{ re: /\.(?:map|Select|flatMap|SelectMany|map_values|collect\{)\s*[({]/, say: (src) => `one for each item in ${src}` },
|
|
9267
9384
|
{ re: /\.(?:filter|Where|filter_map|select|reject|grep)\s*[({]/, say: (src) => `the items in ${src} that match` },
|
|
@@ -9284,14 +9401,27 @@ function sayChain(value) {
|
|
|
9284
9401
|
}
|
|
9285
9402
|
function classifyStatement(raw, { inner = 0 } = {}) {
|
|
9286
9403
|
const text = String(raw).trim();
|
|
9287
|
-
const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.");
|
|
9404
|
+
const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
|
|
9288
9405
|
const code = clip(head, 90);
|
|
9289
9406
|
let m;
|
|
9290
9407
|
const innerNote = inner ? ` (${inner} step${inner === 1 ? "" : "s"} inside)` : "";
|
|
9408
|
+
let inl;
|
|
9409
|
+
if ((inl = head.match(/^(if|else\s+if)\s*\((.+?)\)\s*((?:return|throw|break|continue|yield)\b.*|[\w$.]+\(.*\);?)$/)) && balanced(inl[2])) {
|
|
9410
|
+
return { kind: "branch", says: `If ${sayCodeCondition(inl[2])}`, cond: inl[2], code, inline: inl[3] };
|
|
9411
|
+
}
|
|
9412
|
+
if ((inl = head.match(/^(.+?)\s+(if|unless)\s+(.+)$/)) && !/\belse\b/.test(head) && !/^(?:if|unless|elsif|while|until|for|return\s+\S+\s+if\s+.+\s+else)\b/.test(head) && !/[=(]\s*$/.test(inl[1]) && !/^(?:[\w$.\[\]]+\s*=)/.test(inl[1])) {
|
|
9413
|
+
const cond = sayCodeCondition(inl[3]);
|
|
9414
|
+
return { kind: "branch", says: inl[2] === "unless" ? `If not: ${cond}` : `If ${cond}`, cond: inl[3], negate: inl[2] === "unless", code, inline: inl[1] };
|
|
9415
|
+
}
|
|
9416
|
+
if (inl = head.match(/^(?:let|var|const)\s+([A-Za-z_$][\w$]*)\s*(?::\s*[^=]+)?;?$/)) return { kind: "set", says: `Starts with no ${words2(inl[1])} yet`, code };
|
|
9417
|
+
if (inl = head.match(/^([\w$.]+)\s*=\s*(?:async\s+)?(?:function\b|\([^()]*\)\s*(?::\s*[^=]+)?=>|[\w$]+\s*=>)/)) return { kind: "set", says: `Defines how ${targetWords(inl[1])} works`, code };
|
|
9418
|
+
if (m = head.match(/^case\s+(.+?)\s*(?::|->)\s*(.*)$/)) return { kind: "check", says: `When it is ${/^[A-Z][A-Z0-9_]+$/.test(m[1].replace(/^[A-Z]\w*\./, "")) ? words2(m[1].replace(/^[A-Z]\w*\./, "")) : sayCodeCondition(plainEnums(m[1]))}`, code, caseLabel: true };
|
|
9419
|
+
if (/^default\s*(?::|->)/.test(head)) return { kind: "check", says: "Otherwise", code, caseLabel: true };
|
|
9291
9420
|
if ((m = head.match(/^(?:throw|raise)\s+(?:new\s+)?([A-Za-z_][\w.]*)?/)) || /^panic!?\s*\(/.test(head)) {
|
|
9292
9421
|
const name = m?.[1] ? m[1].split(".").pop() : null;
|
|
9293
9422
|
const msg = (head.match(/["'`]([^"'`]{1,60})["'`]/) || [])[1];
|
|
9294
|
-
|
|
9423
|
+
const said = name && /^[a-z]/.test(name) ? `the error made by ${words2(name)}` : name;
|
|
9424
|
+
return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
|
|
9295
9425
|
}
|
|
9296
9426
|
if (m = head.match(/^return\b\s*(.*)$/)) {
|
|
9297
9427
|
const expr = stripTail(m[1]);
|
|
@@ -9307,12 +9437,19 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9307
9437
|
}
|
|
9308
9438
|
const chain = sayChain(expr);
|
|
9309
9439
|
if (chain) return { kind: "return", says: `Returns ${chain}`, code };
|
|
9310
|
-
if (
|
|
9440
|
+
if (/^\(?\s*\{/.test(expr)) return { kind: "return", says: "Returns an object", code };
|
|
9311
9441
|
if (/^\(?\s*</.test(expr)) return { kind: "return", says: "Returns what to show on screen", code };
|
|
9312
|
-
const v = sayValue(expr);
|
|
9442
|
+
const v = sayValue(expr) || sayWhether(expr);
|
|
9313
9443
|
return { kind: "return", says: v ? `Returns ${v}` : "Returns a computed value", code, ...v ? {} : { value: clip(expr, 60) } };
|
|
9314
9444
|
}
|
|
9315
|
-
if (m = head.match(/^for\s*\(?\s*(?:
|
|
9445
|
+
if (m = head.match(/^for\b\s*\(?\s*(?:(?:var|let|const|int|long|size_t|auto|\$)\s*)?\$?(\w+)\s*:?=\s*([^;]+?)\s*;\s*([^;]*?)\s*;\s*[^)]*?\)?\s*\{?\s*$/)) {
|
|
9446
|
+
return { kind: "loop", says: `Counts ${words2(m[1])} from ${clip(m[2], 20)}${m[3] ? ` while ${sayCodeCondition(m[3])}` : ""}${innerNote}`, code };
|
|
9447
|
+
}
|
|
9448
|
+
if (m = head.match(/^for\b\s*\(?\s*(?:const|let|var|val)?\s*[\[{(]?\s*([\w$]+)\s*,\s*([\w$]+)\s*[\]})]?\s+(?:of|in)\s+(.+?)\)?\s*(?:\{|:|do)?\s*$/)) {
|
|
9449
|
+
const src = stripTail(m[3]).replace(/\($/, "()").replace(/^Object\.entries\((.+)\)$/, "$1").replace(/\.(?:items|entries)\(\)$/, "");
|
|
9450
|
+
return { kind: "loop", says: `For each ${words2(m[1])} and ${words2(m[2])} in ${words2(src.split(".").pop())}${innerNote}`, code };
|
|
9451
|
+
}
|
|
9452
|
+
if (m = head.match(/^for\b\s*\(?\s*(?:const|let|var|val|final|auto|[\w<>\[\],? ]+?\s)?\s*\(?([\w$, _]+?)\)?\s+(?:of|in|:)\s+(.+?)\)?\s*(?:\{|:|do)?\s*$/)) {
|
|
9316
9453
|
return { kind: "loop", says: `For each ${words2(m[1].split(",").pop().trim())} in ${words2(stripTail(m[2]).split(".").pop().replace(/\(\)$/, ""))}${innerNote}`, code };
|
|
9317
9454
|
}
|
|
9318
9455
|
if (m = head.match(/^for\s+[\w, _]+\s*:=\s*range\s+(.+?)\s*\{?$/)) return { kind: "loop", says: `For each item in ${words2(stripTail(m[1]).split(".").pop())}${innerNote}`, code };
|
|
@@ -9320,7 +9457,12 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9320
9457
|
if (m = head.match(/^foreach\s*\(\s*(.+?)\s+as\s+(?:\w+\s*=>\s*)?(\w+)\s*\)\s*\{?$/)) return { kind: "loop", says: `For each ${words2(m[2])} in ${words2(m[1].split(".").pop())}${innerNote}`, code };
|
|
9321
9458
|
if (m = head.match(/^([\w.]+)\.each(?:_with_index)?\s+do\s*\|(\w+)/)) return { kind: "loop", says: `For each ${words2(m[2])} in ${words2(m[1].split(".").pop())}${innerNote}`, code };
|
|
9322
9459
|
if (m = head.match(/^([\w.]+)\.(?:forEach|each|map|filter|for_each)\s*[({]/)) return { kind: "loop", says: `For each item in ${words2(m[1].split(".").pop())}${innerNote}`, code };
|
|
9323
|
-
if (m = head.match(/^(?:while|until|loop)\b\s*\(?(.*?)\)?\s*(?:\{|:|do)?\s*$/)) return { kind: "loop", says: m[1] ? `Repeats while ${
|
|
9460
|
+
if (m = head.match(/^(?:while|until|loop)\b\s*\(?(.*?)\)?\s*(?:\{|:|do)?\s*$/)) return { kind: "loop", says: m[1] ? `Repeats while ${sayCodeCondition(m[1])}${innerNote}` : `Repeats${innerNote}`, code };
|
|
9461
|
+
if (m = head.match(/^(?:if|else\s+if)\s+(?:[\w]+\s*,\s*)?err\s*:?=\s*([\w.]+)\(.*\);\s*err\s*!=\s*nil\s*\{?\s*$/)) return { kind: "branch", says: `If ${lastWords(m[1])} fails${innerNote}`, code };
|
|
9462
|
+
if (m = head.match(/^(?:if|else\s+if)\s+[^;{]*:=[^;{]*;\s*(.+?)\s*\{?\s*$/)) {
|
|
9463
|
+
const cond = sayCodeCondition(m[1]);
|
|
9464
|
+
return { kind: "branch", says: `If ${cond}${innerNote}`, cond: m[1], code };
|
|
9465
|
+
}
|
|
9324
9466
|
if (m = head.match(/^(?:if|elif|else\s+if|unless|when)\b\s*(.*?)\s*(?:\{|:|then)?\s*$/)) {
|
|
9325
9467
|
const cond = sayCodeCondition(m[1]);
|
|
9326
9468
|
return { kind: "branch", says: `If ${/^unless\b/.test(head) ? "not: " : ""}${cond}${innerNote}`, cond: m[1].replace(/^\((.*)\)$/, "$1"), code, negate: /^unless\b/.test(head) };
|
|
@@ -9362,6 +9504,8 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9362
9504
|
const value = stripTail(m[3]);
|
|
9363
9505
|
const target = words2(m[2]);
|
|
9364
9506
|
const c2 = value ? callee(value) : null;
|
|
9507
|
+
const everyday = value ? sayPython(value) || sayCommon(value) : null;
|
|
9508
|
+
if (everyday) return { kind: "set", says: `Sets ${target} to ${everyday}`, code };
|
|
9365
9509
|
if (c2) {
|
|
9366
9510
|
const known = sayCall(c2, firstArgs(value));
|
|
9367
9511
|
if (known) return { kind: "call", says: `${known}, keeping the result as ${target}`, code, callee: c2 };
|
|
@@ -9371,11 +9515,17 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9371
9515
|
const v = value ? sayValue(value) : null;
|
|
9372
9516
|
return { kind: "set", says: v ? `Sets ${target} to ${v}` : `Works out ${target}`, code };
|
|
9373
9517
|
}
|
|
9374
|
-
if ((m = head.match(/^(?:(?:const|let|var|val|final|auto|my|local)\s+)?(?:mut\s+)?([@A-Za-z_$#][\w$#.\[\]'"@]*?(?:\s*,\s*[@A-Za-z_$#][\w$#.@]*)*)(?:\s*:\s*[\w<>\[\]?, .|]+)?\s*(:=|\+=|-=|\*=|\/=|\|\|=|\?\?=|=)(?!=)\s*(.*)$/)) && !/^(?:if|for|while|return)\b/.test(head)) {
|
|
9375
|
-
const target = m[1].split(/\s*,\s*/).map(targetWords).join(", ");
|
|
9518
|
+
if ((m = head.replace(/^(?:final\s+)?(?!return\b|throw\b|yield\b|await\b|new\b)[A-Z][\w.]*(?:<[^=;]*?>)?(?:\[\])*\??\s+(?=[a-z_]\w*\s*=[^=])/, "").match(/^(?:(?:const|let|var|val|final|auto|my|local)\s+)?(?:mut\s+)?([@A-Za-z_$#][\w$#.\[\]'"@]*?(?:\s*,\s*[@A-Za-z_$#][\w$#.@]*)*)(?:\s*:\s*[\w<>\[\]?, .|]+)?\s*(:=|\+=|-=|\*=|\/=|\|\|=|\?\?=|=)(?!=)\s*(.*)$/)) && !/^(?:if|for|while|return)\b/.test(head)) {
|
|
9519
|
+
const target = m[1].split(/\s*,\s*/).filter((t) => t !== "_").map(targetWords).join(", ") || targetWords(m[1]);
|
|
9376
9520
|
const value = stripTail(m[3]);
|
|
9377
|
-
|
|
9521
|
+
if (m[2] === "=" && !/[(?]/.test(value.replace(/^\(|\)$/g, "")) && /(&&|\|\||\band\b|\bor\b|[!=]==?|(?<![-=])[<>]=?)/.test(value.replace(/->|=>/g, ".")) && !/=>/.test(value)) return { kind: "set", says: `Works out ${target}: whether ${sayCodeCondition(value)}`, code };
|
|
9522
|
+
if (m[2] === "=" && /^[A-Za-z_]\w*$/.test(value) && m[1].split(".").pop() === value && /^(self|this)\./.test(m[1])) return { kind: "set", says: `Keeps the ${words2(value)} it is given`, code };
|
|
9523
|
+
const chain = value ? sayPython(value) || sayChain(value) : null;
|
|
9378
9524
|
if (chain) return { kind: "set", says: `Works out ${target}: ${chain}`, code };
|
|
9525
|
+
const common = value ? sayCommon(m[3].trim().replace(/;$/, "")) || sayCommon(value) : null;
|
|
9526
|
+
if (common) return { kind: "set", says: `Sets ${target} to ${common}`, code };
|
|
9527
|
+
const keyed = m[2] === "=" && m[1].match(/^([\w$.]+)\[\s*([^\]]+?)\s*\]$/);
|
|
9528
|
+
if (keyed) return { kind: "set", says: `Records ${words2(keyed[2].replace(/["'`]/g, ""))} in ${targetWords(keyed[1])}`, code };
|
|
9379
9529
|
const c2 = callee(value);
|
|
9380
9530
|
if (c2) {
|
|
9381
9531
|
const known = sayCall(c2, firstArgs(value));
|
|
@@ -9384,10 +9534,25 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9384
9534
|
return { kind: "set", says: `Works out ${target} from ${lastWords(c2)}`, code, callee: c2 };
|
|
9385
9535
|
}
|
|
9386
9536
|
if (!value) return { kind: "set", says: `Works out ${target}`, code };
|
|
9387
|
-
if (m[2] === "+=" || m[2] === "-=")
|
|
9537
|
+
if (m[2] === "+=" || m[2] === "-=") {
|
|
9538
|
+
const what = /^[\w.]+$/.test(value) ? `${value.split(".").filter((p) => !/^(self|this)$/.test(p)).slice(-2).map(words2).join(" ")} ` : /^-?\d+(\.\d+)?$/.test(value) ? `${value} ` : "";
|
|
9539
|
+
return { kind: "set", says: what ? `${m[2] === "+=" ? "Adds" : "Subtracts"} ${what}${m[2] === "+=" ? "to" : "from"} ${target}` : `${m[2] === "+=" ? "Adds to" : "Subtracts from"} ${target}`, code };
|
|
9540
|
+
}
|
|
9388
9541
|
const v = sayValue(value);
|
|
9389
9542
|
return { kind: "set", says: v ? `Sets ${target} to ${v}` : `Works out ${target}`, code };
|
|
9390
9543
|
}
|
|
9544
|
+
if (m = head.match(/^([\w$.]+)\.(?:set|Set|put|setdefault|Add)\(\s*["'`]([\w.\-: ]{1,40})["'`]\s*,/)) return { kind: "call", says: `Sets "${m[2]}" on ${lastSeg(m[1])}`, code, callee: `${m[1]}.set` };
|
|
9545
|
+
if ((m = head.match(/^([\w$.]+)\.(?:remove|Remove|discard|delete|pop)\(\s*([\w$]+)\s*\)/)) && !/^(?:db|session|repo|conn|cursor)\b/.test(m[1])) {
|
|
9546
|
+
const owner = m[1].split(".").filter((p) => !/^(self|this)$/.test(p));
|
|
9547
|
+
const where = owner.length > 1 ? `${words2(owner[owner.length - 2])}'s ${words2(owner[owner.length - 1])}` : words2(owner[0] || m[1]);
|
|
9548
|
+
return { kind: "call", says: `Removes ${words2(m[2])} from ${where}`, code, callee: m[1] };
|
|
9549
|
+
}
|
|
9550
|
+
if ((m = head.match(/^([\w$.]+)\.(?:append|push|add|Add|insert|appendleft|extend)\(\s*([\w$.]*)\s*\)?/)) && !/^(?:db|session|repo|conn|cursor)\b/.test(m[1])) {
|
|
9551
|
+
const owner = m[1].split(".").filter((p) => !/^(self|this)$/.test(p));
|
|
9552
|
+
const where = owner.length > 1 ? `${words2(owner[owner.length - 2])}'s ${words2(owner[owner.length - 1])}` : words2(owner[0] || m[1]);
|
|
9553
|
+
const added = /^new\s+([A-Z]\w*)/.exec(head.slice(head.indexOf("(") + 1))?.[1];
|
|
9554
|
+
return { kind: "call", says: added ? `Adds a new ${words2(added)} to ${where}` : m[2] && /^[A-Za-z_][\w$]*$/.test(m[2]) && m[2] !== "new" ? `Adds ${words2(m[2])} to ${where}` : `Adds to ${where}`, code, callee: m[1] };
|
|
9555
|
+
}
|
|
9391
9556
|
const c = callee(head);
|
|
9392
9557
|
if (c) {
|
|
9393
9558
|
const known = sayCall(c, firstArgs(head));
|
|
@@ -9396,61 +9561,175 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9396
9561
|
if ((m = head.match(/^([a-z_][\w.]*[?!]?)\s+(?![=<>!+\-*/%]|and\b|or\b|if\b|unless\b)(.+)$/)) && !/^(?:if|for|while|return|else|elsif|when|case|def|class|module|end|not|const|let|var|val|new|await|typeof|delete|void|in|of|throw|import|export|from|as|is)$/.test(m[1])) {
|
|
9397
9562
|
if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code };
|
|
9398
9563
|
const known = sayCall(m[1], m[2]);
|
|
9399
|
-
|
|
9564
|
+
const named = /^[:'"]([\w ]+)['"]?/.exec(m[2].trim())?.[1];
|
|
9565
|
+
return { kind: "call", says: known || (named ? `Calls ${lastWords(m[1])}: ${words2(named)}` : `Calls ${lastWords(m[1])}`), code, callee: m[1] };
|
|
9400
9566
|
}
|
|
9401
9567
|
return { kind: "other", says: clip(head, 70), code };
|
|
9402
9568
|
}
|
|
9403
9569
|
var spanOf = (s) => ({ startLine: s.line, endLine: s.endLine ?? s.line, ...s.start != null && s.end != null ? { start: s.start, end: s.end } : {} });
|
|
9570
|
+
var BARE_CALL = /^[a-z_][\w.]*[?!]?$/;
|
|
9571
|
+
var balanced = (x) => {
|
|
9572
|
+
let d = 0;
|
|
9573
|
+
for (const ch of x) {
|
|
9574
|
+
if (ch === "(") d++;
|
|
9575
|
+
else if (ch === ")" && --d < 0) return false;
|
|
9576
|
+
}
|
|
9577
|
+
return d === 0;
|
|
9578
|
+
};
|
|
9579
|
+
function asCall(list, i) {
|
|
9580
|
+
const st = list[i];
|
|
9581
|
+
if (st?.kind === "return" && BARE_CALL.test(st.code || "") && !/^(?:self|nil|true|false|null|none)$/i.test(st.code)) {
|
|
9582
|
+
list[i] = { ...st, kind: "call", says: `Calls ${lastWords(st.code)}`, callee: st.code };
|
|
9583
|
+
}
|
|
9584
|
+
}
|
|
9585
|
+
var CLAUSE = /^(?:elif\b|elsif\b|else\s+if\b|else\b|except\b|catch\b|rescue\b|finally\b|ensure\b)/;
|
|
9586
|
+
function attachClause(step, clause) {
|
|
9587
|
+
const kw = clause.kind;
|
|
9588
|
+
const kids2 = stepsFrom(clause.children || []).steps;
|
|
9589
|
+
let target = step;
|
|
9590
|
+
while (target.otherwise?.length === 1 && target.otherwise[0].elseIf) target = target.otherwise[0];
|
|
9591
|
+
if (kw === "elif") {
|
|
9592
|
+
const head = clause.head.replace(/^(?:elif|elsif|else\s+if)\b/, "if");
|
|
9593
|
+
const branch = { ...classifyStatement(head), line: clause.line, span: { startLine: clause.line, endLine: clause.endLine ?? clause.line }, elseIf: true };
|
|
9594
|
+
if (kids2.length) branch.children = kids2;
|
|
9595
|
+
target.otherwise = [branch];
|
|
9596
|
+
} else if (kw === "else") {
|
|
9597
|
+
target.otherwise = kids2;
|
|
9598
|
+
target.otherwiseLine = clause.line;
|
|
9599
|
+
} else if (kw === "catch") {
|
|
9600
|
+
const what = (clause.head.replace(/\\/g, ".").replace(/\(\s*\./, "(").match(/^(?:except|catch|rescue)\s*\(?\s*(?:[\w.]+\s+)?\(?\.?([A-Z][\w.:]*(?:\s*[,|]\s*\.?[A-Z][\w.:]*)*)/) || [])[1]?.replace(/::/g, ".");
|
|
9601
|
+
(step.handlers ||= []).push({ says: what ? `If ${what.split(/\s*[,|]\s*/).map((x) => x.split(".").pop()).join(" or ")} goes wrong` : "If anything goes wrong", line: clause.line, steps: kids2 });
|
|
9602
|
+
} else if (kw === "finally") {
|
|
9603
|
+
for (let i = 0; i < kids2.length; i++) asCall(kids2, i);
|
|
9604
|
+
step.always = { line: clause.line, steps: kids2 };
|
|
9605
|
+
}
|
|
9606
|
+
}
|
|
9404
9607
|
function stepsFrom(statements) {
|
|
9405
9608
|
const steps = [];
|
|
9406
9609
|
const skipped = [];
|
|
9610
|
+
let into = null, intoAlways = false;
|
|
9407
9611
|
for (const s of statements) {
|
|
9408
|
-
|
|
9612
|
+
const t0 = (s.text || "").trim();
|
|
9613
|
+
if (into && !CLAUSE.test(t0) && t0 && !/^(?:end\b|#)/.test(t0)) {
|
|
9614
|
+
const st = stepsFrom([s]).steps;
|
|
9615
|
+
into.push(...st);
|
|
9616
|
+
for (let i = 0; i < into.length - (intoAlways ? 0 : 1); i++) asCall(into, i);
|
|
9617
|
+
continue;
|
|
9618
|
+
}
|
|
9619
|
+
if (CLAUSE.test(t0)) {
|
|
9620
|
+
const prev = steps[steps.length - 1];
|
|
9621
|
+
if (/^(?:rescue|ensure|except|finally)\b/.test(t0) && steps.length && !(prev && prev.kind === "try")) {
|
|
9622
|
+
const tried = steps.splice(0, steps.length);
|
|
9623
|
+
for (let i = 0; i < tried.length - 1; i++) asCall(tried, i);
|
|
9624
|
+
steps.push({ kind: "try", says: "Tries these steps and handles any error", code: "(the whole method)", line: tried[0].line, span: { startLine: tried[0].span.startLine, endLine: tried[tried.length - 1].span.endLine }, children: tried });
|
|
9625
|
+
}
|
|
9626
|
+
const prev2 = steps[steps.length - 1];
|
|
9627
|
+
if (prev2 && (prev2.kind === "branch" || prev2.kind === "try")) {
|
|
9628
|
+
const prev3 = prev2;
|
|
9629
|
+
const kw = /^(?:elif|elsif|else\s+if)\b/.test(t0) ? "elif" : /^else\b/.test(t0) ? "else" : /^(?:finally|ensure)\b/.test(t0) ? "finally" : "catch";
|
|
9630
|
+
attachClause(prev3, { kind: kw, head: t0.replace(/:\s*$/, ""), line: s.line, endLine: s.endLine, children: s.children || [] });
|
|
9631
|
+
intoAlways = kw === "finally";
|
|
9632
|
+
into = s.children?.length ? null : kw === "catch" ? prev3.handlers?.[prev3.handlers.length - 1]?.steps ?? null : kw === "finally" ? prev3.always?.steps ?? null : null;
|
|
9633
|
+
prev3.span = { ...prev3.span, endLine: Math.max(prev3.span.endLine, s.endLine ?? s.line) };
|
|
9634
|
+
continue;
|
|
9635
|
+
}
|
|
9409
9636
|
skipped.push(spanOf(s));
|
|
9410
9637
|
continue;
|
|
9411
9638
|
}
|
|
9412
|
-
if (!
|
|
9413
|
-
|
|
9414
|
-
|
|
9639
|
+
if (!t0 || /^(?:end\b|\}|pass$|break$|continue$|#)/.test(t0)) {
|
|
9640
|
+
if (t0 && !/^#/.test(t0)) skipped.push(spanOf(s));
|
|
9641
|
+
continue;
|
|
9642
|
+
}
|
|
9643
|
+
if (/^(?:"""|'''|r"""|\/\*\*|\*)/.test(t0)) {
|
|
9415
9644
|
skipped.push(spanOf(s));
|
|
9416
9645
|
continue;
|
|
9417
9646
|
}
|
|
9418
|
-
if (/^[)\]}]+[):;,]*$/.test(
|
|
9647
|
+
if (/^[)\]}]+[):;,]*$/.test(t0) || /^\.\.\.$/.test(t0) || /^\.[A-Za-z_]/.test(t0) || /^@\w+(?:\(.*\))?$/.test(t0) || /^#?\[[\w:]+(?:\(.*\))?\]$/.test(t0) || /^:(?:param|rtype|return|raises|type)\b/.test(t0)) {
|
|
9419
9648
|
skipped.push(spanOf(s));
|
|
9420
9649
|
continue;
|
|
9421
9650
|
}
|
|
9422
9651
|
const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
|
|
9423
9652
|
if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
|
|
9424
|
-
const kids2 = stepsFrom(s.children
|
|
9653
|
+
const kids2 = stepsFrom(s.children).steps;
|
|
9425
9654
|
if (kids2.length) {
|
|
9426
9655
|
step.children = kids2;
|
|
9427
9656
|
step.says = step.says.replace(/ \(\d+ steps? inside\)$/, "");
|
|
9428
9657
|
}
|
|
9429
9658
|
}
|
|
9659
|
+
if (step.inline && !step.children) {
|
|
9660
|
+
const kid = classifyStatement(step.inline);
|
|
9661
|
+
step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
|
|
9662
|
+
delete step.inline;
|
|
9663
|
+
} else delete step.inline;
|
|
9664
|
+
for (const c of s.clauses || []) attachClause(step, c);
|
|
9430
9665
|
steps.push(step);
|
|
9431
9666
|
}
|
|
9667
|
+
for (let i = 0; i < steps.length - 1; i++) asCall(steps, i);
|
|
9432
9668
|
const more = Math.max(0, steps.length - MAX_STEPS);
|
|
9433
|
-
|
|
9669
|
+
for (const st of steps) if (restates(st)) st.restates = true;
|
|
9670
|
+
return { steps, more, skipped, readable: readableShare(steps) };
|
|
9671
|
+
}
|
|
9672
|
+
var GENERIC_CALLS = /^(?:get|set|run|do|call|apply|handle|process|execute|exec|make|build|create|new|init|load|fetch|parse|convert|to|from|str|int|float|bool|list|dict|set|tuple|len|any|all|map|filter|next|iter|super|format|join|split|strip|copy|update|value|values|items|keys)$/;
|
|
9673
|
+
function restates(st) {
|
|
9674
|
+
const s = st.says || "";
|
|
9675
|
+
if (st.kind === "other") return false;
|
|
9676
|
+
if (/^Works out [^:]+$/.test(s) && !/ from /.test(s)) return true;
|
|
9677
|
+
const same = s.match(/^Works out (.+) from (.+)$/);
|
|
9678
|
+
if (same && same[1].trim() === same[2].trim()) return true;
|
|
9679
|
+
if (/^(Returns a computed value|Returns a value|Sets .+ to a computed value)$/.test(s)) return true;
|
|
9680
|
+
const via = s.match(/(?:the result of|from|^Calls) ([\w ]+?)$/);
|
|
9681
|
+
if (via && GENERIC_CALLS.test(via[1].trim())) return true;
|
|
9682
|
+
return false;
|
|
9434
9683
|
}
|
|
9684
|
+
var readableShare = (steps) => steps.length ? steps.filter((x) => x.kind !== "other" && !x.restates).length / steps.length : 0;
|
|
9685
|
+
var blockEnd = (text, open) => {
|
|
9686
|
+
let depth = 0;
|
|
9687
|
+
for (let i = open; i < text.length; i++) {
|
|
9688
|
+
const c = text[i];
|
|
9689
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
9690
|
+
for (i++; i < text.length && text[i] !== c; i++) if (text[i] === "\\") i++;
|
|
9691
|
+
continue;
|
|
9692
|
+
}
|
|
9693
|
+
if (c === "{") depth++;
|
|
9694
|
+
else if (c === "}" && --depth === 0) return i;
|
|
9695
|
+
}
|
|
9696
|
+
return -1;
|
|
9697
|
+
};
|
|
9435
9698
|
function braceStatements(stmts, split = null) {
|
|
9436
9699
|
return stmts.map((s) => {
|
|
9437
|
-
const
|
|
9438
|
-
|
|
9700
|
+
const text = s.text;
|
|
9701
|
+
const open = text.indexOf("{");
|
|
9702
|
+
const lineAtPos = (pos) => s.line + (text.slice(0, pos).match(/\n/g) || []).length;
|
|
9703
|
+
const read = (o, e) => {
|
|
9704
|
+
const body = e > o ? text.slice(o + 1, e) : "";
|
|
9705
|
+
const base = s.start != null ? s.start + o + 1 : null;
|
|
9706
|
+
if (!body || !split) return [];
|
|
9707
|
+
const kids2 = split(body, lineAtPos(o + 1)).map((c) => ({ text: c.text, line: c.line, endLine: c.endLine, ...base != null && c.start != null ? { start: base + c.start, end: base + c.end } : {} }));
|
|
9708
|
+
return braceStatements(kids2, split);
|
|
9709
|
+
};
|
|
9710
|
+
let children = [], inner = 0;
|
|
9711
|
+
const clauses = [];
|
|
9439
9712
|
if (open >= 0) {
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9713
|
+
const end = blockEnd(text, open);
|
|
9714
|
+
const body = end > open ? text.slice(open + 1, end) : "";
|
|
9715
|
+
inner = body ? body.split(/;|\n/).filter((l) => l.trim() && !/^[{}]$/.test(l.trim())).length : 0;
|
|
9716
|
+
children = read(open, end);
|
|
9717
|
+
let pos = end + 1;
|
|
9718
|
+
while (end >= 0) {
|
|
9719
|
+
const rest2 = text.slice(pos);
|
|
9720
|
+
const m = rest2.match(/^\s*(else\s+if\b|elseif\b|elsif\b|else\b|catch\b|rescue\b|finally\b|ensure\b)/);
|
|
9721
|
+
if (!m) break;
|
|
9722
|
+
const kw = m[1].replace(/\s+/g, " ");
|
|
9723
|
+
const o = text.indexOf("{", pos + m[0].length);
|
|
9724
|
+
if (o < 0) break;
|
|
9725
|
+
const e = blockEnd(text, o);
|
|
9726
|
+
const clauseHead = text.slice(pos + m[0].length - m[1].length, o).trim();
|
|
9727
|
+
clauses.push({ kind: /^(else if|elseif|elsif)$/.test(kw) ? "elif" : kw === "else" ? "else" : kw === "finally" || kw === "ensure" ? "finally" : "catch", head: clauseHead, line: lineAtPos(pos + rest2.indexOf(m[1])), children: read(o, e) });
|
|
9728
|
+
if (e < 0) break;
|
|
9729
|
+
pos = e + 1;
|
|
9730
|
+
}
|
|
9731
|
+
}
|
|
9732
|
+
return { text, line: s.line, endLine: s.endLine, start: s.start, end: s.end, inner, children, ...clauses.length ? { clauses } : {} };
|
|
9454
9733
|
});
|
|
9455
9734
|
}
|
|
9456
9735
|
function indentStatements(body, { depthKey = "indent" } = {}) {
|
|
@@ -9483,24 +9762,11 @@ function indentStatements(body, { depthKey = "indent" } = {}) {
|
|
|
9483
9762
|
for (let i = 0; i < body.length; i++) {
|
|
9484
9763
|
const l = body[i];
|
|
9485
9764
|
if ((l[depthKey] ?? 0) !== base) continue;
|
|
9486
|
-
let
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
inner++;
|
|
9492
|
-
const d = body[k][depthKey] ?? 0;
|
|
9493
|
-
if (childDepth === null) childDepth = d;
|
|
9494
|
-
if (d === childDepth) children.push({ text: body[k].text, line: body[k].line });
|
|
9495
|
-
last = body[k].line;
|
|
9496
|
-
}
|
|
9497
|
-
children.forEach((c, n) => {
|
|
9498
|
-
const next = children[n + 1];
|
|
9499
|
-
const nextIdx = next ? body.findIndex((x) => x.line === next.line) : -1;
|
|
9500
|
-
const until = next ? body[nextIdx - 1]?.line ?? c.line : last;
|
|
9501
|
-
c.endLine = Math.max(c.line, until);
|
|
9502
|
-
});
|
|
9503
|
-
out.push({ text: l.text, line: l.line, endLine: last, inner, children });
|
|
9765
|
+
let k = i + 1;
|
|
9766
|
+
while (k < body.length && (body[k][depthKey] ?? 0) > base) k++;
|
|
9767
|
+
const block = body.slice(i + 1, k);
|
|
9768
|
+
const children = block.length ? indentStatements(block, { depthKey }) : [];
|
|
9769
|
+
out.push({ text: l.text, line: l.line, endLine: block.length ? block[block.length - 1].line : l.endLine ?? l.line, inner: block.length, children });
|
|
9504
9770
|
}
|
|
9505
9771
|
return out;
|
|
9506
9772
|
}
|
|
@@ -9523,7 +9789,27 @@ function detectLanguage(source, file = "") {
|
|
|
9523
9789
|
if (/:\s*(number|string|boolean)\b|\binterface\s+\w+|\bexport\s+(function|const)\b/.test(s)) return "typescript";
|
|
9524
9790
|
return "javascript";
|
|
9525
9791
|
}
|
|
9526
|
-
var
|
|
9792
|
+
var lineStarts = /* @__PURE__ */ new Map();
|
|
9793
|
+
function startsOf(src) {
|
|
9794
|
+
let starts = lineStarts.get(src);
|
|
9795
|
+
if (!starts) {
|
|
9796
|
+
starts = [0];
|
|
9797
|
+
for (let i = src.indexOf("\n"); i >= 0; i = src.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
9798
|
+
if (lineStarts.size > 8) lineStarts.delete(lineStarts.keys().next().value);
|
|
9799
|
+
lineStarts.set(src, starts);
|
|
9800
|
+
}
|
|
9801
|
+
return starts;
|
|
9802
|
+
}
|
|
9803
|
+
var lineAt = (src, idx) => {
|
|
9804
|
+
const starts = startsOf(src);
|
|
9805
|
+
let lo = 0, hi = starts.length - 1;
|
|
9806
|
+
while (lo < hi) {
|
|
9807
|
+
const mid = lo + hi + 1 >> 1;
|
|
9808
|
+
if (starts[mid] <= idx) lo = mid;
|
|
9809
|
+
else hi = mid - 1;
|
|
9810
|
+
}
|
|
9811
|
+
return lo + 1;
|
|
9812
|
+
};
|
|
9527
9813
|
function matchClose(src, open) {
|
|
9528
9814
|
const pairs = { "{": "}", "(": ")", "[": "]" };
|
|
9529
9815
|
const stack = [pairs[src[open]]];
|
|
@@ -9582,6 +9868,7 @@ function skipString(src, i) {
|
|
|
9582
9868
|
}
|
|
9583
9869
|
var stripComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
9584
9870
|
function parseParams2(raw, language) {
|
|
9871
|
+
raw = String(raw).replace(/#\[[^\]]*\]\s*/g, "").replace(/\[\w+(?:\([^)]*\))?\]\s*/g, "");
|
|
9585
9872
|
const parts = [];
|
|
9586
9873
|
let depth = 0, cur = "";
|
|
9587
9874
|
for (const ch of raw) {
|
|
@@ -9624,6 +9911,37 @@ function parseParams2(raw, language) {
|
|
|
9624
9911
|
for (const g of pendingGo) out.push({ name: g, type: null });
|
|
9625
9912
|
return out;
|
|
9626
9913
|
}
|
|
9914
|
+
function balancedReturnHead(after) {
|
|
9915
|
+
const lead = after.match(/^\s*:/);
|
|
9916
|
+
if (!lead) return null;
|
|
9917
|
+
let i = lead[0].length, depth = 0;
|
|
9918
|
+
for (; i < after.length; i++) {
|
|
9919
|
+
const c = after[i];
|
|
9920
|
+
if (c === "=" && after[i + 1] === ">") {
|
|
9921
|
+
if (depth === 0) break;
|
|
9922
|
+
i++;
|
|
9923
|
+
continue;
|
|
9924
|
+
}
|
|
9925
|
+
if (c === "<" || c === "(" || c === "[") depth++;
|
|
9926
|
+
else if (c === ">" || c === ")" || c === "]") depth--;
|
|
9927
|
+
else if (c === "{") {
|
|
9928
|
+
if (depth === 0) break;
|
|
9929
|
+
depth++;
|
|
9930
|
+
} else if (c === "}") depth--;
|
|
9931
|
+
else if (c === ";" && depth === 0) break;
|
|
9932
|
+
else if (c === '"' || c === "'" || c === "`") {
|
|
9933
|
+
const q = c;
|
|
9934
|
+
i++;
|
|
9935
|
+
while (i < after.length && after[i] !== q) i++;
|
|
9936
|
+
}
|
|
9937
|
+
}
|
|
9938
|
+
const type = after.slice(lead[0].length, i).trim();
|
|
9939
|
+
const tail = after.slice(i).match(/^\s*(?:throws\s+[\w.,\s]+)?\s*(=>|\{|;)/);
|
|
9940
|
+
if (!type || !tail) return null;
|
|
9941
|
+
const whole = after.slice(0, i) + tail[0];
|
|
9942
|
+
const m = [whole, type, void 0, void 0, tail[1]];
|
|
9943
|
+
return m;
|
|
9944
|
+
}
|
|
9627
9945
|
function simpleType(t) {
|
|
9628
9946
|
if (!t) return null;
|
|
9629
9947
|
const s = String(t).trim().replace(/^&(mut\s+)?/, "");
|
|
@@ -9636,13 +9954,30 @@ function findFunctions(src, language) {
|
|
|
9636
9954
|
const fns = [];
|
|
9637
9955
|
if (language === "python") {
|
|
9638
9956
|
const lines = src.split("\n");
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9957
|
+
let decorators = [];
|
|
9958
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9959
|
+
const l = lines[i];
|
|
9960
|
+
if (/^\s*@/.test(l)) {
|
|
9961
|
+
const { text, end } = pyBalanced(lines, i, l.indexOf("@"));
|
|
9962
|
+
decorators.push(text.replace(/\s+/g, " ").trim());
|
|
9963
|
+
i = end;
|
|
9964
|
+
continue;
|
|
9965
|
+
}
|
|
9966
|
+
const start = l.match(/^(\s*)(?:async\s+)?def\s+(\w+)\s*\(/);
|
|
9967
|
+
if (!start) {
|
|
9968
|
+
if (l.trim() && !/^\s*#/.test(l)) decorators = [];
|
|
9969
|
+
continue;
|
|
9970
|
+
}
|
|
9971
|
+
const head = pyHeader(lines, i, start[0].length - 1);
|
|
9972
|
+
if (!head) {
|
|
9973
|
+
decorators = [];
|
|
9974
|
+
continue;
|
|
9975
|
+
}
|
|
9976
|
+
const indent = start[1].length;
|
|
9643
9977
|
const body = [];
|
|
9644
|
-
|
|
9645
|
-
|
|
9978
|
+
const inline = pyNoComment(head.after).trim();
|
|
9979
|
+
if (inline) body.push({ text: inline, line: head.endLine + 1, indent: indent + 4 });
|
|
9980
|
+
for (let j = head.endLine + 1; j < lines.length; j++) {
|
|
9646
9981
|
const t = lines[j];
|
|
9647
9982
|
if (!t.trim() || /^\s*#/.test(t)) continue;
|
|
9648
9983
|
const ind = t.match(/^\s*/)[0].length;
|
|
@@ -9651,8 +9986,10 @@ function findFunctions(src, language) {
|
|
|
9651
9986
|
if (!code) continue;
|
|
9652
9987
|
body.push({ text: code, line: j + 1, indent: ind });
|
|
9653
9988
|
}
|
|
9654
|
-
|
|
9655
|
-
|
|
9989
|
+
const doc = inline ? null : pyDocstring(lines, head.endLine + 1);
|
|
9990
|
+
fns.push({ name: start[2], line: i + 1, params: parseParams2(head.params, language), returns: head.returns, pyBody: body, ...decorators.length ? { decorators } : {}, ...doc ? { doc } : {} });
|
|
9991
|
+
decorators = [];
|
|
9992
|
+
}
|
|
9656
9993
|
annotateRoutes(fns, src);
|
|
9657
9994
|
return fns;
|
|
9658
9995
|
}
|
|
@@ -9681,9 +10018,11 @@ function findFunctions(src, language) {
|
|
|
9681
10018
|
if (KEYWORDS_NOT_FN.has(name) || open < 0) continue;
|
|
9682
10019
|
const close = matchClose(src, open);
|
|
9683
10020
|
if (close < 0) continue;
|
|
9684
|
-
const after = src.slice(close + 1);
|
|
9685
|
-
const
|
|
10021
|
+
const after = src.slice(close + 1, close + 1 + 4e3);
|
|
10022
|
+
const typed = language === "typescript" || language === "javascript" ? balancedReturnHead(after) : null;
|
|
10023
|
+
const head = typed ?? (language === "kotlin" ? after.match(/^\s*(?::\s*([^{=]+?))?()()\s*(?:where\s+[^{=]+)?(=(?![=>])|\{)/) : after.match(/^\s*(?::\s*([^{=;]+?)|->\s*([^{;]+?)|\s+(\([^)]*\)|[\w.<>\[\]*&' ]+?))?\s*(?:throws\s+[\w.,\s]+)?\s*(=>|\{|;)/));
|
|
9686
10024
|
if (!head || head[4] === ";") continue;
|
|
10025
|
+
if (/\(\?:const\|let\|var\)/.test(re.source) && head[4] !== "=>") continue;
|
|
9687
10026
|
if (language === "kotlin" && head[4] === "=") {
|
|
9688
10027
|
const markerAt2 = close + 1 + head[0].length - 1;
|
|
9689
10028
|
const fnLine2 = lineAt(src, m.index + m[0].lastIndexOf(name));
|
|
@@ -9746,15 +10085,178 @@ function findFunctions(src, language) {
|
|
|
9746
10085
|
fns.push({ name: `${method} ${m[2]}`, line: lineAt(src, m.index), params: [], returns: null, bodyStart: brace + 1, body: src.slice(brace + 1, bc), route: { method, path: m[2] } });
|
|
9747
10086
|
}
|
|
9748
10087
|
}
|
|
10088
|
+
if (language === "typescript" || language === "javascript") {
|
|
10089
|
+
const re = /\b\w+\.route\(\s*\{/g;
|
|
10090
|
+
let m;
|
|
10091
|
+
while (m = re.exec(src)) {
|
|
10092
|
+
const objOpen = m.index + m[0].length - 1;
|
|
10093
|
+
const objClose = matchClose(src, objOpen);
|
|
10094
|
+
if (objClose < 0) continue;
|
|
10095
|
+
const obj = src.slice(objOpen, objClose);
|
|
10096
|
+
const method = (obj.match(/\bmethod\s*:\s*['"`](\w+)['"`]/) || [])[1];
|
|
10097
|
+
const url = (obj.match(/\b(?:url|path)\s*:\s*['"`]([^'"`]+)['"`]/) || [])[1];
|
|
10098
|
+
const h = obj.match(/\bhandler\s*:\s*(?:async\s*)?(?:function\s*\w*\s*)?\(/);
|
|
10099
|
+
if (!method || !url || !h) continue;
|
|
10100
|
+
const pOpen = objOpen + h.index + h[0].length - 1;
|
|
10101
|
+
const pClose = matchClose(src, pOpen);
|
|
10102
|
+
const brace = pClose < 0 ? -1 : src.indexOf("{", pClose);
|
|
10103
|
+
if (brace < 0 || !/^\s*(=>\s*)?(:\s*[\w<>\[\]|. ]+)?\s*(=>\s*)?$/.test(src.slice(pClose + 1, brace))) continue;
|
|
10104
|
+
const bc = matchClose(src, brace);
|
|
10105
|
+
if (bc < 0) continue;
|
|
10106
|
+
fns.push({ name: `${method.toUpperCase()} ${url}`, line: lineAt(src, m.index), params: [], returns: null, bodyStart: brace + 1, body: src.slice(brace + 1, bc), route: { method: method.toUpperCase(), path: url } });
|
|
10107
|
+
}
|
|
10108
|
+
}
|
|
9749
10109
|
annotateRoutes(fns, src);
|
|
9750
10110
|
return fns.sort((a, b) => a.line - b.line);
|
|
9751
10111
|
}
|
|
10112
|
+
function displayLabel(name) {
|
|
10113
|
+
const w = String(name).replace(/^_+|_+$/g, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
|
|
10114
|
+
return w ? w.charAt(0).toUpperCase() + w.slice(1) : String(name);
|
|
10115
|
+
}
|
|
10116
|
+
var PLUMBING = /^(self|this|cls|db|session|conn|connection|cursor|tx|transaction|request|req|res|response|ctx|context|c|w|r|next|logger|log|deps|container|di|cancellationToken|ct|ec|app|g)$/i;
|
|
10117
|
+
var PLUMBING_TYPE = /\b(Session|AsyncSession|DbContext|Connection|HttpRequest|HttpResponse|Request|Response|Context|ResponseWriter|CancellationToken|ILogger|Logger|NextFunction)\b/;
|
|
10118
|
+
var allSteps = (steps) => (steps || []).flatMap((s) => [s, ...allSteps(s.children), ...allSteps(s.otherwise), ...(s.handlers || []).flatMap((h) => allSteps(h.steps)), ...allSteps(s.always?.steps)]);
|
|
10119
|
+
function completenessOf(item2) {
|
|
10120
|
+
const reasons = [];
|
|
10121
|
+
if (item2.kind === "decision") {
|
|
10122
|
+
if (item2.unread?.length) reasons.push(`${item2.unread.length} line${item2.unread.length === 1 ? "" : "s"} not read`);
|
|
10123
|
+
return { level: reasons.length ? "partly explained" : "explained", reasons };
|
|
10124
|
+
}
|
|
10125
|
+
const steps = allSteps(item2.steps);
|
|
10126
|
+
if (!steps.length) return { level: "found", reasons: ["No steps could be read; see the original code."] };
|
|
10127
|
+
const code = steps.filter((s) => s.kind === "other").length;
|
|
10128
|
+
const restated = steps.filter((s) => s.restates).length;
|
|
10129
|
+
if (code) reasons.push(`${code} step${code === 1 ? "" : "s"} shown as code`);
|
|
10130
|
+
if (restated) reasons.push(`${restated} step${restated === 1 ? "" : "s"} only restate the code`);
|
|
10131
|
+
if (item2.anchor && item2.anchor.coverage < 1) reasons.push(`${item2.anchor.missing.length ? `lines ${item2.anchor.missing.join(", ")}` : "some lines"} not tied to a step`);
|
|
10132
|
+
return { level: reasons.length ? "partly explained" : "explained", reasons };
|
|
10133
|
+
}
|
|
10134
|
+
function pyBalanced(lines, i, col) {
|
|
10135
|
+
let depth = 0, text = "", quote = null;
|
|
10136
|
+
for (let j = i; j < lines.length; j++) {
|
|
10137
|
+
const l = j === i ? lines[j].slice(col) : lines[j];
|
|
10138
|
+
for (let k = 0; k < l.length; k++) {
|
|
10139
|
+
const c = l[k];
|
|
10140
|
+
if (quote) {
|
|
10141
|
+
if (c === "\\") k++;
|
|
10142
|
+
else if (c === quote) quote = null;
|
|
10143
|
+
continue;
|
|
10144
|
+
}
|
|
10145
|
+
if (c === '"' || c === "'") quote = c;
|
|
10146
|
+
else if (c === "#") break;
|
|
10147
|
+
else if ("([{".includes(c)) depth++;
|
|
10148
|
+
else if (")]}".includes(c)) depth--;
|
|
10149
|
+
}
|
|
10150
|
+
text += (j === i ? "" : "\n") + l;
|
|
10151
|
+
quote = null;
|
|
10152
|
+
if (depth <= 0) return { text, end: j };
|
|
10153
|
+
}
|
|
10154
|
+
return { text, end: lines.length - 1 };
|
|
10155
|
+
}
|
|
10156
|
+
function pyHeader(lines, i, open) {
|
|
10157
|
+
let depth = 0, quote = null, params = "", closed = false, tail = "";
|
|
10158
|
+
for (let j = i; j < lines.length && j < i + 80; j++) {
|
|
10159
|
+
const l = lines[j];
|
|
10160
|
+
for (let k = j === i ? open : 0; k < l.length; k++) {
|
|
10161
|
+
const c = l[k];
|
|
10162
|
+
if (!closed) {
|
|
10163
|
+
if (quote) {
|
|
10164
|
+
params += c;
|
|
10165
|
+
if (c === "\\") {
|
|
10166
|
+
params += l[k + 1] ?? "";
|
|
10167
|
+
k++;
|
|
10168
|
+
} else if (c === quote) quote = null;
|
|
10169
|
+
continue;
|
|
10170
|
+
}
|
|
10171
|
+
if (c === "#") break;
|
|
10172
|
+
if (c === '"' || c === "'") {
|
|
10173
|
+
quote = c;
|
|
10174
|
+
params += c;
|
|
10175
|
+
continue;
|
|
10176
|
+
}
|
|
10177
|
+
if (c === "(") {
|
|
10178
|
+
if (depth++ === 0) continue;
|
|
10179
|
+
} else if (c === ")") {
|
|
10180
|
+
if (--depth === 0) {
|
|
10181
|
+
closed = true;
|
|
10182
|
+
continue;
|
|
10183
|
+
}
|
|
10184
|
+
}
|
|
10185
|
+
params += c;
|
|
10186
|
+
continue;
|
|
10187
|
+
}
|
|
10188
|
+
if (c === "#" && depth === 0) break;
|
|
10189
|
+
if ("([{".includes(c)) depth++;
|
|
10190
|
+
else if (")]}".includes(c)) depth--;
|
|
10191
|
+
if (c === ":" && depth === 0) {
|
|
10192
|
+
const ret = tail.trim().replace(/^->\s*/, "").replace(/\s+/g, " ").trim();
|
|
10193
|
+
return { params: params.replace(/\s+/g, " ").trim(), returns: ret || null, after: l.slice(k + 1), endLine: j };
|
|
10194
|
+
}
|
|
10195
|
+
tail += c;
|
|
10196
|
+
}
|
|
10197
|
+
if (!closed) params += " ";
|
|
10198
|
+
else tail += " ";
|
|
10199
|
+
}
|
|
10200
|
+
return null;
|
|
10201
|
+
}
|
|
10202
|
+
function pyDocstring(lines, from) {
|
|
10203
|
+
let j = from;
|
|
10204
|
+
while (j < lines.length && (!lines[j].trim() || /^\s*#/.test(lines[j]))) j++;
|
|
10205
|
+
const first = lines[j]?.trim();
|
|
10206
|
+
const m = first?.match(/^([rRuU]?)("""|\'\'\'|"|')/);
|
|
10207
|
+
if (!m) return null;
|
|
10208
|
+
const q = m[2];
|
|
10209
|
+
let text = first.slice(m[0].length);
|
|
10210
|
+
if (text.includes(q)) text = text.slice(0, text.indexOf(q));
|
|
10211
|
+
else {
|
|
10212
|
+
if (q.length === 1) return null;
|
|
10213
|
+
for (let k = j + 1; k < lines.length && k < j + 60; k++) {
|
|
10214
|
+
const at = lines[k].indexOf(q);
|
|
10215
|
+
if (at >= 0) {
|
|
10216
|
+
text += "\n" + lines[k].slice(0, at);
|
|
10217
|
+
break;
|
|
10218
|
+
}
|
|
10219
|
+
text += "\n" + lines[k];
|
|
10220
|
+
}
|
|
10221
|
+
}
|
|
10222
|
+
return cleanDoc(text);
|
|
10223
|
+
}
|
|
10224
|
+
function cleanDoc(text) {
|
|
10225
|
+
const para = [];
|
|
10226
|
+
for (const raw of String(text).split("\n")) {
|
|
10227
|
+
const t = raw.replace(/^\s*(\*|\/\/\/?|#)?\s?/, "").trim();
|
|
10228
|
+
if (/^(@\w+|:(param|return|rtype|raises|type)\b|(Args|Arguments|Parameters|Returns|Raises|Yields|Example|Examples|Note|Notes)\s*:|<\/?(summary|param|returns)\b)/i.test(t)) break;
|
|
10229
|
+
if (!t) {
|
|
10230
|
+
if (para.length) break;
|
|
10231
|
+
continue;
|
|
10232
|
+
}
|
|
10233
|
+
para.push(t.replace(/<\/?summary>/g, ""));
|
|
10234
|
+
}
|
|
10235
|
+
const s = para.join(" ").replace(/\s+/g, " ").trim();
|
|
10236
|
+
if (!s) return null;
|
|
10237
|
+
return s.length > 300 ? `${s.slice(0, 299)}\u2026` : s;
|
|
10238
|
+
}
|
|
10239
|
+
function leadingDoc(lines, fnLine, language) {
|
|
10240
|
+
let k = fnLine - 2;
|
|
10241
|
+
while (k >= 0 && /^\s*(@|#\[|\[[A-Z])/.test(lines[k])) k--;
|
|
10242
|
+
if (k < 0) return null;
|
|
10243
|
+
if (/\*\/\s*$/.test(lines[k])) {
|
|
10244
|
+
const end = k;
|
|
10245
|
+
while (k >= 0 && !/\/\*\*/.test(lines[k])) k--;
|
|
10246
|
+
if (k < 0) return null;
|
|
10247
|
+
return cleanDoc(lines.slice(k, end + 1).join("\n").replace(/^\s*\/\*\*/, "").replace(/\*\/\s*$/, ""));
|
|
10248
|
+
}
|
|
10249
|
+
const lineDoc = language === "go" ? /^\s*\/\/(?!\/)/ : language === "ruby" ? /^\s*#(?![!{])/ : /^\s*\/\/\//;
|
|
10250
|
+
const got = [];
|
|
10251
|
+
while (k >= 0 && lineDoc.test(lines[k])) got.unshift(lines[k--]);
|
|
10252
|
+
return got.length ? cleanDoc(got.join("\n")) : null;
|
|
10253
|
+
}
|
|
9752
10254
|
function annotateRoutes(fns, src) {
|
|
9753
10255
|
const lines = src.split("\n");
|
|
9754
10256
|
for (const fn of fns) {
|
|
9755
10257
|
if (fn.route) continue;
|
|
9756
|
-
|
|
9757
|
-
|
|
10258
|
+
const above = fn.decorators ? [...fn.decorators].reverse() : lines.slice(Math.max(0, fn.line - 6), Math.max(0, fn.line - 1)).reverse().map((x) => x.trim());
|
|
10259
|
+
for (const l of above) {
|
|
9758
10260
|
let m;
|
|
9759
10261
|
if (m = l.match(/^@\w+\.(get|post|put|patch|delete)\(\s*['"]([^'"]*)['"]/i)) {
|
|
9760
10262
|
fn.route = { method: m[1].toUpperCase(), path: m[2] };
|
|
@@ -10108,7 +10610,7 @@ function toThunderOutcome(text) {
|
|
|
10108
10610
|
if (/^[A-Z][A-Za-z0-9_]*$/.test(s)) return s;
|
|
10109
10611
|
return null;
|
|
10110
10612
|
}
|
|
10111
|
-
var
|
|
10613
|
+
var lastSeg2 = (s) => String(s).split(/\.|::/).pop();
|
|
10112
10614
|
var firstString = (s) => (String(s).match(/^\s*(?:f|r|b)?["'`]([^"'`]{1,80})["'`]/) || [])[1] || null;
|
|
10113
10615
|
function splitTop(str2, delim) {
|
|
10114
10616
|
const out = [];
|
|
@@ -10134,21 +10636,21 @@ function splitTop(str2, delim) {
|
|
|
10134
10636
|
function terminatorEffect(stmt, language) {
|
|
10135
10637
|
const s = String(stmt).trim().replace(/;$/, "").trim();
|
|
10136
10638
|
let m;
|
|
10137
|
-
if (m = s.match(/^throw\s+new\s+([\w.$]+)\s*\(([\s\S]*)\)$/)) return { kind: "fails", name:
|
|
10138
|
-
if (m = s.match(/^throw\s+([\w.$]+)$/)) return { kind: "fails", name:
|
|
10139
|
-
if (m = s.match(/^throw\s+([A-Z][\w.$]*)\s*\(([\s\S]*)\)$/)) return { kind: "fails", name:
|
|
10639
|
+
if (m = s.match(/^throw\s+new\s+([\w.$]+)\s*\(([\s\S]*)\)$/)) return { kind: "fails", name: lastSeg2(m[1]), detail: firstString(m[2]) };
|
|
10640
|
+
if (m = s.match(/^throw\s+([\w.$]+)$/)) return { kind: "fails", name: lastSeg2(m[1]) };
|
|
10641
|
+
if (m = s.match(/^throw\s+([A-Z][\w.$]*)\s*\(([\s\S]*)\)$/)) return { kind: "fails", name: lastSeg2(m[1]), detail: firstString(m[2]) };
|
|
10140
10642
|
if ((m = s.match(/^error\(([\s\S]*)\)$/)) && language === "kotlin") return { kind: "fails", name: "IllegalStateException", detail: firstString(m[1]) };
|
|
10141
10643
|
if (m = s.match(/^abort\(\s*(\d{3})\b/)) return { kind: "responds", name: m[1] };
|
|
10142
|
-
if (m = s.match(/^raise\s+([\w.]+)(?:\(([\s\S]*)\))?$/)) return { kind: "fails", name:
|
|
10644
|
+
if (m = s.match(/^raise\s+([\w.]+)(?:\(([\s\S]*)\))?$/)) return { kind: "fails", name: lastSeg2(m[1]), detail: m[2] ? firstString(m[2]) : null };
|
|
10143
10645
|
if (language === "ruby") {
|
|
10144
|
-
if (m = s.match(/^raise\s+([A-Z][\w:]*)(?:\.new)?\s*(?:,\s*|\(\s*)?([\s\S]*?)\)?$/)) return { kind: "fails", name:
|
|
10646
|
+
if (m = s.match(/^raise\s+([A-Z][\w:]*)(?:\.new)?\s*(?:,\s*|\(\s*)?([\s\S]*?)\)?$/)) return { kind: "fails", name: lastSeg2(m[1]), detail: firstString(m[2] || "") };
|
|
10145
10647
|
if (m = s.match(/^(?:raise|fail)\s+(["'][\s\S]*)$/)) return { kind: "fails", name: "RuntimeError", detail: firstString(m[1]) };
|
|
10146
10648
|
if (m = s.match(/^(?:head|halt)\s+(?::|")?(\w+)"?/)) return { kind: "responds", name: m[1] };
|
|
10147
10649
|
}
|
|
10148
10650
|
if (m = s.match(/^panic!?\(([\s\S]*)\)$/)) return { kind: "fails", name: "panic", detail: firstString(m[1]) };
|
|
10149
10651
|
if (m = s.match(/^return\s+Err\(([\s\S]*)\)$/)) {
|
|
10150
10652
|
const inner = m[1].trim();
|
|
10151
|
-
return { kind: "fails", name: firstString(inner) ? "error" :
|
|
10653
|
+
return { kind: "fails", name: firstString(inner) ? "error" : lastSeg2(inner.replace(/\(.*$/s, "")), detail: firstString(inner) };
|
|
10152
10654
|
}
|
|
10153
10655
|
if (s === "return") return { kind: "stops" };
|
|
10154
10656
|
if ((m = s.match(/^render\b.*\bstatus:\s*(?::|")?(\w+)/)) && language === "ruby") return { kind: "responds", name: m[1] };
|
|
@@ -10446,11 +10948,14 @@ function splitStatements(body, baseLine) {
|
|
|
10446
10948
|
}
|
|
10447
10949
|
}
|
|
10448
10950
|
} else if (c === ";" && depth === 0) {
|
|
10951
|
+
if (/^\s*(?:if|for|switch|else\s+if)\b/.test(src.slice(start, i)) && !src.slice(start, i).includes("{") && /\{/.test(src.slice(i, src.indexOf("\n", i) < 0 ? void 0 : src.indexOf("\n", i)))) continue;
|
|
10449
10952
|
i++;
|
|
10450
10953
|
break;
|
|
10451
10954
|
} else if (c === "\n" && depth === 0) {
|
|
10452
10955
|
const before = src.slice(start, i).trimEnd();
|
|
10453
|
-
|
|
10956
|
+
let j = i + 1;
|
|
10957
|
+
while (j < src.length && (src[j] === " " || src[j] === " " || src[j] === "\n" || src[j] === "\r")) j++;
|
|
10958
|
+
const after = src.slice(j, j + 24);
|
|
10454
10959
|
if (before && !/[,(\[{+\-*/%&|^=<>?:.!]$/.test(before) && !/^[.)\]}{+\-*/%&|^=<>?:,]/.test(after) && !/^(?:else|catch|finally)\b/.test(after)) {
|
|
10455
10960
|
i++;
|
|
10456
10961
|
break;
|
|
@@ -10459,7 +10964,9 @@ function splitStatements(body, baseLine) {
|
|
|
10459
10964
|
}
|
|
10460
10965
|
const raw = src.slice(start, i);
|
|
10461
10966
|
const text = raw.trim();
|
|
10462
|
-
|
|
10967
|
+
let e = raw.length;
|
|
10968
|
+
while (e > 0 && /[\s;]/.test(raw[e - 1])) e--;
|
|
10969
|
+
const end = start + e;
|
|
10463
10970
|
if (text) out.push({ text, line: baseLine + lineAt(src, start) - 1, endLine: baseLine + lineAt(src, Math.max(start, end - 1)) - 1, start, end });
|
|
10464
10971
|
}
|
|
10465
10972
|
return out;
|
|
@@ -10495,7 +11002,7 @@ function readBraceStatements(stmts, language, inputs) {
|
|
|
10495
11002
|
const head = splitIf(t, language);
|
|
10496
11003
|
if (head && !/^else\b/.test(head.remaining)) {
|
|
10497
11004
|
const single = head.branch.replace(/^return\s+/, "").replace(/;\s*$/, "");
|
|
10498
|
-
const looksLikeError = /^(Err[A-Z]\w*|\w*(Error|Exception))$/.test(
|
|
11005
|
+
const looksLikeError = /^(Err[A-Z]\w*|\w*(Error|Exception))$/.test(lastSeg2(single));
|
|
10499
11006
|
const isFixedReturn = /^return\s/.test(head.branch) && toThunderOutcome(single) && !looksLikeError && (language !== "go" || !single.includes(","));
|
|
10500
11007
|
if (!isFixedReturn) {
|
|
10501
11008
|
const g = makeGuard(head.cond, head.branch, language, inputs, st.line);
|
|
@@ -11128,7 +11635,7 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
11128
11635
|
let stmts = [];
|
|
11129
11636
|
try {
|
|
11130
11637
|
if (lang === "python") stmts = indentStatements(fn.pyBody, { depthKey: "indent" });
|
|
11131
|
-
else if (lang === "ruby") stmts = indentStatements(fn.rbBody, { depthKey: "depth" });
|
|
11638
|
+
else if (lang === "ruby") stmts = indentStatements(fn.rbBody.map((l) => /^(elsif|else|rescue|ensure)\b/.test(l.text) ? { ...l, depth: Math.max(0, l.depth - 1) } : l), { depthKey: "depth" });
|
|
11132
11639
|
else if (typeof fn.body === "string" && fn.bodyStart != null) stmts = braceStatements(splitStatements(lang === "kotlin" ? kotlinTerminate(fn.body) : fn.body, lineAt(code, fn.bodyStart)), splitStatements);
|
|
11133
11640
|
} catch {
|
|
11134
11641
|
return null;
|
|
@@ -11160,8 +11667,9 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
11160
11667
|
}
|
|
11161
11668
|
for (const st of r.steps) {
|
|
11162
11669
|
if (st.kind !== "branch" || !st.cond) continue;
|
|
11163
|
-
const
|
|
11164
|
-
|
|
11670
|
+
const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
|
|
11671
|
+
const cond = bareProperty ? null : toThunderCondition(st.cond, names);
|
|
11672
|
+
if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
|
|
11165
11673
|
delete st.cond;
|
|
11166
11674
|
delete st.negate;
|
|
11167
11675
|
}
|
|
@@ -11176,6 +11684,7 @@ function readCode(source, { language, file = "" } = {}) {
|
|
|
11176
11684
|
const code = lang === "php" ? normalizePhp(src) : src;
|
|
11177
11685
|
const items = [];
|
|
11178
11686
|
const srcLines = src.split("\n");
|
|
11687
|
+
const codeLines = code.split("\n");
|
|
11179
11688
|
for (const fn of findFunctions(code, lang)) {
|
|
11180
11689
|
const inputs = fn.params;
|
|
11181
11690
|
const names = inputs.map((p) => p.name);
|
|
@@ -11194,13 +11703,17 @@ function readCode(source, { language, file = "" } = {}) {
|
|
|
11194
11703
|
guards.sort((a, b) => a.line - b.line);
|
|
11195
11704
|
}
|
|
11196
11705
|
const guardNote = guards.length ? ` It checks ${guards.length} condition${guards.length === 1 ? "" : "s"} first: ${guards.map((g) => g.says.replace(/\.$/, "")).join("; ")}.` : "";
|
|
11706
|
+
const doc = fn.doc ?? (lang === "python" ? null : leadingDoc(codeLines, fn.line, lang));
|
|
11197
11707
|
const base = {
|
|
11198
11708
|
id: `${fn.name}:${fn.line}`,
|
|
11199
11709
|
name: fn.name,
|
|
11710
|
+
label: displayLabel(fn.name),
|
|
11200
11711
|
line: fn.line,
|
|
11201
|
-
|
|
11712
|
+
// Framework plumbing (a database session, the request, a context) is marked so views can leave it out of "You give it".
|
|
11713
|
+
inputs: inputs.map((p) => PLUMBING.test(p.name) || PLUMBING_TYPE.test(String(p.type ?? "")) ? { ...p, plumbing: true } : p),
|
|
11202
11714
|
returns: simpleType(fn.returns),
|
|
11203
11715
|
...fn.route ? { route: fn.route } : {},
|
|
11716
|
+
...doc ? { doc } : {},
|
|
11204
11717
|
provenance: "inferred-from-code"
|
|
11205
11718
|
};
|
|
11206
11719
|
if (isDecision) {
|
|
@@ -11223,6 +11736,9 @@ function readCode(source, { language, file = "" } = {}) {
|
|
|
11223
11736
|
status: "signature-only",
|
|
11224
11737
|
...st ? { steps: st.steps, stepsMore: st.more, stepsReadable: Math.round(st.readable * 100) / 100, ...st.anchor ? { anchor: st.anchor } : {} } : {},
|
|
11225
11738
|
says: fn.route ? `Handles ${fn.route.method} ${fn.route.path || "(this controller's path)"}.${guardNote}` : `${fn.name} takes ${inputs.length ? inputs.map((p) => p.type && !/[<>\[\]]/.test(p.type) ? `${p.name} (${p.type})` : p.name).join(", ") : "no inputs"}${fn.returns ? ` and returns ${simpleType(fn.returns)}` : ""}. ${guards.length ? "" : " Its body does more than choose between fixed answers, so no rules are shown."}${guardNote}`,
|
|
11739
|
+
// The same facts as separate fields, so a view never has to cut sentences out of `says`.
|
|
11740
|
+
headline: fn.route ? `Handles ${fn.route.method} ${fn.route.path || "(this controller's path)"}.` : `${displayLabel(fn.name)} takes ${inputs.length ? inputs.map((p) => p.name).join(", ") : "no inputs"}${fn.returns ? ` and returns ${simpleType(fn.returns)}` : ""}.`,
|
|
11741
|
+
...guards.length ? {} : { note: "Its body does more than choose between fixed answers, so no rules are shown." },
|
|
11226
11742
|
guards,
|
|
11227
11743
|
unread: read.unread
|
|
11228
11744
|
});
|
|
@@ -11232,6 +11748,7 @@ function readCode(source, { language, file = "" } = {}) {
|
|
|
11232
11748
|
for (const e of facts?.errors || []) items.push({ id: `error:${e.name}:${e.line}`, kind: "error", name: e.name, line: e.line, status: "read", says: /\s/.test(e.name) ? `Can fail with the error "${e.name}".` : `Raises ${e.name}.`, provenance: "inferred-from-code" });
|
|
11233
11749
|
for (const t of facts?.tests || []) items.push({ id: `test:${t.name}:${t.line}`, kind: "test", name: t.name, line: t.line, status: "read", says: `A test named "${t.name}".`, provenance: "inferred-from-code" });
|
|
11234
11750
|
items.sort((a, b) => a.line - b.line);
|
|
11751
|
+
for (const it of items) if (it.kind === "function" || it.kind === "decision") it.completeness = completenessOf(it);
|
|
11235
11752
|
const counts = { decision: 0, function: 0, error: 0, test: 0, partial: 0, guarded: 0, route: 0 };
|
|
11236
11753
|
for (const it of items) {
|
|
11237
11754
|
counts[it.kind]++;
|
|
@@ -11867,8 +12384,8 @@ function readUnknowns(ast, source) {
|
|
|
11867
12384
|
}
|
|
11868
12385
|
function previewHumanContract(source) {
|
|
11869
12386
|
const first = source.split(/\r?\n/).find((l) => l.trim() && !l.trim().startsWith("#"))?.trim() ?? "";
|
|
11870
|
-
const
|
|
11871
|
-
const canonicalSource =
|
|
12387
|
+
const compact2 = first.startsWith("contract ");
|
|
12388
|
+
const canonicalSource = compact2 ? compileHumanContract(source) : source;
|
|
11872
12389
|
const ast = parseIntent(canonicalSource);
|
|
11873
12390
|
const tests = runTests(ast);
|
|
11874
12391
|
const declared = (ast.tests ?? []).flatMap((t) => t.cases);
|
|
@@ -11877,7 +12394,7 @@ function previewHumanContract(source) {
|
|
|
11877
12394
|
const report = {
|
|
11878
12395
|
schema: "thunder-human-preview-v1",
|
|
11879
12396
|
experimental: true,
|
|
11880
|
-
origin: ast.lift?.inferred ? "inferred-code" :
|
|
12397
|
+
origin: ast.lift?.inferred ? "inferred-code" : compact2 ? "human-v1" : "thunderlang",
|
|
11881
12398
|
mission: ast.mission,
|
|
11882
12399
|
purpose: ast.goal,
|
|
11883
12400
|
canonicalSource,
|
|
@@ -12722,6 +13239,614 @@ function startLspServer({ readable = process.stdin, writable = process.stdout }
|
|
|
12722
13239
|
});
|
|
12723
13240
|
}
|
|
12724
13241
|
|
|
13242
|
+
// src/plain-contract.mjs
|
|
13243
|
+
var PLAIN_SCHEMA = "thunder-plain-v1";
|
|
13244
|
+
var COMPARISONS = [
|
|
13245
|
+
{ op: ">=", words: ["at least"] },
|
|
13246
|
+
{ op: "<=", words: ["at most"] },
|
|
13247
|
+
{ op: "<", words: ["under", "less than", "below"] },
|
|
13248
|
+
{ op: ">", words: ["over", "more than", "above"] },
|
|
13249
|
+
{ op: "==", words: ["exactly"] }
|
|
13250
|
+
];
|
|
13251
|
+
var opWord = (op) => COMPARISONS.find((c) => c.op === op)?.words[0] ?? op;
|
|
13252
|
+
var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
13253
|
+
var pascal4 = (s) => s.replace(/[^A-Za-z0-9 ]/g, " ").trim().split(/\s+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join("");
|
|
13254
|
+
function formatValue(input, value) {
|
|
13255
|
+
if (input.kind === "yesno") return value ? input.yes : input.no;
|
|
13256
|
+
if (input.kind === "text") return value === "" ? "empty" : JSON.stringify(String(value));
|
|
13257
|
+
if (input.kind === "dollars") return `${value < 0 ? "-" : ""}$${Math.abs(value)}`;
|
|
13258
|
+
return String(value);
|
|
13259
|
+
}
|
|
13260
|
+
function conditionText(model, c) {
|
|
13261
|
+
const input = model.inputs.find((i) => i.id === c.input);
|
|
13262
|
+
if (!input) return "(unknown input)";
|
|
13263
|
+
if (input.kind === "yesno") return `it is ${c.value ? input.yes : input.no}`;
|
|
13264
|
+
if (input.kind === "text") return `${input.label} is ${c.op === "!=" ? "not " : ""}${formatValue(input, c.value)}`;
|
|
13265
|
+
return `${input.label} is ${opWord(c.op)} ${formatValue(input, c.value)}`;
|
|
13266
|
+
}
|
|
13267
|
+
function renderPlainContract(model) {
|
|
13268
|
+
const out = [model.title];
|
|
13269
|
+
if (model.why) out.push(`Why: ${model.why}`);
|
|
13270
|
+
out.push("", "We need");
|
|
13271
|
+
for (const i of model.inputs) out.push(` ${i.kind === "yesno" ? `whether it is ${i.yes} or ${i.no}` : `${i.label}, ${i.kind === "dollars" ? "in dollars" : "a number"}`}`);
|
|
13272
|
+
out.push("", model.question);
|
|
13273
|
+
for (const r of model.rules) {
|
|
13274
|
+
if (r.conditions.length === 1) out.push(` ${r.outcome} when ${conditionText(model, r.conditions[0])}.`);
|
|
13275
|
+
else {
|
|
13276
|
+
out.push(` ${r.outcome} when ${r.join} of these ${r.join === "all" ? "are" : "is"} true:`);
|
|
13277
|
+
for (const c of r.conditions) out.push(` ${conditionText(model, c)}`);
|
|
13278
|
+
}
|
|
13279
|
+
}
|
|
13280
|
+
out.push(` Otherwise, ${model.otherwise}.`, "", "Examples");
|
|
13281
|
+
const cells = model.examples.map((e) => [model.inputs.map((i) => formatValue(i, e.values[i.id])).join(", "), `gives ${e.expected}`, `(${e.name})`]);
|
|
13282
|
+
const w0 = Math.max(...cells.map((c) => c[0].length)), w1 = Math.max(...cells.map((c) => c[1].length));
|
|
13283
|
+
for (const c of cells) out.push(` ${c[0].padEnd(w0)} ${c[1].padEnd(w1)} ${c[2]}`);
|
|
13284
|
+
return out.join("\n") + "\n";
|
|
13285
|
+
}
|
|
13286
|
+
function conditionExpr(model, c) {
|
|
13287
|
+
const input = model.inputs.find((i) => i.id === c.input);
|
|
13288
|
+
if (input.kind === "yesno") return `${input.id} == ${c.value}`;
|
|
13289
|
+
if (input.kind === "text") return `${input.id} ${c.op === "!=" ? "!=" : "=="} ${JSON.stringify(String(c.value))}`;
|
|
13290
|
+
return `${input.id} ${c.op} ${c.value}`;
|
|
13291
|
+
}
|
|
13292
|
+
function plainToThunder(model) {
|
|
13293
|
+
const name = pascal4(model.title);
|
|
13294
|
+
const lit2 = (v) => typeof v === "boolean" ? String(v) : String(v);
|
|
13295
|
+
const out = [
|
|
13296
|
+
`# Compiled from plain ThunderLang (${PLAIN_SCHEMA}). Edit the plain file, not this one.`,
|
|
13297
|
+
`mission ${name}`,
|
|
13298
|
+
"",
|
|
13299
|
+
`title ${JSON.stringify(model.title)}`,
|
|
13300
|
+
"",
|
|
13301
|
+
"goal",
|
|
13302
|
+
` ${model.why || model.title}`,
|
|
13303
|
+
"",
|
|
13304
|
+
`# ${model.question}`,
|
|
13305
|
+
`decision ${name}`,
|
|
13306
|
+
" inputs",
|
|
13307
|
+
...model.inputs.map((i) => ` ${i.id}${i.kind === "yesno" ? ": boolean" : i.kind === "number" || i.kind === "dollars" ? ": number" : i.kind === "text" ? ": string" : ""}`)
|
|
13308
|
+
];
|
|
13309
|
+
const used = /* @__PURE__ */ new Map();
|
|
13310
|
+
for (const r of model.rules) {
|
|
13311
|
+
const base = lowerFirst(r.outcome);
|
|
13312
|
+
const n = (used.get(base) ?? 0) + 1;
|
|
13313
|
+
used.set(base, n);
|
|
13314
|
+
out.push(` rule ${n === 1 ? base : `${base}_${n}`}`, ` when ${r.conditions.map((c) => conditionExpr(model, c)).join(r.join === "all" ? " and " : " or ")}`, ` return ${r.outcome}`);
|
|
13315
|
+
}
|
|
13316
|
+
out.push(" default", ` return ${model.otherwise}`, "", `test ${name}`);
|
|
13317
|
+
for (const e of model.examples) {
|
|
13318
|
+
out.push(` case ${e.name}`, ` given ${model.inputs.map((i) => `${i.id} ${lit2(e.values[i.id])}`).join(", ")}`, ` expect ${e.expected}`);
|
|
13319
|
+
}
|
|
13320
|
+
return out.join("\n") + "\n";
|
|
13321
|
+
}
|
|
13322
|
+
function explainPlain(model, values, ast = parseIntent(plainToThunder(model))) {
|
|
13323
|
+
const run = evaluateDecision(ast.decisions[0], values);
|
|
13324
|
+
const rules = model.rules.map((r) => ({
|
|
13325
|
+
outcome: r.outcome,
|
|
13326
|
+
join: r.join,
|
|
13327
|
+
checks: r.conditions.map((c) => ({ text: conditionText(model, c), ok: !!compileExpr(conditionExpr(model, c))(values), actual: formatValue(model.inputs.find((i) => i.id === c.input), values[c.input]), input: c.input }))
|
|
13328
|
+
}));
|
|
13329
|
+
const index = run.matched === "default" ? -1 : ast.decisions[0].rules.findIndex((r) => r.name === run.matched);
|
|
13330
|
+
return { outcome: run.result, ruleIndex: index, rules, ok: run.ok };
|
|
13331
|
+
}
|
|
13332
|
+
var spaced = (s) => s.replace(/([a-z0-9])([A-Z])/g, (_m, a, b) => `${a} ${b.toLowerCase()}`).replace(/_/g, " ").toLowerCase();
|
|
13333
|
+
function plainFromReading(item2) {
|
|
13334
|
+
if (!item2 || item2.kind !== "decision" || !item2.rules?.length || !item2.otherwise) return null;
|
|
13335
|
+
const inferred = [];
|
|
13336
|
+
const whens = (item2.rules ?? []).map((r) => r.when ?? "").join(" and ");
|
|
13337
|
+
const typed = (item2.inputs ?? []).map((i) => {
|
|
13338
|
+
if (i.type) return i;
|
|
13339
|
+
const esc2 = i.name.replace(/[$]/g, "\\$");
|
|
13340
|
+
if (new RegExp(`\\b${esc2}\\s*(>=|<=|<|>|==)\\s*-?\\d`).test(whens)) {
|
|
13341
|
+
inferred.push(i.name);
|
|
13342
|
+
return { ...i, type: "number" };
|
|
13343
|
+
}
|
|
13344
|
+
if (new RegExp(`(^|\\s|not\\s+|!)${esc2}(\\s|$)`).test(whens)) {
|
|
13345
|
+
inferred.push(i.name);
|
|
13346
|
+
return { ...i, type: "boolean" };
|
|
13347
|
+
}
|
|
13348
|
+
return i;
|
|
13349
|
+
});
|
|
13350
|
+
const inputs = typed.map((i) => i.type === "boolean" ? { id: i.name, kind: "yesno", label: `it is ${spaced(i.name)}`, yes: spaced(i.name), no: `not ${spaced(i.name)}` } : i.type === "number" ? { id: i.name, kind: "number", label: `the ${spaced(i.name)}` } : { id: i.name, kind: "other", label: `the ${spaced(i.name)}` });
|
|
13351
|
+
const model = {
|
|
13352
|
+
schema: PLAIN_SCHEMA,
|
|
13353
|
+
title: spaced(item2.name).replace(/^./, (c) => c.toUpperCase()),
|
|
13354
|
+
why: "",
|
|
13355
|
+
question: `How is ${spaced(item2.name)} decided?`,
|
|
13356
|
+
inputs,
|
|
13357
|
+
rules: [],
|
|
13358
|
+
otherwise: "",
|
|
13359
|
+
examples: [],
|
|
13360
|
+
provenance: "inferred-from-code",
|
|
13361
|
+
needsReview: []
|
|
13362
|
+
};
|
|
13363
|
+
const outcome = (t) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(t) || /^-?\d+(\.\d+)?$/.test(t) ? t : null;
|
|
13364
|
+
const stateFacts = [];
|
|
13365
|
+
const input = (id2) => inputs.find((i) => i.id === id2);
|
|
13366
|
+
const factFor = (path) => {
|
|
13367
|
+
const id2 = path.replace(/[^A-Za-z0-9_]/g, "_");
|
|
13368
|
+
let f = input(id2);
|
|
13369
|
+
if (!f) {
|
|
13370
|
+
const word = spaced(path.split(".").pop());
|
|
13371
|
+
f = { id: id2, kind: "yesno", label: `it is ${word}`, yes: word, no: `not ${word}`, fromState: true };
|
|
13372
|
+
if (inputs.some((i) => i.kind === "yesno" && (i.yes === f.yes || i.no === f.yes))) return null;
|
|
13373
|
+
inputs.push(f);
|
|
13374
|
+
stateFacts.push(path);
|
|
13375
|
+
}
|
|
13376
|
+
return f;
|
|
13377
|
+
};
|
|
13378
|
+
for (const r of item2.rules) {
|
|
13379
|
+
const when = r.when.trim();
|
|
13380
|
+
const join3 = / or /.test(when) ? "any" : "all";
|
|
13381
|
+
if (/ or /.test(when) && / and /.test(when)) return null;
|
|
13382
|
+
const conditions = [];
|
|
13383
|
+
for (const part of when.split(join3 === "all" ? " and " : " or ")) {
|
|
13384
|
+
const t = part.trim();
|
|
13385
|
+
let m;
|
|
13386
|
+
const input2 = (id2) => inputs.find((i) => i.id === id2);
|
|
13387
|
+
if ((m = t.match(/^(not\s+|!)?([A-Za-z_]\w*)$/)) && input2(m[2])?.kind === "yesno") conditions.push({ input: m[2], op: "is", value: !m[1] });
|
|
13388
|
+
else if ((m = t.match(/^([A-Za-z_]\w*)\s*(>=|<=|<|>|==)\s*(-?\d+(?:\.\d+)?)$/)) && input2(m[1])?.kind === "number") conditions.push({ input: m[1], op: m[2], value: Number(m[3]) });
|
|
13389
|
+
else if (m = t.match(/^([A-Za-z_][\w.]*)\s*(==|!=)\s*"([^"]*)"$/)) {
|
|
13390
|
+
let f = input2(m[1]);
|
|
13391
|
+
if (!f) {
|
|
13392
|
+
const id2 = m[1].replace(/[^A-Za-z0-9_]/g, "_");
|
|
13393
|
+
f = { id: id2, kind: "text", label: `the ${spaced(m[1].split(".").pop())}` };
|
|
13394
|
+
if (m[1].includes(".")) stateFacts.push(m[1]);
|
|
13395
|
+
inputs.push(f);
|
|
13396
|
+
}
|
|
13397
|
+
if (f.kind === "yesno" || f.kind === "number") return null;
|
|
13398
|
+
f.kind = "text";
|
|
13399
|
+
conditions.push({ input: f.id, op: m[2], value: m[3] });
|
|
13400
|
+
} else if ((m = t.match(/^(not\s+|!)?([A-Za-z_][\w.]*)$/)) && !input2(m[2])) {
|
|
13401
|
+
const f = factFor(m[2]);
|
|
13402
|
+
if (!f) return null;
|
|
13403
|
+
conditions.push({ input: f.id, op: "is", value: !m[1] });
|
|
13404
|
+
} else return null;
|
|
13405
|
+
}
|
|
13406
|
+
if (!outcome(r.result)) return null;
|
|
13407
|
+
model.rules.push({ outcome: r.result, join: join3, conditions });
|
|
13408
|
+
}
|
|
13409
|
+
if (!outcome(item2.otherwise.result)) return null;
|
|
13410
|
+
model.otherwise = item2.otherwise.result;
|
|
13411
|
+
for (const i of inputs) {
|
|
13412
|
+
model.needsReview.push(i.kind === "yesno" ? `What does "${i.yes}" mean in business words?` : `Is ${i.label} money, a count, or something else?`);
|
|
13413
|
+
}
|
|
13414
|
+
for (const path of stateFacts) model.needsReview.push(`${spaced(path.split(".").pop())} comes from the code's own state, not from an input.`);
|
|
13415
|
+
if (item2.status === "partial") {
|
|
13416
|
+
model.partial = true;
|
|
13417
|
+
model.needsReview.unshift(`Thunder could not read ${item2.unread?.length || "some"} line(s) of this function, so the picture may be incomplete.`);
|
|
13418
|
+
}
|
|
13419
|
+
for (const name of inferred) model.needsReview.push(`The code does not declare a type for ${spaced(name)}; Thunder inferred it from how the rule uses it.`);
|
|
13420
|
+
model.needsReview.push("Why does this rule exist? Code shows what happens, not why.", "No examples yet: add cases before relying on it.");
|
|
13421
|
+
return model;
|
|
13422
|
+
}
|
|
13423
|
+
|
|
13424
|
+
// src/visual.mjs
|
|
13425
|
+
var VISUAL_SCHEMA = "thunder-visual-v1";
|
|
13426
|
+
var PRINCIPLE = "We are no longer writing code for the computer. We are writing code for humans.";
|
|
13427
|
+
var FORMS = [
|
|
13428
|
+
{ id: "picture", name: "Thunder", role: "main", says: "The visual form: cards, steps, and maps. What most people read." },
|
|
13429
|
+
{ id: "text", name: "Thunder Text", role: "detail", says: "The same meaning in structured words, for reading in detail, reviewing, and storing." },
|
|
13430
|
+
{ id: "meaning", name: "The meaning", role: "model", says: "The one reading both views are made from. The picture and Thunder Text are two views of it, never translations of each other." },
|
|
13431
|
+
{ id: "source", name: "Original code", role: "evidence", says: "The code in its own language. Always one click away (View original)." }
|
|
13432
|
+
];
|
|
13433
|
+
var ZOOM = [
|
|
13434
|
+
{ level: 0, name: "App", from: "A product or a repository", element: "app", atlas: "Z0" },
|
|
13435
|
+
{ level: 1, name: "Area", from: "A feature area, service, package, or folder (Atlas; optional in Read in Thunder)", element: "area", atlas: "Z1" },
|
|
13436
|
+
{ level: 2, name: "File", from: "A file, module, or class", element: "file", atlas: "Z2" },
|
|
13437
|
+
{ level: 3, name: "Action", from: "A door into the app: an endpoint or a screen, and the handler behind it", element: "action", atlas: "Z3" },
|
|
13438
|
+
{ level: 4, name: "Rule", from: "One decision (a Thunder card) or the steps of a function", element: "decision", atlas: "Z3" },
|
|
13439
|
+
{ level: 5, name: "Original", from: "The exact lines in the original language", element: "source", atlas: "Z4" }
|
|
13440
|
+
];
|
|
13441
|
+
var COLORS = {
|
|
13442
|
+
structure: { hex: "#C4B5FD", name: "violet", for: "Structure words: when, otherwise, all of these, for each" },
|
|
13443
|
+
question: { hex: "#7FB2FF", name: "blue", for: "A decision's question and branches (If)" },
|
|
13444
|
+
fact: { hex: "#FCD34D", name: "yellow", for: "Facts a rule reads, values a step works out, routes" },
|
|
13445
|
+
comparison: { hex: "#F472B6", name: "pink", for: "Comparisons and checks: at least, at most, is set" },
|
|
13446
|
+
amount: { hex: "#FDBA74", name: "orange", for: "Amounts and numbers" },
|
|
13447
|
+
outcome: { hex: "#67E8F9", name: "cyan", for: "Outcomes and what a function hands back" },
|
|
13448
|
+
name: { hex: "#BEF264", name: "lime", for: "Example names" },
|
|
13449
|
+
failure: { hex: "#FDBA74", name: "orange", for: "Ways a function fails (always with the \u2715 mark and the word Fails, which tell it apart from amounts)" },
|
|
13450
|
+
pass: { hex: "#34D399", name: "green", for: "ONLY a check that ran and passed" },
|
|
13451
|
+
fail: { hex: "#F87171", name: "red", for: "ONLY a check that ran and failed" },
|
|
13452
|
+
unread: { hex: "#9CA3AF", name: "grey, dashed", for: "Not established: not read, not confirmed, or not run" }
|
|
13453
|
+
};
|
|
13454
|
+
var LINES = {
|
|
13455
|
+
solid: "From code (read exactly) or confirmed by a person",
|
|
13456
|
+
dashed: "Not established: not read, only partly read, an AI summary, or not yet run"
|
|
13457
|
+
};
|
|
13458
|
+
var PROVENANCE2 = {
|
|
13459
|
+
"from-code": { label: "From code", line: "solid", says: "Read exactly from the source by the Thunder compiler, with no AI." },
|
|
13460
|
+
confirmed: { label: "Confirmed", line: "solid", says: "A person confirmed this reading is what the software should do." },
|
|
13461
|
+
"authors-note": { label: "Author's note", line: "solid", says: "The code author's own words (docstring or doc comment), verbatim. A statement, not a reading." },
|
|
13462
|
+
"ai-summary": { label: "AI summary", line: "dashed", says: "Written by AI to explain. Never evidence; the exact reading is shown beneath it." },
|
|
13463
|
+
"not-read": { label: "Not read yet", line: "dashed", says: "Thunder could not read this yet. The original code is shown instead, never a guess." }
|
|
13464
|
+
};
|
|
13465
|
+
var STEP_MARKS = {
|
|
13466
|
+
check: { mark: "\u2713", label: "Check", color: "comparison", show: "words" },
|
|
13467
|
+
branch: { mark: "\u25C7", label: "If", color: "question", show: "words" },
|
|
13468
|
+
loop: { mark: "\u21BB", label: "For each", color: "structure", show: "words" },
|
|
13469
|
+
set: { mark: "=", label: "Works out", color: "fact", show: "words" },
|
|
13470
|
+
call: { mark: "\u2192", label: "Calls", color: "outcome", show: "words" },
|
|
13471
|
+
return: { mark: "\u21E5", label: "Gives back", color: "outcome", show: "words" },
|
|
13472
|
+
fail: { mark: "\u2715", label: "Fails", color: "failure", show: "words" },
|
|
13473
|
+
try: { mark: "\u26C9", label: "Tries", color: "structure", show: "words" },
|
|
13474
|
+
restates: { mark: "\xB7", label: "Code", color: "unread", show: "code", line: "dashed" },
|
|
13475
|
+
other: { mark: "\xB7", label: "Not read yet", color: "unread", show: "code", line: "dashed" }
|
|
13476
|
+
};
|
|
13477
|
+
var ELEMENTS = {
|
|
13478
|
+
app: { zoom: 0, name: "App", shape: "map", status: "available", shows: "Its folders or areas, how many actions, decisions, and functions each holds, and what could not be read yet.", text: "App <name>" },
|
|
13479
|
+
area: { zoom: 1, name: "Area", shape: "map-region", status: "available", shows: "A folder, package, or service, with its files.", text: "Area <name>" },
|
|
13480
|
+
file: { zoom: 2, name: "File", shape: "stack", status: "available", shows: "What you can do here: every action and function in the file, in order.", text: "File <path>" },
|
|
13481
|
+
"data-shape": { zoom: 2, name: "Data shape", shape: "table-card", status: "planned", shows: "A record, class, enum, or database table: its fields, their kinds, and the allowed values.", text: "A <Name> has\n <field>, <kind>" },
|
|
13482
|
+
action: { zoom: 3, name: "Action", shape: "steps-card", badge: "route", status: "available", shows: "A door into the app (an endpoint with its method and path, or a screen), then what its handler does as steps.", text: "When someone calls <METHOD> <path>" },
|
|
13483
|
+
decision: { zoom: 4, name: "Thunder card", shape: "card", status: "available", shows: "One decision: its question, the facts it reads, each rule, the outcome otherwise, and examples you can ask.", text: "<Question>?\n <Outcome> when ...\n Otherwise, <Outcome>." },
|
|
13484
|
+
function: { zoom: 4, name: "Steps card", shape: "steps-card", status: "available", shows: "What a function does, as a short list of steps with one level of nesting.", text: "What <name> does\n - <step>" },
|
|
13485
|
+
"not-read": { zoom: 4, name: "Not-read-yet card", shape: "dashed-card", line: "dashed", status: "available", shows: "A function Thunder cannot read well yet, with its original code.", text: "Not read: <name> (see the code)" },
|
|
13486
|
+
error: { zoom: 4, name: "Failure", shape: "chip", mark: "\u2715", color: "failure", status: "available", shows: "A way the code can fail, by name.", text: "Can fail with <Name>" },
|
|
13487
|
+
test: { zoom: 4, name: "Test", shape: "chip", mark: "\u2691", color: "structure", status: "available", shows: "A test that exists. Green or red only once it has run.", text: "Test: <name>" },
|
|
13488
|
+
event: { zoom: 3, name: "Trigger", shape: "steps-card", badge: "when", status: "planned", shows: "Something that runs when an event happens (a database trigger, a message handler, a schedule).", text: "When <event>, it\n - <step>" },
|
|
13489
|
+
source: { zoom: 5, name: "Original code", shape: "code", status: "available", shows: "The exact lines, highlighted, in the original language.", text: "(the original code)" }
|
|
13490
|
+
};
|
|
13491
|
+
var LANGUAGES = {
|
|
13492
|
+
python: { name: "Python", status: "available", action: "@app.get / @router.post (FastAPI), @app.route (Flask)", decision: "a def that returns fixed answers", doc: "docstring", "data-shape": "@dataclass, pydantic BaseModel, Enum (planned)" },
|
|
13493
|
+
typescript: { name: "TypeScript", status: "available", action: "NestJS @Get/@Post, Express router.post(...)", decision: "a function that returns fixed answers", doc: "/** JSDoc */", "data-shape": "interface, type, enum (planned)" },
|
|
13494
|
+
javascript: { name: "JavaScript", status: "available", action: "Express app.get / router.post(...)", decision: "a function that returns fixed answers", doc: "/** JSDoc */", "data-shape": "classes (planned)" },
|
|
13495
|
+
go: { name: "Go", status: "available", action: "not yet (net/http, Gin planned)", decision: "a func that returns fixed answers", doc: "// comment above the func", "data-shape": "struct, const iota (planned)" },
|
|
13496
|
+
rust: { name: "Rust", status: "available", action: "not yet (Actix, Axum planned)", decision: "a fn with match or if returning fixed answers", doc: "/// doc comment", "data-shape": "struct, enum (planned)" },
|
|
13497
|
+
csharp: { name: "C#", status: "available", action: "[HttpGet] / [HttpPost]", decision: "a method that returns fixed answers", doc: "/// <summary>", "data-shape": "class, record, enum (planned)" },
|
|
13498
|
+
java: { name: "Java", status: "available", action: "@GetMapping / @PostMapping (Spring)", decision: "a method that returns fixed answers", doc: "/** Javadoc */", "data-shape": "class, record, enum (planned)" },
|
|
13499
|
+
kotlin: { name: "Kotlin", status: "available", action: "Spring annotations", decision: "a fun with when or if returning fixed answers", doc: "/** KDoc */", "data-shape": "data class, enum class (planned)" },
|
|
13500
|
+
php: { name: "PHP", status: "available", action: "#[Route] (Symfony)", decision: "a function that returns fixed answers", doc: "/** PHPDoc */", "data-shape": "class, enum (planned)" },
|
|
13501
|
+
ruby: { name: "Ruby", status: "available", action: "Sinatra get/post blocks (Rails routes.rb planned)", decision: "a def that returns fixed answers", doc: "# comment above the def", "data-shape": "class, Struct (planned)" },
|
|
13502
|
+
sql: { name: "SQL", status: "planned", action: "(none: SQL is reached through the app)", decision: "CHECK constraints, CASE expressions, IF in procedures", doc: "-- comment above, COMMENT ON", "data-shape": "CREATE TABLE / VIEW", event: "CREATE TRIGGER", steps: "SELECT / INSERT / UPDATE / DELETE: which data, filtered by which conditions, changed how" }
|
|
13503
|
+
};
|
|
13504
|
+
var RULES = [
|
|
13505
|
+
"Show the picture first, Thunder Text second, and the original code one click away.",
|
|
13506
|
+
"Never draw a guess. What Thunder cannot read is shown as Not read yet, dashed, with the original code.",
|
|
13507
|
+
"Green and red mean only a check that ran and passed or failed.",
|
|
13508
|
+
"Every element shows where it came from: From code, Confirmed, Author's note, AI summary, or Not read yet.",
|
|
13509
|
+
"An AI summary is labeled, dashed, and always sits above the exact reading it summarizes, never instead of it.",
|
|
13510
|
+
"The author's note (a docstring) is shown as the author's statement, verbatim, separate from what the code does.",
|
|
13511
|
+
"Say the action that is really possible: Propose rule change until a change is written back and checked; never Update code.",
|
|
13512
|
+
"Use the reader's words: plain names, no syntax. A step that would only restate the code shows the code instead."
|
|
13513
|
+
];
|
|
13514
|
+
var words4 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
|
|
13515
|
+
function visualFor(item2) {
|
|
13516
|
+
if (!item2 || typeof item2 !== "object") throw new Error("visualFor needs a reader item.");
|
|
13517
|
+
const base = { provenance: item2.provenance === "confirmed" ? "confirmed" : "from-code", ...item2.doc ? { doc: { text: item2.doc, provenance: "authors-note" } } : {} };
|
|
13518
|
+
if (item2.kind === "error") return { element: "error", shape: "chip", line: "solid", mark: "\u2715", color: "failure", title: `Can fail with ${item2.name}`, ...base };
|
|
13519
|
+
if (item2.kind === "test") return { element: "test", shape: "chip", line: "solid", mark: "\u2691", color: "structure", title: `Test: ${item2.name}`, ...base };
|
|
13520
|
+
const badge = item2.route ? { kind: "route", text: `${item2.route.method} ${item2.route.path}`.trim() } : void 0;
|
|
13521
|
+
if (item2.kind === "decision") {
|
|
13522
|
+
const card = safePlain(item2);
|
|
13523
|
+
return { element: "decision", shape: "card", line: item2.status === "partial" ? "dashed" : "solid", title: card?.question || `How ${words4(item2.name)} decides`, ...badge ? { badge } : {}, ...item2.status === "partial" ? { note: "Partly read" } : {}, ...base };
|
|
13524
|
+
}
|
|
13525
|
+
const readable = (item2.stepsReadable ?? 0) >= 0.5 && item2.steps?.length;
|
|
13526
|
+
if (!readable) return { element: "not-read", shape: "dashed-card", line: "dashed", title: `What ${words4(item2.name)} does`, ...badge ? { badge } : {}, ...base, provenance: "not-read" };
|
|
13527
|
+
return { element: item2.route ? "action" : "function", shape: "steps-card", line: "solid", title: item2.route ? `When someone calls ${badge.text}` : `What ${words4(item2.name)} does`, ...badge ? { badge } : {}, ...base };
|
|
13528
|
+
}
|
|
13529
|
+
function visualForStep(step) {
|
|
13530
|
+
const key = step?.restates ? "restates" : STEP_MARKS[step?.kind] ? step.kind : "other";
|
|
13531
|
+
const m = STEP_MARKS[key];
|
|
13532
|
+
return { mark: m.mark, label: m.label, color: m.color, show: m.show, line: m.line || "solid", text: m.show === "code" ? step.code ?? step.says : step.says };
|
|
13533
|
+
}
|
|
13534
|
+
function safePlain(item2) {
|
|
13535
|
+
try {
|
|
13536
|
+
return plainFromReading(item2);
|
|
13537
|
+
} catch {
|
|
13538
|
+
return null;
|
|
13539
|
+
}
|
|
13540
|
+
}
|
|
13541
|
+
function thunderText(item2) {
|
|
13542
|
+
const v = visualFor(item2);
|
|
13543
|
+
if (item2.kind === "error" || item2.kind === "test") return `${v.title}
|
|
13544
|
+
`;
|
|
13545
|
+
if (item2.kind === "decision") {
|
|
13546
|
+
const card = safePlain(item2);
|
|
13547
|
+
if (card) {
|
|
13548
|
+
if (item2.doc && !card.why) card.why = item2.doc;
|
|
13549
|
+
return renderPlainContract(card).replace(/\n+Examples\s*$/, "\n");
|
|
13550
|
+
}
|
|
13551
|
+
}
|
|
13552
|
+
const out = [v.title];
|
|
13553
|
+
if (item2.doc) out.push(` Author's note: "${item2.doc}"`);
|
|
13554
|
+
if (item2.inputs?.length) out.push(` Takes ${item2.inputs.map((p) => words4(p.name)).join(", ")}`);
|
|
13555
|
+
const steps = item2.steps || [];
|
|
13556
|
+
const lines = (list, depth) => {
|
|
13557
|
+
for (const st of list) {
|
|
13558
|
+
const s = visualForStep(st);
|
|
13559
|
+
const pad = " ".repeat(depth + 1);
|
|
13560
|
+
out.push(s.show === "code" ? `${pad}- \`${s.text}\` (code, not explained)` : `${pad}- ${s.text}`);
|
|
13561
|
+
if (st.children?.length) lines(st.children, depth + 1);
|
|
13562
|
+
if (st.otherwise?.length) {
|
|
13563
|
+
out.push(`${pad} Otherwise:`);
|
|
13564
|
+
lines(st.otherwise, depth + 2);
|
|
13565
|
+
}
|
|
13566
|
+
for (const h of st.handlers || []) {
|
|
13567
|
+
out.push(`${pad} ${h.says}:`);
|
|
13568
|
+
lines(h.steps, depth + 2);
|
|
13569
|
+
}
|
|
13570
|
+
if (st.always) {
|
|
13571
|
+
out.push(`${pad} Always, at the end:`);
|
|
13572
|
+
lines(st.always.steps, depth + 2);
|
|
13573
|
+
}
|
|
13574
|
+
}
|
|
13575
|
+
};
|
|
13576
|
+
if (steps.length) lines(steps, 0);
|
|
13577
|
+
else if (item2.kind === "decision" && item2.rules?.length) {
|
|
13578
|
+
for (const r of item2.rules) out.push(` - ${r.result} when ${r.says ?? r.when}`);
|
|
13579
|
+
if (item2.otherwise) out.push(` - Otherwise, ${item2.otherwise.result}`);
|
|
13580
|
+
} else out.push(" Not read: see the original code.");
|
|
13581
|
+
return `${out.join("\n")}
|
|
13582
|
+
`;
|
|
13583
|
+
}
|
|
13584
|
+
var SYMBOLS = {
|
|
13585
|
+
app: { name: "App", says: "The whole program, as a map.", color: "structure", paths: ["M6 11 L16 7 L28 11 L38 7 V33 L28 37 L16 33 L6 37 Z", "M16 7 V33 M28 11 V37"] },
|
|
13586
|
+
area: { name: "Area", says: "A part of the app that belongs together.", color: "structure", paths: ["M5 13 H17 L21 17 H39 V35 H5 Z"] },
|
|
13587
|
+
file: { name: "File", says: "One page of the program.", color: "structure", paths: ["M11 5 H27 L35 13 V39 H11 Z", "M27 5 V13 H35", "M16 22 H30 M16 28 H30 M16 34 H24"] },
|
|
13588
|
+
thing: { name: "Thing", says: "Something the app knows about. It knows stuff and can do stuff.", color: "outcome", beginner: true, paths: ["M22 5 L38 13 V31 L22 39 L6 31 V13 Z", "M6 13 L22 21 L38 13 M22 21 V39"] },
|
|
13589
|
+
data: { name: "Data", says: "Information: a record of facts, or a list of allowed choices.", color: "outcome", beginner: true, paths: ["M8 10 C8 6 36 6 36 10 V34 C36 38 8 38 8 34 Z", "M8 10 C8 14 36 14 36 10", "M8 22 C8 26 36 26 36 22"] },
|
|
13590
|
+
record: { name: "Record", says: "A Thing that only remembers facts, like an ID card.", color: "outcome", group: "data", paths: ["M9 10 H35 A4 4 0 0 1 39 14 V30 A4 4 0 0 1 35 34 H9 A4 4 0 0 1 5 30 V14 A4 4 0 0 1 9 10 Z", "M11 29 H19 M24 18 H34 M24 24 H34 M24 30 H30"], circles: [[15, 20, 4]] },
|
|
13591
|
+
choices: { name: "Choices", says: "Only one of these values is allowed.", color: "outcome", group: "data", paths: ["M10 7 H34 A4 4 0 0 1 34 15 H10 A4 4 0 0 1 10 7 Z", "M10 18 H34 A4 4 0 0 1 34 26 H10 A4 4 0 0 1 10 18 Z", "M10 29 H34 A4 4 0 0 1 34 37 H10 A4 4 0 0 1 10 29 Z"], circles: [[12, 22, 1.8]], fill: true },
|
|
13592
|
+
action: { name: "Action", says: "A door into the app: something a person can do.", color: "fact", beginner: true, paths: ["M11 39 V6 H33 V39", "M6 39 H38"], circles: [[27, 23, 1.8]], fill: true },
|
|
13593
|
+
rule: { name: "Rule", says: "A decision: look at some facts, pick one answer.", color: "question", beginner: true, paths: ["M22 4 L38 20 L22 36 L6 20 Z", "M22 36 V41 M15 29 L9 37 M29 29 L35 37"] },
|
|
13594
|
+
steps: { name: "Steps", says: "A how-to: do this, then this, then this.", color: "structure", beginner: true, paths: ["M10 5 H34 A4 4 0 0 1 38 9 V35 A4 4 0 0 1 34 39 H10 A4 4 0 0 1 6 35 V9 A4 4 0 0 1 10 5 Z", "M13 14 H14 M19 14 H31 M13 22 H14 M19 22 H31 M13 30 H14 M19 30 H27"] },
|
|
13595
|
+
setup: { name: "Starts with", says: "What a new Thing has when it is made.", color: "structure", paths: ["M22 5 V15 M22 29 V39 M5 22 H15 M29 22 H39 M10 10 L16 16 M28 28 L34 34 M34 10 L28 16 M16 28 L10 34"] },
|
|
13596
|
+
stop: { name: "Stop", says: "Something is wrong, so it stops and says why.", color: "failure", beginner: true, paths: ["M15 5 H29 L39 15 V29 L29 39 H15 L5 29 V15 Z", "M16 22 H28"] },
|
|
13597
|
+
"not-read": { name: "Not read yet", says: "Thunder shows the code, because it can't explain it yet.", color: "unread", dashed: true, paths: ["M11 5 H33 V39 H11 Z", "M17 22 H27"] }
|
|
13598
|
+
};
|
|
13599
|
+
var DOES = {
|
|
13600
|
+
start: { label: "Starts", mark: "\u25B6", color: "fact" },
|
|
13601
|
+
find: { label: "Finds", mark: "\u2315", color: "fact" },
|
|
13602
|
+
"keep-only": { label: "Keeps only", mark: "\u23DA", color: "fact" },
|
|
13603
|
+
check: { label: "Checks", mark: "\u2713", color: "comparison" },
|
|
13604
|
+
decide: { label: "Asks", mark: "\u25C7", color: "question" },
|
|
13605
|
+
calculate: { label: "Works out", mark: "=", color: "fact" },
|
|
13606
|
+
save: { label: "Saves", mark: "\u2913", color: "outcome" },
|
|
13607
|
+
send: { label: "Tells someone", mark: "\u2709", color: "outcome" },
|
|
13608
|
+
ask: { label: "Asks another part", mark: "\u21C4", color: "outcome" },
|
|
13609
|
+
repeat: { label: "For each", mark: "\u21BB", color: "structure" },
|
|
13610
|
+
answer: { label: "Gives back", mark: "\u21E5", color: "outcome" },
|
|
13611
|
+
stop: { label: "Stops", mark: "\u25A0", color: "failure", symbol: "stop" },
|
|
13612
|
+
do: { label: "Does", mark: "\u2192", color: "outcome" },
|
|
13613
|
+
code: { label: "Not read yet", mark: "\xB7", color: "unread", dashed: true }
|
|
13614
|
+
};
|
|
13615
|
+
var BEGINNER = ["thing", "action", "rule", "steps", "data", "stop"];
|
|
13616
|
+
var THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE2, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
|
|
13617
|
+
|
|
13618
|
+
// src/thunderize.mjs
|
|
13619
|
+
var THUNDERIZE_SCHEMA = "thunderize-v1";
|
|
13620
|
+
var THUNDER_TEXT_EXT = ".thunder-text";
|
|
13621
|
+
var LANGUAGE_NAMES = { typescript: "TypeScript", javascript: "JavaScript", python: "Python", go: "Go", rust: "Rust", csharp: "C#", java: "Java", kotlin: "Kotlin", php: "PHP", ruby: "Ruby" };
|
|
13622
|
+
function thunderizeFile(path, source, language = readableLanguage(path)) {
|
|
13623
|
+
const reading = readCode(source, { language, file: path });
|
|
13624
|
+
const main = reading.items.filter((i) => i.kind === "decision" || i.kind === "function");
|
|
13625
|
+
const failures = [...new Set(reading.items.filter((i) => i.kind === "error").map((i) => i.name))];
|
|
13626
|
+
const counts = { actions: 0, rules: 0, functions: 0, notReadYet: 0, failures: failures.length };
|
|
13627
|
+
const parts = main.map((item2) => {
|
|
13628
|
+
const v = visualFor(item2);
|
|
13629
|
+
if (v.element === "action") counts.actions++;
|
|
13630
|
+
else if (v.element === "decision") counts.rules++;
|
|
13631
|
+
else if (v.element === "not-read") counts.notReadYet++;
|
|
13632
|
+
else counts.functions++;
|
|
13633
|
+
return `# line ${item2.line}${v.line === "dashed" ? " \xB7 not read yet" : ""}
|
|
13634
|
+
${thunderText(item2).trimEnd()}`;
|
|
13635
|
+
});
|
|
13636
|
+
const header = `File ${path} (${LANGUAGE_NAMES[reading.language] || reading.language})
|
|
13637
|
+
Read from code by the Thunder compiler, no AI. ${summary(counts)}`;
|
|
13638
|
+
const footer = failures.length ? `
|
|
13639
|
+
Can fail with: ${failures.join(", ")}` : "";
|
|
13640
|
+
return { path, language: reading.language, out: `${path}${THUNDER_TEXT_EXT}`, counts, items: main.map((i) => ({ name: i.name, line: i.line, ...pick(visualFor(i)) })), text: `${header}
|
|
13641
|
+
|
|
13642
|
+
${parts.join("\n\n")}${footer}
|
|
13643
|
+
` };
|
|
13644
|
+
}
|
|
13645
|
+
var pick = (v) => ({ element: v.element, title: v.title, ...v.badge ? { route: v.badge.text } : {} });
|
|
13646
|
+
var plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
13647
|
+
function summary(c) {
|
|
13648
|
+
const bits = [c.actions && plural(c.actions, "action"), c.rules && plural(c.rules, "rule"), c.functions && plural(c.functions, "function"), c.notReadYet && `${c.notReadYet} not read yet`].filter(Boolean);
|
|
13649
|
+
return bits.length ? `${bits.join(", ")}.` : "Nothing to read.";
|
|
13650
|
+
}
|
|
13651
|
+
function thunderizeFiles(files, { name = "app" } = {}) {
|
|
13652
|
+
const out = [], skipped = [];
|
|
13653
|
+
for (const f of files) {
|
|
13654
|
+
const language = readableLanguage(f.path);
|
|
13655
|
+
if (!language) {
|
|
13656
|
+
skipped.push({ path: f.path, reason: "not a language Thunder reads yet" });
|
|
13657
|
+
continue;
|
|
13658
|
+
}
|
|
13659
|
+
if (!f.source) {
|
|
13660
|
+
skipped.push({ path: f.path, reason: f.size ? "too large to read" : "empty" });
|
|
13661
|
+
continue;
|
|
13662
|
+
}
|
|
13663
|
+
try {
|
|
13664
|
+
out.push(thunderizeFile(f.path, f.source, language));
|
|
13665
|
+
} catch (e) {
|
|
13666
|
+
skipped.push({ path: f.path, reason: `could not be read: ${e.message}` });
|
|
13667
|
+
}
|
|
13668
|
+
}
|
|
13669
|
+
out.sort((a, b) => a.path.localeCompare(b.path));
|
|
13670
|
+
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
13671
|
+
for (const f of out) for (const k of ["actions", "rules", "functions", "notReadYet"]) total[k] += f.counts[k];
|
|
13672
|
+
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
|
13673
|
+
const areas = /* @__PURE__ */ new Map();
|
|
13674
|
+
for (const f of out) {
|
|
13675
|
+
const area = f.path.includes("/") ? f.path.slice(0, f.path.lastIndexOf("/")) : ".";
|
|
13676
|
+
if (!areas.has(area)) areas.set(area, []);
|
|
13677
|
+
areas.get(area).push(f);
|
|
13678
|
+
}
|
|
13679
|
+
const lines = [
|
|
13680
|
+
`App ${name}`,
|
|
13681
|
+
` ${plural(total.files, "file")} read in ${langs.join(", ") || "no language"}: ${summary(total).replace(/\.$/, "")}.`,
|
|
13682
|
+
" Read from code by the Thunder compiler, no AI. Each file has its own Thunder Text beside it."
|
|
13683
|
+
];
|
|
13684
|
+
for (const [area, list] of areas) {
|
|
13685
|
+
lines.push("", `Area ${area === "." ? "(top level)" : area}`);
|
|
13686
|
+
for (const f of list) {
|
|
13687
|
+
const doors = f.items.filter((i) => i.element === "action" || i.element === "decision");
|
|
13688
|
+
lines.push(` File ${f.path}: ${summary(f.counts)}`);
|
|
13689
|
+
for (const d of doors) lines.push(` ${d.element === "action" ? d.title : `Rule: ${d.title}`}`);
|
|
13690
|
+
}
|
|
13691
|
+
}
|
|
13692
|
+
if (skipped.length) {
|
|
13693
|
+
lines.push("", "Not read");
|
|
13694
|
+
for (const s of skipped) lines.push(` ${s.path}: ${s.reason}`);
|
|
13695
|
+
}
|
|
13696
|
+
return { schema: THUNDERIZE_SCHEMA, name, counts: total, languages: langs, files: out, skipped, index: `${lines.join("\n")}
|
|
13697
|
+
` };
|
|
13698
|
+
}
|
|
13699
|
+
|
|
13700
|
+
// src/same.mjs
|
|
13701
|
+
var SAME_SCHEMA = "thunder-same-v1";
|
|
13702
|
+
var MAX_CASES = 4096;
|
|
13703
|
+
var nameKey = (name) => String(name).replace(/[_\s-]/g, "").toLowerCase();
|
|
13704
|
+
var norm4 = (s) => String(s).toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
13705
|
+
var stemKey = (path) => nameKey(String(path).replace(/\.[^./]+$/, "").replace(/\\/g, "/"));
|
|
13706
|
+
function compact(it, key, file, language) {
|
|
13707
|
+
const base = { key, file, language, name: it.name, kind: it.kind, line: it.line, route: it.route, element: visualFor(it).element };
|
|
13708
|
+
return it.kind === "decision" ? { ...it, ...base } : { ...base, flat: flatSteps(it.steps) };
|
|
13709
|
+
}
|
|
13710
|
+
function readAll(files) {
|
|
13711
|
+
const items = /* @__PURE__ */ new Map(), byName = /* @__PURE__ */ new Map(), unreadable = [];
|
|
13712
|
+
for (const f of files) {
|
|
13713
|
+
const language = readableLanguage(f.path);
|
|
13714
|
+
if (!language || !f.source) continue;
|
|
13715
|
+
let reading;
|
|
13716
|
+
try {
|
|
13717
|
+
reading = readCode(f.source, { language, file: f.path });
|
|
13718
|
+
} catch (e) {
|
|
13719
|
+
unreadable.push({ path: f.path, reason: e.message });
|
|
13720
|
+
continue;
|
|
13721
|
+
}
|
|
13722
|
+
const seen = /* @__PURE__ */ new Map();
|
|
13723
|
+
for (const it of reading.items) {
|
|
13724
|
+
if (it.kind !== "decision" && it.kind !== "function") continue;
|
|
13725
|
+
const n = nameKey(it.name);
|
|
13726
|
+
const nth = (seen.get(n) || 0) + 1;
|
|
13727
|
+
seen.set(n, nth);
|
|
13728
|
+
const key = `${stemKey(f.path)}#${n}${nth > 1 ? `#${nth}` : ""}`;
|
|
13729
|
+
items.set(key, compact(it, key, f.path, language));
|
|
13730
|
+
byName.set(n, byName.has(n) ? null : key);
|
|
13731
|
+
}
|
|
13732
|
+
}
|
|
13733
|
+
return { items, byName, unreadable };
|
|
13734
|
+
}
|
|
13735
|
+
function caseValues(models) {
|
|
13736
|
+
const byInput = /* @__PURE__ */ new Map();
|
|
13737
|
+
for (const m of models) for (const input of m.inputs) {
|
|
13738
|
+
if (!byInput.has(input.id)) byInput.set(input.id, { kind: input.kind, values: /* @__PURE__ */ new Set() });
|
|
13739
|
+
const slot = byInput.get(input.id);
|
|
13740
|
+
if (input.kind === "yesno") {
|
|
13741
|
+
slot.values.add(true);
|
|
13742
|
+
slot.values.add(false);
|
|
13743
|
+
}
|
|
13744
|
+
}
|
|
13745
|
+
for (const m of models) for (const r of m.rules) for (const c of r.conditions) {
|
|
13746
|
+
const slot = byInput.get(c.input);
|
|
13747
|
+
if (!slot || slot.kind === "yesno" || typeof c.value !== "number") continue;
|
|
13748
|
+
for (const v of [c.value - 1, c.value, c.value + 1, c.value - 0.01, c.value + 0.01]) slot.values.add(Math.round(v * 100) / 100);
|
|
13749
|
+
}
|
|
13750
|
+
for (const slot of byInput.values()) if (slot.kind !== "yesno") slot.values.add(0);
|
|
13751
|
+
return [...byInput.entries()].map(([id2, s]) => [id2, [...s.values].sort((a, b) => a > b ? 1 : a < b ? -1 : 0)]);
|
|
13752
|
+
}
|
|
13753
|
+
function* product(axes, i = 0, acc = {}) {
|
|
13754
|
+
if (i === axes.length) {
|
|
13755
|
+
yield { ...acc };
|
|
13756
|
+
return;
|
|
13757
|
+
}
|
|
13758
|
+
const [id2, values] = axes[i];
|
|
13759
|
+
for (const v of values) {
|
|
13760
|
+
acc[id2] = v;
|
|
13761
|
+
yield* product(axes, i + 1, acc);
|
|
13762
|
+
}
|
|
13763
|
+
}
|
|
13764
|
+
function compareRules(oldItem, newItem) {
|
|
13765
|
+
let a, b;
|
|
13766
|
+
try {
|
|
13767
|
+
a = plainFromReading(oldItem);
|
|
13768
|
+
b = plainFromReading(newItem);
|
|
13769
|
+
} catch {
|
|
13770
|
+
a = b = null;
|
|
13771
|
+
}
|
|
13772
|
+
if (!a || !b) return null;
|
|
13773
|
+
const key = (i) => `${nameKey(i.label)}:${i.kind}`;
|
|
13774
|
+
const toA = new Map(a.inputs.map((i) => [key(i), i.id]));
|
|
13775
|
+
if (a.inputs.length !== b.inputs.length || !b.inputs.every((i) => toA.has(key(i)))) {
|
|
13776
|
+
return { same: false, tried: 0, reason: `They need different facts: ${a.inputs.map((i) => i.label).join(", ")} versus ${b.inputs.map((i) => i.label).join(", ")}.` };
|
|
13777
|
+
}
|
|
13778
|
+
const bAsA = { ...b, inputs: b.inputs.map((i) => ({ ...i, id: toA.get(key(i)) })), rules: b.rules.map((r) => ({ ...r, conditions: r.conditions.map((c) => ({ ...c, input: toA.get(key(b.inputs.find((i) => i.id === c.input))) })) })) };
|
|
13779
|
+
let tried = 0;
|
|
13780
|
+
for (const values of product(caseValues([a, bAsA]))) {
|
|
13781
|
+
if (++tried > MAX_CASES) {
|
|
13782
|
+
tried--;
|
|
13783
|
+
break;
|
|
13784
|
+
}
|
|
13785
|
+
const x = explainPlain(a, values).outcome, y = explainPlain(bAsA, values).outcome;
|
|
13786
|
+
if (x !== y) return { same: false, tried, counterexample: { values: { ...values }, facts: a.inputs.map((i) => `${i.label} ${i.kind === "yesno" ? values[i.id] ? i.yes ?? "yes" : i.no ?? "no" : values[i.id]}`).join(", "), old: x, new: y } };
|
|
13787
|
+
}
|
|
13788
|
+
return { same: true, tried };
|
|
13789
|
+
}
|
|
13790
|
+
var flatSteps = (steps, depth = 0) => (steps || []).flatMap((s) => [
|
|
13791
|
+
{ sig: `${depth}:${s.restates ? "code" : s.kind}:${s.restates || s.kind === "other" ? "" : norm4(s.says)}`, text: s.restates || s.kind === "other" ? `\`${s.code ?? s.says}\`` : s.says },
|
|
13792
|
+
...flatSteps(s.children, depth + 1)
|
|
13793
|
+
]);
|
|
13794
|
+
function compareItems(o, n) {
|
|
13795
|
+
const where = { old: { file: o.file, line: o.line, language: o.language }, new: { file: n.file, line: n.line, language: n.language } };
|
|
13796
|
+
if (o.element === "not-read" || n.element === "not-read") return { status: "cannot-check", reason: "Thunder cannot read one side yet, so it cannot confirm they mean the same.", ...where };
|
|
13797
|
+
if (o.kind !== n.kind) return { status: "different", reason: `One is a ${o.kind === "decision" ? "rule" : "list of steps"}, the other is a ${n.kind === "decision" ? "rule" : "list of steps"}.`, ...where };
|
|
13798
|
+
if ((o.route?.method || "") !== (n.route?.method || "") || (o.route?.path || "") !== (n.route?.path || "")) {
|
|
13799
|
+
return { status: "different", reason: `The address changed: ${o.route ? `${o.route.method} ${o.route.path}` : "none"} became ${n.route ? `${n.route.method} ${n.route.path}` : "none"}.`, ...where };
|
|
13800
|
+
}
|
|
13801
|
+
if (o.kind === "decision") {
|
|
13802
|
+
const r = compareRules(o, n);
|
|
13803
|
+
if (!r) return { status: "cannot-check", reason: "One rule could not be drawn as a card, so its answers could not be compared.", ...where };
|
|
13804
|
+
if (r.same) return { status: "same", reason: `Same answer on all ${r.tried} edge cases.`, ...where };
|
|
13805
|
+
if (r.counterexample) {
|
|
13806
|
+
const facts = r.counterexample.facts;
|
|
13807
|
+
return { status: "different", reason: `Different answer for ${facts}: ${r.counterexample.old} before, ${r.counterexample.new} after.`, counterexample: r.counterexample, ...where };
|
|
13808
|
+
}
|
|
13809
|
+
return { status: "different", reason: r.reason, ...where };
|
|
13810
|
+
}
|
|
13811
|
+
const so = o.flat, sn = n.flat;
|
|
13812
|
+
const at = so.findIndex((s, i2) => s.sig !== sn[i2]?.sig);
|
|
13813
|
+
if (at === -1 && so.length === sn.length) return { status: "same", reason: `Same ${so.length} steps.`, ...where };
|
|
13814
|
+
const i = at === -1 ? Math.min(so.length, sn.length) : at;
|
|
13815
|
+
return { status: "different", reason: `Steps differ from step ${i + 1}: "${so[i]?.text ?? "(nothing)"}" became "${sn[i]?.text ?? "(nothing)"}".`, ...where };
|
|
13816
|
+
}
|
|
13817
|
+
function sameMeaning(oldFiles, newFiles) {
|
|
13818
|
+
const A = readAll(oldFiles), B = readAll(newFiles);
|
|
13819
|
+
const items = [], used = /* @__PURE__ */ new Set();
|
|
13820
|
+
const partner = (key, o) => {
|
|
13821
|
+
if (B.items.has(key) && !used.has(key)) return key;
|
|
13822
|
+
const n = nameKey(o.name), a = A.byName.get(n), b = B.byName.get(n);
|
|
13823
|
+
return a && b && !used.has(b) ? b : null;
|
|
13824
|
+
};
|
|
13825
|
+
for (const [key, o] of A.items) {
|
|
13826
|
+
const k = partner(key, o);
|
|
13827
|
+
if (k) used.add(k);
|
|
13828
|
+
const n = k && B.items.get(k);
|
|
13829
|
+
items.push({ name: o.name, ...n ? compareItems(o, n) : { status: "only-old", reason: "Not found in the new code.", old: { file: o.file, line: o.line, language: o.language } } });
|
|
13830
|
+
}
|
|
13831
|
+
for (const [key, n] of B.items) if (!used.has(key)) items.push({ name: n.name, status: "only-new", reason: "New: not in the old code.", new: { file: n.file, line: n.line, language: n.language } });
|
|
13832
|
+
const counts = { same: 0, different: 0, "only-old": 0, "only-new": 0, "cannot-check": 0 };
|
|
13833
|
+
for (const it of items) counts[it.status]++;
|
|
13834
|
+
const verdict2 = counts.different || counts["only-old"] || counts["only-new"] ? "different" : counts["cannot-check"] ? "partly-checked" : "same";
|
|
13835
|
+
return { schema: SAME_SCHEMA, verdict: verdict2, counts, items, unreadable: [...A.unreadable, ...B.unreadable] };
|
|
13836
|
+
}
|
|
13837
|
+
function renderSame(r) {
|
|
13838
|
+
const head = r.verdict === "same" ? "Same meaning." : r.verdict === "partly-checked" ? "No differences found, but some parts could not be checked." : "Different meaning.";
|
|
13839
|
+
const lines = [`${head} ${r.counts.same} same, ${r.counts.different} different, ${r.counts["only-old"]} only in the old code, ${r.counts["only-new"]} only in the new code, ${r.counts["cannot-check"]} not checked.`];
|
|
13840
|
+
const order = ["different", "only-old", "only-new", "cannot-check", "same"];
|
|
13841
|
+
const label = { different: "different", "only-old": "only old", "only-new": "only new", "cannot-check": "not checked", same: "same" };
|
|
13842
|
+
for (const st of order) for (const it of r.items.filter((x) => x.status === st)) {
|
|
13843
|
+
const loc = [it.old && `${it.old.file}:${it.old.line}`, it.new && `${it.new.file}:${it.new.line}`].filter(Boolean).join(" \u2192 ");
|
|
13844
|
+
lines.push(` ${label[st].padEnd(11)} ${it.name} (${loc}) ${it.reason}`);
|
|
13845
|
+
}
|
|
13846
|
+
return `${lines.join("\n")}
|
|
13847
|
+
`;
|
|
13848
|
+
}
|
|
13849
|
+
|
|
12725
13850
|
// src/write.mjs
|
|
12726
13851
|
var WRITE_SCHEMA = "thunder-write-v1";
|
|
12727
13852
|
var CMP = /* @__PURE__ */ new Set(["<", "<=", ">", ">=", "==", "!="]);
|
|
@@ -12944,7 +14069,7 @@ function changedCases(before, after) {
|
|
|
12944
14069
|
return { checked: a.all.length, changed, note: `Checked ${a.all.length} boundary input${a.all.length === 1 ? "" : "s"}; ${changed.length} now get${changed.length === 1 ? "s" : ""} a different answer. These are the values on each side of every limit, not every possible input.` };
|
|
12945
14070
|
}
|
|
12946
14071
|
var CMP_WORDS = { "<=": "at most", "<": "less than", ">=": "at least", ">": "more than", "==": "is", "!=": "is not" };
|
|
12947
|
-
var COMPARISON_CHOICES = Object.entries(CMP_WORDS).map(([op,
|
|
14072
|
+
var COMPARISON_CHOICES = Object.entries(CMP_WORDS).map(([op, words5]) => ({ op, words: words5 }));
|
|
12948
14073
|
function ruleParts(when) {
|
|
12949
14074
|
return tokenize(when).map((t) => {
|
|
12950
14075
|
if (t.t === "num") return { kind: "number", value: t.v };
|
|
@@ -13059,6 +14184,8 @@ function joinRuleParts(parts) {
|
|
|
13059
14184
|
SUPPORTED_LANGUAGES,
|
|
13060
14185
|
SYNC_SCHEMA,
|
|
13061
14186
|
TEST_SCHEMA,
|
|
14187
|
+
THUNDER_TEXT_EXT,
|
|
14188
|
+
THUNDER_VISUAL,
|
|
13062
14189
|
TOKEN_PATHS,
|
|
13063
14190
|
TWELVE_FACTOR_SCHEMA,
|
|
13064
14191
|
UNSETTLED,
|
|
@@ -13066,6 +14193,7 @@ function joinRuleParts(parts) {
|
|
|
13066
14193
|
VERIFY_DIFF_SCHEMA,
|
|
13067
14194
|
VIEWS,
|
|
13068
14195
|
VIEW_SCHEMA,
|
|
14196
|
+
VISUAL_SCHEMA,
|
|
13069
14197
|
WRITE_SCHEMA,
|
|
13070
14198
|
acceptedRisks,
|
|
13071
14199
|
adoptRegion,
|
|
@@ -13219,6 +14347,7 @@ function joinRuleParts(parts) {
|
|
|
13219
14347
|
renderMarker,
|
|
13220
14348
|
renderMermaid,
|
|
13221
14349
|
renderReviewBrief,
|
|
14350
|
+
renderSame,
|
|
13222
14351
|
renderTestplan,
|
|
13223
14352
|
resolveObligations,
|
|
13224
14353
|
resolveState,
|
|
@@ -13227,6 +14356,7 @@ function joinRuleParts(parts) {
|
|
|
13227
14356
|
ruleNamespace,
|
|
13228
14357
|
ruleParts,
|
|
13229
14358
|
runTests,
|
|
14359
|
+
sameMeaning,
|
|
13230
14360
|
sarifLevel,
|
|
13231
14361
|
scanIntent,
|
|
13232
14362
|
scanProject,
|
|
@@ -13248,6 +14378,8 @@ function joinRuleParts(parts) {
|
|
|
13248
14378
|
startMcpServer,
|
|
13249
14379
|
styleDiagnostics,
|
|
13250
14380
|
subjectName,
|
|
14381
|
+
thunderText,
|
|
14382
|
+
thunderizeFiles,
|
|
13251
14383
|
timeline,
|
|
13252
14384
|
toBPMN,
|
|
13253
14385
|
toCSharp,
|
|
@@ -13279,6 +14411,8 @@ function joinRuleParts(parts) {
|
|
|
13279
14411
|
verifyDiffToEvidence,
|
|
13280
14412
|
verifyLedger,
|
|
13281
14413
|
violatesArchitecture,
|
|
14414
|
+
visualFor,
|
|
14415
|
+
visualForStep,
|
|
13282
14416
|
whyBuilt,
|
|
13283
14417
|
writeRule
|
|
13284
14418
|
});
|