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