@skillstech/thunderlang 1.6.1 → 1.8.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +10 -3
  3. package/dist/core.cjs +264 -47
  4. package/dist/index.cjs +9118 -1077
  5. package/dist/learn.cjs +1419 -90
  6. package/package.json +1 -1
  7. package/src/ai.mjs +2 -1
  8. package/src/atlas.mjs +2 -1
  9. package/src/behaviour.mjs +246 -0
  10. package/src/cli-main.mjs +3015 -0
  11. package/src/cli.mjs +9 -2799
  12. package/src/conflict.mjs +0 -0
  13. package/src/core/ThunderDotnet.cs +195 -0
  14. package/src/core/check.mjs +316 -10
  15. package/src/core/cli.mjs +67 -10
  16. package/src/core/csharp-run.mjs +29 -8
  17. package/src/core/diagnostics.mjs +12 -1
  18. package/src/core/engine-core.mjs +161 -20
  19. package/src/core/engine-values.mjs +1 -0
  20. package/src/core/engine.mjs +131 -7
  21. package/src/core/go-run.mjs +3 -2
  22. package/src/core/index.mjs +6 -2
  23. package/src/core/java-run.mjs +3 -3
  24. package/src/core/kind.mjs +45 -0
  25. package/src/core/lexer.mjs +16 -2
  26. package/src/core/parser.mjs +254 -22
  27. package/src/core/project-root.mjs +18 -0
  28. package/src/core/project.mjs +18 -18
  29. package/src/core/react-run.mjs +3 -3
  30. package/src/core/runtime-go/thunder_runtime.go +269 -1
  31. package/src/core/runtime-npm.mjs +79 -0
  32. package/src/core/runtime-python.mjs +365 -3
  33. package/src/core/runtime-react.mjs +2 -1
  34. package/src/core/runtime-typescript.mjs +155 -6
  35. package/src/core/rust-run.mjs +3 -2
  36. package/src/core/serving.mjs +12 -0
  37. package/src/core/store-format.mjs +110 -0
  38. package/src/core/target-csharp.mjs +5 -1
  39. package/src/core/target-go.mjs +11 -4
  40. package/src/core/target-python.mjs +39 -6
  41. package/src/core/target-rust.mjs +1 -1
  42. package/src/core/target-typescript.mjs +95 -7
  43. package/src/core/typescript-run.mjs +14 -7
  44. package/src/core-changes-fs.mjs +28 -0
  45. package/src/core-changes.d.mts +67 -0
  46. package/src/core-changes.mjs +603 -0
  47. package/src/core-rules.mjs +146 -0
  48. package/src/core-services.d.mts +4 -0
  49. package/src/core-services.mjs +49 -0
  50. package/src/decision.mjs +2 -1
  51. package/src/distributed.mjs +2 -1
  52. package/src/emit.mjs +2 -2
  53. package/src/evidence.mjs +28 -0
  54. package/src/examples.d.mts +21 -0
  55. package/src/examples.mjs +175 -0
  56. package/src/focus.mjs +2 -1
  57. package/src/index.d.ts +4 -0
  58. package/src/index.mjs +4 -0
  59. package/src/intent-atlas.mjs +4 -3
  60. package/src/mcp.mjs +52 -6
  61. package/src/passport-fs.mjs +2 -1
  62. package/src/passport.mjs +2 -1
  63. package/src/privacy.mjs +2 -1
  64. package/src/program.d.mts +4 -0
  65. package/src/program.mjs +4 -0
  66. package/src/read-repo-fs.mjs +2 -1
  67. package/src/read-repo.mjs +3 -2
  68. package/src/report.mjs +3 -2
  69. package/src/review.mjs +71 -4
  70. package/src/select.mjs +2 -1
  71. package/src/semantic-diff.mjs +7 -6
  72. package/src/system.mjs +3 -2
  73. package/src/text-order.mjs +6 -0
  74. package/src/thunderize.mjs +2 -1
  75. package/src/trace-cli.mjs +8 -3
  76. package/src/trace-data.mjs +3 -2
  77. package/src/trace-fs.mjs +29 -3
  78. package/src/trace.mjs +27 -10
  79. package/src/write-across-cli.mjs +22 -4
  80. package/src/write-across.mjs +2 -1
  81. package/syntaxes/thunder.tmLanguage.json +196 -0
