@skillstech/thunderlang 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/core.cjs +105 -33
- package/dist/index.cjs +103 -31
- package/dist/learn.cjs +1 -1
- package/package.json +1 -1
- package/src/emit.mjs +1 -1
- package/src/write-steps.mjs +14 -3
- package/src/write-words.mjs +59 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# 1.6.1
|
|
2
|
+
|
|
3
|
+
- **Fix: Thunder write wrote names the code does not have.** A word that is no name in the function or file
|
|
4
|
+
(`"amount is big"`, `"total is at least 75"` when the input is `amount`) was written as a new name
|
|
5
|
+
(`if amount == big:`) and passed the proof; code with such a name (`amount >= total`) was written too. Both are now
|
|
6
|
+
refused, naming the function's inputs (`its inputs are "amount", "coupon"`). The function's own names, the file's
|
|
7
|
+
names, the language's built-ins (`len`, `Math`, …), names an earlier edit in the list added, and a new local the
|
|
8
|
+
step itself sets (`total = amount * 2`) are all still accepted. Reported by Skills Tech Talk.
|
|
9
|
+
|
|
1
10
|
# 1.6.0
|
|
2
11
|
|
|
3
12
|
- **Thunder write in Thunder's words.** `thunder write <file> --edit` (step edits: inputs, questions, Stops, steps,
|
package/dist/core.cjs
CHANGED
|
@@ -1778,7 +1778,7 @@ function literalDecimal(n) {
|
|
|
1778
1778
|
return null;
|
|
1779
1779
|
}
|
|
1780
1780
|
function renderExpr(src, inputs, D, money = {}, dialect = "js") {
|
|
1781
|
-
const
|
|
1781
|
+
const known2 = new Set(inputs);
|
|
1782
1782
|
const isMoney = (n) => n.k === "ref" && Object.prototype.hasOwnProperty.call(money, n.path);
|
|
1783
1783
|
const moneyRefs = (n, out = []) => {
|
|
1784
1784
|
if (isMoney(n)) out.push(n.path);
|
|
@@ -1839,7 +1839,7 @@ function renderExpr(src, inputs, D, money = {}, dialect = "js") {
|
|
|
1839
1839
|
case "lit":
|
|
1840
1840
|
return typeof n.v === "string" ? JSON.stringify(n.v) : typeof n.v === "boolean" ? D.bool(n.v) : D.num ? D.num(n.v) : String(n.v);
|
|
1841
1841
|
case "ref":
|
|
1842
|
-
return
|
|
1842
|
+
return known2.has(n.path) || known2.has(n.path.split(".")[0]) ? n.path : JSON.stringify(n.path);
|
|
1843
1843
|
default:
|
|
1844
1844
|
return D.nil;
|
|
1845
1845
|
}
|
|
@@ -10134,8 +10134,8 @@ function commandSays(cmd) {
|
|
|
10134
10134
|
case "bunx": {
|
|
10135
10135
|
const rest2 = args.filter((a) => a !== "--yes" && a !== "-y" && !a.startsWith("--package"));
|
|
10136
10136
|
const name = (rest2[0] ?? "").replace(/^(@[^/]+\/)?([^@]+).*$/, "$2");
|
|
10137
|
-
const
|
|
10138
|
-
return
|
|
10137
|
+
const known2 = JS_TOOLS[name]?.(rest2.slice(1));
|
|
10138
|
+
return known2 ?? (name ? `Runs ${name}` : null);
|
|
10139
10139
|
}
|
|
10140
10140
|
case "node": {
|
|
10141
10141
|
if (args[0] === "-p" || args[0] === "-e" || args[0] === "--eval" || args[0] === "--print") {
|
|
@@ -11648,7 +11648,7 @@ function actionWords(uses, w) {
|
|
|
11648
11648
|
if (w.cache) s += ", reusing saved downloads";
|
|
11649
11649
|
return s;
|
|
11650
11650
|
}
|
|
11651
|
-
const
|
|
11651
|
+
const known2 = {
|
|
11652
11652
|
"pnpm/action-setup": () => `Sets up pnpm${ver(w.version)}`,
|
|
11653
11653
|
"oven-sh/setup-bun": () => `Sets up Bun${ver(w["bun-version"])}`,
|
|
11654
11654
|
"denoland/setup-deno": () => "Sets up Deno",
|
|
@@ -11685,7 +11685,7 @@ function actionWords(uses, w) {
|
|
|
11685
11685
|
"codecov/codecov-action": () => "Sends test coverage to Codecov",
|
|
11686
11686
|
"actions/dependency-review-action": () => "Checks new dependencies for known problems"
|
|
11687
11687
|
}[key];
|
|
11688
|
-
if (
|
|
11688
|
+
if (known2) return known2();
|
|
11689
11689
|
return `Uses ${repo}`;
|
|
11690
11690
|
}
|
|
11691
11691
|
function readWorkflow(src, file = "workflow.yml") {
|
|
@@ -14175,12 +14175,12 @@ function secretLiteral(name, value) {
|
|
|
14175
14175
|
return !/^(true|false|yes|no|on|off|\d+|enabled|disabled|none|null|changeme|<.*>)$/i.test(v);
|
|
14176
14176
|
}
|
|
14177
14177
|
var HOST_KEY = /(host|hostname|addr|address|url|uri|server|servers|endpoint|dsn|broker|brokers|connection|conn)$/i;
|
|
14178
|
-
function servicesNamed(key, value,
|
|
14178
|
+
function servicesNamed(key, value, known2) {
|
|
14179
14179
|
const out = [];
|
|
14180
14180
|
const v = String(value ?? "").trim();
|
|
14181
14181
|
const add = (h) => {
|
|
14182
14182
|
const host = String(h).toLowerCase();
|
|
14183
|
-
if ((!
|
|
14183
|
+
if ((!known2 || known2.has(host)) && !out.includes(host) && !/^(localhost|0\.0\.0\.0|127\.0\.0\.1)$/.test(host)) out.push(host);
|
|
14184
14184
|
};
|
|
14185
14185
|
for (const part of v.split(/[,\s]+/)) {
|
|
14186
14186
|
if (!part) continue;
|
|
@@ -17261,8 +17261,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17261
17261
|
const everyday = value ? sayPython(value) || sayCommon(value) : null;
|
|
17262
17262
|
if (everyday) return { kind: "set", says: `Sets ${target} to ${everyday}`, code: code3 };
|
|
17263
17263
|
if (c2 && wholeValueCall(value)) {
|
|
17264
|
-
const
|
|
17265
|
-
if (
|
|
17264
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
17265
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
17266
17266
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, m[1]))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
17267
17267
|
return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
|
|
17268
17268
|
}
|
|
@@ -17334,8 +17334,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17334
17334
|
if (common) return { kind: "set", says: `Sets ${target} to ${common}`, code: code3 };
|
|
17335
17335
|
const c2 = callee(value);
|
|
17336
17336
|
if (c2 && wholeValueCall(value)) {
|
|
17337
|
-
const
|
|
17338
|
-
if (
|
|
17337
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
17338
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
17339
17339
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, declType))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
17340
17340
|
return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
|
|
17341
17341
|
}
|
|
@@ -17398,8 +17398,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17398
17398
|
}
|
|
17399
17399
|
const c = callee(head);
|
|
17400
17400
|
if (c) {
|
|
17401
|
-
const
|
|
17402
|
-
if (
|
|
17401
|
+
const known2 = sayCall(c, firstArgs(head));
|
|
17402
|
+
if (known2) return { kind: "call", says: known2, code: code3, callee: c };
|
|
17403
17403
|
const o = head.indexOf("("), cl = o >= 0 ? closeOf(head, o) : -1;
|
|
17404
17404
|
const only = cl > o && /^\s*;?\s*$/.test(head.slice(cl + 1)) ? splitTopArgs(head.slice(o + 1, cl)) : [];
|
|
17405
17405
|
if ((LANG === "typescript" || LANG === "javascript" || LANG === "python") && only.length === 1 && !/^\s*(?:async\s*)?(?:\(|function\b|[A-Za-z_$][\w$]*\s*=>)/.test(only[0]) && !/^(?:exec|eval|compile|__import__|execfile|Function|setTimeout|setInterval)$/.test(c)) {
|
|
@@ -17411,9 +17411,9 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
17411
17411
|
}
|
|
17412
17412
|
if ((m = head.match(/^([a-z_][\w.]*[?!]?)\s+(?![=<>!+\-*/%]|and\b|or\b|if\b|unless\b)(.+)$/)) && !/^(?:if|for|while|return|else|elsif|when|case|def|class|module|end|not|const|let|var|val|new|await|typeof|delete|void|in|of|throw|import|export|from|as|is)$/.test(m[1])) {
|
|
17413
17413
|
if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
|
|
17414
|
-
const
|
|
17414
|
+
const known2 = sayCall(m[1], m[2]);
|
|
17415
17415
|
const named2 = /^[:'"]([\w ]+)['"]?/.exec(m[2].trim())?.[1];
|
|
17416
|
-
return { kind: "call", says:
|
|
17416
|
+
return { kind: "call", says: known2 || (named2 ? `Calls ${lastWords(m[1])}: ${words7(named2)}` : `Calls ${lastWords(m[1])}`), code: code3, callee: m[1] };
|
|
17417
17417
|
}
|
|
17418
17418
|
return { kind: "other", says: clip(head, 70), code: code3 };
|
|
17419
17419
|
}
|
|
@@ -19407,7 +19407,7 @@ function notesSummary(ast) {
|
|
|
19407
19407
|
byLens
|
|
19408
19408
|
};
|
|
19409
19409
|
}
|
|
19410
|
-
var COMPILER_VERSION = "1.6.
|
|
19410
|
+
var COMPILER_VERSION = "1.6.1";
|
|
19411
19411
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
19412
19412
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
19413
19413
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -22874,8 +22874,8 @@ function simpleSaysInner(n, ctx = null) {
|
|
|
22874
22874
|
return { kind: "fail", says: `Fails with exit code ${DIES.get(name)}${msg ? `: "${msg}"` : ""}`, error: `exit code ${DIES.get(name)}`, ...msg ? { message: msg } : {}, callee: name };
|
|
22875
22875
|
}
|
|
22876
22876
|
if (KNOWN_FNS.has(name)) return out(`Runs ${words9(name)}${args.length ? ` with ${list2(args.slice(0, 4).map(sayWord))}${args.length > 4 ? ", \u2026" : ""}` : ""}`, { callee: name });
|
|
22877
|
-
const
|
|
22878
|
-
if (
|
|
22877
|
+
const known2 = sayCommand(name, args, sayWord);
|
|
22878
|
+
if (known2) return out(known2, { callee: name });
|
|
22879
22879
|
if (/^"?\$/.test(name)) return out(`Runs the command in ${sayWord(name)}`, { callee: name });
|
|
22880
22880
|
if (scriptPath(name)) return out(`Runs the script ${sayWord(name)}`, { callee: name });
|
|
22881
22881
|
return out(`Runs ${name}${args[0] && /^[a-z][\w-]*$/.test(args[0]) ? ` ${args[0]}` : ""}`, { callee: name });
|
|
@@ -24075,8 +24075,8 @@ function commandWords(toks2, ctx = {}) {
|
|
|
24075
24075
|
return `${VERB[verb]} the ${many ? pluralNoun(noun) : noun}${object ? dup ? ` named by ${object}` : ` ${object}` : ""}${more}`;
|
|
24076
24076
|
}
|
|
24077
24077
|
const raws = argGroups(rest2).map(toksCode);
|
|
24078
|
-
const
|
|
24079
|
-
if (
|
|
24078
|
+
const known2 = sayCommand(raw.replace(/\.exe$/i, ""), raws, (w) => sayValue2(tokenize3(w)) ?? quoteText(w));
|
|
24079
|
+
if (known2) return known2;
|
|
24080
24080
|
if (/[\\/]|\.ps1$/i.test(raw)) return `Runs the script ${quoteText(raw)}${withArgs(a)}`;
|
|
24081
24081
|
return `Runs ${raw}${withArgs(a)}`;
|
|
24082
24082
|
}
|
|
@@ -27069,13 +27069,13 @@ var WRAPS_FUNCTION = /^(?:React\.)?(?:useCallback|useMemo|memo|forwardRef|useEve
|
|
|
27069
27069
|
var TEST_CALLS = /^(?:describe|it|test|context|suite|specify|before|after|beforeEach|afterEach|beforeAll|afterAll|setup|teardown|x?it|f?it|xdescribe|fdescribe|xtest|bench)(?:\.\w+)*$/;
|
|
27070
27070
|
function jsMoreFunctions(src, fns) {
|
|
27071
27071
|
const clean = stripCommentsKeepLayout(src);
|
|
27072
|
-
const
|
|
27072
|
+
const known2 = new Set(fns.map((f) => f.bodyStart));
|
|
27073
27073
|
const found = [];
|
|
27074
27074
|
const add = (fnIdx, paramsOpen, paramsClose, arrowParam, bo) => {
|
|
27075
|
-
if (
|
|
27075
|
+
if (known2.has(bo + 1)) return null;
|
|
27076
27076
|
const bc = matchClose(src, bo);
|
|
27077
27077
|
if (bc < 0) return null;
|
|
27078
|
-
|
|
27078
|
+
known2.add(bo + 1);
|
|
27079
27079
|
const line = lineAt(src, fnIdx);
|
|
27080
27080
|
const params = arrowParam != null ? parseParams2(arrowParam, "typescript") : parseParams2(src.slice(paramsOpen + 1, paramsClose), "typescript");
|
|
27081
27081
|
const f = { key: `fn@${fnIdx}`, line, params, returns: null, bodyStart: bo + 1, body: src.slice(bo + 1, bc), at: fnIdx, end: bc };
|
|
@@ -27105,7 +27105,7 @@ function jsMoreFunctions(src, fns) {
|
|
|
27105
27105
|
const arrowRe = /=>\s*\{/g;
|
|
27106
27106
|
while (m = arrowRe.exec(clean)) {
|
|
27107
27107
|
const bo = m.index + m[0].length - 1;
|
|
27108
|
-
if (
|
|
27108
|
+
if (known2.has(bo + 1)) continue;
|
|
27109
27109
|
let j = m.index - 1;
|
|
27110
27110
|
while (j >= 0 && /\s/.test(clean[j])) j--;
|
|
27111
27111
|
let start, paramText = null, pOpen = -1, pClose = -1;
|
|
@@ -30962,6 +30962,31 @@ var lit4 = (type, value, raw) => ({ kind: "literal", type, value, raw });
|
|
|
30962
30962
|
var NULL_RAW = { python: "None", go: "nil", typescript: "null", javascript: "null" };
|
|
30963
30963
|
var Unsaid = class extends Error {
|
|
30964
30964
|
};
|
|
30965
|
+
var Unknown = class extends Error {
|
|
30966
|
+
constructor(word) {
|
|
30967
|
+
super(word);
|
|
30968
|
+
this.word = word;
|
|
30969
|
+
}
|
|
30970
|
+
};
|
|
30971
|
+
function inputsOf2(scope) {
|
|
30972
|
+
const code3 = codeOnly(scope || ""), open = code3.indexOf("(");
|
|
30973
|
+
if (open < 0) return [];
|
|
30974
|
+
let depth = 0, end2 = open;
|
|
30975
|
+
for (; end2 < code3.length; end2++) {
|
|
30976
|
+
if (code3[end2] === "(") depth++;
|
|
30977
|
+
else if (code3[end2] === ")" && --depth === 0) break;
|
|
30978
|
+
}
|
|
30979
|
+
const out = [];
|
|
30980
|
+
for (const part of code3.slice(open + 1, end2).split(",")) {
|
|
30981
|
+
const id2 = part.replace(/^\s*[*&.]*\s*/, "").match(/^[A-Za-z_]\w*/)?.[0];
|
|
30982
|
+
if (id2 && !KEYWORDS.has(id2) && id2 !== "self" && id2 !== "cls" && !out.includes(id2)) out.push(id2);
|
|
30983
|
+
}
|
|
30984
|
+
return out;
|
|
30985
|
+
}
|
|
30986
|
+
var unknownWord = (word, scope) => {
|
|
30987
|
+
const inputs = inputsOf2(scope);
|
|
30988
|
+
return `"${word}" is not a name in this function or file${inputs.length ? `; its inputs are ${inputs.map((i) => `"${nameWords2(i) || i}"`).join(", ")}` : ""}. Use one of its names, or add an input first (addInput).`;
|
|
30989
|
+
};
|
|
30965
30990
|
var no2 = (why) => {
|
|
30966
30991
|
throw new Unsaid(why);
|
|
30967
30992
|
};
|
|
@@ -30984,8 +31009,8 @@ function toTree(n, language, names) {
|
|
|
30984
31009
|
case "nothing":
|
|
30985
31010
|
return lit4("null", null, NULL_RAW[language]);
|
|
30986
31011
|
case "name": {
|
|
30987
|
-
const id2 = names.get(n.name)
|
|
30988
|
-
if (!id2)
|
|
31012
|
+
const id2 = names.get(n.name);
|
|
31013
|
+
if (!id2) throw new Unknown(n.name);
|
|
30989
31014
|
return nm(id2);
|
|
30990
31015
|
}
|
|
30991
31016
|
case "field":
|
|
@@ -31055,8 +31080,8 @@ function toTree(n, language, names) {
|
|
|
31055
31080
|
}
|
|
31056
31081
|
function parseThunder(text2, source, scope) {
|
|
31057
31082
|
const names = namesOf(source, scope);
|
|
31058
|
-
const
|
|
31059
|
-
const ep = new ExprParser({ known, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
31083
|
+
const known2 = new Map([...names.keys()].map((k) => [k, "var"]));
|
|
31084
|
+
const ep = new ExprParser({ known: known2, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
31060
31085
|
const lexed = tokenizeLine(String(text2), 1);
|
|
31061
31086
|
const tokens = Array.isArray(lexed) ? lexed : lexed.tokens;
|
|
31062
31087
|
return { node: ep.parse(tokens, 1), names };
|
|
@@ -31072,6 +31097,7 @@ function thunderTree(text2, language, source, scope = "") {
|
|
|
31072
31097
|
return { tree: toTree(parsed.node, language, parsed.names) };
|
|
31073
31098
|
} catch (e) {
|
|
31074
31099
|
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
31100
|
+
if (e instanceof Unknown) return { error: unknownWord(e.word, scope), unknown: e.word };
|
|
31075
31101
|
throw e;
|
|
31076
31102
|
}
|
|
31077
31103
|
}
|
|
@@ -31093,6 +31119,42 @@ function thunderStep(text2, language, source, scope = "") {
|
|
|
31093
31119
|
}
|
|
31094
31120
|
return null;
|
|
31095
31121
|
}
|
|
31122
|
+
var BUILTINS = {
|
|
31123
|
+
python: "abs all any ascii bin bool bytearray bytes callable chr dict dir divmod enumerate filter float format frozenset getattr globals hasattr hash hex id int isinstance issubclass iter len list locals map max min next object oct open ord pow print range repr reversed round set setattr slice sorted str sum super tuple type vars zip Exception ValueError TypeError KeyError IndexError RuntimeError AttributeError NotImplementedError StopIteration LookupError ArithmeticError ZeroDivisionError OSError NotImplemented Ellipsis __name__ __file__",
|
|
31124
|
+
typescript: "Math JSON Object Array String Number Boolean Date Error TypeError RangeError Promise Map Set WeakMap Symbol BigInt RegExp console parseInt parseFloat isNaN isFinite undefined NaN Infinity globalThis window document process require module exports",
|
|
31125
|
+
go: "len cap append make new copy delete panic recover print println close complex real imag min max clear error string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 bool byte rune any iota fmt errors strings strconv"
|
|
31126
|
+
};
|
|
31127
|
+
BUILTINS.javascript = BUILTINS.typescript;
|
|
31128
|
+
function unknownName(tree, language, source, scope = "") {
|
|
31129
|
+
const known2 = new Set(BUILTINS[language]?.split(" ") ?? []);
|
|
31130
|
+
for (const text2 of [codeOnly(source), codeOnly(scope)]) for (const m of text2.matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) known2.add(m[0]);
|
|
31131
|
+
for (const k of KEYWORDS) known2.add(k);
|
|
31132
|
+
const bound = /* @__PURE__ */ new Set();
|
|
31133
|
+
const all = [];
|
|
31134
|
+
const walk = (n) => {
|
|
31135
|
+
if (Array.isArray(n)) {
|
|
31136
|
+
n.forEach(walk);
|
|
31137
|
+
return;
|
|
31138
|
+
}
|
|
31139
|
+
if (!n || typeof n !== "object") return;
|
|
31140
|
+
if (n.kind === "lambda" || n.kind === "code") {
|
|
31141
|
+
bound.add("*");
|
|
31142
|
+
return;
|
|
31143
|
+
}
|
|
31144
|
+
if (n.kind === "name") all.push(n.name);
|
|
31145
|
+
if ((n.kind === "assign" || n.kind === "declare") && n.target?.kind === "name") bound.add(n.target.name);
|
|
31146
|
+
if (n.kind === "declare" && typeof n.name === "string") bound.add(n.name);
|
|
31147
|
+
if (n.kind === "loop") for (const v of [n.variable, n.var, n.name, n.target]) {
|
|
31148
|
+
if (typeof v === "string") bound.add(v);
|
|
31149
|
+
else if (v?.kind === "name") bound.add(v.name);
|
|
31150
|
+
}
|
|
31151
|
+
for (const [k, v] of Object.entries(n)) if (k !== "raw" && v && typeof v === "object") walk(v);
|
|
31152
|
+
};
|
|
31153
|
+
walk(tree);
|
|
31154
|
+
if (bound.has("*")) return null;
|
|
31155
|
+
return all.find((id2) => !known2.has(id2) && !bound.has(id2)) ?? null;
|
|
31156
|
+
}
|
|
31157
|
+
var unknownNameReason = (word, scope) => unknownWord(word, scope);
|
|
31096
31158
|
|
|
31097
31159
|
// src/read-repo.mjs
|
|
31098
31160
|
var READ_REPO_SCHEMA = "thunder-repo-reading-v1";
|
|
@@ -31356,8 +31418,8 @@ function parseCondition(text2, inputs, line) {
|
|
|
31356
31418
|
}
|
|
31357
31419
|
fail3(line, `Compare ${input.label} with at least, at most, under, over, or exactly. For example: "${input.label} is at most ${formatValue(input, 100)}".`);
|
|
31358
31420
|
}
|
|
31359
|
-
const
|
|
31360
|
-
fail3(line, `This condition does not name an input. Start with one of: ${
|
|
31421
|
+
const known2 = inputs.map((i) => i.kind === "yesno" ? `"it is ${i.yes}"` : `"${i.label} is \u2026"`).join(", ");
|
|
31422
|
+
fail3(line, `This condition does not name an input. Start with one of: ${known2}.`);
|
|
31361
31423
|
}
|
|
31362
31424
|
function parsePlainContract(source) {
|
|
31363
31425
|
if (typeof source !== "string" || source.length > 1e5) throw new Error("A plain contract must be text of at most 100 KB.");
|
|
@@ -39304,11 +39366,17 @@ function exprFrom(input, language, what = "expression") {
|
|
|
39304
39366
|
if (looksThunder(input) && words15().tree) return words15().tree;
|
|
39305
39367
|
for (const l of PARSE_ORDER(language)) {
|
|
39306
39368
|
const t = parseExpr(input, l);
|
|
39307
|
-
if (t && t.kind !== "code" && !misreadIs(t)) return adapt(t, language);
|
|
39369
|
+
if (t && t.kind !== "code" && !misreadIs(t)) return known(adapt(t, language), language);
|
|
39308
39370
|
}
|
|
39309
39371
|
if (words15().tree) return words15().tree;
|
|
39372
|
+
if (said?.unknown) refuse(`The ${what} "${input}" could not be read: ${said.error}`);
|
|
39310
39373
|
refuse(`The ${what} "${input}" could not be read${said?.error ? ` (${said.error})` : ""}. Write it in Thunder's words, for example "days is more than 10 and not member's vip", or as code.`);
|
|
39311
39374
|
}
|
|
39375
|
+
function known(tree, language) {
|
|
39376
|
+
const word = unknownName(tree, language, wordsSource, wordsScope);
|
|
39377
|
+
if (word) refuse(`It cannot be written: ${unknownNameReason(word, wordsScope)}`);
|
|
39378
|
+
return tree;
|
|
39379
|
+
}
|
|
39312
39380
|
function adapt(tree, language) {
|
|
39313
39381
|
const t = cloneShape(tree);
|
|
39314
39382
|
for (const n of nodesOf(t)) {
|
|
@@ -39338,9 +39406,10 @@ function statementFrom(input, language) {
|
|
|
39338
39406
|
const a = adapt(t, language);
|
|
39339
39407
|
try {
|
|
39340
39408
|
renderStatement(a, language);
|
|
39341
|
-
return a;
|
|
39342
39409
|
} catch {
|
|
39410
|
+
continue;
|
|
39343
39411
|
}
|
|
39412
|
+
return known(a, language);
|
|
39344
39413
|
}
|
|
39345
39414
|
}
|
|
39346
39415
|
refuse(`The step "${input}" could not be read as one statement.`);
|
|
@@ -40337,6 +40406,9 @@ function opAddFunction(state, edit) {
|
|
|
40337
40406
|
if (language === "go" && inputs.some((p) => !p.type)) refuse("Go needs a type for every input.");
|
|
40338
40407
|
const ctx = { language, source, item: { name, line: 1 } };
|
|
40339
40408
|
if (language === "go" && edit.returns) ctx.goResults = edit.returns;
|
|
40409
|
+
wordsScope = `${name}(${inputs.map((p) => p.name).join(", ")})`;
|
|
40410
|
+
wordsSource = `${wordsScope}
|
|
40411
|
+
${source}`;
|
|
40340
40412
|
const nodes2 = (edit.steps || []).map((s) => stepSpec(s, { ...ctx, source: `${source}
|
|
40341
40413
|
func ${name}() (${edit.returns || ""}) {}` }));
|
|
40342
40414
|
if (!nodes2.length) refuse("A new function needs at least one step.");
|
package/dist/index.cjs
CHANGED
|
@@ -2585,7 +2585,7 @@ function notesSummary(ast) {
|
|
|
2585
2585
|
byLens
|
|
2586
2586
|
};
|
|
2587
2587
|
}
|
|
2588
|
-
var COMPILER_VERSION = "1.6.
|
|
2588
|
+
var COMPILER_VERSION = "1.6.1";
|
|
2589
2589
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
2590
2590
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
2591
2591
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -5489,7 +5489,7 @@ function literalDecimal(n) {
|
|
|
5489
5489
|
return null;
|
|
5490
5490
|
}
|
|
5491
5491
|
function renderExpr(src, inputs2, D, money = {}, dialect = "js") {
|
|
5492
|
-
const
|
|
5492
|
+
const known2 = new Set(inputs2);
|
|
5493
5493
|
const isMoney = (n) => n.k === "ref" && Object.prototype.hasOwnProperty.call(money, n.path);
|
|
5494
5494
|
const moneyRefs = (n, out = []) => {
|
|
5495
5495
|
if (isMoney(n)) out.push(n.path);
|
|
@@ -5550,7 +5550,7 @@ function renderExpr(src, inputs2, D, money = {}, dialect = "js") {
|
|
|
5550
5550
|
case "lit":
|
|
5551
5551
|
return typeof n.v === "string" ? JSON.stringify(n.v) : typeof n.v === "boolean" ? D.bool(n.v) : D.num ? D.num(n.v) : String(n.v);
|
|
5552
5552
|
case "ref":
|
|
5553
|
-
return
|
|
5553
|
+
return known2.has(n.path) || known2.has(n.path.split(".")[0]) ? n.path : JSON.stringify(n.path);
|
|
5554
5554
|
default:
|
|
5555
5555
|
return D.nil;
|
|
5556
5556
|
}
|
|
@@ -15376,8 +15376,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15376
15376
|
const everyday = value ? sayPython(value) || sayCommon(value) : null;
|
|
15377
15377
|
if (everyday) return { kind: "set", says: `Sets ${target} to ${everyday}`, code: code3 };
|
|
15378
15378
|
if (c2 && wholeValueCall(value)) {
|
|
15379
|
-
const
|
|
15380
|
-
if (
|
|
15379
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
15380
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
15381
15381
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, m[1]))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
15382
15382
|
return { kind: "set", says: `Works out ${target} from ${callWords(c2, value)}`, code: code3, callee: c2 };
|
|
15383
15383
|
}
|
|
@@ -15449,8 +15449,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15449
15449
|
if (common) return { kind: "set", says: `Sets ${target} to ${common}`, code: code3 };
|
|
15450
15450
|
const c2 = callee(value);
|
|
15451
15451
|
if (c2 && wholeValueCall(value)) {
|
|
15452
|
-
const
|
|
15453
|
-
if (
|
|
15452
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
15453
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
15454
15454
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, declType))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
15455
15455
|
return { kind: "set", says: `Works out ${target} from ${callWords(c2, value)}`, code: code3, callee: c2 };
|
|
15456
15456
|
}
|
|
@@ -15513,8 +15513,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15513
15513
|
}
|
|
15514
15514
|
const c = callee(head);
|
|
15515
15515
|
if (c) {
|
|
15516
|
-
const
|
|
15517
|
-
if (
|
|
15516
|
+
const known2 = sayCall(c, firstArgs(head));
|
|
15517
|
+
if (known2) return { kind: "call", says: known2, code: code3, callee: c };
|
|
15518
15518
|
const o = head.indexOf("("), cl = o >= 0 ? closeOf(head, o) : -1;
|
|
15519
15519
|
const only = cl > o && /^\s*;?\s*$/.test(head.slice(cl + 1)) ? splitTopArgs(head.slice(o + 1, cl)) : [];
|
|
15520
15520
|
if ((LANG === "typescript" || LANG === "javascript" || LANG === "python") && only.length === 1 && !/^\s*(?:async\s*)?(?:\(|function\b|[A-Za-z_$][\w$]*\s*=>)/.test(only[0]) && !/^(?:exec|eval|compile|__import__|execfile|Function|setTimeout|setInterval)$/.test(c)) {
|
|
@@ -15526,9 +15526,9 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15526
15526
|
}
|
|
15527
15527
|
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])) {
|
|
15528
15528
|
if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
|
|
15529
|
-
const
|
|
15529
|
+
const known2 = sayCall(m[1], m[2]);
|
|
15530
15530
|
const named2 = /^[:'"]([\w ]+)['"]?/.exec(m[2].trim())?.[1];
|
|
15531
|
-
return { kind: "call", says:
|
|
15531
|
+
return { kind: "call", says: known2 || (named2 ? `Calls ${lastWords(m[1])}: ${words3(named2)}` : `Calls ${lastWords(m[1])}`), code: code3, callee: m[1] };
|
|
15532
15532
|
}
|
|
15533
15533
|
return { kind: "other", says: clip(head, 70), code: code3 };
|
|
15534
15534
|
}
|
|
@@ -21647,8 +21647,8 @@ function commandSays(cmd) {
|
|
|
21647
21647
|
case "bunx": {
|
|
21648
21648
|
const rest2 = args.filter((a) => a !== "--yes" && a !== "-y" && !a.startsWith("--package"));
|
|
21649
21649
|
const name = (rest2[0] ?? "").replace(/^(@[^/]+\/)?([^@]+).*$/, "$2");
|
|
21650
|
-
const
|
|
21651
|
-
return
|
|
21650
|
+
const known2 = JS_TOOLS[name]?.(rest2.slice(1));
|
|
21651
|
+
return known2 ?? (name ? `Runs ${name}` : null);
|
|
21652
21652
|
}
|
|
21653
21653
|
case "node": {
|
|
21654
21654
|
if (args[0] === "-p" || args[0] === "-e" || args[0] === "--eval" || args[0] === "--print") {
|
|
@@ -23161,7 +23161,7 @@ function actionWords(uses, w) {
|
|
|
23161
23161
|
if (w.cache) s += ", reusing saved downloads";
|
|
23162
23162
|
return s;
|
|
23163
23163
|
}
|
|
23164
|
-
const
|
|
23164
|
+
const known2 = {
|
|
23165
23165
|
"pnpm/action-setup": () => `Sets up pnpm${ver(w.version)}`,
|
|
23166
23166
|
"oven-sh/setup-bun": () => `Sets up Bun${ver(w["bun-version"])}`,
|
|
23167
23167
|
"denoland/setup-deno": () => "Sets up Deno",
|
|
@@ -23198,7 +23198,7 @@ function actionWords(uses, w) {
|
|
|
23198
23198
|
"codecov/codecov-action": () => "Sends test coverage to Codecov",
|
|
23199
23199
|
"actions/dependency-review-action": () => "Checks new dependencies for known problems"
|
|
23200
23200
|
}[key];
|
|
23201
|
-
if (
|
|
23201
|
+
if (known2) return known2();
|
|
23202
23202
|
return `Uses ${repo}`;
|
|
23203
23203
|
}
|
|
23204
23204
|
function readWorkflow(src, file = "workflow.yml") {
|
|
@@ -25688,12 +25688,12 @@ function secretLiteral(name, value) {
|
|
|
25688
25688
|
return !/^(true|false|yes|no|on|off|\d+|enabled|disabled|none|null|changeme|<.*>)$/i.test(v);
|
|
25689
25689
|
}
|
|
25690
25690
|
var HOST_KEY = /(host|hostname|addr|address|url|uri|server|servers|endpoint|dsn|broker|brokers|connection|conn)$/i;
|
|
25691
|
-
function servicesNamed(key, value,
|
|
25691
|
+
function servicesNamed(key, value, known2) {
|
|
25692
25692
|
const out = [];
|
|
25693
25693
|
const v = String(value ?? "").trim();
|
|
25694
25694
|
const add = (h) => {
|
|
25695
25695
|
const host = String(h).toLowerCase();
|
|
25696
|
-
if ((!
|
|
25696
|
+
if ((!known2 || known2.has(host)) && !out.includes(host) && !/^(localhost|0\.0\.0\.0|127\.0\.0\.1)$/.test(host)) out.push(host);
|
|
25697
25697
|
};
|
|
25698
25698
|
for (const part of v.split(/[,\s]+/)) {
|
|
25699
25699
|
if (!part) continue;
|
|
@@ -28797,8 +28797,8 @@ function simpleSaysInner(n, ctx = null) {
|
|
|
28797
28797
|
return { kind: "fail", says: `Fails with exit code ${DIES.get(name)}${msg ? `: "${msg}"` : ""}`, error: `exit code ${DIES.get(name)}`, ...msg ? { message: msg } : {}, callee: name };
|
|
28798
28798
|
}
|
|
28799
28799
|
if (KNOWN_FNS.has(name)) return out(`Runs ${words9(name)}${args.length ? ` with ${list2(args.slice(0, 4).map(sayWord))}${args.length > 4 ? ", \u2026" : ""}` : ""}`, { callee: name });
|
|
28800
|
-
const
|
|
28801
|
-
if (
|
|
28800
|
+
const known2 = sayCommand(name, args, sayWord);
|
|
28801
|
+
if (known2) return out(known2, { callee: name });
|
|
28802
28802
|
if (/^"?\$/.test(name)) return out(`Runs the command in ${sayWord(name)}`, { callee: name });
|
|
28803
28803
|
if (scriptPath(name)) return out(`Runs the script ${sayWord(name)}`, { callee: name });
|
|
28804
28804
|
return out(`Runs ${name}${args[0] && /^[a-z][\w-]*$/.test(args[0]) ? ` ${args[0]}` : ""}`, { callee: name });
|
|
@@ -29998,8 +29998,8 @@ function commandWords(toks, ctx = {}) {
|
|
|
29998
29998
|
return `${VERB[verb]} the ${many ? pluralNoun(noun) : noun}${object ? dup ? ` named by ${object}` : ` ${object}` : ""}${more}`;
|
|
29999
29999
|
}
|
|
30000
30000
|
const raws = argGroups(rest2).map(toksCode);
|
|
30001
|
-
const
|
|
30002
|
-
if (
|
|
30001
|
+
const known2 = sayCommand(raw.replace(/\.exe$/i, ""), raws, (w) => sayValue2(tokenize3(w)) ?? quoteText(w));
|
|
30002
|
+
if (known2) return known2;
|
|
30003
30003
|
if (/[\\/]|\.ps1$/i.test(raw)) return `Runs the script ${quoteText(raw)}${withArgs(a)}`;
|
|
30004
30004
|
return `Runs ${raw}${withArgs(a)}`;
|
|
30005
30005
|
}
|
|
@@ -32992,13 +32992,13 @@ var WRAPS_FUNCTION = /^(?:React\.)?(?:useCallback|useMemo|memo|forwardRef|useEve
|
|
|
32992
32992
|
var TEST_CALLS = /^(?:describe|it|test|context|suite|specify|before|after|beforeEach|afterEach|beforeAll|afterAll|setup|teardown|x?it|f?it|xdescribe|fdescribe|xtest|bench)(?:\.\w+)*$/;
|
|
32993
32993
|
function jsMoreFunctions(src, fns) {
|
|
32994
32994
|
const clean = stripCommentsKeepLayout(src);
|
|
32995
|
-
const
|
|
32995
|
+
const known2 = new Set(fns.map((f) => f.bodyStart));
|
|
32996
32996
|
const found = [];
|
|
32997
32997
|
const add = (fnIdx, paramsOpen, paramsClose, arrowParam, bo) => {
|
|
32998
|
-
if (
|
|
32998
|
+
if (known2.has(bo + 1)) return null;
|
|
32999
32999
|
const bc = matchClose(src, bo);
|
|
33000
33000
|
if (bc < 0) return null;
|
|
33001
|
-
|
|
33001
|
+
known2.add(bo + 1);
|
|
33002
33002
|
const line = lineAt2(src, fnIdx);
|
|
33003
33003
|
const params = arrowParam != null ? parseParams2(arrowParam, "typescript") : parseParams2(src.slice(paramsOpen + 1, paramsClose), "typescript");
|
|
33004
33004
|
const f = { key: `fn@${fnIdx}`, line, params, returns: null, bodyStart: bo + 1, body: src.slice(bo + 1, bc), at: fnIdx, end: bc };
|
|
@@ -33028,7 +33028,7 @@ function jsMoreFunctions(src, fns) {
|
|
|
33028
33028
|
const arrowRe = /=>\s*\{/g;
|
|
33029
33029
|
while (m = arrowRe.exec(clean)) {
|
|
33030
33030
|
const bo = m.index + m[0].length - 1;
|
|
33031
|
-
if (
|
|
33031
|
+
if (known2.has(bo + 1)) continue;
|
|
33032
33032
|
let j = m.index - 1;
|
|
33033
33033
|
while (j >= 0 && /\s/.test(clean[j])) j--;
|
|
33034
33034
|
let start, paramText = null, pOpen = -1, pClose = -1;
|
|
@@ -43266,6 +43266,31 @@ var lit3 = (type, value, raw) => ({ kind: "literal", type, value, raw });
|
|
|
43266
43266
|
var NULL_RAW = { python: "None", go: "nil", typescript: "null", javascript: "null" };
|
|
43267
43267
|
var Unsaid = class extends Error {
|
|
43268
43268
|
};
|
|
43269
|
+
var Unknown = class extends Error {
|
|
43270
|
+
constructor(word) {
|
|
43271
|
+
super(word);
|
|
43272
|
+
this.word = word;
|
|
43273
|
+
}
|
|
43274
|
+
};
|
|
43275
|
+
function inputsOf2(scope) {
|
|
43276
|
+
const code3 = codeOnly(scope || ""), open = code3.indexOf("(");
|
|
43277
|
+
if (open < 0) return [];
|
|
43278
|
+
let depth = 0, end2 = open;
|
|
43279
|
+
for (; end2 < code3.length; end2++) {
|
|
43280
|
+
if (code3[end2] === "(") depth++;
|
|
43281
|
+
else if (code3[end2] === ")" && --depth === 0) break;
|
|
43282
|
+
}
|
|
43283
|
+
const out = [];
|
|
43284
|
+
for (const part of code3.slice(open + 1, end2).split(",")) {
|
|
43285
|
+
const id2 = part.replace(/^\s*[*&.]*\s*/, "").match(/^[A-Za-z_]\w*/)?.[0];
|
|
43286
|
+
if (id2 && !KEYWORDS.has(id2) && id2 !== "self" && id2 !== "cls" && !out.includes(id2)) out.push(id2);
|
|
43287
|
+
}
|
|
43288
|
+
return out;
|
|
43289
|
+
}
|
|
43290
|
+
var unknownWord = (word, scope) => {
|
|
43291
|
+
const inputs2 = inputsOf2(scope);
|
|
43292
|
+
return `"${word}" is not a name in this function or file${inputs2.length ? `; its inputs are ${inputs2.map((i) => `"${nameWords2(i) || i}"`).join(", ")}` : ""}. Use one of its names, or add an input first (addInput).`;
|
|
43293
|
+
};
|
|
43269
43294
|
var no2 = (why) => {
|
|
43270
43295
|
throw new Unsaid(why);
|
|
43271
43296
|
};
|
|
@@ -43288,8 +43313,8 @@ function toTree(n, language, names) {
|
|
|
43288
43313
|
case "nothing":
|
|
43289
43314
|
return lit3("null", null, NULL_RAW[language]);
|
|
43290
43315
|
case "name": {
|
|
43291
|
-
const id2 = names.get(n.name)
|
|
43292
|
-
if (!id2)
|
|
43316
|
+
const id2 = names.get(n.name);
|
|
43317
|
+
if (!id2) throw new Unknown(n.name);
|
|
43293
43318
|
return nm(id2);
|
|
43294
43319
|
}
|
|
43295
43320
|
case "field":
|
|
@@ -43359,8 +43384,8 @@ function toTree(n, language, names) {
|
|
|
43359
43384
|
}
|
|
43360
43385
|
function parseThunder(text2, source, scope) {
|
|
43361
43386
|
const names = namesOf(source, scope);
|
|
43362
|
-
const
|
|
43363
|
-
const ep = new ExprParser({ known, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
43387
|
+
const known2 = new Map([...names.keys()].map((k) => [k, "var"]));
|
|
43388
|
+
const ep = new ExprParser({ known: known2, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
43364
43389
|
const lexed = tokenizeLine(String(text2), 1);
|
|
43365
43390
|
const tokens = Array.isArray(lexed) ? lexed : lexed.tokens;
|
|
43366
43391
|
return { node: ep.parse(tokens, 1), names };
|
|
@@ -43376,6 +43401,7 @@ function thunderTree(text2, language, source, scope = "") {
|
|
|
43376
43401
|
return { tree: toTree(parsed.node, language, parsed.names) };
|
|
43377
43402
|
} catch (e) {
|
|
43378
43403
|
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
43404
|
+
if (e instanceof Unknown) return { error: unknownWord(e.word, scope), unknown: e.word };
|
|
43379
43405
|
throw e;
|
|
43380
43406
|
}
|
|
43381
43407
|
}
|
|
@@ -43397,6 +43423,42 @@ function thunderStep(text2, language, source, scope = "") {
|
|
|
43397
43423
|
}
|
|
43398
43424
|
return null;
|
|
43399
43425
|
}
|
|
43426
|
+
var BUILTINS = {
|
|
43427
|
+
python: "abs all any ascii bin bool bytearray bytes callable chr dict dir divmod enumerate filter float format frozenset getattr globals hasattr hash hex id int isinstance issubclass iter len list locals map max min next object oct open ord pow print range repr reversed round set setattr slice sorted str sum super tuple type vars zip Exception ValueError TypeError KeyError IndexError RuntimeError AttributeError NotImplementedError StopIteration LookupError ArithmeticError ZeroDivisionError OSError NotImplemented Ellipsis __name__ __file__",
|
|
43428
|
+
typescript: "Math JSON Object Array String Number Boolean Date Error TypeError RangeError Promise Map Set WeakMap Symbol BigInt RegExp console parseInt parseFloat isNaN isFinite undefined NaN Infinity globalThis window document process require module exports",
|
|
43429
|
+
go: "len cap append make new copy delete panic recover print println close complex real imag min max clear error string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 bool byte rune any iota fmt errors strings strconv"
|
|
43430
|
+
};
|
|
43431
|
+
BUILTINS.javascript = BUILTINS.typescript;
|
|
43432
|
+
function unknownName(tree, language, source, scope = "") {
|
|
43433
|
+
const known2 = new Set(BUILTINS[language]?.split(" ") ?? []);
|
|
43434
|
+
for (const text2 of [codeOnly(source), codeOnly(scope)]) for (const m of text2.matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) known2.add(m[0]);
|
|
43435
|
+
for (const k of KEYWORDS) known2.add(k);
|
|
43436
|
+
const bound = /* @__PURE__ */ new Set();
|
|
43437
|
+
const all = [];
|
|
43438
|
+
const walk = (n) => {
|
|
43439
|
+
if (Array.isArray(n)) {
|
|
43440
|
+
n.forEach(walk);
|
|
43441
|
+
return;
|
|
43442
|
+
}
|
|
43443
|
+
if (!n || typeof n !== "object") return;
|
|
43444
|
+
if (n.kind === "lambda" || n.kind === "code") {
|
|
43445
|
+
bound.add("*");
|
|
43446
|
+
return;
|
|
43447
|
+
}
|
|
43448
|
+
if (n.kind === "name") all.push(n.name);
|
|
43449
|
+
if ((n.kind === "assign" || n.kind === "declare") && n.target?.kind === "name") bound.add(n.target.name);
|
|
43450
|
+
if (n.kind === "declare" && typeof n.name === "string") bound.add(n.name);
|
|
43451
|
+
if (n.kind === "loop") for (const v of [n.variable, n.var, n.name, n.target]) {
|
|
43452
|
+
if (typeof v === "string") bound.add(v);
|
|
43453
|
+
else if (v?.kind === "name") bound.add(v.name);
|
|
43454
|
+
}
|
|
43455
|
+
for (const [k, v] of Object.entries(n)) if (k !== "raw" && v && typeof v === "object") walk(v);
|
|
43456
|
+
};
|
|
43457
|
+
walk(tree);
|
|
43458
|
+
if (bound.has("*")) return null;
|
|
43459
|
+
return all.find((id2) => !known2.has(id2) && !bound.has(id2)) ?? null;
|
|
43460
|
+
}
|
|
43461
|
+
var unknownNameReason = (word, scope) => unknownWord(word, scope);
|
|
43400
43462
|
|
|
43401
43463
|
// src/same.mjs
|
|
43402
43464
|
var SAME_SCHEMA = "thunder-same-v1";
|
|
@@ -43813,11 +43875,17 @@ function exprFrom(input, language, what = "expression") {
|
|
|
43813
43875
|
if (looksThunder(input) && words14().tree) return words14().tree;
|
|
43814
43876
|
for (const l of PARSE_ORDER(language)) {
|
|
43815
43877
|
const t = parseExpr(input, l);
|
|
43816
|
-
if (t && t.kind !== "code" && !misreadIs(t)) return adapt(t, language);
|
|
43878
|
+
if (t && t.kind !== "code" && !misreadIs(t)) return known(adapt(t, language), language);
|
|
43817
43879
|
}
|
|
43818
43880
|
if (words14().tree) return words14().tree;
|
|
43881
|
+
if (said?.unknown) refuse(`The ${what} "${input}" could not be read: ${said.error}`);
|
|
43819
43882
|
refuse(`The ${what} "${input}" could not be read${said?.error ? ` (${said.error})` : ""}. Write it in Thunder's words, for example "days is more than 10 and not member's vip", or as code.`);
|
|
43820
43883
|
}
|
|
43884
|
+
function known(tree, language) {
|
|
43885
|
+
const word = unknownName(tree, language, wordsSource, wordsScope);
|
|
43886
|
+
if (word) refuse(`It cannot be written: ${unknownNameReason(word, wordsScope)}`);
|
|
43887
|
+
return tree;
|
|
43888
|
+
}
|
|
43821
43889
|
function adapt(tree, language) {
|
|
43822
43890
|
const t = cloneShape(tree);
|
|
43823
43891
|
for (const n of nodesOf(t)) {
|
|
@@ -43847,9 +43915,10 @@ function statementFrom(input, language) {
|
|
|
43847
43915
|
const a = adapt(t, language);
|
|
43848
43916
|
try {
|
|
43849
43917
|
renderStatement(a, language);
|
|
43850
|
-
return a;
|
|
43851
43918
|
} catch {
|
|
43919
|
+
continue;
|
|
43852
43920
|
}
|
|
43921
|
+
return known(a, language);
|
|
43853
43922
|
}
|
|
43854
43923
|
}
|
|
43855
43924
|
refuse(`The step "${input}" could not be read as one statement.`);
|
|
@@ -44846,6 +44915,9 @@ function opAddFunction(state, edit) {
|
|
|
44846
44915
|
if (language === "go" && inputs2.some((p) => !p.type)) refuse("Go needs a type for every input.");
|
|
44847
44916
|
const ctx = { language, source, item: { name, line: 1 } };
|
|
44848
44917
|
if (language === "go" && edit.returns) ctx.goResults = edit.returns;
|
|
44918
|
+
wordsScope = `${name}(${inputs2.map((p) => p.name).join(", ")})`;
|
|
44919
|
+
wordsSource = `${wordsScope}
|
|
44920
|
+
${source}`;
|
|
44849
44921
|
const nodes2 = (edit.steps || []).map((s) => stepSpec(s, { ...ctx, source: `${source}
|
|
44850
44922
|
func ${name}() (${edit.returns || ""}) {}` }));
|
|
44851
44923
|
if (!nodes2.length) refuse("A new function needs at least one step.");
|
package/dist/learn.cjs
CHANGED
|
@@ -17250,7 +17250,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
|
|
|
17250
17250
|
var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
|
|
17251
17251
|
|
|
17252
17252
|
// src/emit.mjs
|
|
17253
|
-
var COMPILER_VERSION = "1.6.
|
|
17253
|
+
var COMPILER_VERSION = "1.6.1";
|
|
17254
17254
|
|
|
17255
17255
|
// src/lift.mjs
|
|
17256
17256
|
var IR_SCHEMA_VERSION = "0.1.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Thunder™, the human programming language: the deterministic ThunderLang™ compiler, CLI, and Language Server. No AI required. Reads code in seventeen languages into Thunder, changes TypeScript, JavaScript, Python, and Go code from Thunder with a proof, compiles rules to six languages, and executes them: run decisions, simulate lifecycles, and check outcome contracts. Interops with DMN, BPMN, JSON Schema, and OpenAPI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
package/src/emit.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export function notesSummary(ast) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const COMPILER_VERSION = '1.6.
|
|
33
|
+
export const COMPILER_VERSION = '1.6.1';
|
|
34
34
|
export const PROOF_SCHEMA_VERSION = '0.1.0';
|
|
35
35
|
// Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
|
|
36
36
|
// Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
|
package/src/write-steps.mjs
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// A patch that fails its proof is never returned as written.
|
|
31
31
|
//
|
|
32
32
|
// Deterministic and browser-safe (no Node APIs): it edits text and reads it; it never runs the code it edits.
|
|
33
|
-
import { thunderTree, thunderStep, looksThunder } from './write-words.mjs';
|
|
33
|
+
import { thunderTree, thunderStep, looksThunder, unknownName, unknownNameReason } from './write-words.mjs';
|
|
34
34
|
import { readCode } from './read.mjs';
|
|
35
35
|
import { readableLanguage } from './read-repo.mjs';
|
|
36
36
|
import { parseExpr, parseStatement, parseStatementSpans, renderExpr, renderStatement, sameExpr, normalizeExpr, nodesOf, sayFull, blockEnd } from './meaning.mjs';
|
|
@@ -275,11 +275,18 @@ function exprFrom(input, language, what = 'expression') {
|
|
|
275
275
|
if (looksThunder(input) && words().tree) return words().tree;
|
|
276
276
|
for (const l of PARSE_ORDER(language)) {
|
|
277
277
|
const t = parseExpr(input, l);
|
|
278
|
-
if (t && t.kind !== 'code' && !misreadIs(t)) return adapt(t, language);
|
|
278
|
+
if (t && t.kind !== 'code' && !misreadIs(t)) return known(adapt(t, language), language);
|
|
279
279
|
}
|
|
280
280
|
if (words().tree) return words().tree;
|
|
281
|
+
if (said?.unknown) refuse(`The ${what} "${input}" could not be read: ${said.error}`);
|
|
281
282
|
refuse(`The ${what} "${input}" could not be read${said?.error ? ` (${said.error})` : ''}. Write it in Thunder's words, for example "days is more than 10 and not member's vip", or as code.`);
|
|
282
283
|
}
|
|
284
|
+
/** A tree written as code, refused when it uses a name the code does not have (it would fail when run). */
|
|
285
|
+
function known(tree, language) {
|
|
286
|
+
const word = unknownName(tree, language, wordsSource, wordsScope);
|
|
287
|
+
if (word) refuse(`It cannot be written: ${unknownNameReason(word, wordsScope)}`);
|
|
288
|
+
return tree;
|
|
289
|
+
}
|
|
283
290
|
/** Adapt a tree read in another language to this file's spelling (== in JavaScript is ===, quotes, true/True). */
|
|
284
291
|
function adapt(tree, language) {
|
|
285
292
|
const t = cloneShape(tree);
|
|
@@ -303,7 +310,8 @@ function statementFrom(input, language) {
|
|
|
303
310
|
const t = parseStatement(input, l);
|
|
304
311
|
if (t && t.kind !== 'code') {
|
|
305
312
|
const a = adapt(t, language);
|
|
306
|
-
try { renderStatement(a, language);
|
|
313
|
+
try { renderStatement(a, language); } catch { continue; /* try the next reading */ }
|
|
314
|
+
return known(a, language);
|
|
307
315
|
}
|
|
308
316
|
}
|
|
309
317
|
refuse(`The step "${input}" could not be read as one statement.`);
|
|
@@ -1240,6 +1248,9 @@ function opAddFunction(state, edit) {
|
|
|
1240
1248
|
if (language === 'go' && inputs.some((p) => !p.type)) refuse('Go needs a type for every input.');
|
|
1241
1249
|
const ctx = { language, source, item: { name, line: 1 } };
|
|
1242
1250
|
if (language === 'go' && edit.returns) ctx.goResults = edit.returns;
|
|
1251
|
+
// The new function's names are its inputs and the file's names.
|
|
1252
|
+
wordsScope = `${name}(${inputs.map((p) => p.name).join(', ')})`;
|
|
1253
|
+
wordsSource = `${wordsScope}\n${source}`;
|
|
1243
1254
|
const nodes = (edit.steps || []).map((s) => stepSpec(s, { ...ctx, source: `${source}\nfunc ${name}() (${edit.returns || ''}) {}` }));
|
|
1244
1255
|
if (!nodes.length) refuse('A new function needs at least one step.');
|
|
1245
1256
|
const unit = indentUnit(source, language);
|
package/src/write-words.mjs
CHANGED
|
@@ -51,6 +51,25 @@ const lit = (type, value, raw) => ({ kind: 'literal', type, value, raw });
|
|
|
51
51
|
const NULL_RAW = { python: 'None', go: 'nil', typescript: 'null', javascript: 'null' };
|
|
52
52
|
|
|
53
53
|
class Unsaid extends Error {}
|
|
54
|
+
class Unknown extends Error { constructor(word) { super(word); this.word = word; } }
|
|
55
|
+
|
|
56
|
+
/** The function's inputs, from its signature (the first parentheses in `scope`). */
|
|
57
|
+
export function inputsOf(scope) {
|
|
58
|
+
const code = codeOnly(scope || ''), open = code.indexOf('(');
|
|
59
|
+
if (open < 0) return [];
|
|
60
|
+
let depth = 0, end = open;
|
|
61
|
+
for (; end < code.length; end++) { if (code[end] === '(') depth++; else if (code[end] === ')' && --depth === 0) break; }
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const part of code.slice(open + 1, end).split(',')) {
|
|
64
|
+
const id = part.replace(/^\s*[*&.]*\s*/, '').match(/^[A-Za-z_]\w*/)?.[0];
|
|
65
|
+
if (id && !KEYWORDS.has(id) && id !== 'self' && id !== 'cls' && !out.includes(id)) out.push(id);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
const unknownWord = (word, scope) => {
|
|
70
|
+
const inputs = inputsOf(scope);
|
|
71
|
+
return `"${word}" is not a name in this function or file${inputs.length ? `; its inputs are ${inputs.map((i) => `"${nameWords(i) || i}"`).join(', ')}` : ''}. Use one of its names, or add an input first (addInput).`;
|
|
72
|
+
};
|
|
54
73
|
const no = (why) => { throw new Unsaid(why); };
|
|
55
74
|
|
|
56
75
|
/** A Core expression (core/parser.mjs) as a meaning tree for `language`. */
|
|
@@ -69,8 +88,10 @@ function toTree(n, language, names) {
|
|
|
69
88
|
case 'bool': return lit('bool', n.v, py ? (n.v ? 'True' : 'False') : String(n.v));
|
|
70
89
|
case 'nothing': return lit('null', null, NULL_RAW[language]);
|
|
71
90
|
case 'name': {
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
// Only a name the code already has: a word that is no name in the function or the file is refused, never
|
|
92
|
+
// written as a new name the code would fail on.
|
|
93
|
+
const id = names.get(n.name);
|
|
94
|
+
if (!id) throw new Unknown(n.name);
|
|
74
95
|
return nm(id);
|
|
75
96
|
}
|
|
76
97
|
case 'field': case 'dot': {
|
|
@@ -152,6 +173,7 @@ export function thunderTree(text, language, source, scope = '') {
|
|
|
152
173
|
try { parsed = parseThunder(text, source, scope); } catch (e) { return { error: String(e.message).replace(/^Line 1: /, '').split('\n')[0] }; }
|
|
153
174
|
try { return { tree: toTree(parsed.node, language, parsed.names) }; } catch (e) {
|
|
154
175
|
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
176
|
+
if (e instanceof Unknown) return { error: unknownWord(e.word, scope), unknown: e.word };
|
|
155
177
|
throw e;
|
|
156
178
|
}
|
|
157
179
|
}
|
|
@@ -180,3 +202,38 @@ export function thunderStep(text, language, source, scope = '') {
|
|
|
180
202
|
}
|
|
181
203
|
return null;
|
|
182
204
|
}
|
|
205
|
+
|
|
206
|
+
// Names every program in the language has without writing them: built-in functions, types, and globals.
|
|
207
|
+
const BUILTINS = {
|
|
208
|
+
python: 'abs all any ascii bin bool bytearray bytes callable chr dict dir divmod enumerate filter float format frozenset getattr globals hasattr hash hex id int isinstance issubclass iter len list locals map max min next object oct open ord pow print range repr reversed round set setattr slice sorted str sum super tuple type vars zip Exception ValueError TypeError KeyError IndexError RuntimeError AttributeError NotImplementedError StopIteration LookupError ArithmeticError ZeroDivisionError OSError NotImplemented Ellipsis __name__ __file__',
|
|
209
|
+
typescript: 'Math JSON Object Array String Number Boolean Date Error TypeError RangeError Promise Map Set WeakMap Symbol BigInt RegExp console parseInt parseFloat isNaN isFinite undefined NaN Infinity globalThis window document process require module exports',
|
|
210
|
+
go: 'len cap append make new copy delete panic recover print println close complex real imag min max clear error string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 bool byte rune any iota fmt errors strings strconv',
|
|
211
|
+
};
|
|
212
|
+
BUILTINS.javascript = BUILTINS.typescript;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The first name in `tree` that the code does not have (not in the file, not built in), or null. Names the step
|
|
216
|
+
* itself introduces are allowed: assignment and declaration targets, loop variables, and a function's own inputs.
|
|
217
|
+
*/
|
|
218
|
+
export function unknownName(tree, language, source, scope = '') {
|
|
219
|
+
const known = new Set(BUILTINS[language]?.split(' ') ?? []);
|
|
220
|
+
// The function's own code counts as code even where the file is read as text around it (a docstring example).
|
|
221
|
+
for (const text of [codeOnly(source), codeOnly(scope)]) for (const m of text.matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) known.add(m[0]);
|
|
222
|
+
for (const k of KEYWORDS) known.add(k);
|
|
223
|
+
const bound = new Set();
|
|
224
|
+
const all = [];
|
|
225
|
+
const walk = (n) => {
|
|
226
|
+
if (Array.isArray(n)) { n.forEach(walk); return; }
|
|
227
|
+
if (!n || typeof n !== 'object') return;
|
|
228
|
+
if (n.kind === 'lambda' || n.kind === 'code') { bound.add('*'); return; }
|
|
229
|
+
if (n.kind === 'name') all.push(n.name);
|
|
230
|
+
if ((n.kind === 'assign' || n.kind === 'declare') && n.target?.kind === 'name') bound.add(n.target.name);
|
|
231
|
+
if (n.kind === 'declare' && typeof n.name === 'string') bound.add(n.name);
|
|
232
|
+
if (n.kind === 'loop') for (const v of [n.variable, n.var, n.name, n.target]) { if (typeof v === 'string') bound.add(v); else if (v?.kind === 'name') bound.add(v.name); }
|
|
233
|
+
for (const [k, v] of Object.entries(n)) if (k !== 'raw' && v && typeof v === 'object') walk(v);
|
|
234
|
+
};
|
|
235
|
+
walk(tree);
|
|
236
|
+
if (bound.has('*')) return null;
|
|
237
|
+
return all.find((id) => !known.has(id) && !bound.has(id)) ?? null;
|
|
238
|
+
}
|
|
239
|
+
export const unknownNameReason = (word, scope) => unknownWord(word, scope);
|