bonescript-compiler 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.
Files changed (146) hide show
  1. package/LICENSE +21 -0
  2. package/dist/algorithm_catalog.d.ts +32 -0
  3. package/dist/algorithm_catalog.js +323 -0
  4. package/dist/algorithm_catalog.js.map +1 -0
  5. package/dist/ast.d.ts +244 -0
  6. package/dist/ast.js +8 -0
  7. package/dist/ast.js.map +1 -0
  8. package/dist/cli.d.ts +4 -0
  9. package/dist/cli.js +605 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/emit_batch.d.ts +7 -0
  12. package/dist/emit_batch.js +133 -0
  13. package/dist/emit_batch.js.map +1 -0
  14. package/dist/emit_capability.d.ts +7 -0
  15. package/dist/emit_capability.js +376 -0
  16. package/dist/emit_capability.js.map +1 -0
  17. package/dist/emit_composition.d.ts +22 -0
  18. package/dist/emit_composition.js +184 -0
  19. package/dist/emit_composition.js.map +1 -0
  20. package/dist/emit_deploy.d.ts +9 -0
  21. package/dist/emit_deploy.js +191 -0
  22. package/dist/emit_deploy.js.map +1 -0
  23. package/dist/emit_events.d.ts +14 -0
  24. package/dist/emit_events.js +305 -0
  25. package/dist/emit_events.js.map +1 -0
  26. package/dist/emit_extras.d.ts +12 -0
  27. package/dist/emit_extras.js +234 -0
  28. package/dist/emit_extras.js.map +1 -0
  29. package/dist/emit_full.d.ts +13 -0
  30. package/dist/emit_full.js +273 -0
  31. package/dist/emit_full.js.map +1 -0
  32. package/dist/emit_maintenance.d.ts +16 -0
  33. package/dist/emit_maintenance.js +442 -0
  34. package/dist/emit_maintenance.js.map +1 -0
  35. package/dist/emit_runtime.d.ts +13 -0
  36. package/dist/emit_runtime.js +691 -0
  37. package/dist/emit_runtime.js.map +1 -0
  38. package/dist/emit_sourcemap.d.ts +29 -0
  39. package/dist/emit_sourcemap.js +123 -0
  40. package/dist/emit_sourcemap.js.map +1 -0
  41. package/dist/emit_tests.d.ts +15 -0
  42. package/dist/emit_tests.js +185 -0
  43. package/dist/emit_tests.js.map +1 -0
  44. package/dist/emit_websocket.d.ts +6 -0
  45. package/dist/emit_websocket.js +223 -0
  46. package/dist/emit_websocket.js.map +1 -0
  47. package/dist/emitter.d.ts +25 -0
  48. package/dist/emitter.js +511 -0
  49. package/dist/emitter.js.map +1 -0
  50. package/dist/extension_manager.d.ts +38 -0
  51. package/dist/extension_manager.js +170 -0
  52. package/dist/extension_manager.js.map +1 -0
  53. package/dist/formatter.d.ts +34 -0
  54. package/dist/formatter.js +317 -0
  55. package/dist/formatter.js.map +1 -0
  56. package/dist/index.d.ts +42 -0
  57. package/dist/index.js +113 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/ir.d.ts +168 -0
  60. package/dist/ir.js +10 -0
  61. package/dist/ir.js.map +1 -0
  62. package/dist/lexer.d.ts +195 -0
  63. package/dist/lexer.js +619 -0
  64. package/dist/lexer.js.map +1 -0
  65. package/dist/lowering.d.ts +25 -0
  66. package/dist/lowering.js +500 -0
  67. package/dist/lowering.js.map +1 -0
  68. package/dist/module_loader.d.ts +25 -0
  69. package/dist/module_loader.js +126 -0
  70. package/dist/module_loader.js.map +1 -0
  71. package/dist/optimizer.d.ts +26 -0
  72. package/dist/optimizer.js +158 -0
  73. package/dist/optimizer.js.map +1 -0
  74. package/dist/parse_decls.d.ts +13 -0
  75. package/dist/parse_decls.js +442 -0
  76. package/dist/parse_decls.js.map +1 -0
  77. package/dist/parse_decls2.d.ts +13 -0
  78. package/dist/parse_decls2.js +295 -0
  79. package/dist/parse_decls2.js.map +1 -0
  80. package/dist/parse_expr.d.ts +7 -0
  81. package/dist/parse_expr.js +197 -0
  82. package/dist/parse_expr.js.map +1 -0
  83. package/dist/parse_types.d.ts +6 -0
  84. package/dist/parse_types.js +51 -0
  85. package/dist/parse_types.js.map +1 -0
  86. package/dist/parser.d.ts +10 -0
  87. package/dist/parser.js +62 -0
  88. package/dist/parser.js.map +1 -0
  89. package/dist/parser_base.d.ts +19 -0
  90. package/dist/parser_base.js +50 -0
  91. package/dist/parser_base.js.map +1 -0
  92. package/dist/parser_recovery.d.ts +26 -0
  93. package/dist/parser_recovery.js +140 -0
  94. package/dist/parser_recovery.js.map +1 -0
  95. package/dist/scaffold.d.ts +13 -0
  96. package/dist/scaffold.js +376 -0
  97. package/dist/scaffold.js.map +1 -0
  98. package/dist/solver.d.ts +26 -0
  99. package/dist/solver.js +281 -0
  100. package/dist/solver.js.map +1 -0
  101. package/dist/typechecker.d.ts +52 -0
  102. package/dist/typechecker.js +534 -0
  103. package/dist/typechecker.js.map +1 -0
  104. package/dist/types.d.ts +38 -0
  105. package/dist/types.js +85 -0
  106. package/dist/types.js.map +1 -0
  107. package/dist/verifier.d.ts +46 -0
  108. package/dist/verifier.js +307 -0
  109. package/dist/verifier.js.map +1 -0
  110. package/package.json +52 -0
  111. package/src/algorithm_catalog.ts +345 -0
  112. package/src/ast.ts +334 -0
  113. package/src/cli.ts +624 -0
  114. package/src/emit_batch.ts +140 -0
  115. package/src/emit_capability.ts +436 -0
  116. package/src/emit_composition.ts +196 -0
  117. package/src/emit_deploy.ts +190 -0
  118. package/src/emit_events.ts +307 -0
  119. package/src/emit_extras.ts +240 -0
  120. package/src/emit_full.ts +309 -0
  121. package/src/emit_maintenance.ts +459 -0
  122. package/src/emit_runtime.ts +731 -0
  123. package/src/emit_sourcemap.ts +140 -0
  124. package/src/emit_tests.ts +205 -0
  125. package/src/emit_websocket.ts +229 -0
  126. package/src/emitter.ts +566 -0
  127. package/src/extension_manager.ts +187 -0
  128. package/src/formatter.ts +297 -0
  129. package/src/index.ts +88 -0
  130. package/src/ir.ts +215 -0
  131. package/src/lexer.ts +630 -0
  132. package/src/lowering.ts +556 -0
  133. package/src/module_loader.ts +114 -0
  134. package/src/optimizer.ts +196 -0
  135. package/src/parse_decls.ts +409 -0
  136. package/src/parse_decls2.ts +244 -0
  137. package/src/parse_expr.ts +197 -0
  138. package/src/parse_types.ts +54 -0
  139. package/src/parser.ts +64 -0
  140. package/src/parser_base.ts +57 -0
  141. package/src/parser_recovery.ts +153 -0
  142. package/src/scaffold.ts +375 -0
  143. package/src/solver.ts +330 -0
  144. package/src/typechecker.ts +591 -0
  145. package/src/types.ts +122 -0
  146. package/src/verifier.ts +348 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BoneScript Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * BoneScript Algorithm Catalog (Leap 2)
