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,681 @@
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
+ if (ident.type !== "IDENTIFIER" /* IDENTIFIER */) {
212
+ next(cx);
213
+ continue;
214
+ }
215
+ const kw = ident.value.toUpperCase();
216
+ if (sym === "\u03A3" && kw === "SYSTEM") {
217
+ next(cx);
218
+ skipNewlines(cx);
219
+ const nameTok = eat(cx, "STRING" /* STRING */);
220
+ ast.system = nameTok.value;
221
+ onLog({ level: "info", event: "parse.system", detail: { name: ast.system } });
222
+ skipNewlines(cx);
223
+ continue;
224
+ }
225
+ if (sym === "\u03A3" && kw === "TARGET") {
226
+ next(cx);
227
+ skipNewlines(cx);
228
+ const targets = [];
229
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "EOF" /* EOF */) {
230
+ const v = peek(cx);
231
+ if (v.type === "IDENTIFIER" /* IDENTIFIER */ || v.type === "STRING" /* STRING */) {
232
+ targets.push(v.value);
233
+ next(cx);
234
+ } else if (v.type === "COMMA" /* COMMA */) {
235
+ next(cx);
236
+ } else {
237
+ break;
238
+ }
239
+ }
240
+ ast.targets = [...ast.targets || [], ...targets];
241
+ onLog({ level: "info", event: "parse.target", detail: { targets } });
242
+ skipNewlines(cx);
243
+ continue;
244
+ }
245
+ if (sym === "\u03A3" && kw === "MODE") {
246
+ next(cx);
247
+ skipNewlines(cx);
248
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
249
+ ast.mode = v.value;
250
+ onLog({ level: "info", event: "parse.mode", detail: { mode: ast.mode } });
251
+ skipNewlines(cx);
252
+ continue;
253
+ }
254
+ if (sym === "\u03A3" && kw === "UI") {
255
+ next(cx);
256
+ skipNewlines(cx);
257
+ const v = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
258
+ ast.ui = v.value;
259
+ onLog({ level: "info", event: "parse.ui", detail: { ui: ast.ui } });
260
+ skipNewlines(cx);
261
+ continue;
262
+ }
263
+ if (sym === "\u03A3" && kw === "MODULE") {
264
+ next(cx);
265
+ skipNewlines(cx);
266
+ const nameTok = eat(cx, "STRING" /* STRING */);
267
+ const module = { type: "module", name: nameTok.value };
268
+ ast.modules.push(module);
269
+ ast.nodes.push(module);
270
+ onLog({ level: "info", event: "parse.module", detail: module });
271
+ skipNewlines(cx);
272
+ continue;
273
+ }
274
+ if (sym === "\u03A3" && kw === "BUILD") {
275
+ next(cx);
276
+ skipNewlines(cx);
277
+ eat(cx, "LBRACE" /* LBRACE */);
278
+ const targets = [];
279
+ skipNewlines(cx);
280
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
281
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
282
+ eat(cx, "COLON" /* COLON */);
283
+ const val = peek(cx);
284
+ if (val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "STRING" /* STRING */) {
285
+ targets.push(val.value);
286
+ next(cx);
287
+ } else {
288
+ throw new Error("Expected identifier or string for build target");
289
+ }
290
+ skipNewlines(cx);
291
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
292
+ next(cx);
293
+ skipNewlines(cx);
294
+ }
295
+ eat(cx, "RBRACE" /* RBRACE */);
296
+ const b = { type: "build", targets };
297
+ ast.build = b;
298
+ ast.nodes.push(b);
299
+ onLog({ level: "info", event: "parse.build", detail: b });
300
+ skipNewlines(cx);
301
+ continue;
302
+ }
303
+ if (sym === "\u0394") {
304
+ let nameTok = null;
305
+ if (kw === "FUNCTION") {
306
+ next(cx);
307
+ skipNewlines(cx);
308
+ const tname = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
309
+ nameTok = tname;
310
+ } else {
311
+ if (ident.type === "IDENTIFIER" /* IDENTIFIER */) {
312
+ nameTok = next(cx);
313
+ }
314
+ }
315
+ if (!nameTok) {
316
+ onLog({ level: "warn", event: "parse.function.missing.name" });
317
+ skipNewlines(cx);
318
+ continue;
319
+ }
320
+ skipNewlines(cx);
321
+ let args = [];
322
+ if (peek(cx) && peek(cx).type === "LPAREN" /* LPAREN */) {
323
+ next(cx);
324
+ skipNewlines(cx);
325
+ while (peek(cx) && peek(cx).type !== "RPAREN" /* RPAREN */) {
326
+ const arg = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
327
+ args.push(arg.value);
328
+ if (peek(cx) && peek(cx).type === "COMMA" /* COMMA */)
329
+ next(cx);
330
+ skipNewlines(cx);
331
+ }
332
+ eat(cx, "RPAREN" /* RPAREN */);
333
+ }
334
+ const steps = [];
335
+ skipNewlines(cx);
336
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
337
+ next(cx);
338
+ const bodyTok = peek(cx);
339
+ if (bodyTok && (bodyTok.type === "IDENTIFIER" /* IDENTIFIER */ || bodyTok.type === "STRING" /* STRING */)) {
340
+ steps.push({ raw: bodyTok.value });
341
+ next(cx);
342
+ }
343
+ skipNewlines(cx);
344
+ }
345
+ onLog({ level: "info", event: "parse.function.start", detail: { name: nameTok.value, args } });
346
+ const fn = { type: "function", name: nameTok.value, args, steps };
347
+ ast.functions.push(fn);
348
+ ast.nodes.push(fn);
349
+ onLog({ level: "info", event: "parse.function.end", detail: fn });
350
+ continue;
351
+ }
352
+ if (sym === "\u03A8") {
353
+ if (kw === "IA") {
354
+ next(cx);
355
+ skipNewlines(cx);
356
+ const nameTok = peek(cx);
357
+ let name = "ia";
358
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
359
+ name = next(cx).value;
360
+ }
361
+ const body = [];
362
+ skipNewlines(cx);
363
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
364
+ next(cx);
365
+ skipNewlines(cx);
366
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
367
+ const cap = peek(cx);
368
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
369
+ body.push(cap.value);
370
+ next(cx);
371
+ } else {
372
+ next(cx);
373
+ }
374
+ skipNewlines(cx);
375
+ }
376
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
377
+ next(cx);
378
+ } else {
379
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */ && peek(cx).type !== "NEWLINE" /* NEWLINE */) {
380
+ const cap = peek(cx);
381
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
382
+ body.push(cap.value);
383
+ next(cx);
384
+ } else
385
+ break;
386
+ skipNewlines(cx);
387
+ }
388
+ }
389
+ const ia = { type: "ia", name, body };
390
+ ast.ias.push(ia);
391
+ ast.nodes.push(ia);
392
+ onLog({ level: "info", event: "parse.ia", detail: ia });
393
+ continue;
394
+ }
395
+ skipNewlines(cx);
396
+ continue;
397
+ }
398
+ if (sym === "\u03A9") {
399
+ skipNewlines(cx);
400
+ const nameTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
401
+ const name = nameTok.value;
402
+ const props = {};
403
+ skipNewlines(cx);
404
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
405
+ next(cx);
406
+ skipNewlines(cx);
407
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
408
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
409
+ skipNewlines(cx);
410
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
411
+ next(cx);
412
+ skipNewlines(cx);
413
+ const val = peek(cx);
414
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
415
+ props[p.value] = val.value;
416
+ next(cx);
417
+ } else {
418
+ props[p.value] = null;
419
+ }
420
+ } else {
421
+ props[p.value] = null;
422
+ }
423
+ skipNewlines(cx);
424
+ }
425
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
426
+ next(cx);
427
+ }
428
+ const obj = { type: "object", name, props };
429
+ ast.objects.push(obj);
430
+ ast.nodes.push(obj);
431
+ onLog({ level: "info", event: "parse.object", detail: obj });
432
+ continue;
433
+ }
434
+ if (sym === "\u03A6") {
435
+ skipNewlines(cx);
436
+ let name = "form";
437
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
438
+ name = next(cx).value;
439
+ }
440
+ const props = {};
441
+ skipNewlines(cx);
442
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
443
+ next(cx);
444
+ skipNewlines(cx);
445
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
446
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
447
+ const key = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
448
+ eat(cx, "COLON" /* COLON */);
449
+ const val = peek(cx);
450
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
451
+ props[key.value] = val.value;
452
+ next(cx);
453
+ } else {
454
+ props[key.value] = true;
455
+ }
456
+ } else {
457
+ next(cx);
458
+ }
459
+ skipNewlines(cx);
460
+ }
461
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
462
+ next(cx);
463
+ }
464
+ const form = { type: "form", name, props };
465
+ ast.forms.push(form);
466
+ ast.nodes.push(form);
467
+ onLog({ level: "info", event: "parse.form", detail: form });
468
+ continue;
469
+ }
470
+ if (sym === "\u0398") {
471
+ skipNewlines(cx);
472
+ const maybeAnim = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
473
+ if (maybeAnim.value.toLowerCase() !== "animation") {
474
+ onLog({ level: "warn", event: "parse.animation.missing.keyword" });
475
+ continue;
476
+ }
477
+ skipNewlines(cx);
478
+ const nameTok = peek(cx);
479
+ let name = "animation";
480
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
481
+ name = next(cx).value;
482
+ }
483
+ const props = {};
484
+ skipNewlines(cx);
485
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */) {
486
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
487
+ const key = next(cx).value;
488
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
489
+ next(cx);
490
+ const val = peek(cx);
491
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "NUMBER" /* NUMBER */ || val.type === "IDENTIFIER" /* IDENTIFIER */)) {
492
+ props[key] = val.value;
493
+ next(cx);
494
+ }
495
+ } else {
496
+ props[key] = true;
497
+ }
498
+ } else {
499
+ break;
500
+ }
501
+ skipNewlines(cx);
502
+ }
503
+ const anim = { type: "animation", name, props };
504
+ ast.animations.push(anim);
505
+ ast.nodes.push(anim);
506
+ onLog({ level: "info", event: "parse.animation", detail: anim });
507
+ continue;
508
+ }
509
+ if (sym === "\u039B") {
510
+ skipNewlines(cx);
511
+ const ifTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
512
+ if (ifTok.value.toLowerCase() !== "if") {
513
+ onLog({ level: "warn", event: "parse.logic.missing.if" });
514
+ continue;
515
+ }
516
+ const leftTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
517
+ let leftName = leftTok.value;
518
+ while (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value === ".") {
519
+ next(cx);
520
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
521
+ leftName += "." + p.value;
522
+ }
523
+ const comp = eat(cx, "COMPARATOR" /* COMPARATOR */);
524
+ const right = peek(cx);
525
+ if (!right || !(right.type === "STRING" /* STRING */ || right.type === "NUMBER" /* NUMBER */ || right.type === "IDENTIFIER" /* IDENTIFIER */))
526
+ throw new Error("Invalid logic right-hand side");
527
+ next(cx);
528
+ const rule = `${leftName} ${comp.value} ${right.value}`;
529
+ const trueFlow = [];
530
+ const falseFlow = [];
531
+ skipNewlines(cx);
532
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
533
+ next(cx);
534
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
535
+ trueFlow.push(step.value);
536
+ skipNewlines(cx);
537
+ }
538
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "else") {
539
+ next(cx);
540
+ skipNewlines(cx);
541
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
542
+ next(cx);
543
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
544
+ falseFlow.push(step.value);
545
+ skipNewlines(cx);
546
+ }
547
+ }
548
+ const logic = { type: "logic", rule, trueFlow, falseFlow };
549
+ ast.logic.push(logic);
550
+ ast.nodes.push(logic);
551
+ onLog({ level: "info", event: "parse.logic", detail: logic });
552
+ continue;
553
+ }
554
+ if (sym === "\u2297") {
555
+ skipNewlines(cx);
556
+ const items = [];
557
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
558
+ next(cx);
559
+ skipNewlines(cx);
560
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
561
+ const parts = [];
562
+ while (peek(cx) && peek(cx).type !== "NEWLINE" /* NEWLINE */ && peek(cx).type !== "RBRACE" /* RBRACE */) {
563
+ const p = peek(cx);
564
+ if (p.type === "IDENTIFIER" /* IDENTIFIER */ || p.type === "STRING" /* STRING */ || p.type === "NUMBER" /* NUMBER */) {
565
+ parts.push(next(cx).value);
566
+ } else {
567
+ next(cx);
568
+ }
569
+ }
570
+ if (parts.length > 0)
571
+ items.push(parts.join(" "));
572
+ if (peek(cx) && peek(cx).type === "NEWLINE" /* NEWLINE */)
573
+ next(cx);
574
+ skipNewlines(cx);
575
+ }
576
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
577
+ next(cx);
578
+ }
579
+ const par = { type: "parallel", items };
580
+ ast.parallels.push(par);
581
+ ast.nodes.push(par);
582
+ onLog({ level: "info", event: "parse.parallel", detail: par });
583
+ continue;
584
+ }
585
+ skipNewlines(cx);
586
+ continue;
587
+ }
588
+ if (t.type === "SYMBOL" /* SYMBOL */ && t.value === "\u0394") {
589
+ next(cx);
590
+ }
591
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */ && t.value.toLowerCase() === "\u0394") {
592
+ next(cx);
593
+ continue;
594
+ }
595
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */) {
596
+ const val = t.value.toLowerCase();
597
+ next(cx);
598
+ skipNewlines(cx);
599
+ continue;
600
+ }
601
+ next(cx);
602
+ skipNewlines(cx);
603
+ }
604
+ return ast;
605
+ }
606
+ function parseFromCode(code, options) {
607
+ const tokens = tokenize(code);
608
+ return parseTokens(tokens, options);
609
+ }
610
+
611
+ // src/parser.ts
612
+ async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
613
+ const fsPromises = await import("fs/promises");
614
+ let attempt = 0;
615
+ const tryWrite = async () => {
616
+ attempt++;
617
+ try {
618
+ await fsPromises.appendFile(filePath, JSON.stringify(entry) + "\n", { encoding: "utf8" });
619
+ if (onLog)
620
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "logfile.write.success", detail: { file: filePath } });
621
+ return;
622
+ } catch (err) {
623
+ const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "logfile.write.retry", detail: { attempt, error: String(err) } };
624
+ if (onLog)
625
+ onLog(errEntry);
626
+ if (attempt < attempts) {
627
+ setTimeout(() => {
628
+ tryWrite().catch(() => {
629
+ });
630
+ }, delay);
631
+ } else {
632
+ const fatal = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.fatal", detail: { attempt, error: String(err) } };
633
+ if (onLog)
634
+ onLog(fatal);
635
+ }
636
+ }
637
+ };
638
+ tryWrite().catch(() => {
639
+ });
640
+ }
641
+ function parse(code, options) {
642
+ const ast = parseFromCode(code, options);
643
+ ast.logs = ast.logs || [];
644
+ return ast;
645
+ }
646
+
647
+ // src/runENY.ts
648
+ function runENY(code, options) {
649
+ const hasSystem = /Σ\s+SYSTEM/i.test(code);
650
+ if (!hasSystem) {
651
+ if (options?.onLog) {
652
+ options.onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } });
653
+ }
654
+ if (options?.logFile) {
655
+ const attempts = options?.logRetryAttempts ?? 3;
656
+ const delay = options?.logRetryDelayMs ?? 1e3;
657
+ writeWithRetry({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "runENY.no-system", detail: { length: code.length } }, options.logFile, attempts, delay, options?.onLog);
658
+ }
659
+ return { raw: code, isEny: false, logs: [] };
660
+ }
661
+ const userOnLog = options?.onLog;
662
+ let wrappedOnLog = userOnLog;
663
+ if (options?.logFile) {
664
+ const attempts = options?.logRetryAttempts ?? 3;
665
+ const delay = options?.logRetryDelayMs ?? 1e3;
666
+ wrappedOnLog = (e) => {
667
+ if (userOnLog)
668
+ userOnLog(e);
669
+ writeWithRetry(e, options.logFile, attempts, delay, userOnLog);
670
+ };
671
+ }
672
+ const ast = parse(code, { ...options, onLog: wrappedOnLog });
673
+ ast.isEny = true;
674
+ return ast;
675
+ }
676
+
677
+ export {
678
+ TokenType,
679
+ tokenize,
680
+ runENY
681
+ };