functionalscript 0.7.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 (125) hide show
  1. package/LICENSE +21 -661
  2. package/README.md +3 -2
  3. package/bnf/data/module.f.d.ts +16 -6
  4. package/bnf/data/module.f.js +115 -23
  5. package/bnf/data/test.f.d.ts +4 -0
  6. package/bnf/data/test.f.js +389 -14
  7. package/bnf/module.f.d.ts +5 -4
  8. package/bnf/module.f.js +1 -1
  9. package/bnf/testlib.f.js +1 -1
  10. package/ci/module.f.d.ts +3 -0
  11. package/ci/module.f.js +169 -0
  12. package/ci/module.js +3 -0
  13. package/crypto/hmac/module.f.d.ts +5 -4
  14. package/crypto/hmac/module.f.js +9 -18
  15. package/crypto/hmac/test.f.d.ts +1 -0
  16. package/crypto/hmac/test.f.js +16 -8
  17. package/crypto/prime_field/module.f.d.ts +1 -1
  18. package/crypto/prime_field/module.f.js +4 -3
  19. package/crypto/prime_field/test.f.js +13 -13
  20. package/crypto/rfc6979/module.f.d.ts +15 -0
  21. package/crypto/rfc6979/module.f.js +98 -0
  22. package/crypto/rfc6979/test.f.d.ts +10 -0
  23. package/crypto/rfc6979/test.f.js +490 -0
  24. package/crypto/secp/module.f.d.ts +4 -4
  25. package/crypto/secp/module.f.js +1 -1
  26. package/crypto/secp/test.f.js +8 -8
  27. package/crypto/sha2/module.f.d.ts +11 -5
  28. package/crypto/sha2/module.f.js +4 -3
  29. package/crypto/sha2/test.f.d.ts +4 -1
  30. package/crypto/sha2/test.f.js +41 -31
  31. package/crypto/sign/module.f.d.ts +1 -1
  32. package/crypto/sign/module.f.js +3 -2
  33. package/dev/tf/all.test.js +9 -1
  34. package/djs/ast/module.f.d.ts +3 -3
  35. package/djs/ast/test.f.js +7 -8
  36. package/djs/parser/module.f.d.ts +3 -3
  37. package/djs/parser/module.f.js +4 -4
  38. package/djs/parser/test.f.js +76 -77
  39. package/djs/serializer/module.f.d.ts +8 -8
  40. package/djs/serializer/module.f.js +4 -7
  41. package/djs/serializer/test.f.js +8 -9
  42. package/djs/tokenizer/module.f.d.ts +2 -2
  43. package/djs/tokenizer/module.f.js +3 -5
  44. package/djs/tokenizer/test.f.js +8 -10
  45. package/djs/transpiler/module.f.d.ts +3 -3
  46. package/djs/transpiler/module.f.js +2 -0
  47. package/fsc/bnf.f.d.ts +1 -1
  48. package/fsc/bnf.f.js +39 -51
  49. package/fsc/json.f.d.ts +1 -1
  50. package/fsc/json.f.js +56 -81
  51. package/fsc/test.f.d.ts +5 -0
  52. package/fsc/test.f.js +69 -7
  53. package/fsm/module.f.js +3 -3
  54. package/fsm/test.f.js +21 -25
  55. package/html/module.f.js +17 -4
  56. package/html/test.f.d.ts +7 -0
  57. package/html/test.f.js +37 -0
  58. package/issues/031-json.f.d.ts +1 -0
  59. package/js/tokenizer/module.f.d.ts +4 -4
  60. package/js/tokenizer/module.f.js +12 -17
  61. package/js/tokenizer/test.f.js +9 -11
  62. package/json/module.f.d.ts +6 -6
  63. package/json/module.f.js +5 -10
  64. package/json/parser/module.f.d.ts +4 -4
  65. package/json/parser/module.f.js +7 -4
  66. package/json/parser/test.f.js +47 -49
  67. package/json/serializer/module.f.d.ts +6 -6
  68. package/json/serializer/module.f.js +3 -2
  69. package/json/serializer/test.f.js +13 -13
  70. package/json/test.f.js +13 -15
  71. package/json/tokenizer/module.f.d.ts +4 -4
  72. package/json/tokenizer/module.f.js +6 -7
  73. package/json/tokenizer/test.f.js +7 -9
  74. package/nanvm-lib/tests/vm/test.f.d.ts +25 -0
  75. package/nanvm-lib/tests/vm/test.f.js +105 -0
  76. package/package.json +8 -8
  77. package/text/ascii/test.f.js +2 -2
  78. package/text/module.f.d.ts +3 -2
  79. package/text/module.f.js +2 -2
  80. package/text/test.f.js +3 -3
  81. package/text/utf16/test.f.js +2 -2
  82. package/text/utf8/test.f.js +2 -2
  83. package/types/array/test.f.js +2 -2
  84. package/types/bigint/module.f.d.ts +6 -3
  85. package/types/bigint/module.f.js +12 -11
  86. package/types/bigint/test.f.d.ts +2 -0
  87. package/types/bigint/test.f.js +21 -2
  88. package/types/bit_vec/module.f.d.ts +66 -34
  89. package/types/bit_vec/module.f.js +97 -32
  90. package/types/bit_vec/test.f.d.ts +7 -0
  91. package/types/bit_vec/test.f.js +283 -62
  92. package/types/btree/find/test.f.js +9 -8
  93. package/types/btree/remove/test.f.js +4 -4
  94. package/types/btree/set/test.f.js +4 -4
  95. package/types/btree/test.f.js +7 -7
  96. package/types/byte_set/test.f.js +2 -2
  97. package/types/function/compare/module.f.d.ts +15 -1
  98. package/types/function/compare/module.f.js +1 -1
  99. package/types/function/compare/test.f.js +37 -4
  100. package/types/list/test.f.js +93 -93
  101. package/types/monoid/module.f.d.ts +4 -4
  102. package/types/monoid/module.f.js +3 -3
  103. package/types/monoid/test.f.js +3 -3
  104. package/types/nominal/module.f.d.ts +5 -0
  105. package/types/nominal/module.f.js +4 -0
  106. package/types/nominal/test.f.d.ts +5 -0
  107. package/types/nominal/test.f.js +53 -0
  108. package/types/number/module.f.js +2 -2
  109. package/types/range_map/test.f.js +21 -21
  110. package/types/sorted_list/test.f.js +10 -10
  111. package/types/sorted_set/test.f.js +14 -14
  112. package/types/string/module.f.js +2 -2
  113. package/types/string_set/module.f.js +3 -3
  114. package/bnf/djs/module.f.d.ts +0 -77
  115. package/bnf/djs/module.f.js +0 -207
  116. package/bnf/djs/test.f.d.ts +0 -8
  117. package/bnf/djs/test.f.js +0 -277
  118. package/bnf/func/module.f.d.ts +0 -148
  119. package/bnf/func/module.f.js +0 -132
  120. package/bnf/func/test.f.d.ts +0 -12
  121. package/bnf/func/test.f.js +0 -171
  122. package/bnf/func/testlib.f.d.ts +0 -25
  123. package/bnf/func/testlib.f.js +0 -150
  124. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  125. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
