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