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,677 @@
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["NEWLINE"] = "NEWLINE";
15
+ TokenType2["COMPARATOR"] = "COMPARATOR";
16
+ TokenType2["EOF"] = "EOF";
17
+ return TokenType2;
18
+ })(TokenType || {});
19
+ var SYMBOLS = /* @__PURE__ */ new Set(["\u03A3", "\u0394", "\u03A8", "\u03A9", "\u03A6", "\u0398", "\u039B", "\u2301", "\u2297"]);
20
+ function isWhitespace(ch) {
21
+ return ch === " " || ch === " " || ch === "\r";
22
+ }
23
+ function isNewline(ch) {
24
+ return ch === "\n";
25
+ }
26
+ function isDigit(ch) {
27
+ return /[0-9]/.test(ch);
28
+ }
29
+ function isIdentifierStart(ch) {
30
+ return /[A-Za-z_\p{L}]/u.test(ch);
31
+ }
32
+ function isIdentifierPart(ch) {
33
+ return /[A-Za-z0-9_\p{L}]/u.test(ch);
34
+ }
35
+ function tokenize(input) {
36
+ const tokens = [];
37
+ const len = input.length;
38
+ let i = 0;
39
+ while (i < len) {
40
+ const ch = input[i];
41
+ if (isWhitespace(ch)) {
42
+ i++;
43
+ continue;
44
+ }
45
+ if (isNewline(ch)) {
46
+ tokens.push({ type: "NEWLINE" /* NEWLINE */, value: "\n", pos: i });
47
+ i++;
48
+ continue;
49
+ }
50
+ if (SYMBOLS.has(ch)) {
51
+ tokens.push({ type: "SYMBOL" /* SYMBOL */, value: ch, pos: i });
52
+ i++;
53
+ continue;
54
+ }
55
+ if (ch === "\u2192" || ch === "-" && input[i + 1] === ">") {
56
+ if (ch === "\u2192") {
57
+ tokens.push({ type: "ARROW" /* ARROW */, value: "\u2192", pos: i });
58
+ i++;
59
+ } else {
60
+ tokens.push({ type: "ARROW" /* ARROW */, value: "->", pos: i });
61
+ i += 2;
62
+ }
63
+ continue;
64
+ }
65
+ if (ch === "{") {
66
+ tokens.push({ type: "LBRACE" /* LBRACE */, value: "{", pos: i });
67
+ i++;
68
+ continue;
69
+ }
70
+ if (ch === "}") {
71
+ tokens.push({ type: "RBRACE" /* RBRACE */, value: "}", pos: i });
72
+ i++;
73
+ continue;
74
+ }
75
+ if (ch === "(") {
76
+ tokens.push({ type: "LPAREN" /* LPAREN */, value: "(", pos: i });
77
+ i++;
78
+ continue;
79
+ }
80
+ if (ch === ")") {
81
+ tokens.push({ type: "RPAREN" /* RPAREN */, value: ")", pos: i });
82
+ i++;
83
+ continue;
84
+ }
85
+ if (ch === ":") {
86
+ tokens.push({ type: "COLON" /* COLON */, value: ":", pos: i });
87
+ i++;
88
+ continue;
89
+ }
90
+ if (ch === ",") {
91
+ tokens.push({ type: "COMMA" /* COMMA */, value: ",", pos: i });
92
+ i++;
93
+ continue;
94
+ }
95
+ if (ch === "=" && input[i + 1] === "=" || ch === "!" && input[i + 1] === "=" || ch === ">" && input[i + 1] === "=" || ch === "<" && input[i + 1] === "=") {
96
+ tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: input.substr(i, 2), pos: i });
97
+ i += 2;
98
+ continue;
99
+ }
100
+ if (ch === ">" || ch === "<") {
101
+ tokens.push({ type: "COMPARATOR" /* COMPARATOR */, value: ch, pos: i });
102
+ i++;
103
+ continue;
104
+ }
105
+ if (ch === '"') {
106
+ let j = i + 1;
107
+ let out = "";
108
+ while (j < len) {
109
+ if (input[j] === "\\" && j + 1 < len) {
110
+ out += input[j + 1];
111
+ j += 2;
112
+ continue;
113
+ }
114
+ if (input[j] === '"') {
115
+ break;
116
+ }
117
+ out += input[j];
118
+ j++;
119
+ }
120
+ tokens.push({ type: "STRING" /* STRING */, value: out, pos: i });
121
+ i = j + 1;
122
+ continue;
123
+ }
124
+ if (isDigit(ch)) {
125
+ let j = i;
126
+ let val = "";
127
+ while (j < len && isDigit(input[j])) {
128
+ val += input[j];
129
+ j++;
130
+ }
131
+ tokens.push({ type: "NUMBER" /* NUMBER */, value: val, pos: i });
132
+ i = j;
133
+ continue;
134
+ }
135
+ if (isIdentifierStart(ch)) {
136
+ let j = i;
137
+ let val = "";
138
+ while (j < len && isIdentifierPart(input[j])) {
139
+ val += input[j];
140
+ j++;
141
+ }
142
+ tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: val, pos: i });
143
+ i = j;
144
+ continue;
145
+ }
146
+ tokens.push({ type: "IDENTIFIER" /* IDENTIFIER */, value: ch, pos: i });
147
+ i++;
148
+ }
149
+ tokens.push({ type: "EOF" /* EOF */, value: "", pos: i });
150
+ return tokens;
151
+ }
152
+
153
+ // src/parser/ebnfParser.ts
154
+ function peek(cx) {
155
+ return cx.tokens[cx.i];
156
+ }
157
+ function next(cx) {
158
+ return cx.tokens[cx.i++];
159
+ }
160
+ function eat(cx, type, value) {
161
+ const t = peek(cx);
162
+ if (!t)
163
+ throw new Error(`Unexpected EOF, expected ${type}`);
164
+ if (t.type !== type)
165
+ throw new Error(`Expected token ${type} but got ${t.type} ('${t.value}') at ${t.pos}`);
166
+ if (value !== void 0 && t.value !== value)
167
+ throw new Error(`Expected token value ${value} but got '${t.value}' at ${t.pos}`);
168
+ return next(cx);
169
+ }
170
+ function skipNewlines(cx) {
171
+ while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
172
+ next(cx);
173
+ }
174
+ function parseTokens(tokens, options) {
175
+ const cx = { tokens, i: 0 };
176
+ const ast = {
177
+ raw: tokens.map((t) => t.value).join(" "),
178
+ functions: [],
179
+ ias: [],
180
+ nodes: [],
181
+ modules: [],
182
+ objects: [],
183
+ forms: [],
184
+ animations: [],
185
+ logic: [],
186
+ parallels: [],
187
+ build: null,
188
+ evolve: null,
189
+ targets: [],
190
+ version: null,
191
+ logs: []
192
+ };
193
+ const onLog = (e) => {
194
+ const entry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...e };
195
+ ast.logs.push(entry);
196
+ if (options?.onLog)
197
+ options.onLog(entry);
198
+ };
199
+ skipNewlines(cx);
200
+ while (peek(cx) && peek(cx).type !== "EOF" /* EOF */) {
201
+ const t = peek(cx);
202
+ if (t.type === "SYMBOL" /* SYMBOL */) {
203
+ const sym = t.value;
204
+ next(cx);
205
+ skipNewlines(cx);
206
+ while (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
207
+ next(cx);
208
+ const ident = peek(cx);
209
+ if (!ident)
210
+ break;
211
+ const kw = ident.type === "IDENTIFIER" /* IDENTIFIER */ ? ident.value.toUpperCase() : void 0;
212
+ if (sym === "\u03A3" && kw === "SYSTEM") {
213
+ next(cx);
214
+ skipNewlines(cx);
215
+ const nameTok = eat(cx, "STRING" /* STRING */);
216
+ ast.system = nameTok.value;
217
+ onLog({ level: "info", event: "parse.system", detail: { name: ast.system } });
218
+ skipNewlines(cx);
219
+ continue;
220
+ }
221
+ if (sym === "\u03A3" && kw === "TARGET") {
222
+ next(cx);
223
+ skipNewlines(cx);
224
+ const targets = [];
225
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "EOF" /* EOF */) {
226
+ const v = peek(cx);
227
+ if (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */) {
228
+ targets.push(v.value);
229
+ next(cx);
230
+ } else if (v.type === "COMMA" /* COMMA */) {
231
+ next(cx);
232
+ } else {
233
+ break;
234
+ }
235
+ }
236
+ ast.targets = [...ast.targets || [], ...targets];
237
+ onLog({ level: "info", event: "parse.target", detail: { targets } });
238
+ skipNewlines(cx);
239
+ continue;
240
+ }
241
+ if (sym === "\u03A3" && kw === "MODE") {
242
+ next(cx);
243
+ skipNewlines(cx);
244
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
245
+ ast.mode = v.value;
246
+ onLog({ level: "info", event: "parse.mode", detail: { mode: ast.mode } });
247
+ skipNewlines(cx);
248
+ continue;
249
+ }
250
+ if (sym === "\u03A3" && kw === "UI") {
251
+ next(cx);
252
+ skipNewlines(cx);
253
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
254
+ ast.ui = v.value;
255
+ onLog({ level: "info", event: "parse.ui", detail: { ui: ast.ui } });
256
+ skipNewlines(cx);
257
+ continue;
258
+ }
259
+ if (sym === "\u03A3" && kw === "MODULE") {
260
+ next(cx);
261
+ skipNewlines(cx);
262
+ const nameTok = eat(cx, "STRING" /* STRING */);
263
+ const module = { type: "module", name: nameTok.value };
264
+ ast.modules.push(module);
265
+ ast.nodes.push(module);
266
+ onLog({ level: "info", event: "parse.module", detail: module });
267
+ skipNewlines(cx);
268
+ continue;
269
+ }
270
+ if (sym === "\u03A3" && kw === "BUILD") {
271
+ next(cx);
272
+ skipNewlines(cx);
273
+ eat(cx, "LBRACE" /* LBRACE */);
274
+ const targets = [];
275
+ skipNewlines(cx);
276
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
277
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
278
+ eat(cx, "COLON" /* COLON */);
279
+ const val = peek(cx);
280
+ if (val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "STRING" /* STRING */) {
281
+ targets.push(val.value);
282
+ next(cx);
283
+ } else {
284
+ throw new Error("Expected identifier or string for build target");
285
+ }
286
+ skipNewlines(cx);
287
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
288
+ next(cx);
289
+ skipNewlines(cx);
290
+ }
291
+ eat(cx, "RBRACE" /* RBRACE */);
292
+ const b = { type: "build", targets };
293
+ ast.build = b;
294
+ ast.nodes.push(b);
295
+ onLog({ level: "info", event: "parse.build", detail: b });
296
+ skipNewlines(cx);
297
+ continue;
298
+ }
299
+ if (sym === "\u0394") {
300
+ let nameTok = null;
301
+ if (kw === "FUNCTION") {
302
+ next(cx);
303
+ skipNewlines(cx);
304
+ const tname = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
305
+ nameTok = tname;
306
+ } else {
307
+ if (ident.type === "IDENTIFIER" /* IDENTIFIER */) {
308
+ nameTok = next(cx);
309
+ }
310
+ }
311
+ if (!nameTok) {
312
+ onLog({ level: "warn", event: "parse.function.missing.name" });
313
+ skipNewlines(cx);
314
+ continue;
315
+ }
316
+ skipNewlines(cx);
317
+ let args = [];
318
+ if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
319
+ next(cx);
320
+ skipNewlines(cx);
321
+ while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */) {
322
+ const arg = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
323
+ args.push(arg.value);
324
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
325
+ next(cx);
326
+ skipNewlines(cx);
327
+ }
328
+ eat(cx, "RPAREN" /* RPAREN */);
329
+ }
330
+ const steps = [];
331
+ skipNewlines(cx);
332
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
333
+ next(cx);
334
+ const bodyTok = peek(cx);
335
+ if (bodyTok && (bodyTok.type === "IDENTIFIER" /* IDENTIFIER */ || bodyTok.type === "STRING" /* STRING */)) {
336
+ steps.push({ raw: bodyTok.value });
337
+ next(cx);
338
+ }
339
+ skipNewlines(cx);
340
+ }
341
+ onLog({ level: "info", event: "parse.function.start", detail: { name: nameTok.value, args } });
342
+ const fn = { type: "function", name: nameTok.value, args, steps };
343
+ ast.functions.push(fn);
344
+ ast.nodes.push(fn);
345
+ onLog({ level: "info", event: "parse.function.end", detail: fn });
346
+ continue;
347
+ }
348
+ if (sym === "\u03A8") {
349
+ if (kw === "IA") {
350
+ next(cx);
351
+ skipNewlines(cx);
352
+ const nameTok = peek(cx);
353
+ let name = "ia";
354
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
355
+ name = next(cx).value;
356
+ }
357
+ const body = [];
358
+ skipNewlines(cx);
359
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
360
+ next(cx);
361
+ skipNewlines(cx);
362
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
363
+ const cap = peek(cx);
364
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
365
+ body.push(cap.value);
366
+ next(cx);
367
+ } else {
368
+ next(cx);
369
+ }
370
+ skipNewlines(cx);
371
+ }
372
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
373
+ next(cx);
374
+ } else {
375
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */ && peek(cx).type !== "NEWLINE" /* NEWLINE */) {
376
+ const cap = peek(cx);
377
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
378
+ body.push(cap.value);
379
+ next(cx);
380
+ } else
381
+ break;
382
+ skipNewlines(cx);
383
+ }
384
+ }
385
+ const ia = { type: "ia", name, body };
386
+ ast.ias.push(ia);
387
+ ast.nodes.push(ia);
388
+ onLog({ level: "info", event: "parse.ia", detail: ia });
389
+ continue;
390
+ }
391
+ skipNewlines(cx);
392
+ continue;
393
+ }
394
+ if (sym === "\u03A9") {
395
+ skipNewlines(cx);
396
+ const nameTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
397
+ const name = nameTok.value;
398
+ const props = {};
399
+ skipNewlines(cx);
400
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
401
+ next(cx);
402
+ skipNewlines(cx);
403
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
404
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
405
+ skipNewlines(cx);
406
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
407
+ next(cx);
408
+ skipNewlines(cx);
409
+ const val = peek(cx);
410
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
411
+ props[p.value] = val.value;
412
+ next(cx);
413
+ } else {
414
+ props[p.value] = null;
415
+ }
416
+ } else {
417
+ props[p.value] = null;
418
+ }
419
+ skipNewlines(cx);
420
+ }
421
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
422
+ next(cx);
423
+ }
424
+ const obj = { type: "object", name, props };
425
+ ast.objects.push(obj);
426
+ ast.nodes.push(obj);
427
+ onLog({ level: "info", event: "parse.object", detail: obj });
428
+ continue;
429
+ }
430
+ if (sym === "\u03A6") {
431
+ skipNewlines(cx);
432
+ let name = "form";
433
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx + 1) && peek(cx + 1).type !== "LBRACE" /* LBRACE */) {
434
+ name = next(cx).value;
435
+ }
436
+ const props = {};
437
+ skipNewlines(cx);
438
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
439
+ next(cx);
440
+ skipNewlines(cx);
441
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
442
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
443
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
444
+ eat(cx, "COLON" /* COLON */);
445
+ const val = peek(cx);
446
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
447
+ props[key.value] = val.value;
448
+ next(cx);
449
+ } else {
450
+ props[key.value] = true;
451
+ }
452
+ } else {
453
+ next(cx);
454
+ }
455
+ skipNewlines(cx);
456
+ }
457
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
458
+ next(cx);
459
+ }
460
+ const form = { type: "form", name, props };
461
+ ast.forms.push(form);
462
+ ast.nodes.push(form);
463
+ onLog({ level: "info", event: "parse.form", detail: form });
464
+ continue;
465
+ }
466
+ if (sym === "\u0398") {
467
+ skipNewlines(cx);
468
+ const maybeAnim = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
469
+ if (maybeAnim.value.toLowerCase() !== "animation") {
470
+ onLog({ level: "warn", event: "parse.animation.missing.keyword" });
471
+ continue;
472
+ }
473
+ skipNewlines(cx);
474
+ const nameTok = peek(cx);
475
+ let name = "animation";
476
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
477
+ name = next(cx).value;
478
+ }
479
+ const props = {};
480
+ skipNewlines(cx);
481
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */) {
482
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
483
+ const key = next(cx).value;
484
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
485
+ next(cx);
486
+ const val = peek(cx);
487
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "NUMBER" /* NUMBER */ || val.type === "IDENTIFIER" /* IDENTIFIER */)) {
488
+ props[key] = val.value;
489
+ next(cx);
490
+ }
491
+ } else {
492
+ props[key] = true;
493
+ }
494
+ } else {
495
+ break;
496
+ }
497
+ skipNewlines(cx);
498
+ }
499
+ const anim = { type: "animation", name, props };
500
+ ast.animations.push(anim);
501
+ ast.nodes.push(anim);
502
+ onLog({ level: "info", event: "parse.animation", detail: anim });
503
+ continue;
504
+ }
505
+ if (sym === "\u039B") {
506
+ skipNewlines(cx);
507
+ const ifTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
508
+ if (ifTok.value.toLowerCase() !== "if") {
509
+ onLog({ level: "warn", event: "parse.logic.missing.if" });
510
+ continue;
511
+ }
512
+ const leftTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
513
+ let leftName = leftTok.value;
514
+ while (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value === ".") {
515
+ next(cx);
516
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
517
+ leftName += "." + p.value;
518
+ }
519
+ const comp = eat(cx, "COMPARATOR" /* COMPARATOR */);
520
+ const right = peek(cx);
521
+ if (!right || !(right.type === "STRING" /* STRING */ || right.type === "NUMBER" /* NUMBER */ || right.type === "IDENTIFIER" /* IDENTIFIER */))
522
+ throw new Error("Invalid logic right-hand side");
523
+ next(cx);
524
+ const rule = `${leftName} ${comp.value} ${right.value}`;
525
+ const trueFlow = [];
526
+ const falseFlow = [];
527
+ skipNewlines(cx);
528
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
529
+ next(cx);
530
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
531
+ trueFlow.push(step.value);
532
+ skipNewlines(cx);
533
+ }
534
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "else") {
535
+ next(cx);
536
+ skipNewlines(cx);
537
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
538
+ next(cx);
539
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
540
+ falseFlow.push(step.value);
541
+ skipNewlines(cx);
542
+ }
543
+ }
544
+ const logic = { type: "logic", rule, trueFlow, falseFlow };
545
+ ast.logic.push(logic);
546
+ ast.nodes.push(logic);
547
+ onLog({ level: "info", event: "parse.logic", detail: logic });
548
+ continue;
549
+ }
550
+ if (sym === "\u2297") {
551
+ skipNewlines(cx);
552
+ const items = [];
553
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
554
+ next(cx);
555
+ skipNewlines(cx);
556
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
557
+ const parts = [];
558
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "RBRACE" /* RBRACE */) {
559
+ const p = peek(cx);
560
+ if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */ || p.type === "NUMBER" /* NUMBER */) {
561
+ parts.push(next(cx).value);
562
+ } else {
563
+ next(cx);
564
+ }
565
+ }
566
+ if (parts.length > 0)
567
+ items.push(parts.join(" "));
568
+ if (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
569
+ next(cx);
570
+ skipNewlines(cx);
571
+ }
572
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
573
+ next(cx);
574
+ }
575
+ const par = { type: "parallel", items };
576
+ ast.parallels.push(par);
577
+ ast.nodes.push(par);
578
+ onLog({ level: "info", event: "parse.parallel", detail: par });
579
+ continue;
580
+ }
581
+ skipNewlines(cx);
582
+ continue;
583
+ }
584
+ if (t.type === "SYMBOL" /* SYMBOL */ && t.value === "\u0394") {
585
+ next(cx);
586
+ }
587
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */ && t.value.toLowerCase() === "\u0394") {
588
+ next(cx);
589
+ continue;
590
+ }
591
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */) {
592
+ const val = t.value.toLowerCase();
593
+ next(cx);
594
+ skipNewlines(cx);
595
+ continue;
596
+ }
597
+ next(cx);
598
+ skipNewlines(cx);
599
+ }
600
+ return ast;
601
+ }
602
+ function parseFromCode(code, options) {
603
+ const tokens = tokenize(code);
604
+ return parseTokens(tokens, options);
605
+ }
606
+
607
+ // src/parser.ts
608
+ async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
609
+ const fsPromises = await import("fs/promises");
610
+ let attempt = 0;
611
+ const tryWrite = async () => {
612
+ attempt++;
613
+ try {
614
+ await fsPromises.appendFile(filePath, JSON.stringify(entry) + "\n", { encoding: "utf8" });
615
+ if (onLog)
616
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "logfile.write.success", detail: { file: filePath } });
617
+ return;
618
+ } catch (err) {
619
+ const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "logfile.write.retry", detail: { attempt, error: String(err) } };
620
+ if (onLog)
621
+ onLog(errEntry);
622
+ if (attempt < attempts) {
623
+ setTimeout(() => {
624
+ tryWrite().catch(() => {
625
+ });
626
+ }, delay);
627
+ } else {
628
+ const fatal = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.fatal", detail: { attempt, error: String(err) } };
629
+ if (onLog)
630
+ onLog(fatal);
631
+ }
632
+ }
633
+ };
634
+ tryWrite().catch(() => {
635
+ });
636
+ }
637
+ function parse(code, options) {
638
+ const ast = parseFromCode(code, options);
639
+ ast.logs = ast.logs || [];
640
+ return ast;
641
+ }
642
+
643
+ // src/runENY.ts
644
+ function runENY(code, options) {
645
+ const hasSystem = /Σ\s+SYSTEM/i.test(code);
646
+ if (!hasSystem) {
647
+ if (options?.onLog) {
648
+ options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
649
+ }
650
+ if (options?.logFile) {
651
+ const attempts = options?.logRetryAttempts ?? 3;
652
+ const delay = options?.logRetryDelayMs ?? 1e3;
653
+ writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
654
+ }
655
+ return { raw: code, isEny: false, logs: [] };
656
+ }
657
+ const userOnLog = options?.onLog;
658
+ let wrappedOnLog = userOnLog;
659
+ if (options?.logFile) {
660
+ const attempts = options?.logRetryAttempts ?? 3;
661
+ const delay = options?.logRetryDelayMs ?? 1e3;
662
+ wrappedOnLog = (e) => {
663
+ if (userOnLog)
664
+ userOnLog(e);
665
+ writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
666
+ };
667
+ }
668
+ const ast = parse(code, { ...options, onLog: wrappedOnLog });
669
+ ast.isEny = true;
670
+ return ast;
671
+ }
672
+
673
+ export {
674
+ TokenType,
675
+ tokenize,
676
+ runENY
677
+ };