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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Typed IR — Raw IR annotated with resolved types and classifications.
3
+ *
4
+ * Produced by the resolve pass. Consumed by the transform.
5
+ * Still TS-shaped (not Lean-shaped).
6
+ */
7
+ export {};
@@ -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
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = void 0;
4
- exports.VERSION = "0.0.1";
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
- }