@skillstech/thunderlang 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +207 -0
- package/dist/core.cjs +13779 -10043
- package/dist/index.cjs +28500 -24392
- package/dist/learn.cjs +12853 -9579
- package/intent-graph.schema.json +11 -0
- package/package.json +6 -2
- package/src/cli.mjs +141 -58
- package/src/codegen.mjs +145 -55
- package/src/conformance.mjs +15 -6
- package/src/core/check.mjs +725 -0
- package/src/core/cli.mjs +133 -0
- package/src/core/diagnostics.mjs +81 -0
- package/src/core/format.mjs +20 -0
- package/src/core/from-python.mjs +645 -0
- package/src/core/index.mjs +38 -0
- package/src/core/lexer.mjs +115 -0
- package/src/core/parser.mjs +742 -0
- package/src/core/project.mjs +167 -0
- package/src/core/round-trip.mjs +150 -0
- package/src/core/runtime-python.mjs +801 -0
- package/src/core/target-python.mjs +486 -0
- package/src/core.d.ts +5 -2
- package/src/core.mjs +5 -2
- package/src/data-schema.mjs +8 -1
- package/src/emit.mjs +1 -1
- package/src/evidence.mjs +1 -1
- package/src/expr.mjs +81 -4
- package/src/form-words.mjs +2 -0
- package/src/index.d.ts +8 -1
- package/src/index.mjs +5 -1
- package/src/intent-schema.mjs +1 -0
- package/src/libraries.mjs +2 -2
- package/src/mcp.mjs +23 -0
- package/src/meaning.mjs +47 -7
- package/src/model.d.mts +7 -3
- package/src/model.mjs +30 -9
- package/src/money.d.mts +18 -0
- package/src/money.mjs +124 -0
- package/src/plain-contract.mjs +18 -2
- package/src/powershell.mjs +24 -5
- package/src/read-repo.mjs +1 -0
- package/src/read.d.mts +11 -0
- package/src/read.mjs +121 -13
- package/src/review-comment.d.mts +16 -0
- package/src/review-comment.mjs +145 -0
- package/src/rlang.mjs +10 -3
- package/src/say-less.mjs +1432 -0
- package/src/shell.mjs +45 -8
- package/src/sql-proc.mjs +1198 -0
- package/src/sql.mjs +87 -119
- package/src/steps.mjs +188 -37
- package/src/system.mjs +153 -44
- package/src/target-cs.mjs +39 -34
- package/src/target-elixir.mjs +40 -30
- package/src/target-go.mjs +41 -36
- package/src/target-java.mjs +34 -27
- package/src/target-kotlin.mjs +43 -35
- package/src/target-py.mjs +57 -55
- package/src/target-result.d.mts +48 -0
- package/src/target-result.mjs +112 -0
- package/src/target-rust.mjs +42 -38
- package/src/target-scala.mjs +45 -35
- package/src/target-ts.mjs +37 -45
- package/src/target-types.mjs +41 -5
- package/src/target-util.mjs +55 -2
- package/src/trace-cli.mjs +58 -0
- package/src/trace-fs.mjs +76 -0
- package/src/trace.mjs +261 -0
- package/src/translate.d.mts +3 -0
- package/src/translate.mjs +62 -32
- package/src/why-cli.mjs +31 -0
- package/src/why.d.mts +28 -0
- package/src/why.mjs +532 -0
- package/src/write-steps.mjs +22 -5
package/src/shell.mjs
CHANGED
|
@@ -399,13 +399,16 @@ function braceWords(inner) {
|
|
|
399
399
|
return `${d} when ${subj} ${colon ? 'is set and not empty' : 'is set'}, otherwise nothing`;
|
|
400
400
|
}
|
|
401
401
|
if ((m = rest.match(/^(##?|%%?)([\s\S]*)$/))) {
|
|
402
|
-
|
|
402
|
+
// (Shell quotes in a pattern only mark text as literal: `${x%', '}` removes ", ".)
|
|
403
|
+
const [, op, p0] = m;
|
|
404
|
+
const p = p0.replace(/'([^']*)'|"([^"$`\\]*)"/g, '$1$2');
|
|
403
405
|
if (/\$/.test(p)) return null;
|
|
404
406
|
const what = GLOBBY.test(p) ? `the ${op.length === 2 ? 'longest' : 'shortest'} match of "${p}"` : `"${p}"`;
|
|
405
407
|
return `${subj} without ${what} at the ${op[0] === '#' ? 'start' : 'end'}`;
|
|
406
408
|
}
|
|
407
409
|
if ((m = rest.match(/^\/([/#%]?)((?:\\.|[^/\\])*)(?:\/([\s\S]*))?$/))) {
|
|
408
|
-
const [, mode,
|
|
410
|
+
const [, mode, p0, r] = m;
|
|
411
|
+
const p = p0.replace(/'([^']*)'|"([^"$`\\]*)"/g, '$1$2');
|
|
409
412
|
if (!p || /\$/.test(p)) return null;
|
|
410
413
|
const pat = GLOBBY.test(p) ? `match of "${p}"` : `"${p}"`;
|
|
411
414
|
const which = mode === '/' ? `every ${pat}` : mode === '#' ? `${pat} at the start` : mode === '%' ? `${pat} at the end` : `the first ${pat}`;
|
|
@@ -575,8 +578,9 @@ const arithSays = (expr) => { const st = arithStatement(expr); if (st) return st
|
|
|
575
578
|
|
|
576
579
|
// ── Tests and conditions ──────────────────────────────────────────────────────────────────────────────
|
|
577
580
|
|
|
578
|
-
|
|
579
|
-
|
|
581
|
+
// (A name says what it is only when it names that kind: `config_dir` is a folder, but `path` can be a file or a folder,
|
|
582
|
+
// so `[ -d "$path" ]` is "the folder path exists", never just "path exists".)
|
|
583
|
+
const fileLeaf = (noun, x, neg) => { const w = sayWord(x); const own = noun === 'file' ? /(?:^|\s)file$/.test(w) : /(?:^|\s)(?:dir|directory|folder)$/.test(w); return neg ? (own ? `${w} does not exist` : `there is no ${noun} ${w}`) : (own ? `${w} exists` : `the ${noun} ${w} exists`); };
|
|
580
584
|
const UNARY = {
|
|
581
585
|
'-f': (x, n) => fileLeaf('file', x, n), '-d': (x, n) => fileLeaf('folder', x, n),
|
|
582
586
|
'-e': (x, n) => `${sayWord(x)} ${n ? 'does not exist' : 'exists'}`, '-a': (x, n) => `${sayWord(x)} ${n ? 'does not exist' : 'exists'}`,
|
|
@@ -615,7 +619,7 @@ function testWords(ws, neg, double) {
|
|
|
615
619
|
if (BINARY[ws[i + 1]] && ws[i + 2] !== undefined) {
|
|
616
620
|
const [a, op, b] = [ws[i], ws[i + 1], ws[i + 2]];
|
|
617
621
|
i += 3;
|
|
618
|
-
if ((op === '==' || op === '=' || op === '!=') && double && isGlob(b)) { const pos = op !== '!='; return `${sayWord(a)} ${pos !== n ? 'matches' : 'does not match'}
|
|
622
|
+
if ((op === '==' || op === '=' || op === '!=') && double && isGlob(b)) { const pos = op !== '!='; return `${sayWord(a)} ${pos !== n ? 'matches' : 'does not match'} the pattern \`${b}\``; }
|
|
619
623
|
// Compared with "" is a question about being empty.
|
|
620
624
|
if ((op === '=' || op === '==' || op === '!=') && /^(?:""|'')$/.test(b)) return `${sayWord(a)} is ${(op === '!=') !== n ? 'not empty' : 'empty'}`;
|
|
621
625
|
const pair = BINARY[op];
|
|
@@ -715,6 +719,25 @@ const TRAP_WHEN = (sigs) => {
|
|
|
715
719
|
return `When it gets the signal ${s.join(' or ')}`;
|
|
716
720
|
};
|
|
717
721
|
|
|
722
|
+
/** The words of a list, split at spaces outside quotes, `$( … )`, `${ … }`, and backticks: `a "b c" $(ls -a)`. */
|
|
723
|
+
function shellWordsOf(text) {
|
|
724
|
+
const out = [];
|
|
725
|
+
let cur = '', depth = 0, q = null;
|
|
726
|
+
for (let i = 0; i < text.length; i++) {
|
|
727
|
+
const c = text[i];
|
|
728
|
+
if (q) { cur += c; if (c === '\\' && q === '"') { cur += text[++i] ?? ''; continue; } if (c === q) q = null; continue; }
|
|
729
|
+
if (c === '\\') { cur += c + (text[++i] ?? ''); continue; }
|
|
730
|
+
if (c === '"' || c === "'" || c === '`') { q = c; cur += c; continue; }
|
|
731
|
+
if (c === '$' && (text[i + 1] === '(' || text[i + 1] === '{')) { depth++; cur += c + text[++i]; continue; }
|
|
732
|
+
if (depth && (c === '(' || c === '{')) { depth++; cur += c; continue; }
|
|
733
|
+
if (depth && (c === ')' || c === '}')) { depth--; cur += c; continue; }
|
|
734
|
+
if (!depth && /\s/.test(c)) { if (cur) out.push(cur); cur = ''; continue; }
|
|
735
|
+
cur += c;
|
|
736
|
+
}
|
|
737
|
+
if (cur) out.push(cur);
|
|
738
|
+
return out;
|
|
739
|
+
}
|
|
740
|
+
|
|
718
741
|
/** One assignment word (`X=val`, `X+=val`, `arr=(a b)`) in words. */
|
|
719
742
|
function assignWords(a, { exported = false, readonly = false } = {}) {
|
|
720
743
|
const m = a.match(/^([A-Za-z_]\w*)(\[[^\]]*\])?(\+?)=([\s\S]*)$/);
|
|
@@ -722,11 +745,12 @@ function assignWords(a, { exported = false, readonly = false } = {}) {
|
|
|
722
745
|
const [, name, index, plus, val] = m;
|
|
723
746
|
const who = `${varWords(name)}${index ? `'s ${sayWord(index.slice(1, -1))}` : ''}`;
|
|
724
747
|
const tail = exported ? ' and shares it with the programs it runs' : readonly ? ' (it cannot change after this)' : '';
|
|
725
|
-
|
|
748
|
+
// (`"${BIN}:${PATH}"`: the quotes go round the whole value, so each part is read inside them.)
|
|
749
|
+
if (name === 'PATH' && /\$\{?PATH\}?/.test(val)) { const q = /^"[^"]*"$/.test(val); const added = (q ? val.slice(1, -1) : val).split(':').filter((x) => !/\$\{?PATH\}?/.test(x)).map((x) => (q ? `"${x}"` : x)); return `Adds ${listWords(added.map(sayWord))} to the PATH (where commands are found)`; }
|
|
726
750
|
if (/^\(/.test(val)) {
|
|
727
751
|
const inner = val.slice(1, -1).trim();
|
|
728
752
|
if (!inner) return `Starts ${who} as an empty list`;
|
|
729
|
-
const items = inner
|
|
753
|
+
const items = shellWordsOf(inner);
|
|
730
754
|
return `${plus ? 'Adds' : 'Sets'} ${plus ? `${listWords(items.map(sayWord))} to ${who}` : `${who} to the list ${listWords(items.slice(0, 6).map(sayWord))}${items.length > 6 ? ', …' : ''}`}${tail}`;
|
|
731
755
|
}
|
|
732
756
|
if (val === '' || val === '""' || val === "''") return `Empties ${who}${tail}`;
|
|
@@ -754,8 +778,21 @@ function redirWords(redirs) {
|
|
|
754
778
|
}
|
|
755
779
|
const toStderr = (redirs) => redirs.some((r) => (r.op === '>&' && r.target === '2' && (!r.fd || r.fd === '1')) || (r.fd === '1' && r.op === '>&' && r.target === '2') || ((r.op === '>' || r.op === '>>') && r.target === '/dev/stderr'));
|
|
756
780
|
|
|
757
|
-
/**
|
|
781
|
+
/**
|
|
782
|
+
* `exec prog args` runs prog in place of this script: the script ends there (`exec -a NAME prog` names it NAME).
|
|
783
|
+
* (`exec >&2` with no command only moves the output, and the script carries on.)
|
|
784
|
+
*/
|
|
758
785
|
function simpleSays(n, ctx = null) {
|
|
786
|
+
const w0 = String(n.words[0] ?? '').replace(/^\\/, '');
|
|
787
|
+
if (w0 !== 'exec' || n.words.length < 2) return simpleSaysInner(n, ctx);
|
|
788
|
+
let ws = n.words.slice(1);
|
|
789
|
+
while (/^-/.test(ws[0] ?? '')) ws = ws[0] === '-a' ? ws.slice(2) : ws.slice(1);
|
|
790
|
+
if (!ws.length) return simpleSaysInner(n, ctx);
|
|
791
|
+
const r = simpleSaysInner({ ...n, words: ws }, ctx);
|
|
792
|
+
return { kind: 'return', says: `${r?.says || `Runs ${sayWord(ws[0])}`}, in place of this script (it does not come back here)`, exec: true };
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function simpleSaysInner(n, ctx = null) {
|
|
759
796
|
// `\command`, `\cd`: a leading backslash only skips aliases; the command is the same.
|
|
760
797
|
let ws = n.words.map((w, i) => (i === 0 ? w.replace(/^\\(?=[\w.])/, '') : w));
|
|
761
798
|
if (!ws.length) {
|