enyosx-ai 0.1.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 (41) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +740 -0
  3. package/dist/chunk-2WM5L76D.js +320 -0
  4. package/dist/chunk-3BNDFBX3.js +324 -0
  5. package/dist/chunk-4LJILSCT.js +30 -0
  6. package/dist/chunk-4ZV5JV6W.js +298 -0
  7. package/dist/chunk-76PHNPTY.js +631 -0
  8. package/dist/chunk-BSSA33NY.js +677 -0
  9. package/dist/chunk-EK6IDRY7.js +105 -0
  10. package/dist/chunk-FI2EBH2N.js +2232 -0
  11. package/dist/chunk-GAKKLY4M.js +276 -0
  12. package/dist/chunk-HR4G5XQI.js +319 -0
  13. package/dist/chunk-HROGCEE5.js +30 -0
  14. package/dist/chunk-MMH7M7MG.js +30 -0
  15. package/dist/chunk-NGLRXS6G.js +2079 -0
  16. package/dist/chunk-NSE6LQJC.js +681 -0
  17. package/dist/chunk-O5XZOSBW.js +2484 -0
  18. package/dist/chunk-OVCMUPMP.js +677 -0
  19. package/dist/chunk-P2YBRE3X.js +2484 -0
  20. package/dist/chunk-VVIL5NIM.js +318 -0
  21. package/dist/chunk-ZNGEBY33.js +273 -0
  22. package/dist/cli.cjs +2509 -0
  23. package/dist/cli.d.ts +1 -0
  24. package/dist/cli.js +99 -0
  25. package/dist/index.cjs +2912 -0
  26. package/dist/index.d.ts +672 -0
  27. package/dist/index.js +379 -0
  28. package/dist/parser-4JXKOWKY.js +8 -0
  29. package/dist/parser-UUB6D2CZ.js +8 -0
  30. package/dist/parser-V44AIVNI.js +8 -0
  31. package/examples/README.md +13 -0
  32. package/examples/ia-demo.eny +37 -0
  33. package/examples/sample.eny +15 -0
  34. package/examples/simple/system.eny +7 -0
  35. package/examples/spec/sample.eny +19 -0
  36. package/examples/starter/README.md +96 -0
  37. package/examples/starter/main.eny +39 -0
  38. package/examples/starter/run.js +68 -0
  39. package/examples/starter.eny +16 -0
  40. package/examples/wasm-demo.eny +34 -0
  41. package/package.json +49 -0
