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