enyosx-ai 0.1.0

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