functionalscript 0.32.4 → 0.34.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 (90) hide show
  1. package/README.md +1 -1
  2. package/fs/asserts/module.f.d.ts +1 -1
  3. package/fs/asserts/module.f.js +4 -1
  4. package/fs/bnf/data/module.f.d.ts +0 -103
  5. package/fs/bnf/data/module.f.js +10 -246
  6. package/fs/bnf/data/proof.f.d.ts +0 -7
  7. package/fs/bnf/data/proof.f.js +3 -636
  8. package/fs/bnf/descent/module.f.d.ts +56 -0
  9. package/fs/bnf/descent/module.f.js +119 -0
  10. package/fs/bnf/descent/proof.f.d.ts +5 -0
  11. package/fs/bnf/descent/proof.f.js +296 -0
  12. package/fs/bnf/ll1/module.f.d.ts +72 -0
  13. package/fs/bnf/ll1/module.f.js +153 -0
  14. package/fs/bnf/ll1/proof.f.d.ts +9 -0
  15. package/fs/bnf/ll1/proof.f.js +358 -0
  16. package/fs/cas/cli/module.f.d.ts +6 -0
  17. package/fs/cas/cli/module.f.js +56 -0
  18. package/fs/cas/cli/proof.f.d.ts +14 -0
  19. package/fs/cas/cli/proof.f.js +149 -0
  20. package/fs/cas/mcp/module.f.d.ts +9 -17
  21. package/fs/cas/mcp/module.f.js +117 -83
  22. package/fs/cas/mcp/proof.f.d.ts +5 -1
  23. package/fs/cas/mcp/proof.f.js +79 -32
  24. package/fs/cas/module.f.d.ts +33 -27
  25. package/fs/cas/module.f.js +151 -126
  26. package/fs/cas/proof.f.d.ts +16 -13
  27. package/fs/cas/proof.f.js +255 -130
  28. package/fs/ci/config/module.f.d.ts +15 -15
  29. package/fs/ci/config/module.f.js +15 -15
  30. package/fs/ci/proof.f.js +8 -6
  31. package/fs/cli/proof.f.js +2 -12
  32. package/fs/djs/parser/module.f.d.ts +0 -5
  33. package/fs/djs/proof.f.js +5 -6
  34. package/fs/djs/serializer/module.f.d.ts +1 -3
  35. package/fs/djs/tokenizer-new/module.f.js +3 -2
  36. package/fs/djs/tokenizer-new/proof.f.d.ts +3 -0
  37. package/fs/djs/tokenizer-new/proof.f.js +458 -296
  38. package/fs/djs/transpiler/proof.f.js +10 -10
  39. package/fs/effects/list/module.f.d.ts +31 -0
  40. package/fs/effects/list/module.f.js +16 -0
  41. package/fs/effects/module.f.d.ts +11 -5
  42. package/fs/effects/module.f.js +16 -6
  43. package/fs/effects/node/module.f.d.ts +29 -3
  44. package/fs/effects/node/module.f.js +35 -1
  45. package/fs/effects/node/module.js +32 -18
  46. package/fs/effects/node/proof.f.js +36 -36
  47. package/fs/effects/node/virtual/module.f.d.ts +16 -2
  48. package/fs/effects/node/virtual/module.f.js +129 -20
  49. package/fs/effects/node/virtual/proof.f.d.ts +4 -0
  50. package/fs/effects/node/virtual/proof.f.js +47 -14
  51. package/fs/effects/proof.f.d.ts +4 -0
  52. package/fs/effects/proof.f.js +18 -1
  53. package/fs/emergent_testing/proof.f.js +3 -11
  54. package/fs/fjs/module.f.js +2 -8
  55. package/fs/fjs/proof.f.js +2 -11
  56. package/fs/html/module.f.js +6 -8
  57. package/fs/js/tokenizer/module.f.d.ts +5 -0
  58. package/fs/js/tokenizer/module.f.js +13 -0
  59. package/fs/json/serializer/module.f.js +0 -1
  60. package/fs/mcp/module.f.d.ts +1 -1
  61. package/fs/mime/module.f.d.ts +101 -5
  62. package/fs/mime/module.f.js +159 -6
  63. package/fs/mime/proof.f.d.ts +25 -0
  64. package/fs/mime/proof.f.js +193 -3
  65. package/fs/text/code_point/module.f.d.ts +39 -2
  66. package/fs/text/code_point/module.f.js +74 -2
  67. package/fs/text/code_point/proof.f.d.ts +8 -0
  68. package/fs/text/code_point/proof.f.js +72 -0
  69. package/fs/text/sgr/proof.f.js +2 -11
  70. package/fs/text/utf16/module.f.js +4 -26
  71. package/fs/text/utf8/module.f.d.ts +27 -0
  72. package/fs/text/utf8/module.f.js +8 -14
  73. package/fs/types/bigint/module.f.d.ts +8 -15
  74. package/fs/types/bigint/module.f.js +9 -22
  75. package/fs/types/bigint/proof.f.d.ts +0 -2
  76. package/fs/types/bigint/proof.f.js +6 -16
  77. package/fs/types/function/operator/module.f.d.ts +26 -0
  78. package/fs/types/list/module.f.d.ts +3 -0
  79. package/fs/types/result/module.d.ts +2 -4
  80. package/fs/types/result/module.js +9 -3
  81. package/package.json +3 -3
  82. package/issues/demo/data/data.f.js +0 -12
  83. package/issues/demo/data/shared.f.js +0 -3
  84. package/issues/demo/fs/app.js +0 -4
  85. package/issues/demo/fs/math.f.js +0 -4
  86. package/issues/demo/sample/proof.f.js +0 -13
  87. /package/{issues → todo}/031-json.f.d.ts +0 -0
  88. /package/{issues → todo}/031-json.f.js +0 -0
  89. /package/{issues → todo}/proof.f.d.ts +0 -0
  90. /package/{issues → todo}/proof.f.js +0 -0
