functionalscript 0.16.1 → 0.18.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 (88) hide show
  1. package/fs/asn.1/module.f.js +6 -0
  2. package/fs/ci/bun/module.f.js +6 -0
  3. package/fs/ci/common/module.f.d.ts +11 -5
  4. package/fs/ci/common/module.f.js +11 -4
  5. package/fs/ci/config/module.f.d.ts +11 -4
  6. package/fs/ci/config/module.f.js +11 -4
  7. package/fs/ci/deno/module.f.js +6 -0
  8. package/fs/ci/node/module.f.js +6 -0
  9. package/fs/ci/playwright/module.f.js +6 -0
  10. package/fs/ci/rust/module.f.js +7 -0
  11. package/fs/ci/test.f.js +2 -4
  12. package/fs/crypto/secp/module.f.d.ts +7 -0
  13. package/fs/dev/index/module.f.d.ts +6 -0
  14. package/fs/dev/index/module.f.js +6 -0
  15. package/fs/dev/module.f.d.ts +4 -3
  16. package/fs/dev/module.f.js +13 -11
  17. package/fs/dev/tf/module.d.ts +1 -0
  18. package/fs/dev/tf/module.f.d.ts +70 -22
  19. package/fs/dev/tf/module.f.js +134 -97
  20. package/fs/dev/tf/module.js +66 -16
  21. package/fs/dev/tf/test.f.d.ts +21 -20
  22. package/fs/dev/tf/test.f.js +249 -31
  23. package/fs/djs/module.f.d.ts +5 -2
  24. package/fs/djs/module.f.js +16 -21
  25. package/fs/djs/test.f.d.ts +11 -0
  26. package/fs/djs/test.f.js +74 -0
  27. package/fs/djs/tokenizer-new/test.f.js +126 -78
  28. package/fs/djs/transpiler/module.f.d.ts +3 -3
  29. package/fs/djs/transpiler/module.f.js +34 -29
  30. package/fs/djs/transpiler/test.f.js +19 -26
  31. package/fs/fjs/module.f.d.ts +2 -7
  32. package/fs/fjs/module.f.js +17 -17
  33. package/fs/fjs/module.js +2 -2
  34. package/fs/html/module.f.d.ts +6 -0
  35. package/fs/html/module.f.js +6 -0
  36. package/fs/io/module.d.ts +3 -3
  37. package/fs/io/module.f.d.ts +8 -2
  38. package/fs/io/module.f.js +25 -4
  39. package/fs/io/module.js +54 -15
  40. package/fs/js/tokenizer/module.f.js +7 -0
  41. package/fs/json/module.f.d.ts +7 -0
  42. package/fs/json/module.f.js +7 -0
  43. package/fs/path/module.f.d.ts +6 -0
  44. package/fs/path/module.f.js +6 -0
  45. package/fs/path/test.f.d.ts +3 -5
  46. package/fs/path/test.f.js +67 -49
  47. package/fs/text/module.f.d.ts +7 -0
  48. package/fs/text/module.f.js +7 -0
  49. package/fs/text/sgr/module.f.d.ts +9 -1
  50. package/fs/text/sgr/module.f.js +16 -5
  51. package/fs/text/utf16/module.f.d.ts +7 -0
  52. package/fs/text/utf16/module.f.js +7 -0
  53. package/fs/types/effects/node/module.f.d.ts +51 -9
  54. package/fs/types/effects/node/module.f.js +39 -2
  55. package/fs/types/effects/node/test.f.d.ts +4 -0
  56. package/fs/types/effects/node/test.f.js +33 -6
  57. package/fs/types/effects/node/virtual/module.f.d.ts +12 -3
  58. package/fs/types/effects/node/virtual/module.f.js +32 -9
  59. package/fs/types/function/compare/module.f.d.ts +12 -0
  60. package/fs/types/function/compare/module.f.js +33 -0
  61. package/fs/types/function/operator/test.f.d.ts +10 -0
  62. package/fs/types/function/operator/test.f.js +81 -0
  63. package/fs/types/monoid/module.f.d.ts +7 -0
  64. package/fs/types/number/module.f.d.ts +6 -0
  65. package/fs/types/number/module.f.js +6 -0
  66. package/fs/types/object/module.f.js +7 -0
  67. package/fs/types/prime_field/module.f.d.ts +8 -0
  68. package/fs/types/range_map/module.f.js +3 -18
  69. package/fs/types/result/module.f.d.ts +4 -0
  70. package/fs/types/result/module.f.js +4 -0
  71. package/fs/types/result/test.f.d.ts +2 -4
  72. package/fs/types/result/test.f.js +24 -16
  73. package/fs/types/rtti/common/module.f.d.ts +10 -1
  74. package/fs/types/rtti/common/module.f.js +7 -2
  75. package/fs/types/rtti/parse/module.f.js +35 -46
  76. package/fs/types/rtti/validate/module.f.js +9 -12
  77. package/fs/types/sorted_list/module.f.d.ts +1 -2
  78. package/fs/types/sorted_list/module.f.js +8 -21
  79. package/fs/types/sorted_set/module.f.d.ts +1 -3
  80. package/fs/types/ts/module.f.d.ts +7 -0
  81. package/fs/types/ts/test.f.d.ts +18 -0
  82. package/fs/types/ts/test.f.js +111 -0
  83. package/fs/types/uint8array/module.f.js +7 -1
  84. package/fs/types/uint8array/test.f.d.ts +1 -0
  85. package/fs/types/uint8array/test.f.js +5 -1
  86. package/package.json +3 -2
  87. package/fs/io/virtual/module.f.d.ts +0 -8
  88. package/fs/io/virtual/module.f.js +0 -43