package/src/trace.mjs CHANGED
@@ -20,6 +20,7 @@ import { thunderModel } from './model.mjs';
20
20
  import { serviceFacts, segsMatch, GENERIC_PATHS } from './system.mjs';
21
21
  import { sha256 } from './hash.mjs';
22
22
  import { packagesIn, settingsIn, tablesIn, isManifest, LOCAL_VERSION, isGenericSetting, DEFINES } from './trace-data.mjs';
23
+ import { byText } from './text-order.mjs';
23
24
 
24
25
  export const TRACE_SCHEMA = 'thunder-trace-v1';
25
26
  export const TRACE_IMPACT_SCHEMA = 'thunder-trace-impact-v1';
@@ -48,18 +49,29 @@ const pathMatch = (a, b) => segsMatch(lower(a), lower(b));
48
49
  * Read each repository and link them. repos: [{ name, files: [{ path, source }], sha?, dirty? }].
49
50
  * Gives back thunder-trace-v1: { repos, links, notLinked, rules, fingerprint }.
50
51
  */
51
- export function buildTrace(repos) {
52
+ /**
53
+ * repos: [{ name, files, sha?, dirty?, coreFacts? }]. Thunder Core programs (.thunder) are read when their facts are
54
+ * given: each repository's `coreFacts`, or `core` (coreServiceFacts from core-services.mjs, which brings the Core
55
+ * compiler, so this module stays small without it). readRepoDir gives coreFacts.
56
+ */
57
+ export function buildTrace(repos, { core = null } = {}) {
52
58
  const names = new Set();
53
59
  const read = repos.map((r) => {
54
60
  if (!r.name || names.has(r.name)) throw new Error(`Each repository needs its own name; "${r.name}" is used twice.`);
55
61
  names.add(r.name);
56
- const model = thunderModel(r.files, { name: r.name });
57
- const facts = serviceFacts(model, r.files);
62
+ // .thunder files are read by core-services.mjs below, not as code in another language.
63
+ const other = r.files.filter((f) => !/\.thunder$/i.test(f.path));
64
+ const model = thunderModel(other, { name: r.name });
65
+ const facts = serviceFacts(model, other);
66
+ // Thunder Core programs (.thunder): their endpoints and calls to other services, read by core-services.mjs.
67
+ const cf = r.coreFacts ?? (core ? core(r.files) : { routes: [], requests: [], unknown: [], files: 0 });
68
+ for (const k of ['routes', 'requests', 'unknown']) facts[k] = [...facts[k], ...cf[k]];
69
+ const coreFiles = cf.files;
58
70
  // Test code is not how services talk to each other: a test's fake route or request is never a link.
59
71
  const real = (x) => !isTestFile(x.file);
60
- const data = dataFacts(r.files, model);
72
+ const data = dataFacts(other, model);
61
73
  const testItems = ['routes', 'listeners', 'requests', 'publishes'].reduce((n, k) => n + facts[k].filter((x) => !real(x)).length, 0) + data.testItems;
62
- return { name: r.name, sha: r.sha ?? null, dirty: !!r.dirty, files: model.files.length, languages: [...new Set(model.files.map((f) => f.language))].sort(),
74
+ return { name: r.name, sha: r.sha ?? null, dirty: !!r.dirty, files: model.files.length + coreFiles, languages: [...new Set([...model.files.map((f) => f.language), ...(coreFiles ? ['thunder'] : [])])].sort(),
63
75
  routes: facts.routes.filter(real), listeners: facts.listeners.filter(real), requests: facts.requests.filter(real), publishes: facts.publishes.filter(real), unknown: facts.unknown.filter(real),
64
76
  packages: data.packages, settings: data.settings, tables: data.tables, testItems };
65
77
  });
@@ -169,8 +181,8 @@ export function linkRepos(read) {
169
181
  const sortKey = (l) => `${l.from.cite}|${l.to?.cite ?? ''}|${l.kind}|${l.call ?? l.event ?? l.path ?? l.package ?? l.table ?? ''}`;
170
182
  // (A step inside a callback is read for the callback and for the function around it: the same call, once.)
171
183
  const once = (xs) => { const seen = new Set(); return xs.filter((x) => { const k = sortKey(x); if (seen.has(k)) return false; seen.add(k); return true; }); };
172
- links.splice(0, links.length, ...once(links).sort((a, b) => sortKey(a).localeCompare(sortKey(b))));
173
- notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => sortKey(a).localeCompare(sortKey(b))));
184
+ links.splice(0, links.length, ...once(links).sort((a, b) => byText(sortKey(a), sortKey(b))));
185
+ notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => byText(sortKey(a), sortKey(b))));
174
186
  const repos = read.map(({ unknown, ...r }) => ({ ...r, unknown: unknown ?? [], packages: pk(r), settings: r.settings ?? [], tables: tb(r) }));