@@ -1,16 +1,9 @@
1
1
  import { stringify } from "../../json/module.f.js";
2
- import { stringToCodePointList } from "../../text/utf16/module.f.js";
3
2
  import { identity } from "../../types/function/module.f.js";
4
- import { map, toArray } from "../../types/list/module.f.js";
5
3
  import { sort } from "../../types/object/module.f.js";
6
- import { commaJoin0Plus, oneEncode, option, range, rangeDecode, repeat0Plus, set } from "../module.f.js";
4
+ import { oneEncode, option, range, rangeDecode, repeat0Plus, set } from "../module.f.js";
7
5
  import { classic, deterministic } from "../testlib.f.js";
8
- import { dispatchMap, parser, parserRuleSet, toData, createEmptyTagMap, descentParser } from "./module.f.js";
9
- const mapCodePoint = (cp) => [cp, undefined];
10
- const descentParserCpOnly = (m, name, cp) => {
11
- const cpm = toArray(map(mapCodePoint)(cp));
12
- return m(name, cpm);
13
- };
6
+ import { toData } from "./module.f.js";
14
7
  export const proof = {
15
8
  rangeDecode: () => {
16
9
  const decoded1 = stringify(sort)(rangeDecode(0x000079_000087));
@@ -120,72 +113,6 @@ export const proof = {
120
113
  }
121
114
  }
122
115
  ],