3
+ *
4
+ * A closed catalog of named algorithms. Each entry has:
5
+ * - inputs: typed parameters the user must bind
6
+ * - outputs: return type
7
+ * - description: human-readable explanation
8
+ * - emit: function that produces a deterministic implementation
9
+ *
10
+ * NEW algorithms can ONLY be added by extending this catalog. The compiler
11
+ * never invents implementations — it picks from this list.
12
+ */
13
+ export interface AlgorithmSpec {
14
+ name: string;
15
+ category: "graph" | "search" | "sort" | "matching" | "scheduling" | "stats" | "crypto";
16
+ description: string;
17
+ inputs: {
18
+ name: string;
19
+ type: string;
20
+ description: string;
21
+ }[];
22
+ output: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ complexity: string;
27
+ emit: (bindings: Record<string, string>) => string;
28
+ }
29
+ export declare const CATALOG: Record<string, AlgorithmSpec>;
30
+ export declare function lookupAlgorithm(name: string): AlgorithmSpec | null;
31
+ export declare function listAlgorithms(): string[];
32
+ export declare function listByCategory(): Record<string, string[]>;
@@ -0,0 +1,323 @@
1
+ "use strict";
2
+ /**
3
+ * BoneScript Algorithm Catalog (Leap 2)
4
+ *
5
+ * A closed catalog of named algorithms. Each entry has:
6
+ * - inputs: typed parameters the user must bind
7
+ * - outputs: return type
8
+ * - description: human-readable explanation
9
+ * - emit: function that produces a deterministic implementation
10
+ *
11
+ * NEW algorithms can ONLY be added by extending this catalog. The compiler
12
+ * never invents implementations — it picks from this list.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.listByCategory = exports.listAlgorithms = exports.lookupAlgorithm = exports.CATALOG = void 0;
16
+ // ─── Algorithm Implementations ───────────────────────────────────────────────
17
+ exports.CATALOG = {
18
+ // ─── Graph Algorithms ──────────────────────────────────────────────────────
19
+ shortest_path: {
20
+ name: "shortest_path",
21
+ category: "graph",
22
+ description: "Dijkstra's algorithm for non-negative weighted shortest path.",
23
+ inputs: [
24
+ { name: "graph", type: "map<string, list<{node: string, weight: number}>>", description: "adjacency list" },
25
+ { name: "source", type: "string", description: "starting node" },
26
+ { name: "target", type: "string", description: "destination node" },
27
+ ],
28
+ output: { type: "{path: string[], distance: number} | null", description: "shortest path or null if unreachable" },
29
+ complexity: "O((V + E) log V)",
30
+ emit: (b) => `
31
+ function shortestPath(
32
+ graph: Map<string, { node: string; weight: number }[]>,
33
+ source: string,
34
+ target: string
35
+ ): { path: string[]; distance: number } | null {
36
+ const distances = new Map<string, number>();
37
+ const previous = new Map<string, string>();
38
+ const queue: { node: string; distance: number }[] = [];
39
+
40
+ for (const node of graph.keys()) distances.set(node, Infinity);
41
+ distances.set(source, 0);
42
+ queue.push({ node: source, distance: 0 });
43
+
44
+ while (queue.length > 0) {
45
+ queue.sort((a, b) => a.distance - b.distance);
46
+ const current = queue.shift()!;
47
+ if (current.node === target) break;
48
+ if (current.distance > (distances.get(current.node) ?? Infinity)) continue;
49
+
50
+ for (const edge of graph.get(current.node) || []) {
51
+ const newDist = current.distance + edge.weight;
52
+ if (newDist < (distances.get(edge.node) ?? Infinity)) {
53
+ distances.set(edge.node, newDist);
54
+ previous.set(edge.node, current.node);
55
+ queue.push({ node: edge.node, distance: newDist });
56
+ }
57
+ }
58
+ }
59
+
60
+ if (!previous.has(target) && source !== target) return null;
61
+ const path: string[] = [];
62
+ let current: string | undefined = target;
63
+ while (current !== undefined) {
64
+ path.unshift(current);
65
+ current = previous.get(current);
66
+ }
67
+ return { path, distance: distances.get(target) || 0 };
68
+ }
69
+ `,
70
+ },
71
+ topological_sort: {
72
+ name: "topological_sort",
73
+ category: "graph",
74
+ description: "Kahn's algorithm — produces a linear ordering of a DAG.",
75
+ inputs: [
76
+ { name: "graph", type: "map<string, string[]>", description: "adjacency list" },
77
+ ],
78
+ output: { type: "string[] | null", description: "topological order, or null if cycle exists" },
79
+ complexity: "O(V + E)",
80
+ emit: (b) => `
81
+ function topologicalSort(graph: Map<string, string[]>): string[] | null {
82
+ const inDegree = new Map<string, number>();
83
+ for (const node of graph.keys()) inDegree.set(node, 0);
84
+ for (const [, neighbors] of graph) {
85
+ for (const n of neighbors) inDegree.set(n, (inDegree.get(n) || 0) + 1);
86
+ }
87
+
88
+ const queue: string[] = [];
89
+ for (const [node, deg] of inDegree) if (deg === 0) queue.push(node);
90
+
91
+ const result: string[] = [];
92
+ while (queue.length > 0) {
93
+ const node = queue.shift()!;
94
+ result.push(node);
95
+ for (const neighbor of graph.get(node) || []) {
96
+ inDegree.set(neighbor, (inDegree.get(neighbor) || 0) - 1);
97
+ if (inDegree.get(neighbor) === 0) queue.push(neighbor);
98
+ }
99
+ }
100
+
101
+ return result.length === graph.size ? result : null;
102
+ }
103
+ `,
104
+ },
105
+ // ─── Search ───────────────────────────────────────────────────────────────
106
+ binary_search: {
107
+ name: "binary_search",
108
+ category: "search",
109
+ description: "Find target in sorted array.",
110
+ inputs: [
111
+ { name: "items", type: "T[]", description: "sorted array" },
112
+ { name: "target", type: "T", description: "value to find" },
113
+ ],
114
+ output: { type: "number", description: "index of target or -1 if not found" },
115
+ complexity: "O(log n)",
116
+ emit: (b) => `
117
+ function binarySearch<T>(items: T[], target: T): number {
118
+ let low = 0, high = items.length - 1;
119
+ while (low <= high) {
120
+ const mid = Math.floor((low + high) / 2);
121
+ if (items[mid] === target) return mid;
122
+ if (items[mid] < target) low = mid + 1;
123
+ else high = mid - 1;
124
+ }
125
+ return -1;
126
+ }
127
+ `,
128
+ },
129
+ // ─── Matching ─────────────────────────────────────────────────────────────
130
+ bipartite_matching: {
131
+ name: "bipartite_matching",
132
+ category: "matching",
133
+ description: "Hopcroft-Karp maximum bipartite matching.",
134
+ inputs: [
135
+ { name: "left", type: "string[]", description: "left vertex set" },
136
+ { name: "right", type: "string[]", description: "right vertex set" },
137
+ { name: "edges", type: "{from: string, to: string}[]", description: "valid pairings" },
138
+ ],
139
+ output: { type: "Map<string, string>", description: "matching from left to right" },
140
+ complexity: "O(E sqrt(V))",
141
+ emit: (b) => `
142
+ function bipartiteMatching(
143
+ left: string[],
144
+ right: string[],
145
+ edges: { from: string; to: string }[]
146
+ ): Map<string, string> {
147
+ const adj = new Map<string, string[]>();
148
+ for (const e of edges) {
149
+ if (!adj.has(e.from)) adj.set(e.from, []);
150
+ adj.get(e.from)!.push(e.to);
151
+ }
152
+
153
+ const matchL = new Map<string, string>();
154
+ const matchR = new Map<string, string>();
155
+
156
+ function dfs(u: string, visited: Set<string>): boolean {
157
+ for (const v of adj.get(u) || []) {
158
+ if (visited.has(v)) continue;
159
+ visited.add(v);
160
+ if (!matchR.has(v) || dfs(matchR.get(v)!, visited)) {
161
+ matchL.set(u, v);
162
+ matchR.set(v, u);
163
+ return true;
164
+ }
165
+ }
166
+ return false;
167
+ }
168
+
169
+ for (const u of left) dfs(u, new Set());
170
+ return matchL;
171
+ }
172
+ `,
173
+ },
174
+ // ─── Scheduling ────────────────────────────────────────────────────────────
175
+ round_robin: {
176
+ name: "round_robin",
177
+ category: "scheduling",
178
+ description: "Cyclic assignment of items to workers.",
179
+ inputs: [
180
+ { name: "items", type: "T[]", description: "items to assign" },
181
+ { name: "workers", type: "W[]", description: "workers" },
182
+ ],
183
+ output: { type: "Map<W, T[]>", description: "assignments per worker" },
184
+ complexity: "O(n)",
185
+ emit: (b) => `
186
+ function roundRobin<T, W>(items: T[], workers: W[]): Map<W, T[]> {
187
+ const result = new Map<W, T[]>();
188
+ for (const w of workers) result.set(w, []);
189
+ for (let i = 0; i < items.length; i++) {
190
+ const w = workers[i % workers.length];
191
+ result.get(w)!.push(items[i]);
192
+ }
193
+ return result;
194
+ }
195
+ `,
196
+ },
197
+ // ─── Stats ─────────────────────────────────────────────────────────────────
198
+ weighted_average: {
199
+ name: "weighted_average",
200
+ category: "stats",
201
+ description: "Weighted arithmetic mean.",
202
+ inputs: [
203
+ { name: "items", type: "{value: number, weight: number}[]", description: "values with weights" },
204
+ ],
205
+ output: { type: "number", description: "weighted average" },
206
+ complexity: "O(n)",
207
+ emit: (b) => `
208
+ function weightedAverage(items: { value: number; weight: number }[]): number {
209
+ let totalWeight = 0;
210
+ let weightedSum = 0;
211
+ for (const item of items) {
212
+ totalWeight += item.weight;
213
+ weightedSum += item.value * item.weight;
214
+ }
215
+ return totalWeight === 0 ? 0 : weightedSum / totalWeight;
216
+ }
217
+ `,
218
+ },
219
+ percentile: {
220
+ name: "percentile",
221
+ category: "stats",
222
+ description: "Compute the kth percentile of a numeric dataset.",
223
+ inputs: [
224
+ { name: "values", type: "number[]", description: "dataset" },
225
+ { name: "k", type: "number", description: "percentile (0-100)" },
226
+ ],
227
+ output: { type: "number", description: "kth percentile value" },
228
+ complexity: "O(n log n)",
229
+ emit: (b) => `
230
+ function percentile(values: number[], k: number): number {
231
+ if (values.length === 0) return 0;
232
+ const sorted = [...values].sort((a, b) => a - b);
233
+ const idx = (k / 100) * (sorted.length - 1);
234
+ const lower = Math.floor(idx);
235
+ const upper = Math.ceil(idx);
236
+ if (lower === upper) return sorted[lower];
237
+ return sorted[lower] + (sorted[upper] - sorted[lower]) * (idx - lower);
238
+ }
239
+ `,
240
+ },
241
+ // ─── Sort ──────────────────────────────────────────────────────────────────
242
+ rank_by: {
243
+ name: "rank_by",
244
+ category: "sort",
245
+ description: "Stable sort by a numeric scoring function.",
246
+ inputs: [
247
+ { name: "items", type: "T[]", description: "items to rank" },
248
+ { name: "score_fn", type: "(item: T) => number", description: "scoring function" },
249
+ { name: "order", type: "'asc' | 'desc'", description: "sort direction" },
250
+ ],
251
+ output: { type: "T[]", description: "sorted array" },
252
+ complexity: "O(n log n)",
253
+ emit: (b) => `
254
+ function rankBy<T>(items: T[], scoreFn: (item: T) => number, order: "asc" | "desc"): T[] {
255
+ const sign = order === "asc" ? 1 : -1;
256
+ return [...items].sort((a, b) => sign * (scoreFn(a) - scoreFn(b)));
257
+ }
258
+ `,
259
+ },
260
+ // ─── Crypto / Hashing ──────────────────────────────────────────────────────
261
+ consistent_hash: {
262
+ name: "consistent_hash",
263
+ category: "crypto",
264
+ description: "Consistent hashing for distributing keys across nodes.",
265
+ inputs: [
266
+ { name: "key", type: "string", description: "key to hash" },
267
+ { name: "nodes", type: "string[]", description: "available nodes" },
268
+ { name: "replicas", type: "number", description: "virtual nodes per real node" },
269
+ ],
270
+ output: { type: "string", description: "node assigned to key" },
271
+ complexity: "O(N log N) build, O(log N) lookup",
272
+ emit: (b) => `
273
+ function consistentHash(key: string, nodes: string[], replicas: number = 100): string {
274
+ if (nodes.length === 0) throw new Error("No nodes available");
275
+
276
+ function fnv1a(s: string): number {
277
+ let hash = 0x811c9dc5;
278
+ for (let i = 0; i < s.length; i++) {
279
+ hash ^= s.charCodeAt(i);
280
+ hash = (hash + ((hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24))) >>> 0;
281
+ }
282
+ return hash;
283
+ }
284
+
285
+ const ring: { hash: number; node: string }[] = [];
286
+ for (const node of nodes) {
287
+ for (let i = 0; i < replicas; i++) {
288
+ ring.push({ hash: fnv1a(node + ":" + i), node });
289
+ }
290
+ }
291
+ ring.sort((a, b) => a.hash - b.hash);
292
+
293
+ const target = fnv1a(key);
294
+ for (const entry of ring) {
295
+ if (entry.hash >= target) return entry.node;
296
+ }
297
+ return ring[0].node;
298
+ }
299
+ `,
300
+ },
301
+ };
302
+ // ─── Public API ──────────────────────────────────────────────────────────────
303
+ function lookupAlgorithm(name) {
304
+ return exports.CATALOG[name] || null;
305
+ }
306
+ exports.lookupAlgorithm = lookupAlgorithm;
307
+ function listAlgorithms() {
308
+ return Object.keys(exports.CATALOG).sort();
309
+ }
310
+ exports.listAlgorithms = listAlgorithms;
311
+ function listByCategory() {
312
+ const result = {};
313
+ for (const [name, spec] of Object.entries(exports.CATALOG)) {
314
+ if (!result[spec.category])
315
+ result[spec.category] = [];
316
+ result[spec.category].push(name);
317
+ }
318
+ for (const cat in result)
319
+ result[cat].sort();
320
+ return result;
321
+ }
322
+ exports.listByCategory = listByCategory;
323
+ //# sourceMappingURL=algorithm_catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algorithm_catalog.js","sourceRoot":"","sources":["../src/algorithm_catalog.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAYH,oLAAoL;AAEvK,QAAA,OAAO,GAAkC;IACpD,gMAAgM;IAEhM,aAAa,EAAE;QACb,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,OAAO;QACjB,WAAW,EAAE,+DAA+D;QAC5E,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,mDAAmD,EAAE,W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CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,MAAM;QAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,wCAQC"}
package/dist/ast.d.ts ADDED
@@ -0,0 +1,244 @@
1
+ /**
2
+ * BoneScript Abstract Syntax Tree
3
+ * Direct representation of the grammar in spec/02_GRAMMAR.peg.
4
+ * Every node type corresponds to a grammar production.
5
+ */
6
+ import { SourceLocation } from "./lexer";
7
+ export interface ASTNode {
8
+ kind: string;
9
+ loc: SourceLocation;
10
+ }
11
+ export interface ProgramNode extends ASTNode {
12
+ kind: "Program";
13
+ systems: SystemDeclNode[];
14
+ }
15
+ export interface SystemDeclNode extends ASTNode {
16
+ kind: "SystemDecl";
17
+ name: string;
18
+ domain: string | null;
19
+ declarations: DeclarationNode[];
20
+ }
21
+ export type DeclarationNode = EntityDeclNode | CapabilityDeclNode | ChannelDeclNode | StoreDeclNode | EventDeclNode | ConstraintDeclNode | PolicyDeclNode | FlowDeclNode | ImportDeclNode | ExtensionPointDeclNode;
22
+ export interface EntityDeclNode extends ASTNode {
23
+ kind: "EntityDecl";
24
+ name: string;
25
+ owns: FieldNode[];
26
+ constraints: ExprNode[];
27
+ states: StateGraphNode | null;
28
+ auth: string | null;
29
+ relations: RelationNode[];
30
+ indexes: string[][];
31
+ derived: DerivedFieldNode[];
32
+ }
33
+ export interface FieldNode extends ASTNode {
34
+ kind: "Field";
35
+ name: string;
36
+ type: TypeExprNode;
37
+ defaultValue: ExprNode | null;
38
+ }
39
+ export interface StateGraphNode extends ASTNode {
40
+ kind: "StateGraph";
41
+ nodes: StateNodeEntry[];
42
+ }
43
+ export interface StateNodeEntry {
44
+ name: string;
45
+ guard: ExprNode | null;
46
+ transitions: string[];
47
+ branches: string[];
48
+ }
49
+ export interface RelationNode extends ASTNode {
50
+ kind: "Relation";
51
+ name: string;
52
+ relationType: "has_one" | "has_many" | "belongs_to" | "many_to_many";
53
+ target: string;
54
+ cardinality: {
55
+ min: number;
56
+ max: number | "*";
57
+ } | null;
58
+ }
59
+ export interface DerivedFieldNode extends ASTNode {
60
+ kind: "DerivedField";
61
+ name: string;
62
+ expr: ExprNode;
63
+ }
64
+ export interface CapabilityDeclNode extends ASTNode {
65
+ kind: "CapabilityDecl";
66
+ name: string;
67
+ params: ParamNode[];
68
+ requires: ExprNode[];
69
+ effects: EffectNode[];
70
+ emits: EmitNode[];
71
+ sync: string | null;
72
+ timeout: string | null;
73
+ retry: RetryPolicyNode | null;
74
+ idempotent: boolean | null;
75
+ pipeline: PipelineNode | null;
76
+ algorithm: AlgorithmNode | null;
77
+ returns: TypeExprNode | null;
78
+ }
79
+ export interface PipelineNode extends ASTNode {
80
+ kind: "Pipeline";
81
+ steps: PipelineStepNode[];
82
+ parallel: boolean;
83
+ onError: PipelineErrorHandler | null;
84
+ }
85
+ export interface PipelineStepNode extends ASTNode {
86
+ kind: "PipelineStep";
87
+ call: CallExprNode;
88
+ bindAs: string | null;
89
+ }
90
+ export interface PipelineErrorHandler {
91
+ kind: "PipelineErrorHandler";
92
+ action: "rollback" | "compensate" | "ignore" | "retry";
93
+ call: CallExprNode | null;
94
+ }
95
+ export interface AlgorithmNode extends ASTNode {
96
+ kind: "Algorithm";
97
+ name: string;
98
+ using: AlgorithmBinding[];
99
+ }
100
+ export interface AlgorithmBinding {
101
+ param: string;
102
+ value: ExprNode;
103
+ }
104
+ export interface ParamNode extends ASTNode {
105
+ kind: "Param";
106
+ name: string;
107
+ type: TypeExprNode;
108
+ }
109
+ export interface EffectNode extends ASTNode {
110
+ kind: "Effect";
111
+ target: FieldRefNode;
112
+ op: "=" | "+=" | "-=";
113
+ value: ExprNode;
114
+ }
115
+ export interface EmitNode extends ASTNode {
116
+ kind: "Emit";
117
+ eventName: string;
118
+ args: ExprNode[];
119
+ }
120
+ export interface RetryPolicyNode extends ASTNode {
121
+ kind: "RetryPolicy";
122
+ maxAttempts: number | null;
123
+ backoff: string | null;
124
+ interval: string | null;
125
+ }
126
+ export interface ChannelDeclNode extends ASTNode {
127
+ kind: "ChannelDecl";
128
+ name: string;
129
+ transport: string | null;
130
+ ordering: string | null;
131
+ participants: TypeExprNode | null;
132
+ persistence: string | null;
133
+ filter: ExprNode | null;
134
+ maxSize: number | null;
135
+ }
136
+ export interface StoreDeclNode extends ASTNode {
137
+ kind: "StoreDecl";
138
+ name: string;
139
+ engine: string | null;
140
+ schema: FieldNode[];
141
+ retention: string | null;
142
+ partition: string | null;
143
+ replicas: number | null;
144
+ }
145
+ export interface EventDeclNode extends ASTNode {
146
+ kind: "EventDecl";
147
+ name: string;
148
+ payload: FieldNode[];
149
+ delivery: string | null;
150
+ ttl: string | null;
151
+ }
152
+ export interface ConstraintDeclNode extends ASTNode {
153
+ kind: "ConstraintDecl";
154
+ name: string;
155
+ expr: ExprNode;
156
+ }
157
+ export interface PolicyDeclNode extends ASTNode {
158
+ kind: "PolicyDecl";
159
+ name: string;
160
+ rateLimit: {
161
+ count: number;
162
+ per: string;
163
+ } | null;
164
+ access: string[];
165
+ audit: boolean | null;
166
+ encryption: string | null;
167
+ }
168
+ export interface FlowDeclNode extends ASTNode {
169
+ kind: "FlowDecl";
170
+ name: string;
171
+ steps: FlowStepNode[];
172
+ }
173
+ export interface FlowStepNode extends ASTNode {
174
+ kind: "FlowStep";
175
+ name: string;
176
+ action: CallExprNode;
177
+ compensate: CallExprNode | null;
178
+ }
179
+ export interface ImportDeclNode extends ASTNode {
180
+ kind: "ImportDecl";
181
+ name: string;
182
+ from: string;
183
+ }
184
+ export type TypeExprNode = PrimitiveTypeNode | GenericTypeNode | EntityRefTypeNode | TupleTypeNode | UnionTypeNode;
185
+ export interface PrimitiveTypeNode extends ASTNode {
186
+ kind: "PrimitiveType";
187
+ name: string;
188
+ }
189
+ export interface GenericTypeNode extends ASTNode {
190
+ kind: "GenericType";
191
+ name: string;
192
+ typeArgs: TypeExprNode[];
193
+ }
194
+ export interface EntityRefTypeNode extends ASTNode {
195
+ kind: "EntityRefType";
196
+ name: string;
197
+ }
198
+ export interface TupleTypeNode extends ASTNode {
199
+ kind: "TupleType";
200
+ elements: TypeExprNode[];
201
+ }
202
+ export interface UnionTypeNode extends ASTNode {
203
+ kind: "UnionType";
204
+ members: TypeExprNode[];
205
+ }
206
+ export type ExprNode = BinaryExprNode | UnaryExprNode | FieldRefNode | LiteralNode | CallExprNode | TernaryExprNode;
207
+ export interface BinaryExprNode extends ASTNode {
208
+ kind: "BinaryExpr";
209
+ op: string;
210
+ left: ExprNode;
211
+ right: ExprNode;
212
+ }
213
+ export interface UnaryExprNode extends ASTNode {
214
+ kind: "UnaryExpr";
215
+ op: string;
216
+ operand: ExprNode;
217
+ }
218
+ export interface FieldRefNode extends ASTNode {
219
+ kind: "FieldRef";
220
+ path: string[];
221
+ }
222
+ export interface LiteralNode extends ASTNode {
223
+ kind: "Literal";
224
+ type: "string" | "int" | "float" | "bool" | "none" | "list" | "map";
225
+ value: string | number | boolean | null | ExprNode[] | [ExprNode, ExprNode][];
226
+ }
227
+ export interface CallExprNode extends ASTNode {
228
+ kind: "CallExpr";
229
+ name: string;
230
+ args: ExprNode[];
231
+ }
232
+ export interface TernaryExprNode extends ASTNode {
233
+ kind: "TernaryExpr";
234
+ condition: ExprNode;
235
+ consequent: ExprNode;
236
+ alternate: ExprNode;
237
+ }
238
+ export interface ExtensionPointDeclNode extends ASTNode {
239
+ kind: "ExtensionPointDecl";
240
+ name: string;
241
+ params: ParamNode[];
242
+ returns: TypeExprNode | null;
243
+ stable: boolean;
244
+ }
package/dist/ast.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * BoneScript Abstract Syntax Tree
4
+ * Direct representation of the grammar in spec/02_GRAMMAR.peg.
5
+ * Every node type corresponds to a grammar production.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * BoneScript compiler CLI
3
+ */
4
+ export {};