@@ -10,8 +10,15 @@ const descentParserCpOnly = (m, name, cp) => {
10
10
  const tokenizeString = s => {
11
11
  const m = descentParser(jsGrammar());
12
12
  const cp = toArray(stringToCodePointList(s));
13
- const mr = descentParserCpOnly(m, '', cp);
14
- const flatTokens = getTokensFromMatchResult(mr);
13
+ const [ast, ok, len] = descentParserCpOnly(m, '', cp);
14
+ if (cp.length === 0) {
15
+ return JSON.stringify([{ kind: 'eof' }]);
16
+ }
17
+ if (!ok)
18
+ return 'error';
19
+ if (cp.length > 0 && len !== cp.length)
20
+ return 'error';
21
+ const flatTokens = getTokensFromAstRule(ast);
15
22
  const filterTokens = concat(filter(filterFunc)(flatTokens))(['']);
16
23
  const tokens = flat(stateScan(scanFunc)(['', []])(filterTokens));
17
24
  const jsTokens = concat(map(toJsToken)(tokens))([{ kind: 'eof' }]);
@@ -19,8 +26,16 @@ const tokenizeString = s => {
19
26
  //return JSON.stringify(toArray(filterTokens))
20
27
  return JSON.stringify(result);
21
28
  };
29
+ const isNlTag = (tag) => tag === '\n' || tag === '\r';
30
+ const isWsTag = (tag) => tag === ' ' || tag === '\t';
22
31
  const scanFunc = (input, state) => {
23
32
  if (typeof input === 'string') {
33
+ if (isNlTag(input) && isNlTag(state[0]))
34
+ return [null, state];
35
+ if (isWsTag(input) && isWsTag(state[0]))
36
+ return [null, state];
37
+ if (isNlTag(input) && isWsTag(state[0]))
38
+ return [null, [input, []]];
24
39
  const newState = [input, []];
25
40
  if (state[0] === '') {
26
41
  return [null, newState];
@@ -42,6 +57,10 @@ const filterFunc = tk => {
42
57
  case ',':
43
58
  case 'number':
44
59
  case 'string':
60
+ case '\n':
61
+ case '\r':
62
+ case ' ':
63
+ case '\t':
45
64
  return true;
46
65
  default:
47
66
  return false;
@@ -56,6 +75,14 @@ const toJsToken = tk => {
56
75
  case ':':
57
76
  case ',':
58
77
  return { kind: tk[0] };
78
+ case '\n':
79
+ case '\r':
80
+ return { kind: 'nl' };
81
+ case ' ':
82
+ case '\t':
83
+ return { kind: 'ws' };
84
+ case 'string':
85
+ return { kind: 'string', value: String.fromCodePoint(...tk[1].slice(1, -1)) };
59
86
  default:
60
87
  return null;
61
88
  }
@@ -81,9 +108,6 @@ const getTokensFromAstRule = ast => {
81
108
  return [token];
82
109
  return { first: token, tail: getTokensFromAstSequence(ast.sequence) };
83
110
  };
84
- const getTokensFromMatchResult = mr => {
85
- return getTokensFromAstRule(mr[0]);
86
- };
87
111
  export default {
88
112
  isValid: [() => {
89
113
  const m = descentParser(jsGrammar());
@@ -319,34 +343,48 @@ export default {
319
343
  throw result;
320
344
  }
321
345
  },
322
- // () => {
323
- // const result = tokenizeString('ᄑ')
324
- // if (result !== '[{"kind":"error","message":"unexpected character"},{"kind":"eof"}]') { throw result }
325
- // },
326
- // () => {
327
- // const result = tokenizeString('{ \t\n\r}')
328
- // if (result !== '[{"kind":"{"},{"kind":"nl"},{"kind":"}"},{"kind":"eof"}]') { throw result }
329
- // },
330
- // () => {
331
- // const result = tokenizeString('""')
332
- // if (result !== '[{"kind":"string","value":""},{"kind":"eof"}]') { throw result }
333
- // },
334
- // () => {
335
- // const result = tokenizeString('"value"')
336
- // if (result !== '[{"kind":"string","value":"value"},{"kind":"eof"}]') { throw result }
337
- // },
338
- // () => {
339
- // const result = tokenizeString('"value')
340
- // if (result !== '[{"kind":"error","message":"\\" are missing"},{"kind":"eof"}]') { throw result }
341
- // },
342
- // () => {
343
- // const result = tokenizeString('"value1" "value2"')
344
- // if (result !== '[{"kind":"string","value":"value1"},{"kind":"ws"},{"kind":"string","value":"value2"},{"kind":"eof"}]') { throw result }
345
- // },
346
- // () => {
347
- // const result = tokenizeString('"')
348
- // if (result !== '[{"kind":"error","message":"\\" are missing"},{"kind":"eof"}]') { throw result }
349
- // },
346
+ () => {
347
+ const result = tokenizeString('ᄑ');
348
+ if (result !== 'error') {
349
+ throw result;
350
+ }
351
+ },
352
+ () => {
353
+ const result = tokenizeString('{ \t\n\r}');
354
+ if (result !== '[{"kind":"{"},{"kind":"nl"},{"kind":"}"},{"kind":"eof"}]') {
355
+ throw result;
356
+ }
357
+ },
358
+ () => {
359
+ const result = tokenizeString('""');
360
+ if (result !== '[{"kind":"string","value":""},{"kind":"eof"}]') {
361
+ throw result;
362
+ }
363
+ },
364
+ () => {
365
+ const result = tokenizeString('"value"');
366
+ if (result !== '[{"kind":"string","value":"value"},{"kind":"eof"}]') {
367
+ throw result;
368
+ }
369
+ },
370
+ () => {
371
+ const result = tokenizeString('"value');
372
+ if (result !== 'error') {
373
+ throw result;
374
+ }
375
+ },
376
+ () => {
377
+ const result = tokenizeString('"value1" "value2"');
378
+ if (result !== '[{"kind":"string","value":"value1"},{"kind":"ws"},{"kind":"string","value":"value2"},{"kind":"eof"}]') {
379
+ throw result;
380
+ }
381
+ },
382
+ () => {
383
+ const result = tokenizeString('"');
384
+ if (result !== 'error') {
385
+ throw result;
386
+ }
387
+ },
350
388
  // () => {
351
389
  // const result = tokenizeString('"\\\\"')
352
390
  // if (result !== '[{"kind":"string","value":"\\\\"},{"kind":"eof"}]') { throw result }
@@ -359,22 +397,30 @@ export default {
359
397
  // const result = tokenizeString('"\\/"')
360
398
  // if (result !== '[{"kind":"string","value":"/"},{"kind":"eof"}]') { throw result }
361
399
  // },
362
- // () => {
363
- // const result = tokenizeString('"\\x"')
364
- // if (result !== '[{"kind":"error","message":"unescaped character"},{"kind":"string","value":"x"},{"kind":"eof"}]') { throw result }
365
- // },
366
- // () => {
367
- // const result = tokenizeString('"\\')
368
- // if (result !== '[{"kind":"error","message":"\\" are missing"},{"kind":"eof"}]') { throw result }
369
- // },
370
- // () => {
371
- // const result = tokenizeString('"\r"')
372
- // if (result !== '[{"kind":"error","message":"unterminated string literal"},{"kind":"nl"},{"kind":"error","message":"\\" are missing"},{"kind":"eof"}]') { throw result }
373
- // },
374
- // () => {
375
- // const result = tokenizeString('"\n null')
376
- // if (result !== '[{"kind":"error","message":"unterminated string literal"},{"kind":"nl"},{"kind":"null"},{"kind":"eof"}]') { throw result }
377
- // },
400
+ () => {
401
+ const result = tokenizeString('"\\x"');
402
+ if (result !== 'error') {
403
+ throw result;
404
+ }
405
+ },
406
+ () => {
407
+ const result = tokenizeString('"\\');
408
+ if (result !== 'error') {
409
+ throw result;
410
+ }
411
+ },
412
+ () => {
413
+ const result = tokenizeString('"\r"');
414
+ if (result !== 'error') {
415
+ throw result;
416
+ }
417
+ },
418
+ () => {
419
+ const result = tokenizeString('"\n null');
420
+ if (result !== 'error') {
421
+ throw result;
422
+ }
423
+ },
378
424
  // () => {
379
425
  // const result = tokenizeString('"\\b\\f\\n\\r\\t"')
380
426
  // if (result !== '[{"kind":"string","value":"\\b\\f\\n\\r\\t"},{"kind":"eof"}]') { throw result }
@@ -387,10 +433,12 @@ export default {
387
433
  // const result = tokenizeString('"\\uaBcDEeFf"')
388
434
  // if (result !== '[{"kind":"string","value":"ꯍEeFf"},{"kind":"eof"}]') { throw result }
389
435
  // },
390
- // () => {
391
- // const result = tokenizeString('"\\uEeFg"')
392
- // if (result !== '[{"kind":"error","message":"invalid hex value"},{"kind":"string","value":"g"},{"kind":"eof"}]') { throw result }
393
- // },
436
+ () => {
437
+ const result = tokenizeString('"\\uEeFg"');
438
+ if (result !== 'error') {
439
+ throw result;
440
+ }
441
+ },
394
442
  // () => {
395
443
  // const result = tokenizeString('0')
396
444
  // if (result !== '[{"bf":[0n,0],"kind":"number","value":"0"},{"kind":"eof"}]') { throw result }
@@ -399,14 +447,14 @@ export default {
399
447
  // const result = tokenizeString('[0]')
400
448
  // if (result !== '[{"kind":"["},{"bf":[0n,0],"kind":"number","value":"0"},{"kind":"]"},{"kind":"eof"}]') { throw result }
401
449
  // },
402
- // () => {
403
- // const result = tokenizeString('00')
404
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
405
- // },
406
- // () => {
407
- // const result = tokenizeString('0abc,')
408
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"abc"},{"kind":","},{"kind":"eof"}]') { throw result }
409
- // },
450
+ // () => {
451
+ // const result = tokenizeString('00')
452
+ // if (result !== 'error') { throw result }
453
+ // },
454
+ // () => {
455
+ // const result = tokenizeString('0abc,')
456
+ // if (result !== 'error') { throw result }
457
+ // },
410
458
  // () => {
411
459
  // const result = tokenizeString('123456789012345678901234567890')
412
460
  // if (result !== '[{"bf":[123456789012345678901234567890n,0],"kind":"number","value":"123456789012345678901234567890"},{"kind":"eof"}]') { throw result }
@@ -421,7 +469,7 @@ export default {
421
469
  // },
422
470
  // () => {
423
471
  // const result = tokenizeString('0. 2')
424
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"ws"},{"bf":[2n,0],"kind":"number","value":"2"},{"kind":"eof"}]') { throw result }
472
+ // if (result !== 'error') { throw result }
425
473
  // },
426
474
  // () => {
427
475
  // const result = tokenizeString('10-0')
@@ -429,7 +477,7 @@ export default {
429
477
  // },
430
478
  // () => {
431
479
  // const result = tokenizeString('9a:')
432
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"a"},{"kind":":"},{"kind":"eof"}]') { throw result }
480
+ // if (result !== 'error') { throw result }
433
481
  // },
434
482
  // () => {
435
483
  // const result = tokenizeString('-10')
@@ -441,7 +489,7 @@ export default {
441
489
  // },
442
490
  // () => {
443
491
  // const result = tokenizeString('-00')
444
- // if (result !== '[{"kind":"-"},{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
492
+ // if (result !== 'error') { throw result }
445
493
  // },
446
494
  // () => {
447
495
  // const result = tokenizeString('-.123')
@@ -457,11 +505,11 @@ export default {
457
505
  // },
458
506
  // () => {
459
507
  // const result = tokenizeString('-0.')
460
- // if (result !== '[{"kind":"-"},{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
508
+ // if (result !== 'error') { throw result }
461
509
  // },
462
510
  // () => {
463
511
  // const result = tokenizeString('-0.]')
464
- // if (result !== '[{"kind":"-"},{"kind":"error","message":"invalid number"},{"kind":"]"},{"kind":"eof"}]') { throw result }
512
+ // if (result !== 'error') { throw result }
465
513
  // },
466
514
  // () => {
467
515
  // const result = tokenizeString('12.34')
@@ -473,11 +521,11 @@ export default {
473
521
  // },
474
522
  // () => {
475
523
  // const result = tokenizeString('-12.')
476
- // if (result !== '[{"kind":"-"},{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
524
+ // if (result !== 'error') { throw result }
477
525
  // },
478
526
  // () => {
479
527
  // const result = tokenizeString('12.]')
480
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"]"},{"kind":"eof"}]') { throw result }
528
+ // if (result !== 'error') { throw result }
481
529
  // },
482
530
  // () => {
483
531
  // const result = tokenizeString('0e1')
@@ -505,11 +553,11 @@ export default {
505
553
  // },
506
554
  // () => {
507
555
  // const result = tokenizeString('0e')
508
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
556
+ // if (result !== 'error') { throw result }
509
557
  // },
510
558
  // () => {
511
559
  // const result = tokenizeString('0e-')
512
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"eof"}]') { throw result }
560
+ // if (result !== 'error') { throw result }
513
561
  // },
514
562
  // () => {
515
563
  // const result = tokenizeString('ABCdef1234567890$_')
@@ -529,11 +577,11 @@ export default {
529
577
  // },
530
578
  // () => {
531
579
  // const result = tokenizeString('123_123')
532
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"_123"},{"kind":"eof"}]') { throw result }
580
+ // if (result !== 'error') { throw result }
533
581
  // },
534
582
  // () => {
535
583
  // const result = tokenizeString('123$123')
536
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"$123"},{"kind":"eof"}]') { throw result }
584
+ // if (result !== 'error') { throw result }
537
585
  // },
538
586
  // () => {
539
587
  // const result = tokenizeString('1234567890n')
@@ -549,19 +597,19 @@ export default {
549
597
  // },
550
598
  // () => {
551
599
  // const result = tokenizeString('123.456n')
552
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"},{"kind":"eof"}]') { throw result }
600
+ // if (result !== 'error') { throw result }
553
601
  // },
554
602
  // () => {
555
603
  // const result = tokenizeString('123e456n')
556
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"},{"kind":"eof"}]') { throw result }
604
+ // if (result !== 'error') { throw result }
557
605
  // },
558
606
  // () => {
559
607
  // const result = tokenizeString('1234567890na')
560
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"a"},{"kind":"eof"}]') { throw result }
608
+ // if (result !== 'error') { throw result }
561
609
  // },
562
610
  // () => {
563
611
  // const result = tokenizeString('1234567890nn')
564
- // if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"},{"kind":"eof"}]') { throw result }
612
+ // if (result !== 'error') { throw result }
565
613
  // },
566
614
  ],
567
615
  // operators:
@@ -876,11 +924,11 @@ export default {
876
924
  // },
877
925
  // () => {
878
926
  // const result = tokenizeString('/* multiline comment *')
879
- // if (result !== '[{"kind":"error","message":"*/ expected"},{"kind":"eof"}]') { throw result }
927
+ // if (result !== 'error') { throw result }
880
928
  // },
881
929
  // () => {
882
930
  // const result = tokenizeString('/* multiline comment ')
883
- // if (result !== '[{"kind":"error","message":"*/ expected"},{"kind":"eof"}]') { throw result }
931
+ // if (result !== 'error') { throw result }
884
932
  // },
885
933
  // () => {
886
934
  // const result = tokenizeString('/* multiline comment \n * **/')
@@ -7,10 +7,10 @@ import { type Unknown } from '../module.f.ts';
7
7
  import { type Result } from '../../types/result/module.f.ts';
8
8
  import { type List } from '../../types/list/module.f.ts';
9
9
  import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
10
- import type { Fs } from '../../io/module.f.ts';
11
10
  import { type ParseError } from '../parser/module.f.ts';
11
+ import { type Effect } from '../../types/effects/module.f.ts';
12
+ import { type ReadFile } from '../../types/effects/node/module.f.ts';
12
13
  export type ParseContext = {
13
- readonly fs: Fs;
14
14
  readonly complete: OrderedMap<djsResult>;
15
15
  readonly stack: List<string>;
16
16
  readonly error: ParseError | null;
@@ -18,4 +18,4 @@ export type ParseContext = {
18
18
  export type djsResult = {
19
19
  djs: Unknown;
20
20
  };
21
- export declare const transpile: (fs: Fs) => (path: string) => Result<Unknown, ParseError>;
21
+ export declare const transpile: (path: string) => Effect<ReadFile, Result<Unknown, ParseError>>;
@@ -5,15 +5,16 @@
5
5
  */
6
6
  import {} from "../module.f.js";
7
7
  import { error, ok } from "../../types/result/module.f.js";
8
- import { fold, drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
9
- import {} from "../../types/function/operator/module.f.js";
8
+ import { drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
10
9
  import { tokenize } from "../tokenizer/module.f.js";
11
10
  import { setReplace, at } from "../../types/ordered_map/module.f.js";
12
11
  import { stringToList } from "../../text/utf16/module.f.js";
13
12
  import { concat as pathConcat } from "../../path/module.f.js";
14
13
  import { parseFromTokens } from "../parser/module.f.js";
15
14
  import { run } from "../ast/module.f.js";
16
- import { decodeUtf8 } from "../../types/uint8array/module.f.js";
15
+ import { pure } from "../../types/effects/module.f.js";
16
+ import { readFile } from "../../types/effects/node/module.f.js";
17
+ import { utf8ToString } from "../../text/module.f.js";
17
18
  const mapDjs = context => path => {
18
19
  const res = at(path)(context.complete);
19
20
  if (res === null) {
@@ -21,46 +22,50 @@ const mapDjs = context => path => {
21
22
  }
22
23
  return res.djs;
23
24
  };
25
+ const parseModule = path => readFile(path).step(result => {
26
+ if (result[0] === 'error') {
27
+ return pure(error({ message: 'file not found', metadata: null }));
28
+ }
29
+ const tokens = tokenize(stringToList(utf8ToString(result[1])))(path);
30
+ return pure(parseFromTokens(tokens));
31
+ });
24
32
  const transpileWithImports = path => parseModuleResult => context => {
25
33
  if (parseModuleResult[0] === 'ok') {
26
34
  const dir = pathConcat(path)('..');
27
35
  const pathsCombine = listMap(pathConcat(dir))(parseModuleResult[1][0]);
28
- const contextWithImports = fold(foldNextModuleOp)({ ...context, stack: { first: path, tail: context.stack } })(pathsCombine);
29
- if (contextWithImports.error !== null) {
30
- return contextWithImports;
31
- }
32
- const args = toArray(listMap(mapDjs(contextWithImports))(pathsCombine));
33
- const djs = { djs: run(parseModuleResult[1][1])(args) };
34
- return { ...contextWithImports, stack: drop(1)(contextWithImports.stack), complete: setReplace(path)(djs)(contextWithImports.complete) };
35
- }
36
- return { ...context, error: parseModuleResult[1] };
37
- };
38
- const parseModule = path => context => {
39
- const content = context.fs.readFileSync(path);
40
- if (content === null) {
41
- return error({ message: 'file not found', metadata: null });
36
+ const pathsArray = toArray(pathsCombine);
37
+ const contextWithStack = { ...context, stack: { first: path, tail: context.stack } };
38
+ return pathsArray.reduce((acc, p) => acc.step(ctx => foldNextModuleOp(p)(ctx)), pure(contextWithStack)).step(contextWithImports => {
39
+ if (contextWithImports.error !== null) {
40
+ return pure(contextWithImports);
41
+ }
42
+ const args = toArray(listMap(mapDjs(contextWithImports))(pathsCombine));
43
+ const djs = { djs: run(parseModuleResult[1][1])(args) };
44
+ return pure({
45
+ ...contextWithImports,
46
+ stack: drop(1)(contextWithImports.stack),
47
+ complete: setReplace(path)(djs)(contextWithImports.complete),
48
+ });
49
+ });
42
50
  }
43
- const tokens = tokenize(stringToList(decodeUtf8(content)))(path);
44
- return parseFromTokens(tokens);
51
+ return pure({ ...context, error: parseModuleResult[1] });
45
52
  };
46
53
  const foldNextModuleOp = path => context => {
47
54
  if (context.error !== null) {
48
- return context;
55
+ return pure(context);
49
56
  }
50
57
  if (includes(path)(context.stack)) {
51
- return { ...context, error: { message: 'circular dependency', metadata: null } };
58
+ return pure({ ...context, error: { message: 'circular dependency', metadata: null } });
52
59
  }
53
60
  if (at(path)(context.complete) !== null) {
54
- return context;
61
+ return pure(context);
55
62
  }
56
- const parseModuleResult = parseModule(path)(context);
57
- return transpileWithImports(path)(parseModuleResult)(context);
63
+ return parseModule(path).step(parseModuleResult => transpileWithImports(path)(parseModuleResult)(context));
58
64
  };
59
- export const transpile = fs => path => {
60
- const context = foldNextModuleOp(path)({ fs, stack: null, complete: null, error: null });
65
+ export const transpile = path => foldNextModuleOp(path)({ stack: null, complete: null, error: null }).step((context) => {
61
66
  if (context.error !== null) {
62
- return error(context.error);
67
+ return pure(error(context.error));
63
68
  }
64
69
  const result = at(path)(context.complete)?.djs;
65
- return ok(result);
66
- };
70
+ return pure(ok(result));
71
+ });
@@ -1,17 +1,15 @@
1
1
  import { sort } from "../../types/object/module.f.js";
2
- import { setReplace } from "../../types/ordered_map/module.f.js";
3
2
  import { transpile } from "./module.f.js";
4
3
  import { stringifyAsTree } from "../serializer/module.f.js";
5
- import { createVirtualIo } from "../../io/virtual/module.f.js";
6
- import { encodeUtf8 } from "../../types/uint8array/module.f.js";
7
- const virtualFs = map => {
8
- return createVirtualIo(map).fs;
4
+ import { virtual, emptyState } from "../../types/effects/node/virtual/module.f.js";
5
+ import { utf8 } from "../../text/module.f.js";
6
+ const run = (root) => (path) => {
7
+ const [_, result] = virtual({ ...emptyState, root })(transpile(path));
8
+ return result;
9
9
  };
10
10
  export default {
11
11
  parse: () => {
12
- const map = setReplace('a')(encodeUtf8('export default 1'))(null);
13
- const fs = virtualFs(map);
14
- const result = transpile(fs)('a');
12
+ const result = run({ a: utf8('export default 1') })('a');
15
13
  if (result[0] === 'error') {
16
14
  throw result[1];
17
15
  }
@@ -21,10 +19,7 @@ export default {
21
19
  }
22
20
  },
23
21
  parseWithSubModule: () => {
24
- const map = setReplace('a/b')(encodeUtf8('import c from "c"\nexport default c'))(null);
25
- const map2 = setReplace('a/c')(encodeUtf8('export default 2'))(map);
26
- const fs = virtualFs(map2);
27
- const result = transpile(fs)('a/b');
22
+ const result = run({ a: { b: utf8('import c from "c"\nexport default c'), c: utf8('export default 2') } })('a/b');
28
23
  if (result[0] === 'error') {
29
24
  throw result[1];
30
25
  }
@@ -34,12 +29,12 @@ export default {
34
29
  }
35
30
  },
36
31
  parseWithSubModules: () => {
37
- const map = setReplace('a')(encodeUtf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'))(null);
38
- const map2 = setReplace('b')(encodeUtf8('import d from "d"\nexport default [0,d]'))(map);
39
- const map3 = setReplace('c')(encodeUtf8('import d from "d"\nexport default [1,d]'))(map2);
40
- const map4 = setReplace('d')(encodeUtf8('export default 2'))(map3);
41
- const fs = virtualFs(map4);
42
- const result = transpile(fs)('a');
32
+ const result = run({
33
+ a: utf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'),
34
+ b: utf8('import d from "d"\nexport default [0,d]'),
35
+ c: utf8('import d from "d"\nexport default [1,d]'),
36
+ d: utf8('export default 2'),
37
+ })('a');
43
38
  if (result[0] === 'error') {
44
39
  throw result[1];
45
40
  }
@@ -49,9 +44,7 @@ export default {
49
44
  }
50
45
  },
51
46
  parseWithFileNotFoundError: () => {
52
- const map = setReplace('a')(encodeUtf8('import b from "b"\nexport default b'))(null);
53
- const fs = virtualFs(map);
54
- const result = transpile(fs)('a');
47
+ const result = run({ a: utf8('import b from "b"\nexport default b') })('a');
55
48
  if (result[0] !== 'error') {
56
49
  throw result;
57
50
  }
@@ -60,11 +53,11 @@ export default {
60
53
  }
61
54
  },
62
55
  parseWithCycleError: () => {
63
- const map = setReplace('a')(encodeUtf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'))(null);
64
- const map2 = setReplace('b')(encodeUtf8('import c from "c"\nexport default c'))(map);
65
- const map3 = setReplace('c')(encodeUtf8('import b from "b"\nexport default b'))(map2);
66
- const fs = virtualFs(map3);
67
- const result = transpile(fs)('a');
56
+ const result = run({
57
+ a: utf8('import b from "b"\nimport c from "c"\nexport default [b,c,b]'),
58
+ b: utf8('import c from "c"\nexport default c'),
59
+ c: utf8('import b from "b"\nexport default b'),
60
+ })('a');
68
61
  if (result[0] !== 'error') {
69
62
  throw result;
70
63
  }
@@ -1,7 +1,2 @@
1
- /**
2
- * FunctionalScript compiler entry points and command handlers.
3
- *
4
- * @module
5
- */
6
- import { type Io } from '../io/module.f.ts';
7
- export declare const main: (io: Io) => Promise<number>;
1
+ import { type NodeProgram } from '../types/effects/node/module.f.ts';
2
+ export declare const main: NodeProgram;
@@ -3,36 +3,36 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { fromIo } from "../io/module.f.js";
7
6
  import { compile } from "../djs/module.f.js";
8
7
  import { main as testMain } from "../dev/tf/module.f.js";
9
8
  import { main as casMain } from "../cas/module.f.js";
10
- export const main = async (io) => {
11
- const { error } = io.console;
12
- const { process, asyncImport } = io;
13
- const { env } = process;
14
- const [command, ...rest] = process.argv.slice(2);
15
- const eRun = fromIo(io);
9
+ import { import_, error } from "../types/effects/node/module.f.js";
10
+ import { pure } from "../types/effects/module.f.js";
11
+ export const main = options => {
12
+ const [command, ...rest] = options.args;
16
13
  switch (command) {
17
14
  case 'test':
18
15
  case 't':
19
- return testMain(io);
16
+ return testMain({ ...options, args: rest });
20
17
  case 'compile':
21
18
  case 'c':
22
- return compile(io)(rest);
19
+ return compile(rest);
23
20
  case 'cas':
24
21
  case 's':
25
- return eRun(casMain(rest));
22
+ return casMain(rest);
26
23
  case 'run':
27
- case 'r':
24
+ case 'r': {
28
25
  const [file, ...args] = rest;
29
- const m = await asyncImport(file);
30
- return eRun(m.default(args, env));
26
+ return import_(file).step(([s, v]) => {
27
+ if (s === 'error') {
28
+ throw v;
29
+ }
30
+ return v.default({ ...options, args });
31
+ });
32
+ }
31
33
  case undefined:
32
- error('Error: command is required');
33
- return Promise.resolve(1);
34
+ return error('Error: command is required').step(() => pure(1));
34
35
  default:
35
- error(`Error: Unknown command "${command}"`);
36
- return Promise.resolve(1);
36
+ return error(`Error: Unknown command "${command}"`).step(() => pure(1));
37
37
  }
38
38
  };
package/fs/fjs/module.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { main } from "./module.f.js";
3
- import { legacyRun } from "../io/module.js";
4
- legacyRun(main);
3
+ import effectRun from "../io/module.js";
4
+ effectRun(main);
@@ -1,3 +1,9 @@
1
+ /**
2
+ * HTML serialization helpers: `Element`/`Attributes` builders, void-tag
3
+ * handling, attribute/text escaping, and a UTF-8 emitter for full documents.
4
+ *
5
+ * @module
6
+ */
1
7
  import { type List } from '../types/list/module.f.ts';
2
8
  import { type Vec } from '../types/bit_vec/module.f.ts';
3
9
  type Tag = string;