lemmascript 0.0.1 → 0.2.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/LICENSE +21 -0
- package/README.md +94 -3
- package/package.json +30 -20
- package/tools/dist/dafny-commands.js +98 -0
- package/tools/dist/dafny-emit.js +738 -0
- package/tools/dist/emit.js +253 -0
- package/tools/dist/extract.js +806 -0
- package/tools/dist/ir.js +7 -0
- package/tools/dist/lean-commands.js +35 -0
- package/tools/dist/lean-emit.js +393 -0
- package/tools/dist/lsc.js +119 -0
- package/tools/dist/rawir.js +10 -0
- package/tools/dist/resolve.js +717 -0
- package/tools/dist/specparser.js +305 -0
- package/tools/dist/transform.js +1091 -0
- package/tools/dist/typedir.js +7 -0
- package/tools/dist/types.js +71 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -4
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -14
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type mapping — TS types → Lean types.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for type-related decisions.
|
|
5
|
+
* The transform phase imports this.
|
|
6
|
+
*/
|
|
7
|
+
/** Split generic type arguments respecting nested angle brackets. */
|
|
8
|
+
function splitTypeArgs(s) {
|
|
9
|
+
const args = [];
|
|
10
|
+
let depth = 0, start = 0;
|
|
11
|
+
for (let i = 0; i < s.length; i++) {
|
|
12
|
+
if (s[i] === '<')
|
|
13
|
+
depth++;
|
|
14
|
+
else if (s[i] === '>')
|
|
15
|
+
depth--;
|
|
16
|
+
else if (s[i] === ',' && depth === 0) {
|
|
17
|
+
args.push(s.slice(start, i));
|
|
18
|
+
start = i + 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
args.push(s.slice(start));
|
|
22
|
+
return args.map(a => a.trim());
|
|
23
|
+
}
|
|
24
|
+
export function parseTsType(tsType) {
|
|
25
|
+
const t = tsType.trim();
|
|
26
|
+
// Union: T | undefined → optional<T>
|
|
27
|
+
if (t.includes(" | ")) {
|
|
28
|
+
const arms = t.split(" | ").map(a => a.trim());
|
|
29
|
+
const nonUndef = arms.filter(a => a !== "undefined");
|
|
30
|
+
if (nonUndef.length === 1 && arms.length === 2) {
|
|
31
|
+
return { kind: "optional", inner: parseTsType(nonUndef[0]) };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (t === "number")
|
|
35
|
+
return { kind: "int" };
|
|
36
|
+
if (t === "bigint")
|
|
37
|
+
return { kind: "int" };
|
|
38
|
+
if (t === "nat")
|
|
39
|
+
return { kind: "nat" };
|
|
40
|
+
if (t === "boolean" || t === "true" || t === "false")
|
|
41
|
+
return { kind: "bool" };
|
|
42
|
+
if (t === "string")
|
|
43
|
+
return { kind: "string" };
|
|
44
|
+
if (t === "void" || t === "undefined")
|
|
45
|
+
return { kind: "void" };
|
|
46
|
+
if (t === "unknown")
|
|
47
|
+
return { kind: "unknown" };
|
|
48
|
+
// Record<K, V> → map
|
|
49
|
+
const recordMatch = t.match(/^Record<(.+)>$/);
|
|
50
|
+
if (recordMatch) {
|
|
51
|
+
const args = splitTypeArgs(recordMatch[1]);
|
|
52
|
+
if (args.length === 2)
|
|
53
|
+
return { kind: "map", key: parseTsType(args[0]), value: parseTsType(args[1]) };
|
|
54
|
+
}
|
|
55
|
+
// Array<T> or T[]
|
|
56
|
+
const m = t.match(/^(?:Array<(.+)>|(.+)\[\])$/);
|
|
57
|
+
if (m)
|
|
58
|
+
return { kind: "array", elem: parseTsType(m[1] || m[2]) };
|
|
59
|
+
// Map<K, V>
|
|
60
|
+
const mapMatch = t.match(/^Map<(.+)>$/);
|
|
61
|
+
if (mapMatch) {
|
|
62
|
+
const args = splitTypeArgs(mapMatch[1]);
|
|
63
|
+
if (args.length === 2)
|
|
64
|
+
return { kind: "map", key: parseTsType(args[0]), value: parseTsType(args[1]) };
|
|
65
|
+
}
|
|
66
|
+
// Set<T>
|
|
67
|
+
const setMatch = t.match(/^Set<(.+)>$/);
|
|
68
|
+
if (setMatch)
|
|
69
|
+
return { kind: "set", elem: parseTsType(setMatch[1]) };
|
|
70
|
+
return { kind: "user", name: t };
|
|
71
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.1";
|
package/dist/index.js
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const VERSION = "0.0.1";
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "Node16",
|
|
5
|
-
"moduleResolution": "Node16",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"]
|
|
14
|
-
}
|