functionalscript 0.8.0 → 0.8.1

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 (113) hide show
  1. package/bnf/data/module.f.d.ts +6 -0
  2. package/bnf/data/module.f.js +57 -4
  3. package/bnf/data/test.f.d.ts +1 -0
  4. package/bnf/data/test.f.js +67 -1
  5. package/ci/module.f.d.ts +3 -0
  6. package/ci/module.f.js +169 -0
  7. package/ci/module.js +3 -0
  8. package/crypto/hmac/module.f.d.ts +5 -4
  9. package/crypto/hmac/module.f.js +9 -18
  10. package/crypto/hmac/test.f.d.ts +1 -0
  11. package/crypto/hmac/test.f.js +16 -8
  12. package/crypto/prime_field/module.f.d.ts +1 -1
  13. package/crypto/prime_field/module.f.js +4 -3
  14. package/crypto/prime_field/test.f.js +13 -13
  15. package/crypto/rfc6979/module.f.d.ts +15 -0
  16. package/crypto/rfc6979/module.f.js +98 -0
  17. package/crypto/rfc6979/test.f.d.ts +10 -0
  18. package/crypto/rfc6979/test.f.js +490 -0
  19. package/crypto/secp/module.f.d.ts +4 -4
  20. package/crypto/secp/module.f.js +1 -1
  21. package/crypto/secp/test.f.js +8 -8
  22. package/crypto/sha2/module.f.d.ts +11 -5
  23. package/crypto/sha2/module.f.js +4 -3
  24. package/crypto/sha2/test.f.d.ts +4 -1
  25. package/crypto/sha2/test.f.js +41 -31
  26. package/crypto/sign/module.f.d.ts +1 -1
  27. package/crypto/sign/module.f.js +3 -2
  28. package/dev/tf/all.test.js +9 -1
  29. package/djs/ast/module.f.d.ts +3 -3
  30. package/djs/ast/test.f.js +7 -8
  31. package/djs/parser/module.f.d.ts +3 -3
  32. package/djs/parser/module.f.js +4 -4
  33. package/djs/parser/test.f.js +76 -77
  34. package/djs/serializer/module.f.d.ts +8 -8
  35. package/djs/serializer/module.f.js +4 -7
  36. package/djs/serializer/test.f.js +8 -9
  37. package/djs/tokenizer/module.f.d.ts +2 -2
  38. package/djs/tokenizer/module.f.js +3 -5
  39. package/djs/tokenizer/test.f.js +8 -10
  40. package/djs/transpiler/module.f.d.ts +3 -3
  41. package/djs/transpiler/module.f.js +2 -0
  42. package/fsc/bnf.f.d.ts +1 -1
  43. package/fsc/bnf.f.js +39 -51
  44. package/fsc/json.f.d.ts +1 -1
  45. package/fsc/json.f.js +56 -81
  46. package/fsc/test.f.js +4 -6
  47. package/fsm/module.f.js +3 -3
  48. package/fsm/test.f.js +21 -25
  49. package/html/module.f.js +17 -4
  50. package/html/test.f.d.ts +7 -0
  51. package/html/test.f.js +37 -0
  52. package/issues/031-json.f.d.ts +1 -0
  53. package/js/tokenizer/module.f.d.ts +4 -4
  54. package/js/tokenizer/module.f.js +12 -17
  55. package/js/tokenizer/test.f.js +9 -11
  56. package/json/module.f.d.ts +6 -6
  57. package/json/module.f.js +5 -10
  58. package/json/parser/module.f.d.ts +4 -4
  59. package/json/parser/module.f.js +7 -4
  60. package/json/parser/test.f.js +47 -49
  61. package/json/serializer/module.f.d.ts +6 -6
  62. package/json/serializer/module.f.js +3 -2
  63. package/json/serializer/test.f.js +13 -13
  64. package/json/test.f.js +13 -15
  65. package/json/tokenizer/module.f.d.ts +4 -4
  66. package/json/tokenizer/module.f.js +6 -7
  67. package/json/tokenizer/test.f.js +7 -9
  68. package/package.json +5 -5
  69. package/text/ascii/test.f.js +2 -2
  70. package/text/module.f.d.ts +3 -2
  71. package/text/module.f.js +2 -2
  72. package/text/test.f.js +3 -3
  73. package/text/utf16/test.f.js +2 -2
  74. package/text/utf8/test.f.js +2 -2
  75. package/types/array/test.f.js +2 -2
  76. package/types/bigint/module.f.d.ts +6 -3
  77. package/types/bigint/module.f.js +12 -11
  78. package/types/bigint/test.f.d.ts +2 -0
  79. package/types/bigint/test.f.js +21 -2
  80. package/types/bit_vec/module.f.d.ts +66 -34
  81. package/types/bit_vec/module.f.js +97 -32
  82. package/types/bit_vec/test.f.d.ts +7 -0
  83. package/types/bit_vec/test.f.js +283 -62
  84. package/types/btree/find/test.f.js +9 -8
  85. package/types/btree/remove/test.f.js +4 -4
  86. package/types/btree/set/test.f.js +4 -4
  87. package/types/btree/test.f.js +7 -7
  88. package/types/byte_set/test.f.js +2 -2
  89. package/types/function/compare/module.f.d.ts +15 -1
  90. package/types/function/compare/module.f.js +1 -1
  91. package/types/function/compare/test.f.js +37 -4
  92. package/types/list/test.f.js +93 -93
  93. package/types/monoid/module.f.d.ts +4 -4
  94. package/types/monoid/module.f.js +3 -3
  95. package/types/monoid/test.f.js +3 -3
  96. package/types/nominal/module.f.d.ts +5 -0
  97. package/types/nominal/module.f.js +4 -0
  98. package/types/nominal/test.f.d.ts +5 -0
  99. package/types/nominal/test.f.js +53 -0
  100. package/types/number/module.f.js +2 -2
  101. package/types/range_map/test.f.js +21 -21
  102. package/types/sorted_list/test.f.js +10 -10
  103. package/types/sorted_set/test.f.js +14 -14
  104. package/types/string/module.f.js +2 -2
  105. package/types/string_set/module.f.js +3 -3
  106. package/bnf/func/module.f.d.ts +0 -148
  107. package/bnf/func/module.f.js +0 -132
  108. package/bnf/func/test.f.d.ts +0 -12
  109. package/bnf/func/test.f.js +0 -171
  110. package/bnf/func/testlib.f.d.ts +0 -25
  111. package/bnf/func/testlib.f.js +0 -150
  112. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  113. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
