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,631 @@
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 (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 (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 (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 (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 (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 (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
+ const fn = { type: "function", name: nameTok.value, args, steps };
346
+ ast.functions.push(fn);
347
+ ast.nodes.push(fn);
348
+ onLog({ level: "info", event: "parse.function", detail: fn });
349
+ continue;
350
+ }
351
+ if (sym === "\u03A8") {
352
+ if (kw === "IA") {
353
+ next(cx);
354
+ skipNewlines(cx);
355
+ const nameTok = peek(cx);
356
+ let name = "ia";
357
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
358
+ name = next(cx).value;
359
+ }
360
+ const body = [];
361
+ skipNewlines(cx);
362
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
363
+ next(cx);
364
+ skipNewlines(cx);
365
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
366
+ const cap = peek(cx);
367
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
368
+ body.push(cap.value);
369
+ next(cx);
370
+ } else {
371
+ next(cx);
372
+ }
373
+ skipNewlines(cx);
374
+ }
375
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
376
+ next(cx);
377
+ } else {
378
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */ && peek(cx).type !== "NEWLINE" /* NEWLINE */) {
379
+ const cap = peek(cx);
380
+ if (cap.type === "IDENTIFIER" /* IDENTIFIER */ || cap.type === "STRING" /* STRING */) {
381
+ body.push(cap.value);
382
+ next(cx);
383
+ } else
384
+ break;
385
+ skipNewlines(cx);
386
+ }
387
+ }
388
+ const ia = { type: "ia", name, body };
389
+ ast.ias.push(ia);
390
+ ast.nodes.push(ia);
391
+ onLog({ level: "info", event: "parse.ia", detail: ia });
392
+ continue;
393
+ }
394
+ skipNewlines(cx);
395
+ continue;
396
+ }
397
+ if (sym === "\u03A9") {
398
+ skipNewlines(cx);
399
+ const nameTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
400
+ const name = nameTok.value;
401
+ const props = {};
402
+ skipNewlines(cx);
403
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
404
+ next(cx);
405
+ skipNewlines(cx);
406
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
407
+ const p = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
408
+ skipNewlines(cx);
409
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
410
+ next(cx);
411
+ skipNewlines(cx);
412
+ const val = peek(cx);
413
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "IDENTIFIER" /* IDENTIFIER */ || val.type === "NUMBER" /* NUMBER */)) {
414
+ props[p.value] = val.value;
415
+ next(cx);
416
+ } else {
417
+ props[p.value] = null;
418
+ }
419
+ } else {
420
+ props[p.value] = null;
421
+ }
422
+ skipNewlines(cx);
423
+ }
424
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
425
+ next(cx);
426
+ }
427
+ const obj = { type: "object", name, props };
428
+ ast.objects.push(obj);
429
+ ast.nodes.push(obj);
430
+ onLog({ level: "info", event: "parse.object", detail: obj });
431
+ continue;
432
+ }
433
+ if (sym === "\u03A6") {
434
+ skipNewlines(cx);
435
+ const tp = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
436
+ const name = tp.value;
437
+ const props = {};
438
+ skipNewlines(cx);
439
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
440
+ next(cx);
441
+ skipNewlines(cx);
442
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
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
+ skipNewlines(cx);
453
+ }
454
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
455
+ next(cx);
456
+ }
457
+ const form = { type: "form", name, props };
458
+ ast.forms.push(form);
459
+ ast.nodes.push(form);
460
+ onLog({ level: "info", event: "parse.form", detail: form });
461
+ continue;
462
+ }
463
+ if (sym === "\u0398") {
464
+ skipNewlines(cx);
465
+ const maybeAnim = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
466
+ if (maybeAnim.value.toLowerCase() !== "animation") {
467
+ onLog({ level: "warn", event: "parse.animation.missing.keyword" });
468
+ continue;
469
+ }
470
+ skipNewlines(cx);
471
+ const nameTok = peek(cx);
472
+ let name = "animation";
473
+ if (nameTok && (nameTok.type === "STRING" /* STRING */ || nameTok.type === "IDENTIFIER" /* IDENTIFIER */)) {
474
+ name = next(cx).value;
475
+ }
476
+ const props = {};
477
+ skipNewlines(cx);
478
+ while (peek(cx) && peek(cx).type !== "SYMBOL" /* SYMBOL */ && peek(cx).type !== "EOF" /* EOF */) {
479
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */) {
480
+ const key = next(cx).value;
481
+ if (peek(cx) && peek(cx).type === "COLON" /* COLON */) {
482
+ next(cx);
483
+ const val = peek(cx);
484
+ if (val && (val.type === "STRING" /* STRING */ || val.type === "NUMBER" /* NUMBER */ || val.type === "IDENTIFIER" /* IDENTIFIER */)) {
485
+ props[key] = val.value;
486
+ next(cx);
487
+ }
488
+ } else {
489
+ props[key] = true;
490
+ }
491
+ } else {
492
+ break;
493
+ }
494
+ skipNewlines(cx);
495
+ }
496
+ const anim = { type: "animation", name, props };
497
+ ast.animations.push(anim);
498
+ ast.nodes.push(anim);
499
+ onLog({ level: "info", event: "parse.animation", detail: anim });
500
+ continue;
501
+ }
502
+ if (sym === "\u039B") {
503
+ skipNewlines(cx);
504
+ const ifTok = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
505
+ if (ifTok.value.toLowerCase() !== "if") {
506
+ onLog({ level: "warn", event: "parse.logic.missing.if" });
507
+ continue;
508
+ }
509
+ const left = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
510
+ const comp = eat(cx, "COMPARATOR" /* COMPARATOR */);
511
+ const right = peek(cx);
512
+ if (!right || !(right.type === "STRING" /* STRING */ || right.type === "NUMBER" /* NUMBER */ || right.type === "IDENTIFIER" /* IDENTIFIER */))
513
+ throw new Error("Invalid logic right-hand side");
514
+ next(cx);
515
+ const rule = `${left.value} ${comp.value} ${right.value}`;
516
+ const trueFlow = [];
517
+ const falseFlow = [];
518
+ skipNewlines(cx);
519
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
520
+ next(cx);
521
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
522
+ trueFlow.push(step.value);
523
+ skipNewlines(cx);
524
+ }
525
+ if (peek(cx) && peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ && peek(cx).value.toLowerCase() === "else") {
526
+ next(cx);
527
+ skipNewlines(cx);
528
+ while (peek(cx) && peek(cx).type === "ARROW" /* ARROW */) {
529
+ next(cx);
530
+ const step = eat(cx, "IDENTIFIER" /* IDENTIFIER */);
531
+ falseFlow.push(step.value);
532
+ skipNewlines(cx);
533
+ }
534
+ }
535
+ const logic = { type: "logic", rule, trueFlow, falseFlow };
536
+ ast.logic.push(logic);
537
+ ast.nodes.push(logic);
538
+ onLog({ level: "info", event: "parse.logic", detail: logic });
539
+ continue;
540
+ }
541
+ if (sym === "\u2297") {
542
+ skipNewlines(cx);
543
+ const items = [];
544
+ if (peek(cx) && peek(cx).type === "LBRACE" /* LBRACE */) {
545
+ next(cx);
546
+ skipNewlines(cx);
547
+ while (peek(cx) && peek(cx).type !== "RBRACE" /* RBRACE */) {
548
+ if (peek(cx).type === "IDENTIFIER" /* IDENTIFIER */ || peek(cx).type === "STRING" /* STRING */) {
549
+ items.push(next(cx).value);
550
+ } else {
551
+ next(cx);
552
+ }
553
+ skipNewlines(cx);
554
+ }
555
+ if (peek(cx) && peek(cx).type === "RBRACE" /* RBRACE */)
556
+ next(cx);
557
+ }
558
+ const par = { type: "parallel", items };
559
+ ast.parallels.push(par);
560
+ ast.nodes.push(par);
561
+ onLog({ level: "info", event: "parse.parallel", detail: par });
562
+ continue;
563
+ }
564
+ skipNewlines(cx);
565
+ continue;
566
+ }
567
+ if (t.type === "SYMBOL" /* SYMBOL */ && t.value === "\u0394") {
568
+ next(cx);
569
+ }
570
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */ && t.value.toLowerCase() === "\u0394") {
571
+ next(cx);
572
+ continue;
573
+ }
574
+ if (t.type === "IDENTIFIER" /* IDENTIFIER */) {
575
+ const val = t.value.toLowerCase();
576
+ next(cx);
577
+ skipNewlines(cx);
578
+ continue;
579
+ }
580
+ next(cx);
581
+ skipNewlines(cx);
582
+ }
583
+ return ast;
584
+ }
585
+ function parseFromCode(code, options) {
586
+ const tokens = tokenize(code);
587
+ return parseTokens(tokens, options);
588
+ }
589
+
590
+ // src/parser.ts
591
+ async function writeWithRetry(entry, filePath, attempts = 3, delay = 1e3, onLog) {
592
+ const fsPromises = await import("fs/promises");
593
+ let attempt = 0;
594
+ const tryWrite = async () => {
595
+ attempt++;
596
+ try {
597
+ await fsPromises.appendFile(filePath, JSON.stringify(entry) + "\n", { encoding: "utf8" });
598
+ if (onLog)
599
+ onLog({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "info", event: "logfile.write.success", detail: { file: filePath } });
600
+ return;
601
+ } catch (err) {
602
+ const errEntry = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "warn", event: "logfile.write.retry", detail: { attempt, error: String(err) } };
603
+ if (onLog)
604
+ onLog(errEntry);
605
+ if (attempt < attempts) {
606
+ setTimeout(() => {
607
+ tryWrite().catch(() => {
608
+ });
609
+ }, delay);
610
+ } else {
611
+ const fatal = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), level: "error", event: "logfile.write.fatal", detail: { attempt, error: String(err) } };
612
+ if (onLog)
613
+ onLog(fatal);
614
+ }
615
+ }
616
+ };
617
+ tryWrite().catch(() => {
618
+ });
619
+ }
620
+ function parse(code, options) {
621
+ const ast = parseFromCode(code, options);
622
+ ast.logs = ast.logs || [];
623
+ return ast;
624
+ }
625
+
626
+ export {
627
+ TokenType,
628
+ tokenize,
629
+ writeWithRetry,
630
+ parse
631
+ };