@@ -1,8 +1,11 @@
1
1
  import { stringify } from "../../json/module.f.js";
2
+ import { stringToCodePointList } from "../../text/utf16/module.f.js";
3
+ import { identity } from "../../types/function/module.f.js";
4
+ import { toArray } from "../../types/list/module.f.js";
2
5
  import { sort } from "../../types/object/module.f.js";
3
- import { range } from "../module.f.js";
6
+ import { join0Plus, max, option, range, remove, repeat, repeat0Plus, set } from "../module.f.js";
4
7
  import { classic, deterministic } from "../testlib.f.js";
5
- import { dispatchMap, toData } from "./module.f.js";
8
+ import { dispatchMap, parser, parserRuleSet, toData, createEmptyTagMap } from "./module.f.js";
6
9
  export default {
7
10
  toData: [
8
11
  () => {
@@ -12,28 +15,28 @@ export default {
12
15
  () => {
13
16
  const stringRule = 'true';
14
17
  const result = stringify(sort)(toData(stringRule));
15
- if (result != '[{"":["0","1","2","3"],"0":1946157172,"1":1912602738,"2":1962934389,"3":1694498917},""]') {
18
+ if (result !== '[{"":["0","1","2","3"],"0":1946157172,"1":1912602738,"2":1962934389,"3":1694498917},""]') {
16
19
  throw result;
17
20
  }
18
21
  },
19
22
  () => {
20
23
  const terminalRangeRule = range('AF');
21
24
  const result = stringify(sort)(toData(terminalRangeRule));
22
- if (result != '[{"":1090519110},""]') {
25
+ if (result !== '[{"":1090519110},""]') {
23
26
  throw result;
24
27
  } //1090519110 = 65 * 2^24 + 70
25
28
  },
26
29
  () => {
27
30
  const sequenceRangeRule = [range('AF'), range('af')];
28
31
  const result = stringify(sort)(toData(sequenceRangeRule));
29
- if (result != '[{"":["0","1"],"0":1090519110,"1":1627390054},""]') {
32
+ if (result !== '[{"":["0","1"],"0":1090519110,"1":1627390054},""]') {
30
33
  throw result;
31
34
  }
32
35
  },
33
36
  () => {
34
37
  const lazyRule = () => 'true';
35
38
  const result = stringify(sort)(toData(lazyRule));
36
- if (result != '[{"":1946157172,"0":1912602738,"1":1962934389,"2":1694498917,"lazyRule":["","0","1","2"]},"lazyRule"]') {
39
+ if (result !== '[{"":1946157172,"0":1912602738,"1":1962934389,"2":1694498917,"lazyRule":["","0","1","2"]},"lazyRule"]') {
37
40
  throw result;
38
41
  }
39
42
  },
@@ -41,7 +44,7 @@ export default {
41
44
  const varintRule = { true: 'true', false: 'false' };
42
45
  const result = stringify(sort)(toData(varintRule));
43
46
  const expected = '[{"":{"false":"5","true":"0"},"0":["1","2","3","4"],"1":1946157172,"2":1912602738,"3":1962934389,"4":1694498917,"5":["6","7","8","9","4"],"6":1711276134,"7":1627390049,"8":1811939436,"9":1929379955},""]';
44
- if (result != expected) {
47
+ if (result !== expected) {
45
48
  throw [result, expected];
46
49
  }
47
50
  },
@@ -50,15 +53,110 @@ export default {
50
53
  const lazyRule0 = () => 'false';
51
54
  const result = stringify(sort)(toData([lazyRule, lazyRule0]));
52
55
  const expected = '[{"":["lazyRule","lazyRule0"],"0":1946157172,"1":1912602738,"2":1962934389,"3":1694498917,"4":1711276134,"5":1627390049,"6":1811939436,"7":1929379955,"lazyRule":["0","1","2","3"],"lazyRule0":["4","5","6","7","3"]},""]';
53
- if (result != expected) {
56
+ if (result !== expected) {
54
57
  throw [result, expected];
55
58
  }
56
59
  },
60
+ () => {
61
+ const emptyRule = '';
62
+ const result = stringify(sort)(toData(emptyRule));
63
+ const expected = '[{"":[]},""]';
64
+ if (result !== expected) {
65
+ throw [result, expected];
66
+ }
67
+ },
68
+ () => {
69
+ const optionRule = option('a');
70
+ const result = stringify(identity)(toData(optionRule));
71
+ if (result !== '[{"0":["1"],"1":1627390049,"2":[],"":{"some":"0","none":"2"}},""]') {
72
+ throw result;
73
+ }
74
+ },
75
+ () => {
76
+ const repeatRule = repeat0Plus(option('a'));
77
+ const result = stringify(identity)(toData(repeatRule));
78
+ if (result !== '[{"0":{"some":"1","none":"3"},"1":["2"],"2":1627390049,"3":[],"":["0","r"],"r":{"some":"","none":"3"}},"r"]') {
79
+ throw result;
80
+ }
81
+ },
82
+ () => {
83
+ const repeatRule = repeat0Plus(set(' \n\r\t'));
84
+ const result = stringify(identity)(toData(repeatRule));
85
+ if (result !== '[{"0":{" ":"1","\\n":"2","\\r":"3","\\t":"4"},"1":536870944,"2":167772170,"3":218103821,"4":150994953,"5":[],"":["0","r"],"r":{"some":"","none":"5"}},"r"]') {
86
+ throw result;
87
+ }
88
+ }
89
+ ],
90
+ emptyTags: [
91
+ () => {
92
+ const stringRule = 'true';
93
+ const data = toData(stringRule);
94
+ const emptyTags = createEmptyTagMap(data);
95
+ const result = JSON.stringify(emptyTags);
96
+ if (result !== '{"0":false,"1":false,"2":false,"3":false,"":false}') {
97
+ throw result;
98
+ }
99
+ },
100
+ () => {
101
+ const terminalRangeRule = range('AF');
102
+ const data = toData(terminalRangeRule);
103
+ const emptyTags = createEmptyTagMap(data);
104
+ const result = JSON.stringify(emptyTags);
105
+ if (result !== '{"":false}') {
106
+ throw result;
107
+ }
108
+ },
109
+ () => {
110
+ const varintRule = { true: 'true', false: 'false' };
111
+ const data = toData(varintRule);
112
+ const emptyTags = createEmptyTagMap(data);
113
+ const result = JSON.stringify(emptyTags);
114
+ if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":false,"6":false,"7":false,"8":false,"9":false,"":false}') {
115
+ throw result;
116
+ }
117
+ },
118
+ () => {
119
+ const emptyRule = '';
120
+ const data = toData(emptyRule);
121
+ const emptyTags = createEmptyTagMap(data);
122
+ const result = JSON.stringify(emptyTags);
123
+ if (result !== '{"":true}') {
124
+ throw result;
125
+ }
126
+ },
127
+ () => {
128
+ const emptyRule = '';
129
+ const varintRule = { true: 'true', e: emptyRule };
130
+ const data = toData(varintRule);
131
+ const emptyTags = createEmptyTagMap(data);
132
+ const result = JSON.stringify(emptyTags);
133
+ if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":true,"":"e"}') {
134
+ throw result;
135
+ }
136
+ },
137
+ () => {
138
+ const repeatRule = repeat0Plus(option('a'));
139
+ const data = toData(repeatRule);
140
+ const emptyTags = createEmptyTagMap(data);
141
+ const result = JSON.stringify(emptyTags);
142
+ if (result !== '{"0":"none","1":false,"2":false,"3":true,"r":"none","":true}') {
143
+ throw result;
144
+ }
145
+ },
146
+ () => {
147
+ const repeatRule = repeat0Plus(set(' \n\r\t'));
148
+ const data = toData(repeatRule);
149
+ const emptyTags = createEmptyTagMap(data);
150
+ const result = JSON.stringify(emptyTags);
151
+ if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":true,"r":"none","":true}') {
152
+ throw result;
153
+ }
154
+ }
57
155
  ],
58
156
  variantTest: () => {
59
157
  const varintRule = { a: 'a', b: 'b' };
60
158
  const result = stringify(sort)(toData(varintRule));
61
- if (result != '[{"":{"a":"0","b":"2"},"0":["1"],"1":1627390049,"2":["3"],"3":1644167266},""]') {
159
+ if (result !== '[{"":{"a":"0","b":"2"},"0":["1"],"1":1627390049,"2":["3"],"3":1644167266},""]') {
62
160
  throw result;
63
161
  }
64
162
  },
@@ -68,7 +166,7 @@ export default {
68
166
  const data = toData(terminalRangeRule);
69
167
  const dm = dispatchMap(data[0]);
70
168
  const result = JSON.stringify(dm);
71
- if (result != '{"":{"rangeMap":[[null,64],[{"rules":[]},70]]}}') {
169
+ if (result !== '{"":{"rangeMap":[[null,64],[{"rules":[]},70]]}}') {
72
170
  throw result;
73
171
  }
74
172
  },
@@ -77,7 +175,18 @@ export default {
77
175
  const data = toData(stringRule);
78
176
  const dm = dispatchMap(data[0]);
79
177
  const result = JSON.stringify(dm);
80
- if (result != '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"rules":[{"rangeMap":[[null,65],[{"rules":[]},66]]}]},65]]}}') {
178
+ if (result !== '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"rules":["1"]},65]]}}') {
179
+ throw result;
180
+ }
181
+ },
182
+ () => {
183
+ const a = range('AA');
184
+ const b = range('BB');
185
+ const ab = [a, b];
186
+ const data = toData(ab);
187
+ const dm = dispatchMap(data[0]);
188
+ const result = JSON.stringify(dm);
189
+ if (result !== '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"rules":["1"]},65]]}}') {
81
190
  throw result;
82
191
  }
83
192
  },
@@ -86,7 +195,7 @@ export default {
86
195
  const data = toData(emptyRule);
87
196
  const dm = dispatchMap(data[0]);
88
197
  const result = JSON.stringify(dm);
89
- if (result != '{"":{"emptyTag":true,"rangeMap":[]}}') {
198
+ if (result !== '{"":{"emptyTag":true,"rangeMap":[]}}') {
90
199
  throw result;
91
200
  }
92
201
  },
@@ -95,7 +204,7 @@ export default {
95
204
  const data = toData(variantRule);
96
205
  const dm = dispatchMap(data[0]);
97
206
  const result = JSON.stringify(dm);
98
- if (result != '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"tag":"a","rules":[]},65],[{"tag":"b","rules":[]},66]]}}') {
207
+ if (result !== '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"tag":"a","rules":[]},65],[{"tag":"b","rules":[]},66]]}}') {
99
208
  throw result;
100
209
  }
101
210
  },
@@ -105,10 +214,276 @@ export default {
105
214
  const data = toData(variantRule);
106
215
  const dm = dispatchMap(data[0]);
107
216
  const result = JSON.stringify(dm);
108
- if (result != '{"0":{"emptyTag":true,"rangeMap":[]},"1":{"rangeMap":[[null,64],[{"rules":[]},65]]},"":{"emptyTag":"e","rangeMap":[[null,64],[{"tag":"a","rules":[]},65]]}}') {
217
+ if (result !== '{"0":{"emptyTag":true,"rangeMap":[]},"1":{"rangeMap":[[null,64],[{"rules":[]},65]]},"":{"emptyTag":"e","rangeMap":[[null,64],[{"tag":"a","rules":[]},65]]}}') {
218
+ throw result;
219
+ }
220
+ },
221
+ () => {
222
+ const emptyRule = '';
223
+ const minursRule = range('--');
224
+ const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
225
+ const digitRule = range('09');
226
+ const numberRule = [optionalMinusRule, digitRule];
227
+ const data = toData(numberRule);
228
+ const dm = dispatchMap(data[0]);
229
+ const result = JSON.stringify(dm);
230
+ if (result !== '{"0":{"emptyTag":"none","rangeMap":[[null,44],[{"tag":"minus","rules":[]},45]]},"1":{"emptyTag":true,"rangeMap":[]},"2":{"rangeMap":[[null,44],[{"rules":[]},45]]},"3":{"rangeMap":[[null,47],[{"rules":[]},57]]},"":{"rangeMap":[[null,44],[{"tag":"minus","rules":["3"]},45],[null,47],[{"rules":[]},57]]}}') {
231
+ throw result;
232
+ }
233
+ },
234
+ () => {
235
+ const emptyRule = '';
236
+ const spaceRule = range(' ');
237
+ const optionalSpaceRule = { 'none': emptyRule, 'space': spaceRule };
238
+ const minusRule = range('--');
239
+ const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
240
+ const digitRule = range('09');
241
+ const numberRule = [optionalSpaceRule, optionalMinusRule, digitRule];
242
+ const data = toData(numberRule);
243
+ const dm = dispatchMap(data[0]);
244
+ const result = JSON.stringify(dm);
245
+ if (result !== '{"0":{"emptyTag":"none","rangeMap":[[null,31],[{"tag":"space","rules":[]},32]]},"1":{"emptyTag":true,"rangeMap":[]},"2":{"rangeMap":[[null,31],[{"rules":[]},32]]},"3":{"emptyTag":"none","rangeMap":[[null,44],[{"tag":"minus","rules":[]},45]]},"4":{"rangeMap":[[null,44],[{"rules":[]},45]]},"5":{"rangeMap":[[null,47],[{"rules":[]},57]]},"":{"rangeMap":[[null,31],[{"tag":"space","rules":["3","5"]},32],[null,44],[{"tag":"minus","rules":["5"]},45],[null,47],[{"rules":[]},57]]}}') {
246
+ throw result;
247
+ }
248
+ }
249
+ ],
250
+ parser: [
251
+ () => {
252
+ const emptyRule = '';
253
+ const m = parser(emptyRule);
254
+ const mr = m("", []);
255
+ const result = JSON.stringify(mr);
256
+ if (result !== '[{"tag":true,"sequence":[]},true,[]]') {
257
+ throw result;
258
+ }
259
+ },
260
+ () => {
261
+ const emptyRule = '';
262
+ const m = parser(emptyRule);
263
+ const mr = m("", [65, 70]);
264
+ const result = JSON.stringify(mr);
265
+ if (result !== '[{"tag":true,"sequence":[]},true,[65,70]]') {
266
+ throw result;
267
+ }
268
+ },
269
+ () => {
270
+ const terminalRangeRule = range('AF');
271
+ const m = parser(terminalRangeRule);
272
+ const mr = m("", [65]);
273
+ const result = JSON.stringify(mr);
274
+ if (result !== '[{"sequence":[65]},true,[]]') {
275
+ throw result;
276
+ }
277
+ },
278
+ () => {
279
+ const terminalRangeRule = range('AF');
280
+ const m = parser(terminalRangeRule);
281
+ const mr = m("", [64]);
282
+ const result = JSON.stringify(mr);
283
+ if (result !== '[{"sequence":[]},false,[64]]') {
284
+ throw result;
285
+ }
286
+ },
287
+ () => {
288
+ const variantRule = { 'a': range('AA'), 'b': range('BB') };
289
+ const m = parser(variantRule);
290
+ const mr = m("", [65]);
291
+ const result = JSON.stringify(mr);
292
+ if (result !== '[{"tag":"a","sequence":[65]},true,[]]') {
293
+ throw result;
294
+ }
295
+ },
296
+ () => {
297
+ const variantRule = { 'a': range('AA'), 'b': range('BB') };
298
+ const m = parser(variantRule);
299
+ const mr = m("", [64]);
300
+ const result = JSON.stringify(mr);
301
+ if (result !== '[{"sequence":[]},false,[64]]') {
302
+ throw result;
303
+ }
304
+ },
305
+ () => {
306
+ const emptyRule = '';
307
+ const variantRule = { 'e': emptyRule, 'a': range('AA') };
308
+ const m = parser(variantRule);
309
+ const mr = m("", []);
310
+ const result = JSON.stringify(mr);
311
+ if (result !== '[{"tag":"e","sequence":[]},true,[]]') {
312
+ throw result;
313
+ }
314
+ },
315
+ () => {
316
+ const emptyRule = '';
317
+ const variantRule = { 'e': emptyRule, 'a': range('AA') };
318
+ const m = parser(variantRule);
319
+ const mr = m("", [64]);
320
+ const result = JSON.stringify(mr);
321
+ if (result !== '[{"tag":"e","sequence":[]},true,[64]]') {
322
+ throw result;
323
+ }
324
+ },
325
+ () => {
326
+ const stringRule = 'AB';
327
+ const m = parser(stringRule);
328
+ const mr = m("", [65, 66]);
329
+ const result = JSON.stringify(mr);
330
+ if (result !== '[{"sequence":[65,{"sequence":[66]}]},true,[]]') {
331
+ throw result;
332
+ }
333
+ },
334
+ () => {
335
+ const stringRule = 'AB';
336
+ const m = parser(stringRule);
337
+ const mr = m("", [65, 67]);
338
+ const result = JSON.stringify(mr);
339
+ if (result !== '[{"sequence":[]},false,[67]]') {
340
+ throw result;
341
+ }
342
+ },
343
+ () => {
344
+ const emptyRule = '';
345
+ const minursRule = range('--');
346
+ const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
347
+ const digitRule = range('09');
348
+ const numberRule = [optionalMinusRule, digitRule];
349
+ const m = parser(numberRule);
350
+ const mr = m("", [50]);
351
+ const result = JSON.stringify(mr);
352
+ if (result !== '[{"sequence":[50]},true,[]]') {
353
+ throw result;
354
+ }
355
+ },
356
+ () => {
357
+ const emptyRule = '';
358
+ const minusRule = range('--');
359
+ const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
360
+ const digitRule = range('09');
361
+ const numberRule = [optionalMinusRule, digitRule];
362
+ const m = parser(numberRule);
363
+ const mr = m("", [45, 50]);
364
+ const result = JSON.stringify(mr);
365
+ if (result !== '[{"tag":"minus","sequence":[45,{"sequence":[50]}]},true,[]]') {
366
+ throw result;
367
+ }
368
+ },
369
+ () => {
370
+ const m = parser(option('a'));
371
+ const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
372
+ const expect = (s, success) => {
373
+ const mr = m('', toArray(stringToCodePointList(s)));
374
+ if (isSuccess(mr) !== success) {
375
+ throw mr;
376
+ }
377
+ };
378
+ expect('a', true);
379
+ expect('', true);
380
+ expect('aa', false);
381
+ expect('b', false);
382
+ },
383
+ () => {
384
+ const ws = repeat0Plus(set(' \n\r\t'));
385
+ const commaJoin0Plus = ([open, close], a) => [
386
+ open,
387
+ ws,
388
+ join0Plus([a, ws], [',', ws]),
389
+ close,
390
+ ];
391
+ const value = () => ({
392
+ object: commaJoin0Plus('{}', 'a'),
393
+ array: commaJoin0Plus('[]', 'a')
394
+ });
395
+ value.name; //bun will fail if no usage of name found
396
+ const m = parser(value);
397
+ const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
398
+ const expect = (s, success) => {
399
+ const mr = m('value', toArray(stringToCodePointList(s)));
400
+ if (isSuccess(mr) !== success) {
401
+ throw mr;
402
+ }
403
+ };
404
+ expect('[]', true);
405
+ expect('[a]', true);
406
+ expect('[a, a]', true);
407
+ expect('{a}', true);
408
+ },
409
+ () => {
410
+ const m = parser(deterministic());
411
+ const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
412
+ const expect = (s, success) => {
413
+ const mr = m('', toArray(stringToCodePointList(s)));
414
+ if (isSuccess(mr) !== success) {
415
+ throw mr;
416
+ }
417
+ };
418
+ expect(' true ', true);
419
+ expect(' tr2ue ', false);
420
+ expect(' true" ', false);
421
+ expect(' "Hello" ', true);
422
+ expect(' "Hello ', false);
423
+ expect(' "Hello\\n\\r\\"" ', true);
424
+ expect(' -56.7e+5 ', true);
425
+ expect(' h-56.7e+5 ', false);
426
+ expect(' -56.7e+5 3', false);
427
+ expect(' [] ', true);
428
+ expect(' {} ', true);
429
+ expect(' [[[]]] ', true);
430
+ expect(' [1] ', true);
431
+ expect(' [ 12, false, "a"] ', true);
432
+ expect(' [ 12, false2, "a"] ', false);
433
+ expect(' { "q": [ 12, false, [{"b" : "c"}], "a"] } ', true);
434
+ expect(' { "q": [ 12, false, [{}], "a"] } ', true);
435
+ expect(' { "q": [ 12, false, [}], "a"] } ', false);
436
+ expect(' [{ "q": [ 12, false, [{}], "a"] }] ', true);
437
+ expect(' [{ "q": [ 12, false, [}], "a"] }] ', false);
438
+ }
439
+ ],
440
+ repeat: [
441
+ () => {
442
+ const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
443
+ const dm = dispatchMap(repeatData[0]);
444
+ const result = JSON.stringify(dm);
445
+ if (result !== '{"ws":{"emptyTag":true,"rangeMap":[]},"a":{"rangeMap":[[null,64],[{"rules":[]},65]]},"repa":{"rangeMap":[[null,64],[{"rules":[""]},65]]},"":{"rangeMap":[[null,64],[{"rules":[""]},65]]}}') {
446
+ throw result;
447
+ }
448
+ }
449
+ ],
450
+ repeatParser: [
451
+ () => {
452
+ const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
453
+ const m = parserRuleSet(repeatData[0]);
454
+ const mr = m("", []);
455
+ const result = JSON.stringify(mr);
456
+ if (result !== '[{"sequence":[]},true,null]') {
457
+ throw result;
458
+ }
459
+ },
460
+ () => {
461
+ const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
462
+ const m = parserRuleSet(repeatData[0]);
463
+ const mr = m("", [65]);
464
+ const result = JSON.stringify(mr);
465
+ if (result !== '[{"sequence":[65,{"sequence":[]}]},true,null]') {
466
+ throw result;
467
+ }
468
+ },
469
+ () => {
470
+ const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
471
+ const m = parserRuleSet(repeatData[0]);
472
+ const mr = m("", [65, 65, 65]);
473
+ const result = JSON.stringify(mr);
474
+ if (result !== '[{"sequence":[65,{"sequence":[65,{"sequence":[65,{"sequence":[]}]}]}]},true,null]') {
109
475
  throw result;
110
476
  }
111
477
  },
478
+ () => {
479
+ const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
480
+ const m = parserRuleSet(repeatData[0]);
481
+ const mr = m("", [66]);
482
+ const result = JSON.stringify(mr);
483
+ if (result !== '[{"sequence":[]},false,[66]]') {
484
+ throw result;
485
+ }
486
+ }
112
487
  ],
113
488
  example: () => {
114
489
  const grammar = {
package/bnf/module.f.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { type Array2 } from '../types/array/module.f.ts';
2
2
  /**
3
- * A range of symbols (48 bits)
3
+ * A range of symbols. Two 24-bit numbers are stored in one JS number (48 bits).
4
+ *
4
5
  * For example: 0xBBBBBB_EEEEEE
5
- * - 0xBBBBBB is the first symbol
6
- * - 0xEEEEEE is the last symbol
6
+ * - 0xBBBBBB is the first symbol (24 bits)
7
+ * - 0xEEEEEE is the last symbol (24 bits)
7
8
  */
8
9
  export type TerminalRange = number;
9
10
  /** A sequence of rules. */
@@ -34,8 +35,8 @@ export declare const remove: (range: TerminalRange, removeSet: RangeVariant) =>
34
35
  export type None = readonly [];
35
36
  export declare const none: None;
36
37
  export type Option<S> = {
37
- none: None;
38
38
  some: S;
39
+ none: None;
39
40
  };
40
41
  export declare const option: <S extends Rule>(some: S) => Option<S>;
41
42
  export type Repeat0Plus<T> = () => Option<readonly [T, Repeat0Plus<T>]>;
package/bnf/module.f.js CHANGED
@@ -69,8 +69,8 @@ export const remove = (range, removeSet) => {
69
69
  };
70
70
  export const none = [];
71
71
  export const option = (some) => ({
72
- none,
73
72
  some,
73
+ none,
74
74
  });
75
75
  /**
76
76
  * Repeat zero or more times.
package/bnf/testlib.f.js CHANGED
@@ -130,8 +130,8 @@ export const deterministic = () => {
130
130
  close,
131
131
  ];
132
132
  const value = () => ({
133
- object: commaJoin0Plus('{}', [string, ws, ':', ws, value]),
134
133
  array: commaJoin0Plus('[]', value),
134
+ object: commaJoin0Plus('{}', [string, ws, ':', ws, value]),
135
135
  string,
136
136
  number,
137
137
  true: 'true',
@@ -0,0 +1,3 @@
1
+ import type { Io } from '../io/module.f.ts';
2
+ declare const _default: (io: Io) => Promise<number>;
3
+ export default _default;