@specverse/engines 4.1.15 → 4.1.17
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/dist/inference/index.d.ts +2 -1
- package/dist/inference/index.d.ts.map +1 -1
- package/dist/inference/index.js +2 -1
- package/dist/inference/index.js.map +1 -1
- package/dist/inference/quint-transpiler.d.ts +18 -1
- package/dist/inference/quint-transpiler.d.ts.map +1 -1
- package/dist/inference/quint-transpiler.js +382 -63
- package/dist/inference/quint-transpiler.js.map +1 -1
- package/dist/inference/verification.d.ts +78 -0
- package/dist/inference/verification.d.ts.map +1 -0
- package/dist/inference/verification.js +482 -0
- package/dist/inference/verification.js.map +1 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +30 -5
- package/dist/realize/index.d.ts.map +1 -1
- package/dist/realize/index.js +9 -26
- package/dist/realize/index.js.map +1 -1
- package/libs/instance-factories/cli/templates/commander/command-generator.ts +35 -5
- package/package.json +1 -1
|
@@ -8,7 +8,8 @@ export * from './deployment/index.js';
|
|
|
8
8
|
export { ComprehensiveInferenceEngine } from './comprehensive-engine.js';
|
|
9
9
|
export type { ComprehensiveInferenceResult } from './comprehensive-engine.js';
|
|
10
10
|
export { generateDevSpecly } from './dev-specly-generator.js';
|
|
11
|
-
export { transpileEntityGuards, transpileQuintFile, generateGuardsModule, type TranspiledGuard } from './quint-transpiler.js';
|
|
11
|
+
export { transpileEntityGuards, extractStateVariables, transpileQuintFile, generateGuardsModule, type TranspiledGuard } from './quint-transpiler.js';
|
|
12
|
+
export { verifySpec, buildSnapshot, formatVerificationResult, type VerificationResult, type VerificationFailure, type VerificationSkip, type VerificationError, type VerifyOptions } from './verification.js';
|
|
12
13
|
export { transpileActions, generateActionsModule, type TranspiledAction } from './quint-transpiler.js';
|
|
13
14
|
import type { InferenceEngine, EngineInfo, ValidationResult, InferenceOptions, InferenceResult } from '@specverse/types';
|
|
14
15
|
declare class SpecVerseInferenceEngine implements InferenceEngine {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,YAAY,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAG9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAS9D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,YAAY,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAG9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAS9D,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACrJ,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC9M,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAMvG,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGzH,cAAM,wBAAyB,YAAW,eAAe;IACvD,IAAI,SAAe;IACnB,OAAO,SAAW;IAClB,YAAY,WAAyE;IAErF,OAAO,CAAC,OAAO,CAA6C;IAEtD,UAAU,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E,OAAO,IAAI,UAAU;IAIf,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKtC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CA6I5E;AAED,eAAO,MAAM,MAAM,0BAAiC,CAAC;AACrD,eAAe,MAAM,CAAC"}
|
package/dist/inference/index.js
CHANGED
|
@@ -17,7 +17,8 @@ import { SpeclyConverter } from './core/specly-converter.js';
|
|
|
17
17
|
// Dev specly generator
|
|
18
18
|
import { generateDevSpecly } from './dev-specly-generator.js';
|
|
19
19
|
// Quint → TypeScript transpiler
|
|
20
|
-
export { transpileEntityGuards, transpileQuintFile, generateGuardsModule } from './quint-transpiler.js';
|
|
20
|
+
export { transpileEntityGuards, extractStateVariables, transpileQuintFile, generateGuardsModule } from './quint-transpiler.js';
|
|
21
|
+
export { verifySpec, buildSnapshot, formatVerificationResult } from './verification.js';
|
|
21
22
|
export { transpileActions, generateActionsModule } from './quint-transpiler.js';
|
|
22
23
|
import { ComprehensiveInferenceEngine } from './comprehensive-engine.js';
|
|
23
24
|
class SpecVerseInferenceEngine {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAwB;AACxB,cAAc,iBAAiB,CAAC;AAEhC,iCAAiC;AACjC,cAAc,oBAAo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,qBAAqB,CAAC;QACtC,CAAC;QAED,2CAA2C;QAC3C,MAAM,OAAO,GAAG,iBAAiB;YAC/B,CAAC,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,CAAC;YAC9D,CAAC,CAAC,SAAS,CAAC;QAEd,OAAO;YACL,SAAS,EAAE,iBAAiB,IAAI,EAAE;YAClC,WAAW,EAAE,MAAM,EAAE,WAAW,IAAI,EAAE;YACtC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE;YACvB,OAAO;YACP,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;YAC3E,UAAU,EAAE;gBACV,GAAG,CAAC,MAAM,EAAE,UAAU,IAAI,EAAE,CAAC;gBAC7B,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,IAAI,CAAC;aACzD;SACF,CAAC;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,wBAAwB,EAAE,CAAC;AACrD,eAAe,MAAM,CAAC"}
|
|
@@ -21,19 +21,36 @@ export interface TranspiledGuard {
|
|
|
21
21
|
typescript: string;
|
|
22
22
|
module: string;
|
|
23
23
|
entity: string;
|
|
24
|
+
/**
|
|
25
|
+
* State variables this guard reads from. Used by the verification
|
|
26
|
+
* runner to decide whether the guard is applicable to a given spec
|
|
27
|
+
* snapshot: if any dependency is not present in the snapshot, the
|
|
28
|
+
* guard is skipped (not failed).
|
|
29
|
+
*/
|
|
30
|
+
dependencies: string[];
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* Transpile all Quint files from entity modules into TypeScript guards.
|
|
27
34
|
*/
|
|
28
35
|
export declare function transpileEntityGuards(entitiesDir: string): TranspiledGuard[];
|
|
36
|
+
/**
|
|
37
|
+
* Scan Quint behaviour files for module-level `var X: ...` declarations.
|
|
38
|
+
* These are the state variables guards read from; the runtime host
|
|
39
|
+
* populates them via `setSpecSnapshot` before invoking any `check_*`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractStateVariables(entitiesDir: string): string[];
|
|
29
42
|
/**
|
|
30
43
|
* Transpile a single Quint file into TypeScript guards.
|
|
31
44
|
*/
|
|
32
45
|
export declare function transpileQuintFile(content: string, entity: string, filename: string): TranspiledGuard[];
|
|
33
46
|
/**
|
|
34
47
|
* Generate a TypeScript guards module from transpiled guards.
|
|
48
|
+
*
|
|
49
|
+
* `stateVars` is the list of Quint module-level `var` declarations the
|
|
50
|
+
* guards reference. When omitted, falls back to a minimal hard-coded
|
|
51
|
+
* set — but callers should pass the real list from `extractStateVariables`.
|
|
35
52
|
*/
|
|
36
|
-
export declare function generateGuardsModule(guards: TranspiledGuard[]): string;
|
|
53
|
+
export declare function generateGuardsModule(guards: TranspiledGuard[], stateVars?: string[]): string;
|
|
37
54
|
export interface TranspiledAction {
|
|
38
55
|
name: string;
|
|
39
56
|
params: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quint-transpiler.d.ts","sourceRoot":"","sources":["../../src/inference/quint-transpiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"quint-transpiler.d.ts","sourceRoot":"","sources":["../../src/inference/quint-transpiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,UAA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**
|
|
43
|
+
* Scan Quint behaviour files for module-level `var X: ...` declarations.
|
|
44
|
+
* These are the state variables guards read from; the runtime host
|
|
45
|
+
* populates them via `setSpecSnapshot` before invoking any `check_*`.
|
|
46
|
+
*/
|
|
47
|
+
export function extractStateVariables(entitiesDir) {
|
|
48
|
+
const found = new Set();
|
|
49
|
+
const varRe = /^\s*var\s+(\w+)\s*:/gm;
|
|
50
|
+
for (const category of ['core', 'extensions']) {
|
|
51
|
+
const categoryDir = join(entitiesDir, category);
|
|
52
|
+
if (!existsSync(categoryDir))
|
|
53
|
+
continue;
|
|
54
|
+
for (const entity of readdirSync(categoryDir)) {
|
|
55
|
+
const behaviourDir = join(categoryDir, entity, 'behaviour');
|
|
56
|
+
if (!existsSync(behaviourDir))
|
|
57
|
+
continue;
|
|
58
|
+
for (const file of readdirSync(behaviourDir).filter(f => f.endsWith('.qnt'))) {
|
|
59
|
+
const content = readFileSync(join(behaviourDir, file), 'utf8');
|
|
60
|
+
let m;
|
|
61
|
+
varRe.lastIndex = 0;
|
|
62
|
+
while ((m = varRe.exec(content)) !== null) {
|
|
63
|
+
// Skip `fullyExpanded` and similar pure-inference state vars
|
|
64
|
+
// — they're booleans, not array-of-entity collections.
|
|
65
|
+
if (m[1] === 'fullyExpanded')
|
|
66
|
+
continue;
|
|
67
|
+
found.add(m[1]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [...found].sort();
|
|
73
|
+
}
|
|
42
74
|
/**
|
|
43
75
|
* Transpile a single Quint file into TypeScript guards.
|
|
44
76
|
*/
|
|
@@ -46,6 +78,15 @@ export function transpileQuintFile(content, entity, filename) {
|
|
|
46
78
|
const guards = [];
|
|
47
79
|
const lines = content.split('\n');
|
|
48
80
|
const moduleName = extractModuleName(content) || entity;
|
|
81
|
+
// Collect file-level `var X: ...` declarations so we know which symbols
|
|
82
|
+
// to treat as dependencies (vs local parameters) when scanning guard
|
|
83
|
+
// bodies.
|
|
84
|
+
const fileStateVars = new Set();
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
const vm = line.match(/^\s*var\s+(\w+)\s*:/);
|
|
87
|
+
if (vm && vm[1] !== 'fullyExpanded')
|
|
88
|
+
fileStateVars.add(vm[1]);
|
|
89
|
+
}
|
|
49
90
|
let i = 0;
|
|
50
91
|
while (i < lines.length) {
|
|
51
92
|
const line = lines[i].trim();
|
|
@@ -64,6 +105,7 @@ export function transpileQuintFile(content, entity, filename) {
|
|
|
64
105
|
typescript: `export function ${name}(${tsParams}): ${tsReturn} {\n ${tsBody}\n}`,
|
|
65
106
|
module: moduleName,
|
|
66
107
|
entity,
|
|
108
|
+
dependencies: extractGuardDependencies(body, fileStateVars),
|
|
67
109
|
});
|
|
68
110
|
i = skipBlock(lines, i);
|
|
69
111
|
continue;
|
|
@@ -79,14 +121,16 @@ export function transpileQuintFile(content, entity, filename) {
|
|
|
79
121
|
body += lines[i].trim() + ' ';
|
|
80
122
|
i++;
|
|
81
123
|
}
|
|
82
|
-
const
|
|
124
|
+
const bodyTrim = body.trim();
|
|
125
|
+
const tsBody = transpileExpression(bodyTrim);
|
|
83
126
|
guards.push({
|
|
84
127
|
name,
|
|
85
128
|
kind: 'invariant',
|
|
86
|
-
quint: `val ${name}: bool = ${
|
|
129
|
+
quint: `val ${name}: bool = ${bodyTrim}`,
|
|
87
130
|
typescript: `export function check_${name}(_data?: any): boolean {\n return ${tsBody};\n}`,
|
|
88
131
|
module: moduleName,
|
|
89
132
|
entity,
|
|
133
|
+
dependencies: extractGuardDependencies(bodyTrim, fileStateVars),
|
|
90
134
|
});
|
|
91
135
|
continue;
|
|
92
136
|
}
|
|
@@ -102,16 +146,41 @@ export function transpileQuintFile(content, entity, filename) {
|
|
|
102
146
|
typescript: `export function check_${name}(data: any): boolean {\n return ${tsExpr};\n}`,
|
|
103
147
|
module: moduleName,
|
|
104
148
|
entity,
|
|
149
|
+
dependencies: extractGuardDependencies(expr.trim(), fileStateVars),
|
|
105
150
|
});
|
|
106
151
|
}
|
|
107
152
|
i++;
|
|
108
153
|
}
|
|
109
154
|
return guards;
|
|
110
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Scan a Quint expression (pre-transpile) and return which file-level
|
|
158
|
+
* state variables it reads. Used to decide whether a guard is applicable
|
|
159
|
+
* to a given spec snapshot: if the snapshot doesn't populate one of the
|
|
160
|
+
* guard's dependencies, verify skips the guard.
|
|
161
|
+
*/
|
|
162
|
+
function extractGuardDependencies(body, fileStateVars) {
|
|
163
|
+
if (!fileStateVars.size)
|
|
164
|
+
return [];
|
|
165
|
+
const deps = new Set();
|
|
166
|
+
// Match bare identifiers not preceded by a word char or dot (so
|
|
167
|
+
// `m.models` — field access on a lambda param — doesn't count, but
|
|
168
|
+
// `models.forall(...)` does).
|
|
169
|
+
for (const v of fileStateVars) {
|
|
170
|
+
const re = new RegExp(`(?<![A-Za-z0-9_.])${v}\\b`);
|
|
171
|
+
if (re.test(body))
|
|
172
|
+
deps.add(v);
|
|
173
|
+
}
|
|
174
|
+
return [...deps].sort();
|
|
175
|
+
}
|
|
111
176
|
/**
|
|
112
177
|
* Generate a TypeScript guards module from transpiled guards.
|
|
178
|
+
*
|
|
179
|
+
* `stateVars` is the list of Quint module-level `var` declarations the
|
|
180
|
+
* guards reference. When omitted, falls back to a minimal hard-coded
|
|
181
|
+
* set — but callers should pass the real list from `extractStateVariables`.
|
|
113
182
|
*/
|
|
114
|
-
export function generateGuardsModule(guards) {
|
|
183
|
+
export function generateGuardsModule(guards, stateVars) {
|
|
115
184
|
if (guards.length === 0)
|
|
116
185
|
return '// No guards generated\nexport {};\n';
|
|
117
186
|
// Deduplicate by name — multiple modules may define the same invariant
|
|
@@ -126,9 +195,19 @@ export function generateGuardsModule(guards) {
|
|
|
126
195
|
});
|
|
127
196
|
const functions = guards.filter(g => g.kind === 'function');
|
|
128
197
|
const invariants = guards.filter(g => g.kind === 'invariant');
|
|
198
|
+
const candidateStateVars = stateVars && stateVars.length > 0
|
|
199
|
+
? stateVars
|
|
200
|
+
: ['models', 'controllers', 'services', 'views', 'events', 'deployments', 'commands', 'conventions', 'measures'];
|
|
201
|
+
// Only declare state vars the surviving guards actually reference —
|
|
202
|
+
// otherwise `noUnusedLocals` flags declarations for vars whose only
|
|
203
|
+
// consumer was a deduplicated guard. Exclude dot-prefixed matches
|
|
204
|
+
// (`d.channels` is a field access on a lambda parameter, not the
|
|
205
|
+
// module-level `channels` state variable).
|
|
206
|
+
const guardBodies = guards.map(g => g.typescript).join('\n');
|
|
207
|
+
const resolvedStateVars = candidateStateVars.filter(v => new RegExp(`(?<![\\w.])${v}\\b`).test(guardBodies));
|
|
208
|
+
const declarations = resolvedStateVars.map(v => `let ${v}: any[] = [];`);
|
|
209
|
+
const assignments = resolvedStateVars.map(v => ` ${v} = snapshot?.${v} ?? [];`);
|
|
129
210
|
const lines = [
|
|
130
|
-
'// @ts-nocheck',
|
|
131
|
-
'/* eslint-disable */',
|
|
132
211
|
'/**',
|
|
133
212
|
' * Runtime Guards — Transpiled from Quint Specifications',
|
|
134
213
|
' *',
|
|
@@ -141,29 +220,27 @@ export function generateGuardsModule(guards) {
|
|
|
141
220
|
' */',
|
|
142
221
|
'',
|
|
143
222
|
'// Quint module-level state variables — initialized via setSpecSnapshot().',
|
|
144
|
-
'// The guards read from these
|
|
145
|
-
'// invoking any check_* function.',
|
|
223
|
+
'// The guards read from these; a host caller populates them before',
|
|
224
|
+
'// invoking any check_* function. Variable set is auto-discovered from',
|
|
225
|
+
'// the guard bodies.',
|
|
146
226
|
'/* eslint-disable @typescript-eslint/no-unused-vars, prefer-const */',
|
|
147
|
-
|
|
148
|
-
'let controllers: any[] = [];',
|
|
149
|
-
'let services: any[] = [];',
|
|
150
|
-
'let views: any[] = [];',
|
|
151
|
-
'let events: any[] = [];',
|
|
152
|
-
'let commands: any[] = [];',
|
|
153
|
-
'let conventions: any[] = [];',
|
|
154
|
-
'let measures: any[] = [];',
|
|
155
|
-
'let deployments: any[] = [];',
|
|
227
|
+
...declarations,
|
|
156
228
|
'',
|
|
157
229
|
'export function setSpecSnapshot(snapshot: any): void {',
|
|
158
|
-
|
|
159
|
-
'
|
|
160
|
-
'
|
|
161
|
-
'
|
|
162
|
-
'
|
|
163
|
-
'
|
|
164
|
-
'
|
|
165
|
-
'
|
|
166
|
-
'
|
|
230
|
+
...assignments,
|
|
231
|
+
'}',
|
|
232
|
+
'',
|
|
233
|
+
'/**',
|
|
234
|
+
' * Cardinality helper for Quint .size() — handles arrays, plain',
|
|
235
|
+
' * objects (Quint Maps), Sets, and undefined safely.',
|
|
236
|
+
' */',
|
|
237
|
+
'function _size(x: any): number {',
|
|
238
|
+
' if (x == null) return 0;',
|
|
239
|
+
' if (Array.isArray(x)) return x.length;',
|
|
240
|
+
' if (typeof x === "string") return x.length;',
|
|
241
|
+
' if (x instanceof Set || x instanceof Map) return x.size;',
|
|
242
|
+
' if (typeof x === "object") return Object.keys(x).length;',
|
|
243
|
+
' return 0;',
|
|
167
244
|
'}',
|
|
168
245
|
'',
|
|
169
246
|
];
|
|
@@ -430,14 +507,7 @@ function transpileBody(body) {
|
|
|
430
507
|
ts = ts.replace(/\}\s*$/, '');
|
|
431
508
|
// Normalize — join multiline into single line, collapse whitespace
|
|
432
509
|
ts = ts.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
|
|
433
|
-
|
|
434
|
-
ts = ts.replace(/\band\b/g, '&&');
|
|
435
|
-
ts = ts.replace(/\bor\b/g, '||');
|
|
436
|
-
ts = ts.replace(/\bnot\b/g, '!');
|
|
437
|
-
ts = transpileValBindings(ts);
|
|
438
|
-
ts = transpileImplies(ts);
|
|
439
|
-
ts = ts.replace(/\.forall\(\s*(\w+)\s*=>\s*/g, '.every(($1: any) => ');
|
|
440
|
-
ts = ts.replace(/\.exists\(\s*(\w+)\s*=>\s*/g, '.some(($1: any) => ');
|
|
510
|
+
ts = applyQuintRewrites(ts);
|
|
441
511
|
// Clean up comments
|
|
442
512
|
ts = ts.replace(/\/\/.*?(?=\bif\b|\belse\b|$)/g, '');
|
|
443
513
|
// Replace if/else chains → ternary (from innermost out)
|
|
@@ -451,6 +521,57 @@ function transpileBody(body) {
|
|
|
451
521
|
}
|
|
452
522
|
return `return ${ts.trim()};`;
|
|
453
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Apply the full sequence of Quint → TypeScript rewrites to an expression
|
|
526
|
+
* string. Ordering matters: method-name rewrites (forall, exists, keys, get)
|
|
527
|
+
* must run BEFORE `transpileImplies`, because the implies walker scans
|
|
528
|
+
* backward through method chains to find the left operand and needs to see
|
|
529
|
+
* JS-shaped method names.
|
|
530
|
+
*/
|
|
531
|
+
function applyQuintRewrites(ts) {
|
|
532
|
+
// 1. Boolean operators
|
|
533
|
+
ts = ts.replace(/\band\b/g, '&&');
|
|
534
|
+
ts = ts.replace(/\bor\b/g, '||');
|
|
535
|
+
ts = ts.replace(/\bnot\b/g, '!');
|
|
536
|
+
// 2. Local `val` bindings inside blocks
|
|
537
|
+
ts = transpileValBindings(ts);
|
|
538
|
+
// 3. Quint collection operations → JS equivalents
|
|
539
|
+
// These run before implies so the walker sees valid JS method names.
|
|
540
|
+
// forall / exists with lambda → .every / .some
|
|
541
|
+
ts = ts.replace(/\.forall\(\s*(\w+)\s*=>\s*/g, '.every(($1: any) => ');
|
|
542
|
+
ts = ts.replace(/\.exists\(\s*(\w+)\s*=>\s*/g, '.some(($1: any) => ');
|
|
543
|
+
// filter / map / flatMap: keep the method name but type the lambda param
|
|
544
|
+
ts = ts.replace(/\.filter\(\s*(\w+)\s*=>\s*/g, '.filter(($1: any) => ');
|
|
545
|
+
ts = ts.replace(/\.map\(\s*(\w+)\s*=>\s*/g, '.map(($1: any) => ');
|
|
546
|
+
ts = ts.replace(/\.flatMap\(\s*(\w+)\s*=>\s*/g, '.flatMap(($1: any) => ');
|
|
547
|
+
// .indices() — returns the indices of a list. In Quint this is a Set
|
|
548
|
+
// of positions; in JS the equivalent is an array of 0..length-1.
|
|
549
|
+
ts = ts.replace(/\.indices\(\s*\)/g, '.map((_: any, __i: number) => __i)');
|
|
550
|
+
// Set literal: Set("a", "b") → ["a", "b"]
|
|
551
|
+
ts = ts.replace(/\bSet\(([^)]+)\)/g, '[$1]');
|
|
552
|
+
// subseteq (subset of) → runtime check via .every + .includes.
|
|
553
|
+
// `X.subseteq(Y)` becomes `X.every((__v: any) => Y.includes(__v))`.
|
|
554
|
+
// Uses a balanced walker because X can be an array literal or method chain.
|
|
555
|
+
ts = rewriteSubseteq(ts);
|
|
556
|
+
// Map operations on plain-object data:
|
|
557
|
+
// X.keys() → Object.keys(X)
|
|
558
|
+
// X.get(k) → X[k]
|
|
559
|
+
// Quint maps use .keys()/.get(); when the runtime data is a plain object
|
|
560
|
+
// (which is what inference produces), these need JS-equivalent forms.
|
|
561
|
+
ts = rewriteKeysGet(ts);
|
|
562
|
+
// .size() — Quint cardinality for Sets/Lists/Maps. In our runtime
|
|
563
|
+
// snapshot a collection can be an array or a keyed object, so rewrite
|
|
564
|
+
// `X.size()` → `_size(X)` (helper injected into the generated module).
|
|
565
|
+
ts = rewriteSize(ts);
|
|
566
|
+
// .contains → .includes
|
|
567
|
+
ts = ts.replace(/\.contains\(/g, '.includes(');
|
|
568
|
+
// != → !==, == → ===
|
|
569
|
+
ts = ts.replace(/([^!<>])==(?!=)/g, '$1===');
|
|
570
|
+
ts = ts.replace(/!=(?!=)/g, '!==');
|
|
571
|
+
// 4. implies → (!A || B). Runs LAST so the walker sees JS-shaped methods.
|
|
572
|
+
ts = transpileImplies(ts);
|
|
573
|
+
return ts;
|
|
574
|
+
}
|
|
454
575
|
/**
|
|
455
576
|
* Transpile `A implies B` → `(!(A) || (B))`.
|
|
456
577
|
* A is the boolean expression immediately to the left of `implies`, which may
|
|
@@ -494,9 +615,12 @@ function transpileImplies(ts) {
|
|
|
494
615
|
let kk = k - 1;
|
|
495
616
|
while (kk >= 0 && /[A-Za-z0-9_.]/.test(out[kk]))
|
|
496
617
|
kk--;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
618
|
+
// If we consumed any chars, it's a method/receiver chain — extend.
|
|
619
|
+
// The consumed range may start with '.' (e.g. `.exists` after `.keys()`)
|
|
620
|
+
// so we can't restrict the first char to a letter.
|
|
621
|
+
if (kk + 1 < k) {
|
|
622
|
+
// Extend through chained receivers: `a.b.c(args)`, `a.b(x).c(y)`
|
|
623
|
+
// (parens), and `[...].c(y)` (array literals).
|
|
500
624
|
let prev = kk;
|
|
501
625
|
while (prev >= 0) {
|
|
502
626
|
const ch = out[prev];
|
|
@@ -504,13 +628,15 @@ function transpileImplies(ts) {
|
|
|
504
628
|
prev--;
|
|
505
629
|
continue;
|
|
506
630
|
}
|
|
507
|
-
if (ch === ')') {
|
|
631
|
+
if (ch === ')' || ch === ']') {
|
|
632
|
+
const close = ch;
|
|
633
|
+
const open = close === ')' ? '(' : '[';
|
|
508
634
|
let d = 1;
|
|
509
635
|
prev--;
|
|
510
636
|
while (prev >= 0 && d > 0) {
|
|
511
|
-
if (out[prev] ===
|
|
637
|
+
if (out[prev] === close)
|
|
512
638
|
d++;
|
|
513
|
-
else if (out[prev] ===
|
|
639
|
+
else if (out[prev] === open)
|
|
514
640
|
d--;
|
|
515
641
|
if (d === 0)
|
|
516
642
|
break;
|
|
@@ -595,6 +721,222 @@ function transpileImplies(ts) {
|
|
|
595
721
|
}
|
|
596
722
|
return out;
|
|
597
723
|
}
|
|
724
|
+
/**
|
|
725
|
+
* Rewrite `X.size()` → `_size(X)` where `_size` is a runtime helper
|
|
726
|
+
* that handles both arrays and plain objects (Quint Sets and Maps).
|
|
727
|
+
*/
|
|
728
|
+
function rewriteSize(ts) {
|
|
729
|
+
let out = ts;
|
|
730
|
+
let guard = 100;
|
|
731
|
+
while (guard-- > 0) {
|
|
732
|
+
const m = out.match(/\.\s*size\s*\(\s*\)/);
|
|
733
|
+
if (!m || m.index === undefined)
|
|
734
|
+
break;
|
|
735
|
+
const dotIdx = m.index;
|
|
736
|
+
const endIdx = dotIdx + m[0].length;
|
|
737
|
+
const receiverStart = findReceiverStart(out, dotIdx);
|
|
738
|
+
if (receiverStart === -1)
|
|
739
|
+
break;
|
|
740
|
+
const receiver = out.substring(receiverStart, dotIdx);
|
|
741
|
+
out = out.substring(0, receiverStart) + `_size(${receiver})` + out.substring(endIdx);
|
|
742
|
+
}
|
|
743
|
+
return out;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Rewrite `X.subseteq(Y)` → `X.every((__v: any) => Y.includes(__v))`.
|
|
747
|
+
* X can be an array literal (including spaces before the dot) or a method
|
|
748
|
+
* chain; walk backward from `.subseteq(` to find its receiver with balanced
|
|
749
|
+
* brackets.
|
|
750
|
+
*/
|
|
751
|
+
function rewriteSubseteq(ts) {
|
|
752
|
+
let out = ts;
|
|
753
|
+
let guard = 50;
|
|
754
|
+
while (guard-- > 0) {
|
|
755
|
+
const m = out.match(/\.\s*subseteq\s*\(/);
|
|
756
|
+
if (!m || m.index === undefined)
|
|
757
|
+
break;
|
|
758
|
+
const dotIdx = m.index;
|
|
759
|
+
const openIdx = dotIdx + m[0].length; // position of `(`
|
|
760
|
+
// Walk backward from dotIdx to find receiver start
|
|
761
|
+
let i = dotIdx - 1;
|
|
762
|
+
// skip whitespace
|
|
763
|
+
while (i >= 0 && /\s/.test(out[i]))
|
|
764
|
+
i--;
|
|
765
|
+
if (i < 0)
|
|
766
|
+
break;
|
|
767
|
+
let receiverStart;
|
|
768
|
+
if (out[i] === ']') {
|
|
769
|
+
// Array literal receiver — balance brackets
|
|
770
|
+
let depth = 1;
|
|
771
|
+
let k = i - 1;
|
|
772
|
+
while (k >= 0 && depth > 0) {
|
|
773
|
+
if (out[k] === ']')
|
|
774
|
+
depth++;
|
|
775
|
+
else if (out[k] === '[')
|
|
776
|
+
depth--;
|
|
777
|
+
if (depth === 0)
|
|
778
|
+
break;
|
|
779
|
+
k--;
|
|
780
|
+
}
|
|
781
|
+
if (depth !== 0)
|
|
782
|
+
break;
|
|
783
|
+
receiverStart = k;
|
|
784
|
+
}
|
|
785
|
+
else if (out[i] === ')') {
|
|
786
|
+
// Call-expression receiver — balance parens
|
|
787
|
+
let depth = 1;
|
|
788
|
+
let k = i - 1;
|
|
789
|
+
while (k >= 0 && depth > 0) {
|
|
790
|
+
if (out[k] === ')')
|
|
791
|
+
depth++;
|
|
792
|
+
else if (out[k] === '(')
|
|
793
|
+
depth--;
|
|
794
|
+
if (depth === 0)
|
|
795
|
+
break;
|
|
796
|
+
k--;
|
|
797
|
+
}
|
|
798
|
+
if (depth !== 0)
|
|
799
|
+
break;
|
|
800
|
+
// Then walk back through any identifier chain preceding the `(`
|
|
801
|
+
let kk = k - 1;
|
|
802
|
+
while (kk >= 0 && /[A-Za-z0-9_.]/.test(out[kk]))
|
|
803
|
+
kk--;
|
|
804
|
+
receiverStart = kk + 1;
|
|
805
|
+
}
|
|
806
|
+
else if (/[A-Za-z0-9_]/.test(out[i])) {
|
|
807
|
+
// Bare identifier receiver
|
|
808
|
+
let k = i;
|
|
809
|
+
while (k >= 0 && /[A-Za-z0-9_.]/.test(out[k]))
|
|
810
|
+
k--;
|
|
811
|
+
receiverStart = k + 1;
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
const receiver = out.substring(receiverStart, i + 1);
|
|
817
|
+
// Find argument end (balanced parens from openIdx)
|
|
818
|
+
let depth = 1;
|
|
819
|
+
let j = openIdx;
|
|
820
|
+
while (j < out.length && depth > 0) {
|
|
821
|
+
const ch = out[j];
|
|
822
|
+
if (ch === '(')
|
|
823
|
+
depth++;
|
|
824
|
+
else if (ch === ')') {
|
|
825
|
+
depth--;
|
|
826
|
+
if (depth === 0)
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
j++;
|
|
830
|
+
}
|
|
831
|
+
if (depth !== 0)
|
|
832
|
+
break;
|
|
833
|
+
const argStr = out.substring(openIdx, j).trim();
|
|
834
|
+
const replacement = `${receiver}.every((__v: any) => ${argStr}.includes(__v))`;
|
|
835
|
+
out = out.substring(0, receiverStart) + replacement + out.substring(j + 1);
|
|
836
|
+
}
|
|
837
|
+
return out;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Rewrite `X.keys()` → `Object.keys(X)` and `X.get(k)` → `X[k]`.
|
|
841
|
+
* Quint Maps use `.keys()`/`.get()`; when the runtime data is a plain object
|
|
842
|
+
* (which is what the inferred SpecVerse AST produces), these need JS forms.
|
|
843
|
+
* Walks backward from the method to capture the receiver (identifier chain
|
|
844
|
+
* or nested call).
|
|
845
|
+
*/
|
|
846
|
+
function rewriteKeysGet(ts) {
|
|
847
|
+
let out = ts;
|
|
848
|
+
// Handle .keys() — no arguments
|
|
849
|
+
let guard = 100;
|
|
850
|
+
while (guard-- > 0) {
|
|
851
|
+
const m = out.match(/\.\s*keys\s*\(\s*\)/);
|
|
852
|
+
if (!m || m.index === undefined)
|
|
853
|
+
break;
|
|
854
|
+
const dotIdx = m.index;
|
|
855
|
+
const endIdx = dotIdx + m[0].length; // one past closing `)`
|
|
856
|
+
// Walk back to receiver start
|
|
857
|
+
const receiverStart = findReceiverStart(out, dotIdx);
|
|
858
|
+
if (receiverStart === -1)
|
|
859
|
+
break;
|
|
860
|
+
const receiver = out.substring(receiverStart, dotIdx);
|
|
861
|
+
out = out.substring(0, receiverStart) + `Object.keys(${receiver})` + out.substring(endIdx);
|
|
862
|
+
}
|
|
863
|
+
// Handle .get(k) — one argument
|
|
864
|
+
guard = 100;
|
|
865
|
+
while (guard-- > 0) {
|
|
866
|
+
const m = out.match(/\.\s*get\s*\(/);
|
|
867
|
+
if (!m || m.index === undefined)
|
|
868
|
+
break;
|
|
869
|
+
const dotIdx = m.index;
|
|
870
|
+
const openIdx = dotIdx + m[0].length; // position after `(`
|
|
871
|
+
// Find closing paren (balanced)
|
|
872
|
+
let depth = 1;
|
|
873
|
+
let j = openIdx;
|
|
874
|
+
while (j < out.length && depth > 0) {
|
|
875
|
+
const ch = out[j];
|
|
876
|
+
if (ch === '(')
|
|
877
|
+
depth++;
|
|
878
|
+
else if (ch === ')') {
|
|
879
|
+
depth--;
|
|
880
|
+
if (depth === 0)
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
j++;
|
|
884
|
+
}
|
|
885
|
+
if (depth !== 0)
|
|
886
|
+
break;
|
|
887
|
+
const argStr = out.substring(openIdx, j).trim();
|
|
888
|
+
// Walk back to receiver start
|
|
889
|
+
const receiverStart = findReceiverStart(out, dotIdx);
|
|
890
|
+
if (receiverStart === -1)
|
|
891
|
+
break;
|
|
892
|
+
const receiver = out.substring(receiverStart, dotIdx);
|
|
893
|
+
out = out.substring(0, receiverStart) + `${receiver}[${argStr}]` + out.substring(j + 1);
|
|
894
|
+
}
|
|
895
|
+
return out;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Walk backward from `dotIdx` (the position of `.`) to find where the
|
|
899
|
+
* receiver expression starts. Returns the index of the first char of the
|
|
900
|
+
* receiver, or -1 if it can't be parsed.
|
|
901
|
+
*/
|
|
902
|
+
function findReceiverStart(s, dotIdx) {
|
|
903
|
+
let i = dotIdx - 1;
|
|
904
|
+
// Skip whitespace
|
|
905
|
+
while (i >= 0 && /\s/.test(s[i]))
|
|
906
|
+
i--;
|
|
907
|
+
if (i < 0)
|
|
908
|
+
return -1;
|
|
909
|
+
if (s[i] === ')' || s[i] === ']') {
|
|
910
|
+
// Balanced close-bracket — walk back to matching open
|
|
911
|
+
const close = s[i];
|
|
912
|
+
const open = close === ')' ? '(' : '[';
|
|
913
|
+
let depth = 1;
|
|
914
|
+
let k = i - 1;
|
|
915
|
+
while (k >= 0 && depth > 0) {
|
|
916
|
+
if (s[k] === close)
|
|
917
|
+
depth++;
|
|
918
|
+
else if (s[k] === open)
|
|
919
|
+
depth--;
|
|
920
|
+
if (depth === 0)
|
|
921
|
+
break;
|
|
922
|
+
k--;
|
|
923
|
+
}
|
|
924
|
+
if (depth !== 0)
|
|
925
|
+
return -1;
|
|
926
|
+
// Then walk back through any identifier chain
|
|
927
|
+
let kk = k - 1;
|
|
928
|
+
while (kk >= 0 && /[A-Za-z0-9_.]/.test(s[kk]))
|
|
929
|
+
kk--;
|
|
930
|
+
return kk + 1;
|
|
931
|
+
}
|
|
932
|
+
if (/[A-Za-z0-9_]/.test(s[i])) {
|
|
933
|
+
let k = i;
|
|
934
|
+
while (k >= 0 && /[A-Za-z0-9_.]/.test(s[k]))
|
|
935
|
+
k--;
|
|
936
|
+
return k + 1;
|
|
937
|
+
}
|
|
938
|
+
return -1;
|
|
939
|
+
}
|
|
598
940
|
/**
|
|
599
941
|
* Handle Quint local `val` bindings inside a block expression.
|
|
600
942
|
* `{ val X = CALL REST }` → `{ const X = CALL; return REST; }`
|
|
@@ -605,29 +947,6 @@ function transpileValBindings(ts) {
|
|
|
605
947
|
return ts.replace(/\{\s*val\s+(\w+)\s*=\s*([\w.]+\([^()]*\))\s+(.+?)\s*\}/g, '{ const $1 = $2; return $3; }');
|
|
606
948
|
}
|
|
607
949
|
function transpileExpression(expr) {
|
|
608
|
-
|
|
609
|
-
// Quint operators → TypeScript
|
|
610
|
-
ts = ts.replace(/\band\b/g, '&&');
|
|
611
|
-
ts = ts.replace(/\bor\b/g, '||');
|
|
612
|
-
ts = ts.replace(/\bnot\b/g, '!');
|
|
613
|
-
// Handle local `val` bindings inside blocks
|
|
614
|
-
ts = transpileValBindings(ts);
|
|
615
|
-
// implies → (!A || B): walk string finding each `implies` keyword,
|
|
616
|
-
// match its left operand as a balanced-paren expression immediately before
|
|
617
|
-
ts = transpileImplies(ts);
|
|
618
|
-
// forall → .every (accept any preceding non-word char)
|
|
619
|
-
ts = ts.replace(/\.forall\(\s*(\w+)\s*=>\s*/g, '.every(($1: any) => ');
|
|
620
|
-
// exists → .some
|
|
621
|
-
ts = ts.replace(/\.exists\(\s*(\w+)\s*=>\s*/g, '.some(($1: any) => ');
|
|
622
|
-
// .size() → .length or .size
|
|
623
|
-
ts = ts.replace(/\.size\(\)/g, '.length');
|
|
624
|
-
// .contains → .includes (for arrays) or .has (for Sets)
|
|
625
|
-
ts = ts.replace(/\.contains\(/g, '.includes(');
|
|
626
|
-
// Set("a", "b") → ["a", "b"]
|
|
627
|
-
ts = ts.replace(/Set\(([^)]+)\)/g, '[$1]');
|
|
628
|
-
// != → !==, == → ===
|
|
629
|
-
ts = ts.replace(/([^!<>])==/g, '$1===');
|
|
630
|
-
ts = ts.replace(/!=/g, '!==');
|
|
631
|
-
return ts;
|
|
950
|
+
return applyQuintRewrites(expr);
|
|
632
951
|
}
|
|
633
952
|
//# sourceMappingURL=quint-transpiler.js.map
|