@@ -1,14 +1,14 @@
1
1
  import { get, merge, fromRange, rangeMap } from "./module.f.js";
2
- import { unsafeCmp } from "../function/compare/module.f.js";
3
- import * as json from "../../json/module.f.js";
2
+ import { stringify } from "../../json/module.f.js";
4
3
  import { sort } from "../object/module.f.js";
5
4
  import { union } from "../sorted_set/module.f.js";
6
5
  import { equal, toArray } from "../list/module.f.js";
7
- import * as operator from "../function/operator/module.f.js";
8
- const stringify = json.stringify(sort);
6
+ import { strictEqual } from "../function/operator/module.f.js";
7
+ import { cmp } from "../string/module.f.js";
8
+ const str = stringify(sort);
9
9
  const op = {
10
- union: union(unsafeCmp),
11
- equal: equal(operator.strictEqual),
10
+ union: union(cmp),
11
+ equal: equal(strictEqual),
12
12
  def: []
13
13
  };
14
14
  export default {
@@ -56,7 +56,7 @@ export default {
56
56
  const a = [[['a'], 1], [['b'], 2]];
57
57
  const b = null;
58
58
  const merged = merge(op)(a)(b);
59
- const result = stringify(toArray(merged));
59
+ const result = str(toArray(merged));
60
60
  if (result !== '[[["a"],1],[["b"],2]]') {
61
61
  throw result;
62
62
  }
@@ -65,7 +65,7 @@ export default {
65
65
  const a = null;
66
66
  const b = [[['a'], 1], [['b'], 2]];
67
67
  const merged = merge(op)(a)(b);
68
- const result = stringify(toArray(merged));
68
+ const result = str(toArray(merged));
69
69
  if (result !== '[[["a"],1],[["b"],2]]') {
70
70
  throw result;
71
71
  }
@@ -74,7 +74,7 @@ export default {
74
74
  const a = [[['a'], 1], [['b'], 2]];
75
75
  const b = [[['a'], 1], [['b'], 2]];
76
76
  const merged = merge(op)(a)(b);
77
- const result = stringify(toArray(merged));
77
+ const result = str(toArray(merged));
78
78
  if (result !== '[[["a"],1],[["b"],2]]') {
79
79
  throw result;
80
80
  }
@@ -83,7 +83,7 @@ export default {
83
83
  const a = [[['a'], 1], [['c'], 3]];
84
84
  const b = [[['b'], 2], [['d'], 4]];
85
85
  const merged = merge(op)(a)(b);
86
- const result = stringify(toArray(merged));
86
+ const result = str(toArray(merged));
87
87
  if (result !== '[[["a","b"],1],[["b","c"],2],[["c","d"],3],[["d"],4]]') {
88
88
  throw result;
89
89
  }
@@ -92,7 +92,7 @@ export default {
92
92
  const a = [[['a'], 1], [['d'], 4]];
93
93
  const b = [[['b'], 2], [['c'], 3]];
94
94
  const merged = merge(op)(a)(b);
95
- const result = stringify(toArray(merged));
95
+ const result = str(toArray(merged));
96
96
  if (result !== '[[["a","b"],1],[["b","d"],2],[["c","d"],3],[["d"],4]]') {
97
97
  throw result;
98
98
  }
@@ -101,7 +101,7 @@ export default {
101
101
  const a = [[['a'], 1], [['b'], 2]];
102
102
  const b = [[['b'], 1], [['a'], 2]];
103
103
  const merged = merge(op)(a)(b);
104
- const result = stringify(toArray(merged));
104
+ const result = str(toArray(merged));
105
105
  if (result !== '[[["a","b"],2]]') {
106
106
  throw result;
107
107
  }
@@ -110,7 +110,7 @@ export default {
110
110
  const a = [[['a'], 1], [['b'], 2], [['a'], 3]];
111
111
  const b = [[['a'], 5]];
112
112
  const merged = merge(op)(a)(b);
113
- const result = stringify(toArray(merged));
113
+ const result = str(toArray(merged));
114
114
  if (result !== '[[["a"],1],[["a","b"],2],[["a"],5]]') {
115
115
  throw result;
116
116
  }
@@ -122,56 +122,56 @@ export default {
122
122
  return [
123
123
  () => {
124
124
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
125
- const result = stringify(at(5)(rm));
125
+ const result = str(at(5)(rm));
126
126
  if (result !== '["a"]') {
127
127
  throw result;
128
128
  }
129
129
  },
130
130
  () => {
131
131
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
132
- const result = stringify(at(10)(rm));
132
+ const result = str(at(10)(rm));
133
133
  if (result !== '["a"]') {
134
134
  throw result;
135
135
  }
136
136
  },
137
137
  () => {
138
138
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
139
- const result = stringify(at(15)(rm));
139
+ const result = str(at(15)(rm));
140
140
  if (result !== '["b"]') {
141
141
  throw result;
142
142
  }
143
143
  },
144
144
  () => {
145
145
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
146
- const result = stringify(at(20)(rm));
146
+ const result = str(at(20)(rm));
147
147
  if (result !== '["b"]') {
148
148
  throw result;
149
149
  }
150
150
  },
151
151
  () => {
152
152
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
153
- const result = stringify(at(25)(rm));
153
+ const result = str(at(25)(rm));
154
154
  if (result !== '["c"]') {
155
155
  throw result;
156
156
  }
157
157
  },
158
158
  () => {
159
159
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
160
- const result = stringify(at(30)(rm));
160
+ const result = str(at(30)(rm));
161
161
  if (result !== '["c"]') {
162
162
  throw result;
163
163
  }
164
164
  },
165
165
  () => {
166
166
  const rm = [[['a'], 10], [['b'], 20], [['c'], 30]];
167
- const result = stringify(at(35)(rm));
167
+ const result = str(at(35)(rm));
168
168
  if (result !== '[]') {
169
169
  throw result;
170
170
  }
171
171
  },
172
172
  () => {
173
173
  const rm = [];
174
- const result = stringify(at(10)(rm));
174
+ const result = str(at(10)(rm));
175
175
  if (result !== '[]') {
176
176
  throw result;
177
177
  }
@@ -1,21 +1,21 @@
1
1
  import { find, merge } from "./module.f.js";
2
- import { unsafeCmp } from "../function/compare/module.f.js";
3
- import * as json from "../../json/module.f.js";
2
+ import { stringify } from "../../json/module.f.js";
4
3
  import { sort } from "../object/module.f.js";
5
4
  import { toArray, countdown, length } from "../list/module.f.js";
6
5
  import { flip } from "../function/module.f.js";
7
- const stringify = json.stringify(sort);
8
- const reverseCmp = flip(unsafeCmp);
6
+ import { cmp } from "../number/module.f.js";
7
+ const str = stringify(sort);
8
+ const reverseCmp = flip(cmp);
9
9
  export default {
10
10
  sortedMergre: [
11
11
  () => {
12
- const result = stringify(toArray(merge(unsafeCmp)([2, 3, 4])([1, 3, 5])));
12
+ const result = str(toArray(merge(cmp)([2, 3, 4])([1, 3, 5])));
13
13
  if (result !== '[1,2,3,4,5]') {
14
14
  throw result;
15
15
  }
16
16
  },
17
17
  () => {
18
- const result = stringify(toArray(merge(unsafeCmp)([1, 2, 3])([])));
18
+ const result = str(toArray(merge(cmp)([1, 2, 3])([])));
19
19
  if (result !== '[1,2,3]') {
20
20
  throw result;
21
21
  }
@@ -32,25 +32,25 @@ export default {
32
32
  ],
33
33
  find: [
34
34
  () => {
35
- const result = find(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
35
+ const result = find(cmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
36
36
  if (result !== 0) {
37
37
  throw result;
38
38
  }
39
39
  },
40
40
  () => {
41
- const result = find(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
41
+ const result = find(cmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
42
42
  if (result !== null) {
43
43
  throw result;
44
44
  }
45
45
  },
46
46
  () => {
47
- const result = find(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
47
+ const result = find(cmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
48
48
  if (result !== null) {
49
49
  throw result;
50
50
  }
51
51
  },
52
52
  () => {
53
- const result = find(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
53
+ const result = find(cmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
54
54
  if (result !== 80) {
55
55
  throw result;
56
56
  }
@@ -1,22 +1,22 @@
1
1
  import { has, intersect, union } from "./module.f.js";
2
- import { unsafeCmp } from "../function/compare/module.f.js";
3
- import * as json from "../../json/module.f.js";
2
+ import { stringify } from "../../json/module.f.js";
4
3
  import { sort } from "../object/module.f.js";
5
4
  import { toArray, countdown, length } from "../list/module.f.js";
6
5
  import { flip } from "../function/module.f.js";
7
- const stringify = a => json.stringify(sort)(a);
8
- const reverseCmp = flip(unsafeCmp);
6
+ import { cmp } from "../number/module.f.js";
7
+ const str = a => stringify(sort)(a);
8
+ const reverseCmp = flip(cmp);
9
9
  export default {
10
10
  example: () => {
11
11
  const cmp = (a) => (b) => a < b ? -1 : a > b ? 1 : 0;
12
12
  const setA = [1, 3, 5];
13
13
  const setB = [3, 4, 5];
14
14
  const unionSet = union(cmp)(setA)(setB); // [1, 3, 4, 5]
15
- if (stringify(unionSet) !== '[1,3,4,5]') {
15
+ if (str(unionSet) !== '[1,3,4,5]') {
16
16
  throw 0;
17
17
  }
18
18
  const intersectionSet = intersect(cmp)(setA)(setB); // [3, 5]
19
- if (stringify(intersectionSet) !== '[3,5]') {
19
+ if (str(intersectionSet) !== '[3,5]') {
20
20
  throw 1;
21
21
  }
22
22
  if (!has(cmp)(3)(setA)) {
@@ -28,13 +28,13 @@ export default {
28
28
  },
29
29
  union: [
30
30
  () => {
31
- const result = stringify(toArray(union(unsafeCmp)([2, 3, 4])([1, 3, 5])));
31
+ const result = str(toArray(union(cmp)([2, 3, 4])([1, 3, 5])));
32
32
  if (result !== '[1,2,3,4,5]') {
33
33
  throw result;
34
34
  }
35
35
  },
36
36
  () => {
37
- const result = stringify(toArray(union(unsafeCmp)([1, 2, 3])([])));
37
+ const result = str(toArray(union(cmp)([1, 2, 3])([])));
38
38
  if (result !== '[1,2,3]') {
39
39
  throw result;
40
40
  }
@@ -51,13 +51,13 @@ export default {
51
51
  ],
52
52
  intersect: [
53
53
  () => {
54
- const result = stringify(toArray(intersect(unsafeCmp)([2, 3, 4])([1, 3, 5])));
54
+ const result = str(toArray(intersect(cmp)([2, 3, 4])([1, 3, 5])));
55
55
  if (result !== '[3]') {
56
56
  throw result;
57
57
  }
58
58
  },
59
59
  () => {
60
- const result = stringify(toArray(intersect(unsafeCmp)([1, 2, 3])([])));
60
+ const result = str(toArray(intersect(cmp)([1, 2, 3])([])));
61
61
  if (result !== '[]') {
62
62
  throw result;
63
63
  }
@@ -65,25 +65,25 @@ export default {
65
65
  ],
66
66
  has: [
67
67
  () => {
68
- const result = has(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
68
+ const result = has(cmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
69
69
  if (!result) {
70
70
  throw result;
71
71
  }
72
72
  },
73
73
  () => {
74
- const result = has(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
74
+ const result = has(cmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
75
75
  if (result) {
76
76
  throw result;
77
77
  }
78
78
  },
79
79
  () => {
80
- const result = has(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
80
+ const result = has(cmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
81
81
  if (result) {
82
82
  throw result;
83
83
  }
84
84
  },
85
85
  () => {
86
- const result = has(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
86
+ const result = has(cmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
87
87
  if (!result) {
88
88
  throw result;
89
89
  }
@@ -17,10 +17,10 @@
17
17
  */
18
18
  import { reduce as listReduce, repeat as listRepeat } from "../list/module.f.js";
19
19
  import { compose } from "../function/module.f.js";
20
- import { unsafeCmp } from "../function/compare/module.f.js";
20
+ import { cmp as uCmp } from "../function/compare/module.f.js";
21
21
  import { join as joinOp, concat as concatOp } from "../function/operator/module.f.js";
22
22
  const reduce = o => listReduce(o)('');
23
23
  export const join = compose(joinOp)(reduce);
24
24
  export const concat = reduce(concatOp);
25
25
  export const repeat = v => compose(listRepeat(v))(concat);
26
- export const cmp = unsafeCmp;
26
+ export const cmp = uCmp;
@@ -19,15 +19,15 @@
19
19
  * if (contains('banana')(mySet)) { throw '4' }
20
20
  * ```
21
21
  */
22
- import * as btree from "../btree/module.f.js";
22
+ import { empty as btEmpty, values as btValues } from "../btree/module.f.js";
23
23
  import { find, isFound } from "../btree/find/module.f.js";
24
24
  import { remove as btreeRemove } from "../btree/remove/module.f.js";
25
25
  import { set as btreeSet } from "../btree/set/module.f.js";
26
26
  import { cmp } from "../string/module.f.js";
27
27
  import { fold } from "../list/module.f.js";
28
28
  import { compose } from "../function/module.f.js";
29
- export const values = btree.values;
30
- export const empty = btree.empty;
29
+ export const values = btValues;
30
+ export const empty = btEmpty;
31
31
  export const contains = value => {
32
32
  const f = find(cmp(value));
33
33
  return s => s !== null && isFound(f(s).first);
@@ -1,148 +0,0 @@
1
- /**
2
- * Types for defining language grammar using Backus-Naur Form (BNF).
3
- *
4
- * Utilities for serializing and deserializing BNF grammar
5
- * and creating a simple LL(1) parser.
6
- *
7
- * See [Backus-Naur form](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form).
8
- *
9
- * @module
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * import type { Rule } from './module.f.ts'
15
- *
16
- * // Matches 'A-Z', 'a-z', and '0-9'
17
- * const grammar: Rule = () => [
18
- * [[65, 90]],
19
- * [[97, 122]],
20
- * [[48, 57]],
21
- * ]
22
- * ```
23
- */
24
- import { type CodePoint } from '../../text/utf16/module.f.ts';
25
- /**
26
- * Represents a terminal range as a pair of Unicode code points.
27
- * Typically used to define character ranges.
28
- *
29
- * @example
30
- *
31
- * ```ts
32
- * const alpha: TerminalRange = [65, 90] // Matches 'A-Z'
33
- * ```
34
- */
35
- export type TerminalRange = readonly [CodePoint, CodePoint];
36
- /**
37
- * Represents a sequence of rules that must match in order.
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * const alpha: TerminalRange = [65, 90] // Matches 'A-Z'
43
- * const id2: Sequence = [alpha, alpha] // Matches two uppercase letters
44
- * ```
45
- */
46
- export type Sequence = readonly (TerminalRange | Rule)[];
47
- /**
48
- * Represents a logical "or" operation between multiple sequences.
49
- * Allows defining alternatives within the grammar.
50
- *
51
- * @example
52
- *
53
- * ```ts
54
- * const alpha: TerminalRange = [65, 90] // Matches 'A-Z'
55
- * const id2: Sequence = [alpha, alpha] // Matches two uppercase letters
56
- * const digit: TerminalRange = [48, 57] // Matches '0-9'
57
- * // Matches two uppercase letters or one digit
58
- * const id2OrDigit: Or = [
59
- * id2,
60
- * [digit],
61
- * ]
62
- * ```
63
- */
64
- export type Or = readonly Sequence[];
65
- /**
66
- * Represents a lazy grammar rule for recursive definitions.
67
- *
68
- * @example
69
- *
70
- * ```ts
71
- * const alpha: TerminalRange = [65, 90] // Matches 'A-Z'
72
- * // zero or more alpha symbols
73
- * const alpha0x: Rule = () => [
74
- * [], // Empty
75
- * [alpha, alpha0x] // Recursive
76
- * ]
77
- * const id: Sequence = [alpha, alpha0x]
78
- * ```
79
- */
80
- export type Rule = () => Or;
81
- /**
82
- * Converts a string to an array of terminal ranges where each character is a separate range.
83
- *
84
- * @param s - The input string.
85
- * @returns An array of terminal ranges representing each character in the string.
86
- *
87
- * @example
88
- *
89
- * ```ts
90
- * const ranges = str('abc') // [[97, 97], [98, 98], [99, 99]]
91
- * ```
92
- */
93
- export declare const str: (s: string) => readonly TerminalRange[];
94
- /**
95
- * Converts a single character string to a terminal range.
96
- *
97
- * @param a - The input character string.
98
- * @returns A terminal range representing the character.
99
- *
100
- * @example
101
- * ```ts
102
- * const range = cp('A'); // [65, 65]
103
- * ```
104
- */
105
- export declare const cp: (a: string) => TerminalRange;
106
- /**
107
- * Converts a two-character string into a terminal range.
108
- *
109
- * @param ab - The input string of two characters.
110
- * @returns A terminal range representing the two characters.
111
- *
112
- * @throws {number} Throws an error if the input string does not have exactly two code points.
113
- *
114
- * @example
115
- * ```ts
116
- * const result = range('AZ'); // [65, 90]
117
- * ```
118
- */
119
- export declare const range: (ab: string) => TerminalRange;
120
- type RangeSet = readonly TerminalRange[];
121
- /**
122
- * A set of terminal ranges compatible with the `Or` rule.
123
- */
124
- export type OrRangeSet = readonly (readonly [TerminalRange])[];
125
- /**
126
- * Convert a sequence of character into `OrRangeSet`
127
- *
128
- * @param s a set of code points
129
- * @returns A set compatible with `Or`
130
- */
131
- export declare const set: (s: string) => OrRangeSet;
132
- /**
133
- * Removes a terminal range from a set of ranges.
134
- *
135
- * @param range the original range.
136
- * @param removeSet the set of ranges to be removed.
137
- * @returns The resulting set of ranges after removal.
138
- *
139
- * @example
140
- *
141
- * ```ts
142
- * const result = remove([65, 90], [cp('C'), cp('W')]) // [A..Z] w/o C and W
143
- * ```
144
- */
145
- export declare const remove: (range: TerminalRange, removeSet: RangeSet) => OrRangeSet;
146
- export declare const repeat0: (rule: Rule) => Rule;
147
- export declare const join0: (rule: Rule, separator: Rule) => Rule;
148
- export {};
@@ -1,132 +0,0 @@
1
- /**
2
- * Types for defining language grammar using Backus-Naur Form (BNF).
3
- *
4
- * Utilities for serializing and deserializing BNF grammar
5
- * and creating a simple LL(1) parser.
6
- *
7
- * See [Backus-Naur form](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form).
8
- *
9
- * @module
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * import type { Rule } from './module.f.ts'
15
- *
16
- * // Matches 'A-Z', 'a-z', and '0-9'
17
- * const grammar: Rule = () => [
18
- * [[65, 90]],
19
- * [[97, 122]],
20
- * [[48, 57]],
21
- * ]
22
- * ```
23
- */
24
- import { stringToCodePointList } from "../../text/utf16/module.f.js";
25
- import { map, toArray } from "../../types/list/module.f.js";
26
- import { one } from "../../types/range/module.f.js";
27
- const toTerminalRangeMap = map(one);
28
- /**
29
- * Converts a string to an array of terminal ranges where each character is a separate range.
30
- *
31
- * @param s - The input string.
32
- * @returns An array of terminal ranges representing each character in the string.
33
- *
34
- * @example
35
- *
36
- * ```ts
37
- * const ranges = str('abc') // [[97, 97], [98, 98], [99, 99]]
38
- * ```
39
- */
40
- export const str = (s) => toArray(toTerminalRangeMap(stringToCodePointList(s)));
41
- /**
42
- * Converts a single character string to a terminal range.
43
- *
44
- * @param a - The input character string.
45
- * @returns A terminal range representing the character.
46
- *
47
- * @example
48
- * ```ts
49
- * const range = cp('A'); // [65, 65]
50
- * ```
51
- */
52
- export const cp = (a) => one(a.codePointAt(0));
53
- /**
54
- * Converts a two-character string into a terminal range.
55
- *
56
- * @param ab - The input string of two characters.
57
- * @returns A terminal range representing the two characters.
58
- *
59
- * @throws {number} Throws an error if the input string does not have exactly two code points.
60
- *
61
- * @example
62
- * ```ts
63
- * const result = range('AZ'); // [65, 90]
64
- * ```
65
- */
66
- export const range = (ab) => {
67
- const a = toArray(stringToCodePointList(ab));
68
- if (a.length !== 2) {
69
- throw a.length;
70
- }
71
- // deno-lint-ignore no-explicit-any
72
- return a;
73
- };
74
- const toOr = (r) => r.map(v => [v]);
75
- /**
76
- * Convert a sequence of character into `OrRangeSet`
77
- *
78
- * @param s a set of code points
79
- * @returns A set compatible with `Or`
80
- */
81
- export const set = (s) => toOr(str(s));
82
- const removeOne = (set, [a, b]) => {
83
- let result = [];
84
- for (const [a0, b0] of set) {
85
- if (a0 < a) {
86
- // [a0
87
- // ]a
88
- result = [...result, [a0, Math.min(b0, a - 1)]];
89
- }
90
- if (b < b0) {
91
- // b0]
92
- // b[
93
- result = [...result, [Math.max(b + 1, a0), b0]];
94
- }
95
- }
96
- return result;
97
- };
98
- /**
99
- * Removes a terminal range from a set of ranges.
100
- *
101
- * @param range the original range.
102
- * @param removeSet the set of ranges to be removed.
103
- * @returns The resulting set of ranges after removal.
104
- *
105
- * @example
106
- *
107
- * ```ts
108
- * const result = remove([65, 90], [cp('C'), cp('W')]) // [A..Z] w/o C and W
109
- * ```
110
- */
111
- export const remove = (range, removeSet) => {
112
- let result = [range];
113
- for (const r of removeSet) {
114
- result = removeOne(result, r);
115
- }
116
- return toOr(result);
117
- };
118
- export const repeat0 = (rule) => {
119
- const result = () => [
120
- [],
121
- [rule, result],
122
- ];
123
- return result;
124
- };
125
- export const join0 = (rule, separator) => {
126
- const tail = repeat0(() => [[separator, rule]]);
127
- const result = () => [
128
- [],
129
- [rule, tail],
130
- ];
131
- return result;
132
- };
@@ -1,12 +0,0 @@
1
- declare const _default: {
2
- example: {
3
- module: () => void;
4
- types: () => void;
5
- str: () => void;
6
- cp: () => void;
7
- range: () => void;
8
- remove: () => void;
9
- };
10
- remove: () => void;
11
- };
12
- export default _default;