123
- emptyTags: [
124
- () => {
125
- const stringRule = 'true';
126
- const data = toData(stringRule);
127
- const emptyTags = createEmptyTagMap(data);
128
- const result = JSON.stringify(emptyTags);
129
- if (result !== '{"0":false,"1":false,"2":false,"3":false,"":false}') {
130
- throw result;
131
- }
132
- },
133
- () => {
134
- const terminalRangeRule = range('AF');
135
- const data = toData(terminalRangeRule);
136
- const emptyTags = createEmptyTagMap(data);
137
- const result = JSON.stringify(emptyTags);
138
- if (result !== '{"":false}') {
139
- throw result;
140
- }
141
- },
142
- () => {
143
- const varintRule = { true: 'true', false: 'false' };
144
- const data = toData(varintRule);
145
- const emptyTags = createEmptyTagMap(data);
146
- const result = JSON.stringify(emptyTags);
147
- if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":false,"6":false,"7":false,"8":false,"9":false,"":false}') {
148
- throw result;
149
- }
150
- },
151
- () => {
152
- const emptyRule = '';
153
- const data = toData(emptyRule);
154
- const emptyTags = createEmptyTagMap(data);
155
- const result = JSON.stringify(emptyTags);
156
- if (result !== '{"":true}') {
157
- throw result;
158
- }
159
- },
160
- () => {
161
- const emptyRule = '';
162
- const varintRule = { true: 'true', e: emptyRule };
163
- const data = toData(varintRule);
164
- const emptyTags = createEmptyTagMap(data);
165
- const result = JSON.stringify(emptyTags);
166
- if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":true,"":"e"}') {
167
- throw result;
168
- }
169
- },
170
- () => {
171
- const repeatRule = repeat0Plus(option('a'));
172
- const data = toData(repeatRule);
173
- const emptyTags = createEmptyTagMap(data);
174
- const result = JSON.stringify(emptyTags);
175
- if (result !== '{"0":"none","1":false,"2":false,"3":true,"r":"none","":true}') {
176
- throw result;
177
- }
178
- },
179
- () => {
180
- const repeatRule = repeat0Plus(set(' \n\r\t'));
181
- const data = toData(repeatRule);
182
- const emptyTags = createEmptyTagMap(data);
183
- const result = JSON.stringify(emptyTags);
184
- if (result !== '{"0":false,"1":false,"2":false,"3":false,"4":false,"5":true,"r":"none","":true}') {
185
- throw result;
186
- }
187
- }
188
- ],
189
116
  variantTest: () => {
190
117
  const varintRule = { a: 'a', b: 'b' };
191
118
  const result = stringify(sort)(toData(varintRule));
@@ -193,566 +120,6 @@ export const proof = {
193
120
  throw result;
194
121
  }
195
122
  },