@@ -0,0 +1,2484 @@
1
+ // src/lexer/tokenize.ts
2
+ var TokenType = /* @__PURE__ */ ((TokenType2) => {
3
+ TokenType2["SYMBOL"] = "SYMBOL";
4
+ TokenType2["IDENTIFIER"] = "IDENTIFIER";
5
+ TokenType2["STRING"] = "STRING";
6
+ TokenType2["NUMBER"] = "NUMBER";
7
+ TokenType2["ARROW"] = "ARROW";
8
+ TokenType2["LBRACE"] = "LBRACE";
9
+ TokenType2["RBRACE"] = "RBRACE";
10
+ TokenType2["COLON"] = "COLON";
11
+ TokenType2["COMMA"] = "COMMA";
12
+ TokenType2["LPAREN"] = "LPAREN";
13
+ TokenType2["RPAREN"] = "RPAREN";
14
+ TokenType2["LBRACKET"] = "LBRACKET";
15
+ TokenType2["RBRACKET"] = "RBRACKET";
16
+ TokenType2["NEWLINE"] = "NEWLINE";
17
+ TokenType2["COMPARATOR"] = "COMPARATOR";
18
+ TokenType2["OPERATOR"] = "OPERATOR";
19
+ TokenType2["EOF"] = "EOF";
20
+ return TokenType2;
21
+ })(TokenType || {});
22
+ var SYMBOLS_STATE = /* @__PURE__ */ new Set([
23
+ "\u03A3",
24
+ // STATE - Estado global
25
+ "\u03C3",
26
+ // SUBSTATE - Estado local
27
+ "\xD8",
28
+ // VOID - Não-existência
29
+ "\u{1F512}",
30
+ // LOCK - Imutável
31
+ "\u{1F513}"
32
+ // UNLOCK - Mutável
33
+ ]);
34
+ var SYMBOLS_EXEC = /* @__PURE__ */ new Set([
35
+ "\u0394",
36
+ // ACTION - Ação/função
37
+ "\u0192",
38
+ // FUNCTION - Capacidade lógica
39
+ "\u21C9",
40
+ // PARALLEL - Execução paralela
41
+ "\u25B3",
42
+ // DEPEND - Dependência
43
+ "\u25CF",
44
+ // CORE - Núcleo
45
+ "\u23F3"
46
+ // DELAY - Espera temporal
47
+ ]);
48
+ var SYMBOLS_STRUCT = /* @__PURE__ */ new Set([
49
+ "\u03A9",
50
+ // OBJECT - Objeto
51
+ "\u25A0",
52
+ // OBJECT ALT - Entidade concreta
53
+ "\u25CB",
54
+ // CLASS - Classe/molde
55
+ "\u2B12",
56
+ // INHERIT - Herança
57
+ "\u2283",
58
+ // CONTAINS - Composição
59
+ "\u2254",
60
+ // ASSIGN - Atribuição
61
+ "\u29C9"
62
+ // MODULE - Módulo
63
+ ]);
64
+ var SYMBOLS_TIME = /* @__PURE__ */ new Set([
65
+ "\u26A1",
66
+ // CAUSE - Causa/origem
67
+ "\u2726",
68
+ // CONSEQUENCE - Resultado
69
+ "\u21BB",
70
+ // LOOP - Repetição
71
+ "\u25CC",
72
+ // EVENT - Evento
73
+ "\u21C4",
74
+ // SYNC - Sincronização
75
+ "\u231B"
76
+ // TIMEOUT - Limite temporal
77
+ ]);
78
+ var SYMBOLS_ENERGY = /* @__PURE__ */ new Set([
79
+ "\u03A8",
80
+ // ENERGY - Energia vital
81
+ "\u23EC",
82
+ // THROTTLE - Limitar
83
+ "\u23EB",
84
+ // BOOST - Acelerar
85
+ "\u20B5"
86
+ // COST - Custo
87
+ ]);
88
+ var SYMBOLS_MEMORY = /* @__PURE__ */ new Set([
89
+ "\u{1D4DC}",
90
+ // MEMORY - Memória
91
+ "\u267E",
92
+ // PERSIST - Persistência
93
+ "\u2302"
94
+ // ROOT - Raiz do sistema
95
+ ]);
96
+ var SYMBOLS_UI = /* @__PURE__ */ new Set([
97
+ "\u03A6",
98
+ // FORM - Form/UI
99
+ "\u0398",
100
+ // ANIMATION - Animação
101
+ "\u2610",
102
+ // INTERFACE - Interface
103
+ "\u{1F441}",
104
+ // VISUAL - Percepção visual
105
+ "\u2328",
106
+ // INPUT - Entrada
107
+ "\u{1F9ED}"
108
+ // POINTER - Ponteiro/direção
109
+ ]);
110
+ var SYMBOLS_SECURITY = /* @__PURE__ */ new Set([
111
+ "\u{1F6E1}",
112
+ // SECURITY - Segurança
113
+ "\u{1F511}",
114
+ // KEY - Chave/autorização
115
+ "\u26A0",
116
+ // RISK - Risco
117
+ "\u26D4",
118
+ // BLOCK - Bloqueio
119
+ "\u{1F9EA}"
120
+ // SANDBOX - Isolamento
121
+ ]);
122
+ var SYMBOLS_EVOLVE = /* @__PURE__ */ new Set([
123
+ "\u2301",
124
+ // EVOLVE BLOCK - Bloco de evolução
125
+ "\u27F3",
126
+ // EVOLVE - Evoluir
127
+ "\u2714",
128
+ // VERIFY - Verificar
129
+ "\u2713",
130
+ // VALID - Válido
131
+ "\u2716",
132
+ // INVALID - Inválido
133
+ "\u{1F4DC}"
134
+ // LOG - Registro
135
+ ]);
136
+ var SYMBOLS_LOGIC = /* @__PURE__ */ new Set([
137
+ "\u039B",
138
+ // LOGIC - Lógica condicional
139
+ "\u2297"
140
+ // PARALLEL BLOCK - Bloco paralelo
141
+ ]);
142
+ var SYMBOLS = /* @__PURE__ */ new Set([
143
+ ...SYMBOLS_STATE,
144
+ ...SYMBOLS_EXEC,
145
+ ...SYMBOLS_STRUCT,
146
+ ...SYMBOLS_TIME,
147
+ ...SYMBOLS_ENERGY,
148
+ ...SYMBOLS_MEMORY,
149
+ ...SYMBOLS_UI,
150
+ ...SYMBOLS_SECURITY,
151
+ ...SYMBOLS_EVOLVE,
152
+ ...SYMBOLS_LOGIC
153
+ ]);
154
+ var SYMBOL_NAMES = {
155
+ "\u03A3": "STATE",
156
+ "\u03C3": "SUBSTATE",
157
+ "\xD8": "VOID",
158
+ "\u{1F512}": "LOCK",
159
+ "\u{1F513}": "UNLOCK",
160
+ "\u0394": "ACTION",
161
+ "\u0192": "FUNCTION",
162
+ "\u21C9": "PARALLEL",
163
+ "\u25B3": "DEPEND",
164
+ "\u25CF": "CORE",
165
+ "\u23F3": "DELAY",
166
+ "\u03A9": "OBJECT",
167
+ "\u25A0": "OBJECT_ALT",
168
+ "\u25CB": "CLASS",
169
+ "\u2B12": "INHERIT",
170
+ "\u2283": "CONTAINS",
171
+ "\u2254": "ASSIGN",
172
+ "\u29C9": "MODULE",
173
+ "\u26A1": "CAUSE",
174
+ "\u2726": "CONSEQUENCE",
175
+ "\u21BB": "LOOP",
176
+ "\u25CC": "EVENT",
177
+ "\u21C4": "SYNC",
178
+ "\u231B": "TIMEOUT",
179
+ "\u03A8": "ENERGY",
180
+ "\u23EC": "THROTTLE",
181
+ "\u23EB": "BOOST",
182
+ "\u20B5": "COST",
183
+ "\u{1D4DC}": "MEMORY",
184
+ "\u267E": "PERSIST",
185
+ "\u2302": "ROOT",
186
+ "\u03A6": "FORM",
187
+ "\u0398": "ANIMATION",
188
+ "\u2610": "INTERFACE",
189
+ "\u{1F441}": "VISUAL",
190
+ "\u2328": "INPUT",
191
+ "\u{1F9ED}": "POINTER",
192
+ "\u{1F6E1}": "SECURITY",
193
+ "\u{1F511}": "KEY",
194
+ "\u26A0": "RISK",
195
+ "\u26D4": "BLOCK",
196
+ "\u{1F9EA}": "SANDBOX",
197
+ "\u2301": "EVOLVE_BLOCK",
198
+ "\u27F3": "EVOLVE",
199
+ "\u2714": "VERIFY",
200
+ "\u2713": "VALID",
201
+ "\u2716": "INVALID",
202
+ "\u{1F4DC}": "LOG",
203
+ "\u039B": "LOGIC",
204
+ "\u2297": "PARALLEL_BLOCK"
205
+ };
206
+ var OPERATORS = /* @__PURE__ */ new Set(["+", "\u2212", "-", "\u2254"]);
207
+ function isWhitespace(ch) {
208
+ return ch === " " || ch === " " || ch === "\r";
209
+ }
210
+ function isNewline(ch) {
211
+ return ch === "\n";
212
+ }
213
+ function isDigit(ch) {
214
+ return /[0-9]/.test(ch);
215
+ }
216
+ function isIdentifierStart(ch) {
217
+ return /[A-Za-z_\p{L}]/u.test(ch);
218
+ }
219
+ function isIdentifierPart(ch) {
220
+ return /[A-Za-z0-9_\p{L}]/u.test(ch);
221
+ }
222
+ function getCodePoint(str, pos) {
223
+ const code = str.codePointAt(pos);
224
+ if (code === void 0)
225
+ return { char: "", len: 0 };
226
+ const char = String.fromCodePoint(code);
227
+ const len = code > 65535 ? 2 : 1;
228
+ return { char, len };
229
+ }
230
+ function tokenize(input) {
231
+ const tokens = [];
232
+ const len = input.length;
233
+ let i = 0;
234
+ while (i < len) {
235
+ const { char: ch, len: charLen } = getCodePoint(input, i);
236
+ if (charLen === 0) {
237
+ i++;
238
+ continue;
239
+ }
240
+ if (isWhitespace(ch)) {
241
+ i += charLen;
242
+ continue;
243
+ }
244
+ if (isNewline(ch)) {
245
+ tokens.push({ type: "NEWLINE" /* NEWLINE */, value: "\n", pos: i });
246
+ i += charLen;
247
+ continue;
248
+ }
249
+ if (SYMBOLS.has(ch)) {
250
+ tokens.push({ type: "SYMBOL" /* SYMBOL */, value: ch, pos: i });
251
+ i += charLen;
252
+ continue;
253
+ }
254
+ if (ch === "\u2192" || ch === "-" && input[i + 1] === ">") {
255
+ if (ch === "\u2192") {
256
+ tokens.push({ type: "ARROW" /* ARROW */, value: "\u2192", pos: i });
257
+ i++;
258
+ } else {
259
+ tokens.push({ type: "ARROW" /* ARROW */, value: "->", pos: i });
260
+ i += 2;
261
+ }
262
+ continue;
263
+ }
264
+ if (ch === "{") {
265
+ tokens.push({ type: "LBRACE" /* LBRACE */, value: "{", pos: i });
266
+ i++;
267
+ continue;
268
+ }
269
+ if (ch === "}") {
270
+ tokens.push({ type: "RBRACE" /* RBRACE */, value: "}", pos: i });
271
+ i++;
272
+ continue;
273
+ }
274
+ if (ch === "(") {
275
+ tokens.push({ type: "LPAREN" /* LPAREN */, value: "(", pos: i });
276
+ i++;
277
+ continue;
278
+ }
279
+ if (ch === ")") {
280
+ tokens.push({ type: "RPAREN" /* RPAREN */, value: ")", pos: i });
281
+ i++;
282
+ continue;
283
+ }
284
+ if (ch === "[") {
285
+ tokens.push({ type: "LBRACKET" /* LBRACKET */, value: "[", pos: i });
286
+ i++;
287
+ continue;
288
+ }
289
+ if (ch === "]") {
290
+ tokens.push({ type: "RBRACKET" /* RBRACKET */, value: "]", pos: i });
291
+ i++;
292
+ continue;
293
+ }
294
+ if (ch === ":") {
295
+ tokens.push({ type: "COLON" /* COLON */, value: ":", pos: i });
296
+ i++;
297
+ continue;
298
+ }
299
+ if (ch === ",") {
300
+ tokens.push({ type: "COMMA" /* COMMA */, value: ",", pos: i });
301
+ i++;
302
+ continue;
303
+ }
304
+ if (ch === "=" && input[i + 1] === "=" || ch === "!" && input[i + 1] === "=" || ch === ">" && input[i + 1] === "=" || ch === "<" && input[i + 1] === "=") {
305
+ tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: input.substr(i, 2), pos: i });
306
+ i += 2;
307
+ continue;
308
+ }
309
+ if (ch === ">" || ch === "<") {
310
+ tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: ch, pos: i });
311
+ i++;
312
+ continue;
313
+ }
314
+ if (ch === "\u2260") {
315
+ tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: "\u2260", pos: i });
316
+ i++;
317
+ continue;
318
+ }
319
+ if (OPERATORS.has(ch) && !SYMBOLS.has(ch)) {
320
+ tokens.push({ type: "OPERATOR" /* OPERATOR */, value: ch, pos: i });
321
+ i++;
322
+ continue;
323
+ }
324
+ if (ch === '"') {
325
+ let j = i + 1;
326
+ let out = "";
327
+ while (j < len) {
328
+ if (input[j] === "\\" && j + 1 < len) {
329
+ out += input[j + 1];
330
+ j += 2;
331
+ continue;
332
+ }
333
+ if (input[j] === '"') {
334
+ break;
335
+ }
336
+ out += input[j];
337
+ j++;
338
+ }
339
+ tokens.push({ type: "STRING" /* STRING */, value: out, pos: i });
340
+ i = j + 1;
341
+ continue;
342
+ }
343
+ if (isDigit(ch)) {
344
+ let j = i;
345
+ let val = "";
346
+ while (j < len && isDigit(input[j])) {
347
+ val += input[j];
348
+ j++;
349
+ }
350
+ tokens.push({ type: "NUMBER" /* NUMBER */, value: val, pos: i });
351
+ i = j;
352
+ continue;
353
+ }
354
+ if (isIdentifierStart(ch)) {
355
+ let j = i;
356
+ let val = "";
357
+ while (j < len && isIdentifierPart(input[j])) {
358
+ val += input[j];
359
+ j++;
360
+ }
361
+ tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: val, pos: i });
362
+ i = j;
363
+ continue;
364
+ }
365
+ tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: ch, pos: i });
366
+ i += charLen;
367
+ }
368
+ tokens.push({ type: "EOF" /* EOF */, value: "", pos: i });
369
+ return tokens;
370
+ }
371
+
372
+ // src/parser/ebnfParser.ts
373
+ function peek(cx) {
374
+ return cx.tokens[cx.i];
375
+ }
376
+ function next(cx) {
377
+ return cx.tokens[cx.i++];
378
+ }
379
+ function eat(cx, type, value) {
380
+ const t = peek(cx);
381
+ if (!t)
382
+ throw new Error(`Unexpected EOF, expected ${type}`);
383
+ if (t.type !== type)
384
+ throw new Error(`Expected token ${type} but got ${t.type} ('${t.value}') at ${t.pos}`);
385
+ if (value !== void 0 && t.value !== value)
386
+ throw new Error(`Expected token value ${value} but got '${t.value}' at ${t.pos}`);
387
+ return next(cx);
388
+ }
389
+ function skipNewlines(cx) {
390
+ while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
391
+ next(cx);
392
+ }
393
+ function parseTokens(tokens, options) {
394
+ const cx = { tokens, i: 0 };
395
+ const ast = {
396
+ raw: tokens.map((t) => t.value).join(" "),
397
+ // Core collections
398
+ functions: [],
399
+ ias: [],
400
+ nodes: [],
401
+ modules: [],
402
+ objects: [],
403
+ forms: [],
404
+ animations: [],
405
+ logic: [],
406
+ parallels: [],
407
+ build: null,
408
+ evolve: null,
409
+ targets: [],
410
+ version: null,
411
+ logs: [],
412
+ // Extended collections from full alphabet
413
+ substates: [],
414
+ classes: [],
415
+ loops: [],
416
+ events: [],
417
+ syncs: [],
418
+ timeouts: [],
419
+ delays: [],
420
+ securities: [],
421
+ keys: [],
422
+ sandboxes: [],
423
+ causes: [],
424
+ consequences: [],
425
+ memories: [],
426
+ persists: [],
427
+ roots: [],
428
+ interfaces: [],
429
+ visuals: [],
430
+ inputs: [],
431
+ throttles: [],
432
+ boosts: [],
433
+ costs: [],
434
+ locks: [],
435
+ unlocks: [],
436
+ voids: [],
437
+ inherits: [],
438
+ contains: [],
439
+ verifies: [],
440
+ logNodes: [],
441
+ database: null,
442
+ kernel: null,
443
+ training: null
444
+ };
445
+ const onLog = (e) => {
446
+ const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
447
+ ast.logs.push(entry);
448
+ if (options?.onLog)
449
+ options.onLog(entry);
450
+ };
451
+ skipNewlines(cx);
452
+ while (peek(cx) && peek(cx).type !== "EOF" /* EOF */) {
453
+ const t = peek(cx);
454
+ if (t.type === "SYMBOL" /* SYMBOL */) {
455
+ const sym = t.value;
456
+ next(cx);
457
+ skipNewlines(cx);
458
+ while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
459
+ next(cx);
460
+ const ident = peek(cx);
461
+ if (!ident)
462
+ break;
463
+ const kw = ident.type === "IDENTIFIER" /* IDENTIFIER */ ? ident.value.toUpperCase() : void 0;
464
+ if (sym === "\u03A3" && kw === "SYSTEM") {
465
+ next(cx);
466
+ skipNewlines(cx);
467
+ const nameTok = eat(cx, "STRING" /* STRING */);
468
+ ast.system = nameTok.value;
469
+ onLog({ level: "info", event: "parse.system", detail: { name: ast.system } });
470
+ skipNewlines(cx);
471
+ continue;
472
+ }
473
+ if (sym === "\u03A3" && kw === "TARGET") {
474
+ next(cx);
475
+ skipNewlines(cx);
476
+ const targets = [];
477
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "EOF" /* EOF */) {
478
+ const v = peek(cx);
479
+ if (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */) {
480
+ targets.push(v.value);
481
+ next(cx);
482
+ } else if (v.type === "COMMA" /* COMMA */) {
483
+ next(cx);
484
+ } else {
485
+ break;
486
+ }
487
+ }
488
+ ast.targets = [...ast.targets || [], ...targets];
489
+ onLog({ level: "info", event: "parse.target", detail: { targets } });
490
+ skipNewlines(cx);
491
+ continue;
492
+ }
493
+ if (sym === "\u03A3" && kw === "MODE") {
494
+ next(cx);
495
+ skipNewlines(cx);
496
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
497
+ ast.mode = v.value;
498
+ onLog({ level: "info", event: "parse.mode", detail: { mode: ast.mode } });
499
+ skipNewlines(cx);
500
+ continue;
501
+ }
502
+ if (sym === "\u03A3" && kw === "UI") {
503
+ next(cx);
504
+ skipNewlines(cx);
505
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
506
+ ast.ui = v.value;
507
+ onLog({ level: "info", event: "parse.ui", detail: { ui: ast.ui } });
508
+ skipNewlines(cx);
509
+ continue;
510
+ }
511
+ if (sym === "\u03A3" && kw === "MODULE") {
512
+ next(cx);
513
+ skipNewlines(cx);
514
+ const nameTok = eat(cx, "STRING" /* STRING */);
515
+ const module = { type: "module", name: nameTok.value };
516
+ ast.modules.push(module);
517
+ ast.nodes.push(module);
518
+ onLog({ level: "info", event: "parse.module", detail: module });
519
+ skipNewlines(cx);
520
+ continue;
521
+ }
522
+ if (sym === "\u03A3" && kw === "BUILD") {
523
+ next(cx);
524
+ skipNewlines(cx);
525
+ eat(cx, "LBRACE" /* LBRACE */);
526
+ const targets = [];
527
+ skipNewlines(cx);
528
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
529
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
530
+ eat(cx, "COLON" /* COLON */);
531
+ const val = peek(cx);
532
+ if (val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "STRING" /* STRING */) {
533
+ targets.push(val.value);
534
+ next(cx);
535
+ } else {
536
+ throw new Error("Expected identifier or string for build target");
537
+ }
538
+ skipNewlines(cx);
539
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
540
+ next(cx);
541
+ skipNewlines(cx);
542
+ }
543
+ eat(cx, "RBRACE" /* RBRACE */);
544
+ const b = { type: "build", targets };
545
+ ast.build = b;
546
+ ast.nodes.push(b);
547
+ onLog({ level: "info", event: "parse.build", detail: b });
548
+ skipNewlines(cx);
549
+ continue;
550
+ }
551
+ if (sym === "\u03A3" && kw === "EVOLVE") {
552
+ next(cx);
553
+ skipNewlines(cx);
554
+ const v = peek(cx);
555
+ if (v && (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */)) {
556
+ const ev = { type: "evolve", steps: [next(cx).value] };
557
+ ast.evolve = ev;
558
+ onLog({ level: "info", event: "parse.evolve", detail: ev });
559
+ }
560
+ skipNewlines(cx);
561
+ continue;
562
+ }
563
+ if (sym === "\u03A3" && kw === "DATABASE") {
564
+ next(cx);
565
+ skipNewlines(cx);
566
+ const v = peek(cx);
567
+ if (v && v.type === "IDENTIFIER" /* IDENTIFIER */) {
568
+ const mode = next(cx).value;
569
+ const db = { type: "database", mode };
570
+ ast.database = db;
571
+ ast.nodes.push(db);
572
+ onLog({ level: "info", event: "parse.database", detail: db });
573
+ }
574
+ skipNewlines(cx);
575
+ continue;
576
+ }
577
+ if (sym === "\u03A3" && kw === "KERNEL") {
578
+ next(cx);
579
+ skipNewlines(cx);
580
+ const hooks = [];
581
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
582
+ next(cx);
583
+ skipNewlines(cx);
584
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
585
+ const p = peek(cx);
586
+ if (p.type === "IDENTIFIER" /* IDENTIFIER */) {
587
+ const hookName = next(cx).value;
588
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
589
+ hooks.push(hookName + " " + next(cx).value);
590
+ } else {
591
+ hooks.push(hookName);
592
+ }
593
+ } else {
594
+ next(cx);
595
+ }
596
+ skipNewlines(cx);
597
+ }
598
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
599
+ next(cx);
600
+ }
601
+ const kernel = { type: "kernel", hooks };
602
+ ast.kernel = kernel;
603
+ ast.nodes.push(kernel);
604
+ onLog({ level: "info", event: "parse.kernel", detail: kernel });
605
+ skipNewlines(cx);
606
+ continue;
607
+ }
608
+ if (sym === "\u03A3" && kw === "TRAINING") {
609
+ next(cx);
610
+ skipNewlines(cx);
611
+ const v = peek(cx);
612
+ if (v && (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */)) {
613
+ const training = { type: "training", topic: next(cx).value };
614
+ ast.training = training;
615
+ ast.nodes.push(training);
616
+ onLog({ level: "info", event: "parse.training", detail: training });
617
+ }
618
+ skipNewlines(cx);
619
+ continue;
620
+ }
621
+ if (sym === "\u03A3" && kw === "LEVEL") {
622
+ next(cx);
623
+ skipNewlines(cx);
624
+ const v = peek(cx);
625
+ if (v && v.type === "NUMBER" /* NUMBER */) {
626
+ if (ast.training) {
627
+ ast.training.level = parseInt(next(cx).value, 10);
628
+ } else {
629
+ next(cx);
630
+ }
631
+ }
632
+ skipNewlines(cx);
633
+ continue;
634
+ }
635
+ if (sym === "\u0394") {
636
+ let nameTok = null;
637
+ if (kw === "FUNCTION") {
638
+ next(cx);
639
+ skipNewlines(cx);
640
+ const tname = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
641
+ nameTok = tname;
642
+ } else {
643
+ if (ident.type === "IDENTIFIER" /* IDENTIFIER */) {
644
+ nameTok = next(cx);
645
+ }
646
+ }
647
+ if (!nameTok) {
648
+ onLog({ level: "warn", event: "parse.function.missing.name" });
649
+ skipNewlines(cx);
650
+ continue;
651
+ }
652
+ skipNewlines(cx);
653
+ let args = [];
654
+ if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
655
+ next(cx);
656
+ skipNewlines(cx);
657
+ while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */) {
658
+ const arg = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
659
+ args.push(arg.value);
660
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
661
+ next(cx);
662
+ skipNewlines(cx);
663
+ }
664
+ eat(cx, "RPAREN" /* RPAREN */);
665
+ }
666
+ const steps = [];
667
+ skipNewlines(cx);
668
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
669
+ next(cx);
670
+ const bodyTok = peek(cx);
671
+ if (bodyTok && (bodyTok.type === "IDENTIFIER" /* IDENTIFIER */ || bodyTok.type === "STRING" /* STRING */)) {
672
+ steps.push({ raw: bodyTok.value });
673
+ next(cx);
674
+ }
675
+ skipNewlines(cx);
676
+ }
677
+ onLog({ level: "info", event: "parse.function.start", detail: { name: nameTok.value, args } });
678
+ const fn = { type: "function", name: nameTok.value, args, steps };
679
+ ast.functions.push(fn);
680
+ ast.nodes.push(fn);
681
+ onLog({ level: "info", event: "parse.function.end", detail: fn });
682
+ continue;
683
+ }
684
+ if (sym === "\u03A8") {
685
+ if (kw === "IA") {
686
+ next(cx);
687
+ skipNewlines(cx);
688
+ const nameTok = peek(cx);
689
+ let name = "ia";
690
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
691
+ name = next(cx).value;
692
+ }
693
+ const body = [];
694
+ skipNewlines(cx);
695
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
696
+ next(cx);
697
+ skipNewlines(cx);
698
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
699
+ const cap = peek(cx);
700
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
701
+ body.push(cap.value);
702
+ next(cx);
703
+ } else {
704
+ next(cx);
705
+ }
706
+ skipNewlines(cx);
707
+ }
708
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
709
+ next(cx);
710
+ } else {
711
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */ && peek(cx).type !== "NEWLINE" /* NEWLINE */) {
712
+ const cap = peek(cx);
713
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
714
+ body.push(cap.value);
715
+ next(cx);
716
+ } else
717
+ break;
718
+ skipNewlines(cx);
719
+ }
720
+ }
721
+ const ia = { type: "ia", name, body };
722
+ ast.ias.push(ia);
723
+ ast.nodes.push(ia);
724
+ onLog({ level: "info", event: "parse.ia", detail: ia });
725
+ continue;
726
+ }
727
+ skipNewlines(cx);
728
+ continue;
729
+ }
730
+ if (sym === "\u03A9") {
731
+ skipNewlines(cx);
732
+ const nameTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
733
+ const name = nameTok.value;
734
+ const props = {};
735
+ skipNewlines(cx);
736
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
737
+ next(cx);
738
+ skipNewlines(cx);
739
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
740
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
741
+ skipNewlines(cx);
742
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
743
+ next(cx);
744
+ skipNewlines(cx);
745
+ const val = peek(cx);
746
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
747
+ props[p.value] = val.value;
748
+ next(cx);
749
+ } else {
750
+ props[p.value] = null;
751
+ }
752
+ } else {
753
+ props[p.value] = null;
754
+ }
755
+ skipNewlines(cx);
756
+ }
757
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
758
+ next(cx);
759
+ }
760
+ const obj = { type: "object", name, props };
761
+ ast.objects.push(obj);
762
+ ast.nodes.push(obj);
763
+ onLog({ level: "info", event: "parse.object", detail: obj });
764
+ continue;
765
+ }
766
+ if (sym === "\u03A6") {
767
+ skipNewlines(cx);
768
+ let name = "form";
769
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && cx.tokens[cx.i + 1] && cx.tokens[cx.i + 1].type !== "LBRACE" /* LBRACE */) {
770
+ name = next(cx).value;
771
+ }
772
+ const props = {};
773
+ skipNewlines(cx);
774
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
775
+ next(cx);
776
+ skipNewlines(cx);
777
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
778
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
779
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
780
+ eat(cx, "COLON" /* COLON */);
781
+ const val = peek(cx);
782
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
783
+ props[key.value] = val.value;
784
+ next(cx);
785
+ } else {
786
+ props[key.value] = true;
787
+ }
788
+ } else {
789
+ next(cx);
790
+ }
791
+ skipNewlines(cx);
792
+ }
793
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
794
+ next(cx);
795
+ }
796
+ const form = { type: "form", name, props };
797
+ ast.forms.push(form);
798
+ ast.nodes.push(form);
799
+ onLog({ level: "info", event: "parse.form", detail: form });
800
+ continue;
801
+ }
802
+ if (sym === "\u0398") {
803
+ skipNewlines(cx);
804
+ const maybeAnim = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
805
+ if (maybeAnim.value.toLowerCase() !== "animation") {
806
+ onLog({ level: "warn", event: "parse.animation.missing.keyword" });
807
+ continue;
808
+ }
809
+ skipNewlines(cx);
810
+ const nameTok = peek(cx);
811
+ let name = "animation";
812
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
813
+ name = next(cx).value;
814
+ }
815
+ const props = {};
816
+ skipNewlines(cx);
817
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */) {
818
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
819
+ const key = next(cx).value;
820
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
821
+ next(cx);
822
+ const val = peek(cx);
823
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "NUMBER" /* NUMBER */ || val.type === "IDENTIFIER" /* IDENTIFIER */)) {
824
+ props[key] = val.value;
825
+ next(cx);
826
+ }
827
+ } else {
828
+ props[key] = true;
829
+ }
830
+ } else {
831
+ break;
832
+ }
833
+ skipNewlines(cx);
834
+ }
835
+ const anim = { type: "animation", name, props };
836
+ ast.animations.push(anim);
837
+ ast.nodes.push(anim);
838
+ onLog({ level: "info", event: "parse.animation", detail: anim });
839
+ continue;
840
+ }
841
+ if (sym === "\u039B") {
842
+ skipNewlines(cx);
843
+ const ifTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
844
+ if (ifTok.value.toLowerCase() !== "if") {
845
+ onLog({ level: "warn", event: "parse.logic.missing.if" });
846
+ continue;
847
+ }
848
+ const leftTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
849
+ let leftName = leftTok.value;
850
+ while (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value === ".") {
851
+ next(cx);
852
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
853
+ leftName += "." + p.value;
854
+ }
855
+ const comp = eat(cx, "COMPARATOR" /* COMPARATOR */);
856
+ const right = peek(cx);
857
+ if (!right || !(right.type === "STRING" /* STRING */ || right.type === "NUMBER" /* NUMBER */ || right.type === "IDENTIFIER" /* IDENTIFIER */))
858
+ throw new Error("Invalid logic right-hand side");
859
+ next(cx);
860
+ const rule = `${leftName} ${comp.value} ${right.value}`;
861
+ const trueFlow = [];
862
+ const falseFlow = [];
863
+ skipNewlines(cx);
864
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
865
+ next(cx);
866
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
867
+ trueFlow.push(step.value);
868
+ skipNewlines(cx);
869
+ }
870
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "else") {
871
+ next(cx);
872
+ skipNewlines(cx);
873
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
874
+ next(cx);
875
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
876
+ falseFlow.push(step.value);
877
+ skipNewlines(cx);
878
+ }
879
+ }
880
+ const logic = { type: "logic", rule, trueFlow, falseFlow };
881
+ ast.logic.push(logic);
882
+ ast.nodes.push(logic);
883
+ onLog({ level: "info", event: "parse.logic", detail: logic });
884
+ continue;
885
+ }
886
+ if (sym === "\u2297") {
887
+ skipNewlines(cx);
888
+ const items = [];
889
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
890
+ next(cx);
891
+ skipNewlines(cx);
892
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
893
+ const parts = [];
894
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "RBRACE" /* RBRACE */) {
895
+ const p = peek(cx);
896
+ if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */ || p.type === "NUMBER" /* NUMBER */) {
897
+ parts.push(next(cx).value);
898
+ } else {
899
+ next(cx);
900
+ }
901
+ }
902
+ if (parts.length > 0)
903
+ items.push(parts.join(" "));
904
+ if (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
905
+ next(cx);
906
+ skipNewlines(cx);
907
+ }
908
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
909
+ next(cx);
910
+ }
911
+ const par = { type: "parallel", items };
912
+ ast.parallels.push(par);
913
+ ast.nodes.push(par);
914
+ onLog({ level: "info", event: "parse.parallel", detail: par });
915
+ continue;
916
+ }
917
+ if (sym === "\u2301" && kw === "EVOLVE") {
918
+ next(cx);
919
+ skipNewlines(cx);
920
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
921
+ next(cx);
922
+ skipNewlines(cx);
923
+ const steps = [];
924
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
925
+ const p = peek(cx);
926
+ if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */) {
927
+ steps.push(p.value);
928
+ next(cx);
929
+ } else {
930
+ next(cx);
931
+ }
932
+ skipNewlines(cx);
933
+ }
934
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
935
+ next(cx);
936
+ const ev = { type: "evolve", steps };
937
+ ast.evolve = ev;
938
+ ast.nodes.push(ev);
939
+ onLog({ level: "info", event: "parse.evolve", detail: ev });
940
+ continue;
941
+ }
942
+ }
943
+ if (sym === "\u03C3") {
944
+ skipNewlines(cx);
945
+ let name = "substate";
946
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
947
+ name = next(cx).value;
948
+ }
949
+ const props = {};
950
+ skipNewlines(cx);
951
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
952
+ next(cx);
953
+ skipNewlines(cx);
954
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
955
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
956
+ const key = next(cx).value;
957
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
958
+ next(cx);
959
+ const val = peek(cx);
960
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
961
+ props[key] = next(cx).value;
962
+ }
963
+ } else {
964
+ props[key] = true;
965
+ }
966
+ } else {
967
+ next(cx);
968
+ }
969
+ skipNewlines(cx);
970
+ }
971
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
972
+ next(cx);
973
+ }
974
+ const substate = { type: "substate", name, props };
975
+ ast.substates.push(substate);
976
+ ast.nodes.push(substate);
977
+ onLog({ level: "info", event: "parse.substate", detail: substate });
978
+ continue;
979
+ }
980
+ if (sym === "\u25CB") {
981
+ skipNewlines(cx);
982
+ let name = "class";
983
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
984
+ name = next(cx).value;
985
+ }
986
+ let extendsClass;
987
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "extends") {
988
+ next(cx);
989
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
990
+ extendsClass = next(cx).value;
991
+ }
992
+ }
993
+ const props = {};
994
+ const methods = [];
995
+ skipNewlines(cx);
996
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
997
+ next(cx);
998
+ skipNewlines(cx);
999
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1000
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1001
+ const key = next(cx).value;
1002
+ if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
1003
+ methods.push(key);
1004
+ next(cx);
1005
+ while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */)
1006
+ next(cx);
1007
+ if (peek(cx))
1008
+ next(cx);
1009
+ } else if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
1010
+ next(cx);
1011
+ const val = peek(cx);
1012
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
1013
+ props[key] = next(cx).value;
1014
+ }
1015
+ } else {
1016
+ props[key] = true;
1017
+ }
1018
+ } else {
1019
+ next(cx);
1020
+ }
1021
+ skipNewlines(cx);
1022
+ }
1023
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1024
+ next(cx);
1025
+ }
1026
+ const classNode = { type: "class", name, extends: extendsClass, props, methods };
1027
+ ast.classes.push(classNode);
1028
+ ast.nodes.push(classNode);
1029
+ onLog({ level: "info", event: "parse.class", detail: classNode });
1030
+ continue;
1031
+ }
1032
+ if (sym === "\u21BB") {
1033
+ skipNewlines(cx);
1034
+ let count;
1035
+ let condition;
1036
+ const body = [];
1037
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1038
+ count = parseInt(next(cx).value, 10);
1039
+ } else if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1040
+ condition = next(cx).value;
1041
+ }
1042
+ skipNewlines(cx);
1043
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1044
+ next(cx);
1045
+ skipNewlines(cx);
1046
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1047
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1048
+ body.push(next(cx).value);
1049
+ } else {
1050
+ next(cx);
1051
+ }
1052
+ skipNewlines(cx);
1053
+ }
1054
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1055
+ next(cx);
1056
+ }
1057
+ const loop = { type: "loop", count, condition, body };
1058
+ ast.loops.push(loop);
1059
+ ast.nodes.push(loop);
1060
+ onLog({ level: "info", event: "parse.loop", detail: loop });
1061
+ continue;
1062
+ }
1063
+ if (sym === "\u25CC") {
1064
+ skipNewlines(cx);
1065
+ let name = "event";
1066
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1067
+ name = next(cx).value;
1068
+ }
1069
+ const handler = [];
1070
+ skipNewlines(cx);
1071
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
1072
+ next(cx);
1073
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1074
+ handler.push(next(cx).value);
1075
+ }
1076
+ skipNewlines(cx);
1077
+ }
1078
+ const event = { type: "event", name, handler };
1079
+ ast.events.push(event);
1080
+ ast.nodes.push(event);
1081
+ onLog({ level: "info", event: "parse.event", detail: event });
1082
+ continue;
1083
+ }
1084
+ if (sym === "\u21C4") {
1085
+ skipNewlines(cx);
1086
+ const sources = [];
1087
+ while (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1088
+ sources.push(next(cx).value);
1089
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
1090
+ next(cx);
1091
+ skipNewlines(cx);
1092
+ }
1093
+ const sync = { type: "sync", sources };
1094
+ ast.syncs.push(sync);
1095
+ ast.nodes.push(sync);
1096
+ onLog({ level: "info", event: "parse.sync", detail: sync });
1097
+ continue;
1098
+ }
1099
+ if (sym === "\u231B") {
1100
+ skipNewlines(cx);
1101
+ let duration = 0;
1102
+ let unit = "ms";
1103
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1104
+ duration = parseInt(next(cx).value, 10);
1105
+ }
1106
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1107
+ const u = peek(cx).value.toLowerCase();
1108
+ if (u === "ms" || u === "s" || u === "m") {
1109
+ unit = u;
1110
+ next(cx);
1111
+ }
1112
+ }
1113
+ const timeout = { type: "timeout", duration, unit };
1114
+ ast.timeouts.push(timeout);
1115
+ ast.nodes.push(timeout);
1116
+ onLog({ level: "info", event: "parse.timeout", detail: timeout });
1117
+ continue;
1118
+ }
1119
+ if (sym === "\u23F3") {
1120
+ skipNewlines(cx);
1121
+ let duration = 0;
1122
+ let unit = "ms";
1123
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1124
+ duration = parseInt(next(cx).value, 10);
1125
+ }
1126
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1127
+ const u = peek(cx).value.toLowerCase();
1128
+ if (u === "ms" || u === "s" || u === "m") {
1129
+ unit = u;
1130
+ next(cx);
1131
+ }
1132
+ }
1133
+ const delay = { type: "delay", duration, unit };
1134
+ ast.delays.push(delay);
1135
+ ast.nodes.push(delay);
1136
+ onLog({ level: "info", event: "parse.delay", detail: delay });
1137
+ continue;
1138
+ }
1139
+ if (sym === "\u{1F6E1}") {
1140
+ skipNewlines(cx);
1141
+ let level;
1142
+ const rules = [];
1143
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1144
+ const lv = peek(cx).value.toLowerCase();
1145
+ if (["low", "medium", "high", "critical"].includes(lv)) {
1146
+ level = lv;
1147
+ next(cx);
1148
+ }
1149
+ }
1150
+ skipNewlines(cx);
1151
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1152
+ next(cx);
1153
+ skipNewlines(cx);
1154
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1155
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1156
+ rules.push(next(cx).value);
1157
+ } else {
1158
+ next(cx);
1159
+ }
1160
+ skipNewlines(cx);
1161
+ }
1162
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1163
+ next(cx);
1164
+ }
1165
+ const security = { type: "security", level, rules };
1166
+ ast.securities.push(security);
1167
+ ast.nodes.push(security);
1168
+ onLog({ level: "info", event: "parse.security", detail: security });
1169
+ continue;
1170
+ }
1171
+ if (sym === "\u{1F511}") {
1172
+ skipNewlines(cx);
1173
+ let name = "key";
1174
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1175
+ name = next(cx).value;
1176
+ }
1177
+ const permissions = [];
1178
+ skipNewlines(cx);
1179
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1180
+ next(cx);
1181
+ skipNewlines(cx);
1182
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1183
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1184
+ permissions.push(next(cx).value);
1185
+ } else {
1186
+ next(cx);
1187
+ }
1188
+ skipNewlines(cx);
1189
+ }
1190
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1191
+ next(cx);
1192
+ }
1193
+ const key = { type: "key", name, permissions };
1194
+ ast.keys.push(key);
1195
+ ast.nodes.push(key);
1196
+ onLog({ level: "info", event: "parse.key", detail: key });
1197
+ continue;
1198
+ }
1199
+ if (sym === "\u{1F9EA}") {
1200
+ skipNewlines(cx);
1201
+ let name = "sandbox";
1202
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1203
+ name = next(cx).value;
1204
+ }
1205
+ const body = [];
1206
+ skipNewlines(cx);
1207
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1208
+ next(cx);
1209
+ skipNewlines(cx);
1210
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1211
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1212
+ body.push(next(cx).value);
1213
+ } else {
1214
+ next(cx);
1215
+ }
1216
+ skipNewlines(cx);
1217
+ }
1218
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1219
+ next(cx);
1220
+ }
1221
+ const sandbox = { type: "sandbox", name, body };
1222
+ ast.sandboxes.push(sandbox);
1223
+ ast.nodes.push(sandbox);
1224
+ onLog({ level: "info", event: "parse.sandbox", detail: sandbox });
1225
+ continue;
1226
+ }
1227
+ if (sym === "\u26A1") {
1228
+ skipNewlines(cx);
1229
+ let trigger = "";
1230
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1231
+ trigger = next(cx).value;
1232
+ }
1233
+ const effects = [];
1234
+ skipNewlines(cx);
1235
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
1236
+ next(cx);
1237
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1238
+ effects.push(next(cx).value);
1239
+ }
1240
+ skipNewlines(cx);
1241
+ }
1242
+ const cause = { type: "cause", trigger, effects };
1243
+ ast.causes.push(cause);
1244
+ ast.nodes.push(cause);
1245
+ onLog({ level: "info", event: "parse.cause", detail: cause });
1246
+ continue;
1247
+ }
1248
+ if (sym === "\u2726") {
1249
+ skipNewlines(cx);
1250
+ let source = "";
1251
+ let result = "";
1252
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1253
+ source = next(cx).value;
1254
+ }
1255
+ skipNewlines(cx);
1256
+ if (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
1257
+ next(cx);
1258
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1259
+ result = next(cx).value;
1260
+ }
1261
+ }
1262
+ const consequence = { type: "consequence", source, result };
1263
+ ast.consequences.push(consequence);
1264
+ ast.nodes.push(consequence);
1265
+ onLog({ level: "info", event: "parse.consequence", detail: consequence });
1266
+ continue;
1267
+ }
1268
+ if (sym === "\u{1D4DC}") {
1269
+ skipNewlines(cx);
1270
+ let name = "memory";
1271
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1272
+ name = next(cx).value;
1273
+ }
1274
+ let size;
1275
+ let persist = false;
1276
+ skipNewlines(cx);
1277
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1278
+ size = parseInt(next(cx).value, 10);
1279
+ }
1280
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "persist") {
1281
+ persist = true;
1282
+ next(cx);
1283
+ }
1284
+ const memory = { type: "memory", name, size, persist };
1285
+ ast.memories.push(memory);
1286
+ ast.nodes.push(memory);
1287
+ onLog({ level: "info", event: "parse.memory", detail: memory });
1288
+ continue;
1289
+ }
1290
+ if (sym === "\u267E") {
1291
+ skipNewlines(cx);
1292
+ let target = "";
1293
+ let storage;
1294
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1295
+ target = next(cx).value;
1296
+ }
1297
+ skipNewlines(cx);
1298
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1299
+ const s = peek(cx).value.toLowerCase();
1300
+ if (["local", "session", "db", "file"].includes(s)) {
1301
+ storage = s;
1302
+ next(cx);
1303
+ }
1304
+ }
1305
+ const persist = { type: "persist", target, storage };
1306
+ ast.persists.push(persist);
1307
+ ast.nodes.push(persist);
1308
+ onLog({ level: "info", event: "parse.persist", detail: persist });
1309
+ continue;
1310
+ }
1311
+ if (sym === "\u2302") {
1312
+ skipNewlines(cx);
1313
+ let name = "root";
1314
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1315
+ name = next(cx).value;
1316
+ }
1317
+ const children = [];
1318
+ skipNewlines(cx);
1319
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1320
+ next(cx);
1321
+ skipNewlines(cx);
1322
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1323
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1324
+ children.push(next(cx).value);
1325
+ } else {
1326
+ next(cx);
1327
+ }
1328
+ skipNewlines(cx);
1329
+ }
1330
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1331
+ next(cx);
1332
+ }
1333
+ const root = { type: "root", name, children };
1334
+ ast.roots.push(root);
1335
+ ast.nodes.push(root);
1336
+ onLog({ level: "info", event: "parse.root", detail: root });
1337
+ continue;
1338
+ }
1339
+ if (sym === "\u2610") {
1340
+ skipNewlines(cx);
1341
+ let name = "interface";
1342
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1343
+ name = next(cx).value;
1344
+ }
1345
+ const methods = [];
1346
+ skipNewlines(cx);
1347
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1348
+ next(cx);
1349
+ skipNewlines(cx);
1350
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1351
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1352
+ methods.push(next(cx).value);
1353
+ } else {
1354
+ next(cx);
1355
+ }
1356
+ skipNewlines(cx);
1357
+ }
1358
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1359
+ next(cx);
1360
+ }
1361
+ const iface = { type: "interface", name, methods };
1362
+ ast.interfaces.push(iface);
1363
+ ast.nodes.push(iface);
1364
+ onLog({ level: "info", event: "parse.interface", detail: iface });
1365
+ continue;
1366
+ }
1367
+ if (sym === "\u{1F441}") {
1368
+ skipNewlines(cx);
1369
+ let name = "visual";
1370
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1371
+ name = next(cx).value;
1372
+ }
1373
+ const props = {};
1374
+ skipNewlines(cx);
1375
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1376
+ next(cx);
1377
+ skipNewlines(cx);
1378
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1379
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1380
+ const key = next(cx).value;
1381
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
1382
+ next(cx);
1383
+ const val = peek(cx);
1384
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
1385
+ props[key] = next(cx).value;
1386
+ }
1387
+ } else {
1388
+ props[key] = true;
1389
+ }
1390
+ } else {
1391
+ next(cx);
1392
+ }
1393
+ skipNewlines(cx);
1394
+ }
1395
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1396
+ next(cx);
1397
+ }
1398
+ const visual = { type: "visual", name, props };
1399
+ ast.visuals.push(visual);
1400
+ ast.nodes.push(visual);
1401
+ onLog({ level: "info", event: "parse.visual", detail: visual });
1402
+ continue;
1403
+ }
1404
+ if (sym === "\u2328") {
1405
+ skipNewlines(cx);
1406
+ let name = "input";
1407
+ let inputType = "text";
1408
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1409
+ name = next(cx).value;
1410
+ }
1411
+ skipNewlines(cx);
1412
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1413
+ const t2 = peek(cx).value.toLowerCase();
1414
+ if (["text", "number", "file", "event"].includes(t2)) {
1415
+ inputType = t2;
1416
+ next(cx);
1417
+ }
1418
+ }
1419
+ const input = { type: "input", name, inputType };
1420
+ ast.inputs.push(input);
1421
+ ast.nodes.push(input);
1422
+ onLog({ level: "info", event: "parse.input", detail: input });
1423
+ continue;
1424
+ }
1425
+ if (sym === "\u23EC") {
1426
+ skipNewlines(cx);
1427
+ let target = "";
1428
+ let limit = 0;
1429
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1430
+ target = next(cx).value;
1431
+ }
1432
+ skipNewlines(cx);
1433
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1434
+ limit = parseInt(next(cx).value, 10);
1435
+ }
1436
+ const throttle = { type: "throttle", target, limit };
1437
+ ast.throttles.push(throttle);
1438
+ ast.nodes.push(throttle);
1439
+ onLog({ level: "info", event: "parse.throttle", detail: throttle });
1440
+ continue;
1441
+ }
1442
+ if (sym === "\u23EB") {
1443
+ skipNewlines(cx);
1444
+ let target = "";
1445
+ let factor;
1446
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1447
+ target = next(cx).value;
1448
+ }
1449
+ skipNewlines(cx);
1450
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1451
+ factor = parseFloat(next(cx).value);
1452
+ }
1453
+ const boost = { type: "boost", target, factor };
1454
+ ast.boosts.push(boost);
1455
+ ast.nodes.push(boost);
1456
+ onLog({ level: "info", event: "parse.boost", detail: boost });
1457
+ continue;
1458
+ }
1459
+ if (sym === "\u20B5") {
1460
+ skipNewlines(cx);
1461
+ let operation = "";
1462
+ let value = 0;
1463
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1464
+ operation = next(cx).value;
1465
+ }
1466
+ skipNewlines(cx);
1467
+ if (peek(cx) && peek(cx).type === "NUMBER" /* NUMBER */) {
1468
+ value = parseFloat(next(cx).value);
1469
+ }
1470
+ const cost = { type: "cost", operation, value };
1471
+ ast.costs.push(cost);
1472
+ ast.nodes.push(cost);
1473
+ onLog({ level: "info", event: "parse.cost", detail: cost });
1474
+ continue;
1475
+ }
1476
+ if (sym === "\u{1F512}") {
1477
+ skipNewlines(cx);
1478
+ let target = "";
1479
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1480
+ target = next(cx).value;
1481
+ }
1482
+ const lock = { type: "lock", target };
1483
+ ast.locks.push(lock);
1484
+ ast.nodes.push(lock);
1485
+ onLog({ level: "info", event: "parse.lock", detail: lock });
1486
+ continue;
1487
+ }
1488
+ if (sym === "\u{1F513}") {
1489
+ skipNewlines(cx);
1490
+ let target = "";
1491
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1492
+ target = next(cx).value;
1493
+ }
1494
+ const unlock = { type: "unlock", target };
1495
+ ast.unlocks.push(unlock);
1496
+ ast.nodes.push(unlock);
1497
+ onLog({ level: "info", event: "parse.unlock", detail: unlock });
1498
+ continue;
1499
+ }
1500
+ if (sym === "\xD8") {
1501
+ skipNewlines(cx);
1502
+ let target;
1503
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1504
+ target = next(cx).value;
1505
+ }
1506
+ const voidNode = { type: "void", target };
1507
+ ast.voids.push(voidNode);
1508
+ ast.nodes.push(voidNode);
1509
+ onLog({ level: "info", event: "parse.void", detail: voidNode });
1510
+ continue;
1511
+ }
1512
+ if (sym === "\u2B12") {
1513
+ skipNewlines(cx);
1514
+ let child = "";
1515
+ let parent = "";
1516
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1517
+ child = next(cx).value;
1518
+ }
1519
+ skipNewlines(cx);
1520
+ if (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
1521
+ next(cx);
1522
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1523
+ parent = next(cx).value;
1524
+ }
1525
+ }
1526
+ const inherit = { type: "inherit", child, parent };
1527
+ ast.inherits.push(inherit);
1528
+ ast.nodes.push(inherit);
1529
+ onLog({ level: "info", event: "parse.inherit", detail: inherit });
1530
+ continue;
1531
+ }
1532
+ if (sym === "\u2283") {
1533
+ skipNewlines(cx);
1534
+ let container = "";
1535
+ const items = [];
1536
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1537
+ container = next(cx).value;
1538
+ }
1539
+ skipNewlines(cx);
1540
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1541
+ next(cx);
1542
+ skipNewlines(cx);
1543
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1544
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1545
+ items.push(next(cx).value);
1546
+ } else {
1547
+ next(cx);
1548
+ }
1549
+ skipNewlines(cx);
1550
+ }
1551
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1552
+ next(cx);
1553
+ }
1554
+ const contains = { type: "contains", container, items };
1555
+ ast.contains.push(contains);
1556
+ ast.nodes.push(contains);
1557
+ onLog({ level: "info", event: "parse.contains", detail: contains });
1558
+ continue;
1559
+ }
1560
+ if (sym === "\u2714") {
1561
+ skipNewlines(cx);
1562
+ let target = "";
1563
+ const rules = [];
1564
+ if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1565
+ target = next(cx).value;
1566
+ }
1567
+ skipNewlines(cx);
1568
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1569
+ next(cx);
1570
+ skipNewlines(cx);
1571
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1572
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1573
+ rules.push(next(cx).value);
1574
+ } else {
1575
+ next(cx);
1576
+ }
1577
+ skipNewlines(cx);
1578
+ }
1579
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1580
+ next(cx);
1581
+ }
1582
+ const verify = { type: "verify", target, rules };
1583
+ ast.verifies.push(verify);
1584
+ ast.nodes.push(verify);
1585
+ onLog({ level: "info", event: "parse.verify", detail: verify });
1586
+ continue;
1587
+ }
1588
+ if (sym === "\u{1F4DC}") {
1589
+ skipNewlines(cx);
1590
+ let message = "";
1591
+ let level = "info";
1592
+ if (peek(cx) && (peek(cx).type === "STRING" /* STRING */ || peek(cx).type === "IDENTIFIER" /* IDENTIFIER */)) {
1593
+ message = next(cx).value;
1594
+ }
1595
+ skipNewlines(cx);
1596
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
1597
+ const lv = peek(cx).value.toLowerCase();
1598
+ if (["debug", "info", "warn", "error"].includes(lv)) {
1599
+ level = lv;
1600
+ next(cx);
1601
+ }
1602
+ }
1603
+ const logNode = { type: "log", message, level };
1604
+ ast.logNodes.push(logNode);
1605
+ ast.nodes.push(logNode);
1606
+ onLog({ level: "info", event: "parse.log", detail: logNode });
1607
+ continue;
1608
+ }
1609
+ if (sym === "\u27F3") {
1610
+ skipNewlines(cx);
1611
+ const steps = [];
1612
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1613
+ next(cx);
1614
+ skipNewlines(cx);
1615
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1616
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
1617
+ steps.push(next(cx).value);
1618
+ } else {
1619
+ next(cx);
1620
+ }
1621
+ skipNewlines(cx);
1622
+ }
1623
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1624
+ next(cx);
1625
+ } else if (peek(cx) && (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */)) {
1626
+ steps.push(next(cx).value);
1627
+ }
1628
+ const ev = { type: "evolve", steps };
1629
+ ast.evolve = ev;
1630
+ ast.nodes.push(ev);
1631
+ onLog({ level: "info", event: "parse.evolve", detail: ev });
1632
+ continue;
1633
+ }
1634
+ if (sym === "\u25A0") {
1635
+ skipNewlines(cx);
1636
+ const nameTok = peek(cx);
1637
+ if (!nameTok || nameTok.type !== "IDENTIFIER" /* IDENTIFIER */) {
1638
+ skipNewlines(cx);
1639
+ continue;
1640
+ }
1641
+ const name = next(cx).value;
1642
+ const props = {};
1643
+ skipNewlines(cx);
1644
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
1645
+ next(cx);
1646
+ skipNewlines(cx);
1647
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
1648
+ const p = peek(cx);
1649
+ if (p && p.type === "IDENTIFIER" /* IDENTIFIER */) {
1650
+ const key = next(cx).value;
1651
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
1652
+ next(cx);
1653
+ const val = peek(cx);
1654
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
1655
+ props[key] = next(cx).value;
1656
+ } else {
1657
+ props[key] = null;
1658
+ }
1659
+ } else {
1660
+ props[key] = null;
1661
+ }
1662
+ } else {
1663
+ next(cx);
1664
+ }
1665
+ skipNewlines(cx);
1666
+ }
1667
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
1668
+ next(cx);
1669
+ }
1670
+ const obj = { type: "object", name, props };
1671
+ ast.objects.push(obj);
1672
+ ast.nodes.push(obj);
1673
+ onLog({ level: "info", event: "parse.object", detail: obj });
1674
+ continue;
1675
+ }
1676
+ skipNewlines(cx);
1677
+ continue;
1678
+ }
1679
+ if (t.type === "SYMBOL" /* SYMBOL */ && t.value === "\u0394") {
1680
+ next(cx);
1681
+ }
1682
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */ && t.value.toLowerCase() === "\u0394") {
1683
+ next(cx);
1684
+ continue;
1685
+ }
1686
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */) {
1687
+ const val = t.value.toLowerCase();
1688
+ next(cx);
1689
+ skipNewlines(cx);
1690
+ continue;
1691
+ }
1692
+ next(cx);
1693
+ skipNewlines(cx);
1694
+ }
1695
+ return ast;
1696
+ }
1697
+ function parseFromCode(code, options) {
1698
+ const tokens = tokenize(code);
1699
+ return parseTokens(tokens, options);
1700
+ }
1701
+
1702
+ // src/parser.ts
1703
+ async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
1704
+ const fsPromises = await import("fs/promises");
1705
+ let attempt = 0;
1706
+ const tryWrite = async () => {
1707
+ attempt++;
1708
+ try {
1709
+ await fsPromises.appendFile(filePath, JSON.stringify(entry) + "\n", { encoding: "utf8" });
1710
+ if (onLog)
1711
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "logfile.write.success", detail: { file: filePath } });
1712
+ return;
1713
+ } catch (err) {
1714
+ const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "logfile.write.retry", detail: { attempt, error: String(err) } };
1715
+ if (onLog)
1716
+ onLog(errEntry);
1717
+ if (attempt < attempts) {
1718
+ setTimeout(() => {
1719
+ tryWrite().catch(() => {
1720
+ });
1721
+ }, delay);
1722
+ } else {
1723
+ const fatal = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.fatal", detail: { attempt, error: String(err) } };
1724
+ if (onLog)
1725
+ onLog(fatal);
1726
+ }
1727
+ }
1728
+ };
1729
+ tryWrite().catch(() => {
1730
+ });
1731
+ }
1732
+ function parse(code, options) {
1733
+ const ast = parseFromCode(code, options);
1734
+ ast.logs = ast.logs || [];
1735
+ return ast;
1736
+ }
1737
+
1738
+ // src/semantic/validate.ts
1739
+ function validateSemantic(ast, options) {
1740
+ const result = validateSemanticFull(ast, options);
1741
+ return result.errors;
1742
+ }
1743
+ function validateSemanticFull(ast, options) {
1744
+ const errors = [];
1745
+ const warnings = [];
1746
+ const pillars = {
1747
+ state: false,
1748
+ action: false,
1749
+ form: false,
1750
+ time: false,
1751
+ energy: false,
1752
+ memory: false,
1753
+ interface: false,
1754
+ security: false,
1755
+ evolve: false
1756
+ };
1757
+ const onLog = (e) => {
1758
+ const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
1759
+ if (options?.onLog)
1760
+ options.onLog(entry);
1761
+ };
1762
+ ast.functions = ast.functions || [];
1763
+ ast.modules = ast.modules || [];
1764
+ ast.objects = ast.objects || [];
1765
+ ast.events = ast.events || [];
1766
+ ast.securities = ast.securities || [];
1767
+ ast.memories = ast.memories || [];
1768
+ ast.interfaces = ast.interfaces || [];
1769
+ if (ast.system) {
1770
+ pillars.state = true;
1771
+ } else {
1772
+ warnings.push("No \u03A3 SYSTEM declared - consider adding a system name");
1773
+ }
1774
+ if (ast.substates?.length) {
1775
+ for (const sub of ast.substates) {
1776
+ if (sub.parent && !ast.substates.some((s) => s.name === sub.parent)) {
1777
+ warnings.push(`Substate '${sub.name}' references unknown parent '${sub.parent}'`);
1778
+ }
1779
+ }
1780
+ }
1781
+ if (ast.functions.length > 0) {
1782
+ pillars.action = true;
1783
+ }
1784
+ const fnMap = /* @__PURE__ */ new Map();
1785
+ for (const fn of ast.functions) {
1786
+ fnMap.set(fn.name, (fnMap.get(fn.name) || 0) + 1);
1787
+ }
1788
+ for (const [name, count] of fnMap.entries()) {
1789
+ if (count > 1) {
1790
+ const msg = `Duplicate function name: ${name}`;
1791
+ errors.push(msg);
1792
+ onLog({ level: "error", event: "parse.semantic.error", detail: { error: msg } });
1793
+ }
1794
+ }
1795
+ const knownFns = new Set(ast.functions.map((f) => f.name));
1796
+ for (const fn of ast.functions) {
1797
+ for (const step of fn.steps || []) {
1798
+ const token = step.raw.trim();
1799
+ if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(token) && !knownFns.has(token)) {
1800
+ const msg = `Undefined function reference in '${fn.name}': '${token}'`;
1801
+ errors.push(msg);
1802
+ onLog({ level: "warn", event: "parse.semantic.error", detail: { error: msg } });
1803
+ }
1804
+ }
1805
+ }
1806
+ if (ast.objects?.length || ast.classes?.length) {
1807
+ pillars.form = true;
1808
+ }
1809
+ if (ast.classes?.length) {
1810
+ const classNames = new Set(ast.classes.map((c) => c.name));
1811
+ for (const cls of ast.classes) {
1812
+ if (cls.extends && !classNames.has(cls.extends)) {
1813
+ warnings.push(`Class '${cls.name}' extends unknown class '${cls.extends}'`);
1814
+ }
1815
+ }
1816
+ }
1817
+ if (ast.inherits?.length) {
1818
+ const allNames = /* @__PURE__ */ new Set([
1819
+ ...ast.classes?.map((c) => c.name) || [],
1820
+ ...ast.objects?.map((o) => o.name) || []
1821
+ ]);
1822
+ for (const inh of ast.inherits) {
1823
+ if (!allNames.has(inh.parent)) {
1824
+ warnings.push(`Inherit: '${inh.child}' extends unknown '${inh.parent}'`);
1825
+ }
1826
+ }
1827
+ }
1828
+ if (ast.events?.length || ast.causes?.length || ast.loops?.length) {
1829
+ pillars.time = true;
1830
+ }
1831
+ if (ast.events?.length) {
1832
+ for (const evt of ast.events) {
1833
+ for (const handler of evt.handler || []) {
1834
+ if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(handler) && !knownFns.has(handler)) {
1835
+ warnings.push(`Event '${evt.name}' handler '${handler}' is not a known function`);
1836
+ }
1837
+ }
1838
+ }
1839
+ }
1840
+ if (ast.throttles?.length || ast.boosts?.length || ast.costs?.length) {
1841
+ pillars.energy = true;
1842
+ }
1843
+ if (ast.throttles?.length) {
1844
+ for (const t of ast.throttles) {
1845
+ if (t.limit <= 0) {
1846
+ errors.push(`Throttle '${t.target}' has invalid limit: ${t.limit}`);
1847
+ }
1848
+ }
1849
+ }
1850
+ if (ast.memories?.length || ast.persists?.length || ast.database) {
1851
+ pillars.memory = true;
1852
+ }
1853
+ if (ast.forms?.length || ast.inputs?.length || ast.visuals?.length || ast.interfaces?.length) {
1854
+ pillars.interface = true;
1855
+ }
1856
+ if (ast.securities?.length || ast.keys?.length || ast.sandboxes?.length) {
1857
+ pillars.security = true;
1858
+ }
1859
+ const validSecurityLevels = ["low", "medium", "high", "critical"];
1860
+ if (ast.securities?.length) {
1861
+ for (const sec of ast.securities) {
1862
+ if (sec.level && !validSecurityLevels.includes(sec.level.toLowerCase())) {
1863
+ warnings.push(`Security rule has unknown level '${sec.level}' (use: low, medium, high, critical)`);
1864
+ }
1865
+ }
1866
+ }
1867
+ if (ast.evolve?.steps?.length) {
1868
+ pillars.evolve = true;
1869
+ }
1870
+ const activePillars = Object.values(pillars).filter(Boolean).length;
1871
+ const score = Math.round(activePillars / 9 * 100);
1872
+ ast.errors = errors;
1873
+ if (errors.length > 0)
1874
+ console.debug("[semantic] errors", errors);
1875
+ return { errors, warnings, pillars, score };
1876
+ }
1877
+
1878
+ // src/evolve/stub.ts
1879
+ function applyEvolve(ast, options) {
1880
+ if (!ast.evolve || !ast.evolve.steps || ast.evolve.steps.length === 0) {
1881
+ return { changed: false, appliedSteps: [], skippedSteps: [] };
1882
+ }
1883
+ const onLog = options?.onLog;
1884
+ const steps = ast.evolve.steps;
1885
+ let changed = false;
1886
+ const appliedSteps = [];
1887
+ const skippedSteps = [];
1888
+ for (const step of steps) {
1889
+ const parts = step.trim().split(/\s+/);
1890
+ const command = parts[0]?.toLowerCase();
1891
+ let applied = false;
1892
+ switch (command) {
1893
+ case "rename": {
1894
+ if (parts.length >= 3) {
1895
+ const [, oldName, newName] = parts;
1896
+ for (const fn of ast.functions || []) {
1897
+ if (fn.name === oldName) {
1898
+ fn.name = newName;
1899
+ applied = true;
1900
+ if (onLog)
1901
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.rename", detail: { from: oldName, to: newName } });
1902
+ }
1903
+ }
1904
+ }
1905
+ break;
1906
+ }
1907
+ case "optimize": {
1908
+ if (parts.length >= 2) {
1909
+ const target = parts[1];
1910
+ for (const fn of ast.functions || []) {
1911
+ if (fn.name === target || target === "*") {
1912
+ fn.optimized = true;
1913
+ applied = true;
1914
+ if (onLog)
1915
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.optimize", detail: { target: fn.name } });
1916
+ }
1917
+ }
1918
+ }
1919
+ break;
1920
+ }
1921
+ case "inline": {
1922
+ if (parts.length >= 2) {
1923
+ const target = parts[1];
1924
+ for (const fn of ast.functions || []) {
1925
+ if (fn.name === target) {
1926
+ fn.inline = true;
1927
+ applied = true;
1928
+ if (onLog)
1929
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.inline", detail: { target } });
1930
+ }
1931
+ }
1932
+ }
1933
+ break;
1934
+ }
1935
+ case "memoize": {
1936
+ if (parts.length >= 2) {
1937
+ const target = parts[1];
1938
+ for (const fn of ast.functions || []) {
1939
+ if (fn.name === target) {
1940
+ fn.memoize = true;
1941
+ applied = true;
1942
+ if (onLog)
1943
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.memoize", detail: { target } });
1944
+ }
1945
+ }
1946
+ }
1947
+ break;
1948
+ }
1949
+ case "parallelize": {
1950
+ if (parts.length >= 2) {
1951
+ const target = parts[1];
1952
+ for (const fn of ast.functions || []) {
1953
+ if (fn.name === target) {
1954
+ fn.parallel = true;
1955
+ applied = true;
1956
+ if (onLog)
1957
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.parallelize", detail: { target } });
1958
+ }
1959
+ }
1960
+ }
1961
+ break;
1962
+ }
1963
+ case "deprecate": {
1964
+ if (parts.length >= 2) {
1965
+ const target = parts[1];
1966
+ for (const fn of ast.functions || []) {
1967
+ if (fn.name === target) {
1968
+ fn.deprecated = true;
1969
+ applied = true;
1970
+ if (onLog)
1971
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "evolve.deprecate", detail: { target } });
1972
+ }
1973
+ }
1974
+ }
1975
+ break;
1976
+ }
1977
+ case "secure": {
1978
+ if (parts.length >= 2) {
1979
+ const target = parts[1];
1980
+ for (const fn of ast.functions || []) {
1981
+ if (fn.name === target) {
1982
+ fn.secure = true;
1983
+ applied = true;
1984
+ if (onLog)
1985
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.secure", detail: { target } });
1986
+ }
1987
+ }
1988
+ }
1989
+ break;
1990
+ }
1991
+ case "cache": {
1992
+ if (parts.length >= 2) {
1993
+ const target = parts[1];
1994
+ for (const obj of ast.objects || []) {
1995
+ if (obj.name === target) {
1996
+ obj.cached = true;
1997
+ applied = true;
1998
+ if (onLog)
1999
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.cache", detail: { target } });
2000
+ }
2001
+ }
2002
+ }
2003
+ break;
2004
+ }
2005
+ case "throttle": {
2006
+ if (parts.length >= 3) {
2007
+ const target = parts[1];
2008
+ const limit = parseInt(parts[2], 10);
2009
+ for (const fn of ast.functions || []) {
2010
+ if (fn.name === target) {
2011
+ fn.throttle = limit;
2012
+ applied = true;
2013
+ if (onLog)
2014
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.throttle", detail: { target, limit } });
2015
+ }
2016
+ }
2017
+ }
2018
+ break;
2019
+ }
2020
+ case "observe": {
2021
+ if (parts.length >= 2) {
2022
+ const target = parts[1];
2023
+ for (const fn of ast.functions || []) {
2024
+ if (fn.name === target || target === "*") {
2025
+ fn.observable = true;
2026
+ applied = true;
2027
+ }
2028
+ }
2029
+ for (const obj of ast.objects || []) {
2030
+ if (obj.name === target || target === "*") {
2031
+ obj.observable = true;
2032
+ applied = true;
2033
+ }
2034
+ }
2035
+ if (applied && onLog) {
2036
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.observe", detail: { target } });
2037
+ }
2038
+ }
2039
+ break;
2040
+ }
2041
+ default:
2042
+ if (step.includes("otimizar") || step.includes("optimize")) {
2043
+ for (const fn of ast.functions || []) {
2044
+ fn.optimized = true;
2045
+ }
2046
+ applied = true;
2047
+ } else if (step.includes("adaptar") || step.includes("adapt")) {
2048
+ ast.adaptive = true;
2049
+ applied = true;
2050
+ }
2051
+ break;
2052
+ }
2053
+ if (applied) {
2054
+ changed = true;
2055
+ appliedSteps.push(step);
2056
+ } else {
2057
+ skippedSteps.push(step);
2058
+ }
2059
+ }
2060
+ if (changed && onLog) {
2061
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "evolve.summary", detail: { appliedSteps, skippedSteps } });
2062
+ }
2063
+ return { changed, appliedSteps, skippedSteps };
2064
+ }
2065
+
2066
+ // src/runENY.ts
2067
+ function runENY(code, options) {
2068
+ const hasSystem = /Σ\s+SYSTEM/i.test(code);
2069
+ if (!hasSystem) {
2070
+ if (options?.onLog) {
2071
+ options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
2072
+ }
2073
+ if (options?.logFile) {
2074
+ const attempts = options?.logRetryAttempts ?? 3;
2075
+ const delay = options?.logRetryDelayMs ?? 1e3;
2076
+ writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
2077
+ }
2078
+ return { raw: code, isEny: false, logs: [] };
2079
+ }
2080
+ const userOnLog = options?.onLog;
2081
+ let wrappedOnLog = userOnLog;
2082
+ if (options?.logFile) {
2083
+ const attempts = options?.logRetryAttempts ?? 3;
2084
+ const delay = options?.logRetryDelayMs ?? 1e3;
2085
+ wrappedOnLog = (e) => {
2086
+ if (userOnLog)
2087
+ userOnLog(e);
2088
+ writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
2089
+ };
2090
+ }
2091
+ const ast = parse(code, { ...options, onLog: wrappedOnLog });
2092
+ try {
2093
+ const errors = validateSemantic(ast, { onLog: wrappedOnLog });
2094
+ if (errors && errors.length > 0) {
2095
+ if (options?.onLog)
2096
+ options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "parse.semantic.summary", detail: { count: errors.length } });
2097
+ }
2098
+ } catch (err) {
2099
+ if (wrappedOnLog)
2100
+ wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.semantic.failed", detail: { error: String(err) } });
2101
+ }
2102
+ if (ast.evolve && ast.evolve.steps && ast.evolve.steps.length > 0) {
2103
+ try {
2104
+ const evolveResult = applyEvolve(ast, { onLog: wrappedOnLog });
2105
+ if (evolveResult.changed && wrappedOnLog) {
2106
+ wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "parse.evolve.summary", detail: { changed: true, stepsApplied: ast.evolve.steps.length } });
2107
+ }
2108
+ } catch (err) {
2109
+ if (wrappedOnLog)
2110
+ wrappedOnLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "parse.evolve.failed", detail: { error: String(err) } });
2111
+ }
2112
+ }
2113
+ ast.isEny = true;
2114
+ return ast;
2115
+ }
2116
+
2117
+ // src/transpile.ts
2118
+ function transpileToJS(ast, options) {
2119
+ const parts = [];
2120
+ const format = options?.moduleFormat || "esm";
2121
+ const isESM = format === "esm";
2122
+ parts.push("// Generated by enyosx-ai (transpiler)");
2123
+ if (ast.system) {
2124
+ parts.push(isESM ? `export const SYSTEM = ${JSON.stringify(ast.system)};` : `const SYSTEM = ${JSON.stringify(ast.system)};
2125
+ module.exports.SYSTEM = SYSTEM;`);
2126
+ }
2127
+ if (ast.mode) {
2128
+ parts.push(isESM ? `export const MODE = ${JSON.stringify(ast.mode)};` : `const MODE = ${JSON.stringify(ast.mode)};
2129
+ module.exports.MODE = MODE;`);
2130
+ }
2131
+ if (ast.ui) {
2132
+ parts.push(isESM ? `export const UI = ${JSON.stringify(ast.ui)};` : `const UI = ${JSON.stringify(ast.ui)};
2133
+ module.exports.UI = UI;`);
2134
+ }
2135
+ const functionNames = [];
2136
+ if (ast.functions && ast.functions.length) {
2137
+ for (const fn of ast.functions) {
2138
+ const args = (fn.args || []).join(", ");
2139
+ const bodyLines = (fn.steps || []).map((s) => ` // ${s.raw}`);
2140
+ functionNames.push(fn.name);
2141
+ if (isESM) {
2142
+ const fnCode = `export function ${fn.name}(${args}) {
2143
+ ${bodyLines.join("\n")}
2144
+ }`;
2145
+ parts.push(fnCode);
2146
+ } else {
2147
+ const fnCode = `function ${fn.name}(${args}) {
2148
+ ${bodyLines.join("\n")}
2149
+ }
2150
+ module.exports.${fn.name} = ${fn.name};`;
2151
+ parts.push(fnCode);
2152
+ }
2153
+ }
2154
+ }
2155
+ const iaNames = [];
2156
+ if (ast.ias && ast.ias.length) {
2157
+ for (const ia of ast.ias) {
2158
+ const body = ia.body.map((b) => ` // ${b}`).join("\n");
2159
+ const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
2160
+ const constName = `IA_${name}`;
2161
+ iaNames.push(constName);
2162
+ if (isESM) {
2163
+ const code = `export const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
2164
+ ${body}
2165
+ } };`;
2166
+ parts.push(code);
2167
+ } else {
2168
+ const code = `const ${constName} = { name: ${JSON.stringify(ia.name)}, run: () => {
2169
+ ${body}
2170
+ } };
2171
+ module.exports.${constName} = ${constName};`;
2172
+ parts.push(code);
2173
+ }
2174
+ }
2175
+ }
2176
+ const objectNames = [];
2177
+ if (ast.objects && ast.objects.length) {
2178
+ for (const o of ast.objects) {
2179
+ objectNames.push(o.name);
2180
+ parts.push(isESM ? `export const ${o.name} = ${JSON.stringify(o.props, null, 2)};` : `const ${o.name} = ${JSON.stringify(o.props, null, 2)};
2181
+ module.exports.${o.name} = ${o.name};`);
2182
+ }
2183
+ }
2184
+ const formNames = [];
2185
+ if (ast.forms && ast.forms.length) {
2186
+ for (const f of ast.forms) {
2187
+ const constName = `FORM_${f.name}`;
2188
+ formNames.push(constName);
2189
+ parts.push(isESM ? `export const ${constName} = ${JSON.stringify(f.props, null, 2)};` : `const ${constName} = ${JSON.stringify(f.props, null, 2)};
2190
+ module.exports.${constName} = ${constName};`);
2191
+ }
2192
+ }
2193
+ const animNames = [];
2194
+ if (ast.animations && ast.animations.length) {
2195
+ for (const a of ast.animations) {
2196
+ const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
2197
+ animNames.push(constName);
2198
+ parts.push(isESM ? `export const ${constName} = ${JSON.stringify(a.props, null, 2)};` : `const ${constName} = ${JSON.stringify(a.props, null, 2)};
2199
+ module.exports.${constName} = ${constName};`);
2200
+ }
2201
+ }
2202
+ if (ast.build) {
2203
+ parts.push(isESM ? `export const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};` : `const BUILD_TARGETS = ${JSON.stringify(ast.build.targets || [])};
2204
+ module.exports.BUILD_TARGETS = BUILD_TARGETS;`);
2205
+ }
2206
+ if (ast.evolve) {
2207
+ parts.push(isESM ? `export const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};` : `const EVOLVE_STEPS = ${JSON.stringify(ast.evolve.steps || [])};
2208
+ module.exports.EVOLVE_STEPS = EVOLVE_STEPS;`);
2209
+ }
2210
+ if (ast.database) {
2211
+ parts.push(isESM ? `export const DATABASE = ${JSON.stringify(ast.database)};` : `const DATABASE = ${JSON.stringify(ast.database)};
2212
+ module.exports.DATABASE = DATABASE;`);
2213
+ }
2214
+ if (ast.kernel) {
2215
+ parts.push(isESM ? `export const KERNEL = ${JSON.stringify(ast.kernel)};` : `const KERNEL = ${JSON.stringify(ast.kernel)};
2216
+ module.exports.KERNEL = KERNEL;`);
2217
+ }
2218
+ if (ast.training) {
2219
+ parts.push(isESM ? `export const TRAINING = ${JSON.stringify(ast.training)};` : `const TRAINING = ${JSON.stringify(ast.training)};
2220
+ module.exports.TRAINING = TRAINING;`);
2221
+ }
2222
+ if (ast.substates && ast.substates.length) {
2223
+ parts.push(isESM ? `export const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};` : `const SUBSTATES = ${JSON.stringify(ast.substates, null, 2)};
2224
+ module.exports.SUBSTATES = SUBSTATES;`);
2225
+ }
2226
+ if (ast.classes && ast.classes.length) {
2227
+ for (const c of ast.classes) {
2228
+ const className = c.name.replace(/[^a-zA-Z0-9_]/g, "_");
2229
+ parts.push(isESM ? `export class ${className} {
2230
+ constructor() {
2231
+ Object.assign(this, ${JSON.stringify(c.props)});
2232
+ }
2233
+ ${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
2234
+ }` : `class ${className} {
2235
+ constructor() {
2236
+ Object.assign(this, ${JSON.stringify(c.props)});
2237
+ }
2238
+ ${(c.methods || []).map((m) => ` ${m}() {}`).join("\n")}
2239
+ }
2240
+ module.exports.${className} = ${className};`);
2241
+ }
2242
+ }
2243
+ if (ast.loops && ast.loops.length) {
2244
+ parts.push(isESM ? `export const LOOPS = ${JSON.stringify(ast.loops, null, 2)};` : `const LOOPS = ${JSON.stringify(ast.loops, null, 2)};
2245
+ module.exports.LOOPS = LOOPS;`);
2246
+ }
2247
+ if (ast.events && ast.events.length) {
2248
+ for (const e of ast.events) {
2249
+ const eventName = `EVENT_${e.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
2250
+ parts.push(isESM ? `export const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };` : `const ${eventName} = { name: ${JSON.stringify(e.name)}, handler: ${JSON.stringify(e.handler || [])} };
2251
+ module.exports.${eventName} = ${eventName};`);
2252
+ }
2253
+ }
2254
+ if (ast.syncs && ast.syncs.length) {
2255
+ parts.push(isESM ? `export const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};` : `const SYNCS = ${JSON.stringify(ast.syncs, null, 2)};
2256
+ module.exports.SYNCS = SYNCS;`);
2257
+ }
2258
+ if (ast.timeouts && ast.timeouts.length) {
2259
+ parts.push(isESM ? `export const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};` : `const TIMEOUTS = ${JSON.stringify(ast.timeouts, null, 2)};
2260
+ module.exports.TIMEOUTS = TIMEOUTS;`);
2261
+ }
2262
+ if (ast.delays && ast.delays.length) {
2263
+ parts.push(isESM ? `export const DELAYS = ${JSON.stringify(ast.delays, null, 2)};` : `const DELAYS = ${JSON.stringify(ast.delays, null, 2)};
2264
+ module.exports.DELAYS = DELAYS;`);
2265
+ }
2266
+ if (ast.securities && ast.securities.length) {
2267
+ parts.push(isESM ? `export const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};` : `const SECURITY_RULES = ${JSON.stringify(ast.securities, null, 2)};
2268
+ module.exports.SECURITY_RULES = SECURITY_RULES;`);
2269
+ }
2270
+ if (ast.keys && ast.keys.length) {
2271
+ parts.push(isESM ? `export const KEYS = ${JSON.stringify(ast.keys, null, 2)};` : `const KEYS = ${JSON.stringify(ast.keys, null, 2)};
2272
+ module.exports.KEYS = KEYS;`);
2273
+ }
2274
+ if (ast.sandboxes && ast.sandboxes.length) {
2275
+ parts.push(isESM ? `export const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};` : `const SANDBOXES = ${JSON.stringify(ast.sandboxes, null, 2)};
2276
+ module.exports.SANDBOXES = SANDBOXES;`);
2277
+ }
2278
+ if (ast.causes && ast.causes.length) {
2279
+ parts.push(isESM ? `export const CAUSES = ${JSON.stringify(ast.causes, null, 2)};` : `const CAUSES = ${JSON.stringify(ast.causes, null, 2)};
2280
+ module.exports.CAUSES = CAUSES;`);
2281
+ }
2282
+ if (ast.consequences && ast.consequences.length) {
2283
+ parts.push(isESM ? `export const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};` : `const CONSEQUENCES = ${JSON.stringify(ast.consequences, null, 2)};
2284
+ module.exports.CONSEQUENCES = CONSEQUENCES;`);
2285
+ }
2286
+ if (ast.memories && ast.memories.length) {
2287
+ parts.push(isESM ? `export const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};` : `const MEMORIES = ${JSON.stringify(ast.memories, null, 2)};
2288
+ module.exports.MEMORIES = MEMORIES;`);
2289
+ }
2290
+ if (ast.persists && ast.persists.length) {
2291
+ parts.push(isESM ? `export const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};` : `const PERSISTS = ${JSON.stringify(ast.persists, null, 2)};
2292
+ module.exports.PERSISTS = PERSISTS;`);
2293
+ }
2294
+ if (ast.interfaces && ast.interfaces.length) {
2295
+ parts.push(isESM ? `export const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};` : `const INTERFACES = ${JSON.stringify(ast.interfaces, null, 2)};
2296
+ module.exports.INTERFACES = INTERFACES;`);
2297
+ }
2298
+ if (ast.visuals && ast.visuals.length) {
2299
+ parts.push(isESM ? `export const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};` : `const VISUALS = ${JSON.stringify(ast.visuals, null, 2)};
2300
+ module.exports.VISUALS = VISUALS;`);
2301
+ }
2302
+ if (ast.inputs && ast.inputs.length) {
2303
+ parts.push(isESM ? `export const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};` : `const INPUTS = ${JSON.stringify(ast.inputs, null, 2)};
2304
+ module.exports.INPUTS = INPUTS;`);
2305
+ }
2306
+ if (ast.throttles && ast.throttles.length) {
2307
+ parts.push(isESM ? `export const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};` : `const THROTTLES = ${JSON.stringify(ast.throttles, null, 2)};
2308
+ module.exports.THROTTLES = THROTTLES;`);
2309
+ }
2310
+ if (ast.boosts && ast.boosts.length) {
2311
+ parts.push(isESM ? `export const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};` : `const BOOSTS = ${JSON.stringify(ast.boosts, null, 2)};
2312
+ module.exports.BOOSTS = BOOSTS;`);
2313
+ }
2314
+ if (ast.costs && ast.costs.length) {
2315
+ parts.push(isESM ? `export const COSTS = ${JSON.stringify(ast.costs, null, 2)};` : `const COSTS = ${JSON.stringify(ast.costs, null, 2)};
2316
+ module.exports.COSTS = COSTS;`);
2317
+ }
2318
+ if (ast.locks && ast.locks.length) {
2319
+ parts.push(isESM ? `export const LOCKS = ${JSON.stringify(ast.locks, null, 2)};` : `const LOCKS = ${JSON.stringify(ast.locks, null, 2)};
2320
+ module.exports.LOCKS = LOCKS;`);
2321
+ }
2322
+ if (ast.unlocks && ast.unlocks.length) {
2323
+ parts.push(isESM ? `export const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};` : `const UNLOCKS = ${JSON.stringify(ast.unlocks, null, 2)};
2324
+ module.exports.UNLOCKS = UNLOCKS;`);
2325
+ }
2326
+ if (ast.voids && ast.voids.length) {
2327
+ parts.push(isESM ? `export const VOIDS = ${JSON.stringify(ast.voids, null, 2)};` : `const VOIDS = ${JSON.stringify(ast.voids, null, 2)};
2328
+ module.exports.VOIDS = VOIDS;`);
2329
+ }
2330
+ if (ast.inherits && ast.inherits.length) {
2331
+ parts.push(isESM ? `export const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};` : `const INHERITS = ${JSON.stringify(ast.inherits, null, 2)};
2332
+ module.exports.INHERITS = INHERITS;`);
2333
+ }
2334
+ if (ast.contains && ast.contains.length) {
2335
+ parts.push(isESM ? `export const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};` : `const CONTAINS = ${JSON.stringify(ast.contains, null, 2)};
2336
+ module.exports.CONTAINS = CONTAINS;`);
2337
+ }
2338
+ if (ast.verifies && ast.verifies.length) {
2339
+ parts.push(isESM ? `export const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};` : `const VERIFIES = ${JSON.stringify(ast.verifies, null, 2)};
2340
+ module.exports.VERIFIES = VERIFIES;`);
2341
+ }
2342
+ if (ast.logNodes && ast.logNodes.length) {
2343
+ parts.push(isESM ? `export const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};` : `const LOG_NODES = ${JSON.stringify(ast.logNodes, null, 2)};
2344
+ module.exports.LOG_NODES = LOG_NODES;`);
2345
+ }
2346
+ if (isESM) {
2347
+ parts.push("\nexport default { SYSTEM, MODE, UI };");
2348
+ } else {
2349
+ parts.push("\nmodule.exports.default = { SYSTEM, MODE, UI };");
2350
+ }
2351
+ return parts.join("\n\n");
2352
+ }
2353
+ function transpileToDTS(ast) {
2354
+ const lines = [];
2355
+ lines.push("// Type declarations generated by enyosx-ai");
2356
+ lines.push("");
2357
+ if (ast.system) {
2358
+ lines.push(`export declare const SYSTEM: string;`);
2359
+ }
2360
+ if (ast.mode) {
2361
+ lines.push(`export declare const MODE: string;`);
2362
+ }
2363
+ if (ast.ui) {
2364
+ lines.push(`export declare const UI: string;`);
2365
+ }
2366
+ if (ast.functions && ast.functions.length) {
2367
+ for (const fn of ast.functions) {
2368
+ const args = (fn.args || []).map((a) => `${a}: any`).join(", ");
2369
+ lines.push(`export declare function ${fn.name}(${args}): void;`);
2370
+ }
2371
+ }
2372
+ if (ast.ias && ast.ias.length) {
2373
+ for (const ia of ast.ias) {
2374
+ const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
2375
+ lines.push(`export declare const IA_${name}: { name: string; run: () => void };`);
2376
+ }
2377
+ }
2378
+ if (ast.objects && ast.objects.length) {
2379
+ for (const o of ast.objects) {
2380
+ const propTypes = Object.keys(o.props).map((k) => `${k}: string | null`).join("; ");
2381
+ lines.push(`export declare const ${o.name}: { ${propTypes} };`);
2382
+ }
2383
+ }
2384
+ if (ast.forms && ast.forms.length) {
2385
+ for (const f of ast.forms) {
2386
+ lines.push(`export declare const FORM_${f.name}: Record<string, any>;`);
2387
+ }
2388
+ }
2389
+ if (ast.animations && ast.animations.length) {
2390
+ for (const a of ast.animations) {
2391
+ const constName = `ANIMATION_${a.name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
2392
+ lines.push(`export declare const ${constName}: Record<string, any>;`);
2393
+ }
2394
+ }
2395
+ if (ast.build) {
2396
+ lines.push(`export declare const BUILD_TARGETS: string[];`);
2397
+ }
2398
+ if (ast.evolve) {
2399
+ lines.push(`export declare const EVOLVE_STEPS: string[];`);
2400
+ }
2401
+ lines.push("");
2402
+ lines.push("declare const _default: { SYSTEM: string; MODE: string; UI: string };");
2403
+ lines.push("export default _default;");
2404
+ return lines.join("\n");
2405
+ }
2406
+ function transpileToWAT(ast) {
2407
+ const lines = [];
2408
+ lines.push(";; WebAssembly Text Format generated by enyosx-ai");
2409
+ lines.push(";; This is a stub for future WASM compilation");
2410
+ lines.push("");
2411
+ lines.push("(module");
2412
+ lines.push(` ;; System: ${ast.system || "unnamed"}`);
2413
+ lines.push(` ;; Mode: ${ast.mode || "default"}`);
2414
+ lines.push("");
2415
+ lines.push(" ;; Memory declaration");
2416
+ lines.push(' (memory (export "memory") 1)');
2417
+ lines.push("");
2418
+ if (ast.system) {
2419
+ const bytes = Array.from(new TextEncoder().encode(ast.system)).join(" ");
2420
+ lines.push(` ;; System name data`);
2421
+ lines.push(` (data (i32.const 0) "${ast.system}")`);
2422
+ lines.push("");
2423
+ }
2424
+ if (ast.functions && ast.functions.length) {
2425
+ lines.push(" ;; Function stubs");
2426
+ for (const fn of ast.functions) {
2427
+ const params = (fn.args || []).map((_, i) => `(param $arg${i} i32)`).join(" ");
2428
+ lines.push(` (func (export "${fn.name}") ${params} (result i32)`);
2429
+ lines.push(` ;; Steps: ${(fn.steps || []).map((s) => s.raw).join(" -> ")}`);
2430
+ lines.push(` i32.const 0 ;; placeholder return`);
2431
+ lines.push(` )`);
2432
+ lines.push("");
2433
+ }
2434
+ }
2435
+ if (ast.ias && ast.ias.length) {
2436
+ lines.push(" ;; IA stubs (table references for future indirect calls)");
2437
+ for (const ia of ast.ias) {
2438
+ const name = ia.name.replace(/[^a-zA-Z0-9_]/g, "_");
2439
+ lines.push(` ;; IA: ${ia.name}`);
2440
+ lines.push(` (func (export "ia_${name}") (result i32)`);
2441
+ lines.push(` ;; Capabilities: ${ia.body.join(", ")}`);
2442
+ lines.push(` i32.const 1 ;; stub: IA ready`);
2443
+ lines.push(` )`);
2444
+ lines.push("");
2445
+ }
2446
+ }
2447
+ lines.push(" ;; Main entry point");
2448
+ lines.push(' (func (export "_start")');
2449
+ lines.push(" ;; Initialize system");
2450
+ lines.push(" nop");
2451
+ lines.push(" )");
2452
+ lines.push("");
2453
+ if (ast.build && ast.build.targets) {
2454
+ lines.push(` ;; Build targets: ${ast.build.targets.join(", ")}`);
2455
+ }
2456
+ lines.push(")");
2457
+ lines.push("");
2458
+ lines.push(";; To compile this WAT to WASM:");
2459
+ lines.push(";; wat2wasm output.wat -o output.wasm");
2460
+ lines.push(";; Or use wasm-pack for Rust-based compilation");
2461
+ return lines.join("\n");
2462
+ }
2463
+ function hasWASMTarget(ast) {
2464
+ if (!ast.build || !ast.build.targets)
2465
+ return false;
2466
+ return ast.build.targets.some(
2467
+ (t) => t.toLowerCase() === "wasm" || t.toLowerCase() === "webassembly" || t.toLowerCase() === "wat"
2468
+ );
2469
+ }
2470
+
2471
+ export {
2472
+ TokenType,
2473
+ SYMBOL_NAMES,
2474
+ tokenize,
2475
+ parse,
2476
+ validateSemantic,
2477
+ validateSemanticFull,
2478
+ applyEvolve,
2479
+ runENY,
2480
+ transpileToJS,
2481
+ transpileToDTS,
2482
+ transpileToWAT,
2483
+ hasWASMTarget
2484
+ };