175
187
  const body = { schema: TRACE_SCHEMA, rulesVersion: TRACE_RULES_VERSION, repos, links, notLinked, shared };
176
188
  return { ...body, fingerprint: sha256(JSON.stringify(body)) };
@@ -228,13 +240,17 @@ export function traceImpact(trace, changes) {
228
240
  if (!repo) continue;
229
241
  const found = findings.length;
230
242
  const hit = (x) => x.file === c.file && (c.status === 'added' || overlaps(x.lines, c.ranges) || within(x.line, c.ranges));
231
- const routes = repo.routes.filter(hit), listeners = repo.listeners.filter(hit);
243
+ // A Thunder Core route is also changed when something it reaches changed (a helper, a kept value): `through` names it.
244
+ const reachHit = (x) => (x.reach ?? []).filter((y) => y.file === c.file && (c.status === 'added' || overlaps(y.lines, c.ranges))).map((y) => y.subject);
245
+ const routes = repo.routes.filter((x) => hit(x) || reachHit(x).length).map((x) => (hit(x) ? x : { ...x, through: reachHit(x) }));
246
+ const listeners = repo.listeners.filter(hit);
232
247
  const requests = repo.requests.filter((x) => x.file === c.file && (c.status === 'added' || within(x.line, c.ranges) || overlaps(x.lines, c.ranges)));
233
248
  const publishes = repo.publishes.filter((x) => x.file === c.file && (c.status === 'added' || within(x.line, c.ranges) || overlaps(x.lines, c.ranges)));
234
249
 
235
250
  for (const r of routes) {
236
251
  const callers = trace.links.filter((l) => l.kind === 'http' && l.to.repo === repo.name && l.to.member === r.member);
237
- findings.push({ risk: callers.length ? 'high' : 'low', kind: 'route-changed', says: callers.length ? `${r.method} ${r.path} changed, and ${count(callers.length, 'caller')} in other repositories ${callers.length === 1 ? 'depends' : 'depend'} on it` : `${r.method} ${r.path} changed; no traced repository calls it`, at: end(repo, r), dependents: callers.map((l) => ({ ...l.from, how: l.base === 'computed' ? 'matched by path; the base address is set when it runs' : l.base === 'this app' ? 'same path from another app' : `through ${l.base}` })) });
252
+ const how = r.through ? ` (through ${r.through.join(', ')}, which changed)` : '';
253
+ findings.push({ risk: callers.length ? 'high' : 'low', kind: 'route-changed', says: callers.length ? `${r.method} ${r.path} changed${how}, and ${count(callers.length, 'caller')} in other repositories ${callers.length === 1 ? 'depends' : 'depend'} on it` : `${r.method} ${r.path} changed${how}; no traced repository calls it`, at: end(repo, r), ...(r.through ? { through: r.through } : {}), dependents: callers.map((l) => ({ ...l.from, how: l.base === 'computed' ? 'matched by path; the base address is set when it runs' : l.base === 'this app' ? 'same path from another app' : `through ${l.base}` })) });
238
254
  }
239
255
  for (const p of publishes) {
240
256
  const ls = trace.links.filter((l) => l.kind === 'event' && l.from.repo === repo.name && l.from.member === p.member && l.event === p.event);
@@ -311,7 +327,7 @@ export function traceImpact(trace, changes) {
311
327
  if (findings.length > found || routes.length || listeners.length || requests.length || publishes.length || c.before) touched.push({ repo: c.repo, file: c.file, status: c.status });
312
328
  }
313
329
  const rank = { high: 0, medium: 1, low: 2 };
314
- findings.sort((a, b) => rank[a.risk] - rank[b.risk] || a.at.cite.localeCompare(b.at.cite));
330
+ findings.sort((a, b) => rank[a.risk] - rank[b.risk] || byText(a.at.cite, b.at.cite));
315
331
  return { schema: TRACE_IMPACT_SCHEMA, traceFingerprint: trace.fingerprint, findings, changed: touched, stopsAt: 1, note: 'Stops at the first hop: callers of the callers are not listed. Links are facts read from code (no code was run); a call whose address is worked out when it runs is not linked.' };
316
332
  }
317
333
 
@@ -446,6 +462,7 @@ export function renderImpact(r) {
446
462
  if (r.matched) out.push(`Read "${r.term}" as: ${r.matched.join('; ')}`);
447
463
  for (const f of r.findings) {
448
464
  out.push('', `${f.risk.toUpperCase().padEnd(6)} ${f.at.repo}: ${f.says}`, ` ${f.at.cite}`);
465
+ for (const x of f.behaviour ?? []) out.push(` what changes: ${x.says}`);
449
466
  for (const d of f.dependents) out.push(` ← ${d.repo}: ${d.label} (${d.how}) ${d.cite}`);
450
467
  }
451
468
  return out.join('\n');
@@ -6,6 +6,7 @@
6
6
  import { readFileSync, writeFileSync, statSync } from 'node:fs';
7
7
  import { basename, dirname, join, resolve } from 'node:path';
8
8
  import { spawnSync } from 'node:child_process';
9
+ import { behaviourCheck } from './behaviour.mjs';
9
10
  import { collectReadableFiles } from './read-repo-fs.mjs';
10
11
  import { writeRuleAcross, writeAcrossEvidence } from './write-across.mjs';
11
12
  import { buildPassport } from './passport-fs.mjs';
@@ -13,17 +14,18 @@ import { renderPassportSummary, renderPassportMarkdown } from './passport.mjs';
13
14
  import { paint, useColor } from './term.mjs';
14
15
 
15
16
  const USAGE = `usage: thunder write <folder…> --decision <name> --rule <n> --when "<condition>" [--write]
16
- [--run "part: cmd" …] [--passport passport.json] [--purpose "…"] [--json]
17
+ [--run "part: cmd" …] [--passport passport.json] [--purpose "…"] [--behaviour] [--json]
17
18
  Finds every implementation of the rule across the folders (each one part, in any language Thunder reads) and
18
19
  changes its number, comparison, or text value in each of them. Without --write: the plan only. With --write: every
19
20
  implementation changes, or none does. Test files are never edited; those that mention the old value are listed.
20
- Exit codes: 0 done (or planned), 1 refused or a --run command failed, 2 usage.`;
21
+ --behaviour runs each Python implementation before and after on inputs made from its code and lists the answers
22
+ that change (it runs that code). Exit codes: 0 done (or planned), 1 refused or a --run command failed, 2 usage.`;
21
23
 
22
24
  /** Is this `thunder write` call about several folders (rather than one file)? */
23
25
  export function isWriteAcross(argv) {
24
26
  const paths = [];
25
27
  for (let i = 0; i < argv.length; i++) {
26
- if (argv[i].startsWith('--')) { if (!['--write', '--json', '-w'].includes(argv[i])) i++; continue; }
28
+ if (argv[i].startsWith('--')) { if (!['--write', '--json', '-w', '--behaviour', '--behavior'].includes(argv[i])) i++; continue; }
27
29
  paths.push(argv[i]);
28
30
  }
29
31
  if (argv.includes('--edit')) return false;
@@ -45,6 +47,7 @@ export async function writeAcrossMain(argv) {
45
47
  else if (x === '--md-out') a.mdOut = need();
46
48
  else if (x === '--purpose') a.purpose = need();
47
49
  else if (x === '--json') a.json = true;
50
+ else if (x === '--behaviour' || x === '--behavior') a.behaviour = true;
48
51
  else if (x === '--help' || x === '-h') { console.log(USAGE); return 0; }
49
52
  else if (x === '--answer') { console.error('thunder write: across folders, only a rule\'s condition can change (--when). Each service may answer in its own way (a label on the page, an amount in billing), so one new answer would not fit them all.'); return 2; }
50
53
  else if (x.startsWith('--')) { console.error(`thunder write: there is no option ${x} for a change across folders.\n${USAGE}`); return 2; }
@@ -100,9 +103,17 @@ export async function writeAcrossMain(argv) {
100
103
  }
101
104
  const failed = runs.filter((x) => x.exitCode !== 0);
102
105
 
106
+ // --behaviour: run each Python implementation before and after the change, on inputs made from its code.
107
+ const behaviour = r.ok && a.behaviour ? r.plan.map((p) => {
108
+ const key = `${p.part}/${p.file}`;
109
+ const before = files.find((f) => f.part === p.part && f.path === p.file)?.source ?? '';
110
+ const after = r.files[key] ?? before;
111
+ return { part: p.part, file: p.file, ...behaviourCheck({ path: dirOf(key), name: p.decision, before, after }) };
112
+ }) : [];
113
+
103
114
  if (a.json) {
104
115
  const { files: _f, ...rest } = r;
105
- console.log(JSON.stringify({ ...rest, written, runs, ...(a.passport ? { passport: a.passport } : {}) }, null, 2));
116
+ console.log(JSON.stringify({ ...rest, written, runs, ...(a.behaviour ? { behaviour } : {}), ...(a.passport ? { passport: a.passport } : {}) }, null, 2));
106
117
  return !r.ok || failed.length ? 1 : 0;
107
118
  }
108
119
  const say = (s = '') => console.log(paint(s, useColor()));
@@ -122,6 +133,13 @@ export async function writeAcrossMain(argv) {
122
133
  for (const c of p.change) say(` line ${c.line}, column ${c.column}: ${c.before} -> ${c.after}`);
123
134
  }
124
135
  say('\nChecked by reading each file again: the rule reads as intended, and every other rule and function in each file reads exactly as before.');
136
+ if (behaviour.length) {
137
+ say('\nWhat the change does, run before and after on inputs made from the code (tested on these inputs only; not a proof):');
138
+ for (const b of behaviour) {
139
+ say(` ${b.part}/${b.file} ${b.status === 'changed' ? `${b.changes.length} of ${b.inputs} inputs give a different answer` : b.status === 'same' ? `all ${b.inputs} inputs give the same answer` : b.status === 'broken' ? `the changed file does not load (${b.reason})` : `not run (${b.reason})`}`);
140
+ for (const ex of (b.examples ?? []).slice(0, 3)) say(` ${ex}`);
141
+ }
142
+ }
125
143
  if (r.notIncluded.length) {
126
144
  say('\nNot included (similar, but Thunder cannot tell it is the same rule; check by hand):');
127
145
  for (const n of r.notIncluded) say(` ${n.part}/${n.file}:${n.line} ${n.why}`);
@@ -20,6 +20,7 @@ import { readCode, sayCondition } from './read.mjs';
20
20
  import { tokenize } from './expr.mjs';
21
21
  import { writeRule } from './write.mjs';
22
22
  import { isTestFile } from './trace.mjs';
23
+ import { byText } from './text-order.mjs';
23
24
 
24
25
  export const WRITE_ACROSS_SCHEMA = 'thunder-write-across-v1';
25
26
 
@@ -150,7 +151,7 @@ export function writeRuleAcross(files, { decision, rule, when }) {
150
151
  }
151
152
  result.files[k] = source;
152
153
  }
153
- result.plan.sort((a, b) => where(a).localeCompare(where(b)) || a.line - b.line);
154
+ result.plan.sort((a, b) => byText(where(a), where(b)) || a.line - b.line);
154
155
  if (problems.length) return { ...base, files: {}, plan: [], rule: result.rule, notIncluded: result.notIncluded, tests: result.tests, problems: ['Nothing was changed: every implementation must be written exactly, or none is.', ...problems] };
155
156
  return { ...result, ok: true };
156
157
  }
@@ -0,0 +1,196 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3
+ "name": "ThunderLang",
4
+ "scopeName": "source.thunder",
5
+ "fileTypes": [
6
+ "thunder",
7
+ "tl",
8
+ "intent"
9
+ ],
10
+ "patterns": [
11
+ {
12
+ "include": "#comment"
13
+ },
14
+ {
15
+ "include": "#string"
16
+ },
17
+ {
18
+ "include": "#core-definition"
19
+ },
20
+ {
21
+ "include": "#core-keyword"
22
+ },
23
+ {
24
+ "include": "#block-keyword"
25
+ },
26
+ {
27
+ "include": "#field-value"
28
+ },
29
+ {
30
+ "include": "#field-type"
31
+ },
32
+ {
33
+ "include": "#operator"
34
+ },
35
+ {
36
+ "include": "#core-value"
37
+ },
38
+ {
39
+ "include": "#core-soft"
40
+ },
41
+ {
42
+ "include": "#number"
43
+ },
44
+ {
45
+ "include": "#type"
46
+ }
47
+ ],
48
+ "repository": {
49
+ "comment": {
50
+ "match": "#.*$",
51
+ "name": "comment.line.number-sign.thunder"
52
+ },
53
+ "string": {
54
+ "name": "string.quoted.double.thunder",
55
+ "begin": "\"",
56
+ "end": "\"",
57
+ "patterns": [
58
+ {
59
+ "match": "\\\\.",
60
+ "name": "constant.character.escape.thunder"
61
+ },
62
+ {
63
+ "match": "\\{[^{}\"]+\\}",
64
+ "name": "variable.other.interpolation.thunder"
65
+ }
66
+ ]
67
+ },
68
+ "block-keyword": {
69
+ "comment": "A line-leading keyword introduces a block or a field (indentation-structured).",
70
+ "match": "^\\s*(mission|use|goal|why|because|requires|inputs?|outputs?|guarantees?|never|constraints?|assumptions?|risks|target|style|verify|errors|examples|service|api|event|database|architecture|selection|title|for|persona|customer|problem|evidence|opportunity|outcome_contract|outcome|metric|scope|include|exclude|non_goal|owner|unknown|question|assumption|experience|pattern|decision|rule|default|when|return|command|on|compensate|notify|preserve|lifecycle|state|transition|from|to|terminal|always|eventually|until|conflict|options|between|resolve_by|resolution|choose|approval|capability|interface|provides|slo|release|result|learning|component|artifact|test|case|scenario|given|expect|events|data|waiver|note|implements|covers|variant|token|classification|purpose|retention|basis|baseline|window|direction|includes|measures|value|kind|ref|version|status|date|reason|approved_by|by|at|decision|expires|before|idempotency_key|timeout|retry|backoff|confidence|source|recover|follows|actor|accessible|responsive|asked_of|resolve|validate)\\b",
71
+ "captures": {
72
+ "1": {
73
+ "name": "keyword.control.thunder"
74
+ }
75
+ }
76
+ },
77
+ "field-value": {
78
+ "comment": "A record or a call written as a block: buy price: $20.00 (every word of the name is the field).",
79
+ "match": "^\\s+([a-z][a-z0-9_]*(?: [a-z][a-z0-9_]*)*)(:)(?=\\s+\\S)",
80
+ "captures": {
81
+ "1": {
82
+ "name": "variable.other.property.thunder"
83
+ },
84
+ "2": {
85
+ "name": "punctuation.separator.key-value.thunder"
86
+ }
87
+ }
88
+ },
89
+ "field-type": {
90
+ "comment": "A typed field: name: Type (optionally List<Type>).",
91
+ "match": "\\b([a-z][A-Za-z0-9_.]*)\\s*(:)\\s*([A-Z][A-Za-z0-9]*(?:<[^>]+>)?)",
92
+ "captures": {
93
+ "1": {
94
+ "name": "variable.other.member.thunder"
95
+ },
96
+ "2": {
97
+ "name": "punctuation.separator.thunder"
98
+ },
99
+ "3": {
100
+ "name": "entity.name.type.thunder"
101
+ }
102
+ }
103
+ },
104
+ "operator": {
105
+ "comment": "Expression operators used in decision conditions (when ...).",
106
+ "match": "(>=|<=|==|!=|>|<|=|\\+|\\-|\\*|/|%)|\\b(and|or|not|in)\\b",
107
+ "name": "keyword.operator.thunder"
108
+ },
109
+ "number": {
110
+ "match": "\\b\\d+(?:\\.\\d+)?%?\\b",
111
+ "name": "constant.numeric.thunder"
112
+ },
113
+ "type": {
114
+ "comment": "PascalCase identifiers are entities/types in ThunderLang.",
115
+ "match": "\\b([A-Z][A-Za-z0-9]*)(?:<[^>]+>)?\\b",
116
+ "name": "entity.name.type.thunder"
117
+ },
118
+ "core-definition": {
119
+ "comment": "Thunder Core: 'To calculate discount:' names a function; 'A Trade has:' names a record.",
120
+ "patterns": [
121
+ {
122
+ "match": "^\\s*(To)\\s+([a-z][\\w ]*?)(:)\\s*$",
123
+ "captures": {
124
+ "1": {
125
+ "name": "keyword.control.thunder"
126
+ },
127
+ "2": {
128
+ "name": "entity.name.function.thunder"
129
+ },
130
+ "3": {
131
+ "name": "punctuation.separator.thunder"
132
+ }
133
+ }
134
+ },
135
+ {
136
+ "match": "^\\s*(An?)\\s+([A-Z]\\w*(?: [A-Z]\\w*)*)\\s+(has)(:)",
137
+ "captures": {
138
+ "1": {
139
+ "name": "keyword.control.thunder"
140
+ },
141
+ "2": {
142
+ "name": "entity.name.type.thunder"
143
+ },
144
+ "3": {
145
+ "name": "keyword.other.thunder"
146
+ },
147
+ "4": {
148
+ "name": "punctuation.separator.thunder"
149
+ }
150
+ }
151
+ },
152
+ {
153
+ "match": "^\\s+([A-Z][\\w ]*?)\\s+(is)\\s+((?:an? )?(?:optional )?(?:text|money|number|whole number|date|yes/no|yes or no|list|map)\\b[\\w ]*)",
154
+ "captures": {
155
+ "1": {
156
+ "name": "variable.other.property.thunder"
157
+ },
158
+ "2": {
159
+ "name": "keyword.operator.thunder"
160
+ },
161
+ "3": {
162
+ "name": "support.type.thunder"
163
+ }
164
+ }
165
+ }
166
+ ]
167
+ },
168
+ "core-keyword": {
169
+ "comment": "Thunder Core statement words at the start of a line.",
170
+ "match": "^\\s*(Set|say|Say|print|Keep|Increase|Decrease|Add|Remove|Sort|Reverse|When|If|Otherwise(?: when| if)?|For each|Repeat(?: while| until)?|Stop with|Give(?: back)?|Receive|Test|Expect|Use|Never allow)\\b",
171
+ "captures": {
172
+ "1": {
173
+ "name": "keyword.control.thunder"
174
+ }
175
+ }
176
+ },
177
+ "core-soft": {
178
+ "comment": "Small words that join a statement's parts.",
179
+ "match": "\\b(to|with|by|from|as|at least|at most|more than|less than|each|while|until|times|of|where|sorted|descending|be|fail|this fails|joined with|split at|replacing|starts with|ends with|contains)\\b",
180
+ "name": "keyword.other.thunder"
181
+ },
182
+ "core-value": {
183
+ "comment": "Money, percents, and yes / no / nothing.",
184
+ "patterns": [
185
+ {
186
+ "match": "-?\\$\\d[\\d,]*(?:\\.\\d+)?",
187
+ "name": "constant.numeric.money.thunder"
188
+ },
189
+ {
190
+ "match": "\\b(yes|no|nothing|true|false)\\b",
191
+ "name": "constant.language.thunder"
192
+ }
193
+ ]
194
+ }
195
+ }
196
+ }