196
- dispatch: [
197
- () => {
198
- const terminalRangeRule = range('AF');
199
- const data = toData(terminalRangeRule);
200
- const dm = dispatchMap(data[0]);
201
- const result = JSON.stringify(dm);
202
- if (result !== '{"":{"rangeMap":[[null,64],[{"rules":[]},70]]}}') {
203
- throw result;
204
- }
205
- },
206
- () => {
207
- const stringRule = 'AB';
208
- const data = toData(stringRule);
209
- const dm = dispatchMap(data[0]);
210
- const result = JSON.stringify(dm);
211
- if (result !== '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"rules":["1"]},65]]}}') {
212
- throw result;
213
- }
214
- },
215
- () => {
216
- const a = range('AA');
217
- const b = range('BB');
218
- const ab = [a, b];
219
- const data = toData(ab);
220
- const dm = dispatchMap(data[0]);
221
- const result = JSON.stringify(dm);
222
- if (result !== '{"0":{"rangeMap":[[null,64],[{"rules":[]},65]]},"1":{"rangeMap":[[null,65],[{"rules":[]},66]]},"":{"rangeMap":[[null,64],[{"rules":["1"]},65]]}}') {
223
- throw result;
224
- }
225
- },
226
- () => {
227
- const emptyRule = '';
228
- const data = toData(emptyRule);
229
- const dm = dispatchMap(data[0]);
230
- const result = JSON.stringify(dm);
231
- if (result !== '{"":{"emptyTag":true,"rangeMap":[]}}') {
232
- throw result;
233
- }
234
- },
235
- () => {
236
- const variantRule = { 'a': range('AA'), 'b': range('BB') };
237
- const data = toData(variantRule);
238
- const dm = dispatchMap(data[0]);
239
- const result = JSON.stringify(dm);
240
- 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]]}}') {
241
- throw result;
242
- }
243
- },
244
- () => {
245
- const emptyRule = '';
246
- const variantRule = { 'e': emptyRule, 'a': range('AA') };
247
- const data = toData(variantRule);
248
- const dm = dispatchMap(data[0]);
249
- const result = JSON.stringify(dm);
250
- if (result !== '{"0":{"emptyTag":true,"rangeMap":[]},"1":{"rangeMap":[[null,64],[{"rules":[]},65]]},"":{"emptyTag":"e","rangeMap":[[null,64],[{"tag":"a","rules":[]},65]]}}') {
251
- throw result;
252
- }
253
- },
254
- () => {
255
- const emptyRule = '';
256
- const minursRule = range('--');
257
- const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
258
- const digitRule = range('09');
259
- const numberRule = [optionalMinusRule, digitRule];
260
- const data = toData(numberRule);
261
- const dm = dispatchMap(data[0]);
262
- const result = JSON.stringify(dm);
263
- 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]]}}') {
264
- throw result;
265
- }
266
- },
267
- () => {
268
- const emptyRule = '';
269
- const spaceRule = range(' ');
270
- const optionalSpaceRule = { 'none': emptyRule, 'space': spaceRule };
271
- const minusRule = range('--');
272
- const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
273
- const digitRule = range('09');
274
- const numberRule = [optionalSpaceRule, optionalMinusRule, digitRule];
275
- const data = toData(numberRule);
276
- const dm = dispatchMap(data[0]);
277
- const result = JSON.stringify(dm);
278
- 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]]}}') {
279
- throw result;
280
- }
281
- }
282
- ],
283
- parser: [
284
- () => {
285
- const emptyRule = '';
286
- const m = parser(emptyRule);
287
- const mr = m("", []);
288
- const result = JSON.stringify(mr);
289
- if (result !== '[{"tag":true,"sequence":[]},true,[]]') {
290
- throw result;
291
- }
292
- },
293
- () => {
294
- const emptyRule = '';
295
- const m = parser(emptyRule);
296
- const mr = m("", [65, 70]);
297
- const result = JSON.stringify(mr);
298
- if (result !== '[{"tag":true,"sequence":[]},true,[65,70]]') {
299
- throw result;
300
- }
301
- },
302
- () => {
303
- const terminalRangeRule = range('AF');
304
- const m = parser(terminalRangeRule);
305
- const mr = m("", [65]);
306
- const result = JSON.stringify(mr);
307
- if (result !== '[{"sequence":[65]},true,[]]') {
308
- throw result;
309
- }
310
- },
311
- () => {
312
- const terminalRangeRule = 0x000079_000087;
313
- const m = parser(terminalRangeRule);
314
- const mr = m("", [64]);
315
- const result = JSON.stringify(mr);
316
- if (result !== '[{"sequence":[]},false,[64]]') {
317
- throw result;
318
- }
319
- },
320
- () => {
321
- const terminalRangeRule = 0x000080_000087; //broken range
322
- const m = parser(terminalRangeRule);
323
- const mr = m("", [64]);
324
- const result = JSON.stringify(mr);
325
- if (result !== '[{"sequence":[]},false,[64]]') {
326
- throw result;
327
- }
328
- },
329
- () => {
330
- const variantRule = { 'a': range('AA'), 'b': range('BB') };
331
- const m = parser(variantRule);
332
- const mr = m("", [65]);
333
- const result = JSON.stringify(mr);
334
- if (result !== '[{"tag":"a","sequence":[65]},true,[]]') {
335
- throw result;
336
- }
337
- },
338
- () => {
339
- const variantRule = { 'a': range('AA'), 'b': range('BB') };
340
- const m = parser(variantRule);
341
- const mr = m("", [64]);
342
- const result = JSON.stringify(mr);
343
- if (result !== '[{"sequence":[]},false,[64]]') {
344
- throw result;
345
- }
346
- },
347
- () => {
348
- const emptyRule = '';
349
- const variantRule = { 'e': emptyRule, 'a': range('AA') };
350
- const m = parser(variantRule);
351
- const mr = m("", []);
352
- const result = JSON.stringify(mr);
353
- if (result !== '[{"tag":"e","sequence":[]},true,[]]') {
354
- throw result;
355
- }
356
- },
357
- () => {
358
- const emptyRule = '';
359
- const variantRule = { 'e': emptyRule, 'a': range('AA') };
360
- const m = parser(variantRule);
361
- const mr = m("", [64]);
362
- const result = JSON.stringify(mr);
363
- if (result !== '[{"tag":"e","sequence":[]},true,[64]]') {
364
- throw result;
365
- }
366
- },
367
- () => {
368
- const stringRule = 'AB';
369
- const m = parser(stringRule);
370
- const mr = m("", [65, 66]);
371
- const result = JSON.stringify(mr);
372
- if (result !== '[{"sequence":[65,{"sequence":[66]}]},true,[]]') {
373
- throw result;
374
- }
375
- },
376
- () => {
377
- const stringRule = 'AB';
378
- const m = parser(stringRule);
379
- const mr = m("", [65, 67]);
380
- const result = JSON.stringify(mr);
381
- if (result !== '[{"sequence":[]},false,[67]]') {
382
- throw result;
383
- }
384
- },
385
- () => {
386
- const emptyRule = '';
387
- const minursRule = range('--');
388
- const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
389
- const digitRule = range('09');
390
- const numberRule = [optionalMinusRule, digitRule];
391
- const m = parser(numberRule);
392
- const mr = m("", [50]);
393
- const result = JSON.stringify(mr);
394
- if (result !== '[{"sequence":[50]},true,[]]') {
395
- throw result;
396
- }
397
- },
398
- () => {
399
- const emptyRule = '';
400
- const minusRule = range('--');
401
- const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
402
- const digitRule = range('09');
403
- const numberRule = [optionalMinusRule, digitRule];
404
- const m = parser(numberRule);
405
- const mr = m("", [45, 50]);
406
- const result = JSON.stringify(mr);
407
- if (result !== '[{"tag":"minus","sequence":[45,{"sequence":[50]}]},true,[]]') {
408
- throw result;
409
- }
410
- },
411
- () => {
412
- const emptyRule = '';
413
- const minusRule = range('--');
414
- const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
415
- const digitRule = range('09');
416
- const numberRule = [optionalMinusRule, digitRule];
417
- const m = parser(numberRule);
418
- const mr = m("", []);
419
- const result = JSON.stringify(mr);
420
- if (result !== '[{"sequence":[]},true,null]') {
421
- throw result;
422
- } //if remainder is null it means failed
423
- },
424
- () => {
425
- const m = parser(option('a'));
426
- const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
427
- const expect = (s, success) => {
428
- const mr = m('', toArray(stringToCodePointList(s)));
429
- if (isSuccess(mr) !== success) {
430
- throw mr;
431
- }
432
- };
433
- expect('a', true);
434
- expect('', true);
435
- expect('aa', false);
436
- expect('b', false);
437
- },
438
- () => {
439
- const ws = repeat0Plus(set(' \n\r\t'));
440
- const cj = commaJoin0Plus(ws);
441
- const value = () => ({
442
- object: cj('{}', 'a'),
443
- array: cj('[]', 'a')
444
- });
445
- value.name; //bun will fail if no usage of name found
446
- const m = parser(value);
447
- const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
448
- const expect = (s, success) => {
449
- const mr = m('value', toArray(stringToCodePointList(s)));
450
- if (isSuccess(mr) !== success) {
451
- throw mr;
452
- }
453
- };
454
- expect('', false);
455
- expect('[]', true);
456
- expect('[a]', true);
457
- expect('[a, a]', true);
458
- expect('{a}', true);
459
- },
460
- () => {
461
- const m = parser(deterministic());
462
- const isSuccess = (mr) => mr[1] && mr[2]?.length === 0;
463
- const expect = (s, success) => {
464
- const mr = m('', toArray(stringToCodePointList(s)));
465
- if (isSuccess(mr) !== success) {
466
- throw mr;
467
- }
468
- };
469
- expect(' true ', true);
470
- expect(' tr2ue ', false);
471
- expect(' true" ', false);
472
- expect(' "Hello" ', true);
473
- expect(' "Hello ', false);
474
- expect(' "Hello\\n\\r\\"" ', true);
475
- expect(' -56.7e+5 ', true);
476
- expect(' h-56.7e+5 ', false);
477
- expect(' -56.7e+5 3', false);
478
- expect(' [] ', true);
479
- expect(' {} ', true);
480
- expect(' [[[]]] ', true);
481
- expect(' [1] ', true);
482
- expect(' [ 12, false, "a"] ', true);
483
- expect(' [ 12, false2, "a"] ', false);
484
- expect(' { "q": [ 12, false, [{"b" : "c"}], "a"] } ', true);
485
- expect(' { "q": [ 12, false, [{}], "a"] } ', true);
486
- expect(' { "q": [ 12, false, [}], "a"] } ', false);
487
- expect(' [{ "q": [ 12, false, [{}], "a"] }] ', true);
488
- expect(' [{ "q": [ 12, false, [}], "a"] }] ', false);
489
- }
490
- ],
491
- descentParser: [
492
- () => {
493
- const emptyRule = '';
494
- const m = descentParser(emptyRule);
495
- const mr = m("", []);
496
- const result = JSON.stringify(mr);
497
- if (result !== '[{"sequence":[]},true,0]') {
498
- throw result;
499
- }
500
- },
501
- () => {
502
- const emptyRule = '';
503
- const m = descentParser(emptyRule);
504
- const mr = descentParserCpOnly(m, "", [65, 70]);
505
- const result = JSON.stringify(mr);
506
- if (result !== '[{"sequence":[]},true,0]') {
507
- throw result;
508
- }
509
- },
510
- () => {
511
- const terminalRangeRule = range('AF');
512
- const m = descentParser(terminalRangeRule);
513
- const mr = descentParserCpOnly(m, "", [65]);
514
- const result = JSON.stringify(mr);
515
- if (result !== '[{"sequence":[[65,null]]},true,1]') {
516
- throw result;
517
- }
518
- },
519
- () => {
520
- const terminalRangeRule = range('AF');
521
- const m = descentParser(terminalRangeRule);
522
- const mr = descentParserCpOnly(m, "", [64]);
523
- const result = JSON.stringify(mr);
524
- if (result !== '[{"sequence":[]},false,0]') {
525
- throw result;
526
- }
527
- },
528
- () => {
529
- const variantRule = { 'a': range('AA'), 'b': range('BB') };
530
- const m = descentParser(variantRule);
531
- const mr = descentParserCpOnly(m, "", [65]);
532
- const result = JSON.stringify(mr);
533
- if (result !== '[{"tag":"a","sequence":[[65,null]]},true,1]') {
534
- throw result;
535
- }
536
- },
537
- () => {
538
- const variantRule = { 'a': range('AA'), 'b': range('BB') };
539
- const m = descentParser(variantRule);
540
- const mr = descentParserCpOnly(m, "", [64]);
541
- const result = JSON.stringify(mr);
542
- if (result !== '[{"sequence":[]},false,0]') {
543
- throw result;
544
- }
545
- },
546
- () => {
547
- const emptyRule = '';
548
- const variantRule = { 'e': emptyRule, 'a': range('AA') };
549
- const m = descentParser(variantRule);
550
- const mr = m("", []);
551
- const result = JSON.stringify(mr);
552
- if (result !== '[{"tag":"e","sequence":[]},true,0]') {
553
- throw result;
554
- }
555
- },
556
- () => {
557
- const emptyRule = '';
558
- const variantRule = { 'e': emptyRule, 'a': range('AA') };
559
- const m = descentParser(variantRule);
560
- const mr = descentParserCpOnly(m, "", [64]);
561
- const result = JSON.stringify(mr);
562
- if (result !== '[{"tag":"e","sequence":[]},true,0]') {
563
- throw result;
564
- }
565
- },
566
- () => {
567
- const stringRule = 'AB';
568
- const m = descentParser(stringRule);
569
- const mr = descentParserCpOnly(m, "", [65, 66]);
570
- const result = JSON.stringify(mr);
571
- if (result !== '[{"sequence":[{"sequence":[[65,null]]},{"sequence":[[66,null]]}]},true,2]') {
572
- throw result;
573
- }
574
- },
575
- () => {
576
- const stringRule = 'AB';
577
- const m = descentParser(stringRule);
578
- const mr = descentParserCpOnly(m, "", [65, 67]);
579
- const result = JSON.stringify(mr);
580
- if (result !== '[{"sequence":[]},false,0]') {
581
- throw result;
582
- }
583
- },
584
- () => {
585
- const emptyRule = '';
586
- const minursRule = range('--');
587
- const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
588
- const digitRule = range('09');
589
- const numberRule = [optionalMinusRule, digitRule];
590
- const m = descentParser(numberRule);
591
- const mr = descentParserCpOnly(m, "", [50]);
592
- const result = JSON.stringify(mr);
593
- if (result !== '[{"sequence":[{"tag":"none","sequence":[]},{"sequence":[[50,null]]}]},true,1]') {
594
- throw result;
595
- }
596
- },
597
- () => {
598
- const emptyRule = '';
599
- const minusRule = range('--');
600
- const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
601
- const digitRule = range('09');
602
- const numberRule = [optionalMinusRule, digitRule];
603
- const m = descentParser(numberRule);
604
- const mr = descentParserCpOnly(m, "", [45, 50]);
605
- const result = JSON.stringify(mr);
606
- if (result !== '[{"sequence":[{"tag":"minus","sequence":[[45,null]]},{"sequence":[[50,null]]}]},true,2]') {
607
- throw result;
608
- }
609
- },
610
- () => {
611
- const emptyRule = '';
612
- const minursRule = range('--');
613
- const optionalMinusRule = { 'none': emptyRule, 'minus': minursRule };
614
- const digitRule = range('09');
615
- const numberRule = [optionalMinusRule, digitRule];
616
- const m = descentParser(numberRule);
617
- const mr = m("", []);
618
- const result = JSON.stringify(mr);
619
- if (result !== '[{"sequence":[]},false,0]') {
620
- throw result;
621
- }
622
- },
623
- () => {
624
- const m = descentParser(option('a'));
625
- const expect = (s, expected) => {
626
- const cp = toArray(stringToCodePointList(s));
627
- const mr = descentParserCpOnly(m, '', cp);
628
- const success = mr[1] && mr[2] === cp.length;
629
- if (success !== expected) {
630
- throw mr;
631
- }
632
- };
633
- expect('a', true);
634
- expect('', true);
635
- expect('aa', false);
636
- expect('b', false);
637
- },
638
- () => {
639
- const ws = repeat0Plus(set(' \n\r\t'));
640
- const cj = commaJoin0Plus(ws);
641
- const value = () => ({
642
- object: cj('{}', 'a'),
643
- array: cj('[]', 'a')
644
- });
645
- value.name; //bun will fail if no usage of name found
646
- const m = descentParser(value);
647
- const expect = (s, expected) => {
648
- const cp = toArray(stringToCodePointList(s));
649
- const mr = descentParserCpOnly(m, 'value', cp);
650
- const success = mr[1] && mr[2] === cp.length;
651
- if (success !== expected) {
652
- throw mr;
653
- }
654
- };
655
- expect('', false);
656
- expect('[]', true);
657
- expect('[a]', true);
658
- expect('[a, a]', true);
659
- expect('{a}', true);
660
- },
661
- () => {
662
- const m = descentParser(deterministic());
663
- const expect = (s, expected) => {
664
- const cp = toArray(stringToCodePointList(s));
665
- const mr = descentParserCpOnly(m, '', cp);
666
- const success = mr[1] && mr[2] === cp.length;
667
- if (success !== expected) {
668
- throw mr;
669
- }
670
- };
671
- expect(' true ', true);
672
- expect(' tr2ue ', false);
673
- expect(' true" ', false);
674
- expect(' "Hello" ', true);
675
- expect(' "Hello ', false);
676
- expect(' "Hello\\n\\r\\"" ', true);
677
- expect(' -56.7e+5 ', true);
678
- expect(' h-56.7e+5 ', false);
679
- expect(' -56.7e+5 3', false);
680
- expect(' [] ', true);
681
- expect(' {} ', true);
682
- expect(' [[[]]] ', true);
683
- expect(' [1] ', true);
684
- expect(' [ 12, false, "a"] ', true);
685
- expect(' [ 12, false2, "a"] ', false);
686
- expect(' { "q": [ 12, false, [{"b" : "c"}], "a"] } ', true);
687
- expect(' { "q": [ 12, false, [{}], "a"] } ', true);
688
- expect(' { "q": [ 12, false, [}], "a"] } ', false);
689
- expect(' [{ "q": [ 12, false, [{}], "a"] }] ', true);
690
- expect(' [{ "q": [ 12, false, [}], "a"] }] ', false);
691
- }
692
- ],
693
- descentParserWithMeta: [
694
- () => {
695
- const emptyRule = '';
696
- const minusRule = range('--');
697
- const optionalMinusRule = { 'none': emptyRule, 'minus': minusRule };
698
- const digitRule = range('09');
699
- const numberRule = [optionalMinusRule, digitRule];
700
- const m = descentParser(numberRule);
701
- const mr = m("", [[45, 'minus'], [50, 'two']]);
702
- const result = JSON.stringify(mr);
703
- if (result !== '[{"sequence":[{"tag":"minus","sequence":[[45,"minus"]]},{"sequence":[[50,"two"]]}]},true,2]') {
704
- throw result;
705
- }
706
- },
707
- ],
708
- repeat: [
709
- () => {
710
- const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
711
- const dm = dispatchMap(repeatData[0]);
712
- const result = JSON.stringify(dm);
713
- if (result !== '{"ws":{"emptyTag":true,"rangeMap":[]},"a":{"rangeMap":[[null,64],[{"rules":[]},65]]},"repa":{"rangeMap":[[null,64],[{"rules":[""]},65]]},"":{"rangeMap":[[null,64],[{"rules":[""]},65]]}}') {
714
- throw result;
715
- }
716
- }
717
- ],
718
- repeatParser: [
719
- () => {
720
- const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
721
- const m = parserRuleSet(repeatData[0]);
722
- const mr = m("", []);
723
- const result = JSON.stringify(mr);
724
- if (result !== '[{"sequence":[]},true,null]') {
725
- throw result;
726
- }
727
- },
728
- () => {
729
- const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
730
- const m = parserRuleSet(repeatData[0]);
731
- const mr = m("", [65]);
732
- const result = JSON.stringify(mr);
733
- if (result !== '[{"sequence":[65,{"sequence":[]}]},true,null]') {
734
- throw result;
735
- }
736
- },
737
- () => {
738
- const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
739
- const m = parserRuleSet(repeatData[0]);
740
- const mr = m("", [65, 65, 65]);
741
- const result = JSON.stringify(mr);
742
- if (result !== '[{"sequence":[65,{"sequence":[65,{"sequence":[65,{"sequence":[]}]}]}]},true,null]') {
743
- throw result;
744
- }
745
- },
746
- () => {
747
- const repeatData = [{ "": ["ws", "repa"], "ws": [], "repa": ["a", ""], "a": 1090519105 }, ""];
748
- const m = parserRuleSet(repeatData[0]);
749
- const mr = m("", [66]);
750
- const result = JSON.stringify(mr);
751
- if (result !== '[{"sequence":[]},false,[66]]') {
752
- throw result;
753
- }
754
- }
755
- ],
756
123
  example: () => {
757
124
  const grammar = {
758
125
  space: 0x000020_000020,
@@ -763,5 +130,5 @@ export const proof = {
763
130
  'digit': 'digit',
764
131
  }
765
132
  };
766
- }
133
+ },
767
134
  };