functionalscript 0.8.0 → 0.8.2
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.
- package/bnf/data/module.f.d.ts +6 -0
- package/bnf/data/module.f.js +57 -4
- package/bnf/data/test.f.d.ts +1 -0
- package/bnf/data/test.f.js +67 -1
- package/ci/module.f.d.ts +3 -0
- package/ci/module.f.js +169 -0
- package/ci/module.js +3 -0
- package/crypto/hmac/module.f.d.ts +5 -4
- package/crypto/hmac/module.f.js +9 -18
- package/crypto/hmac/test.f.d.ts +1 -0
- package/crypto/hmac/test.f.js +16 -8
- package/crypto/secp/module.f.d.ts +14 -11
- package/crypto/secp/module.f.js +33 -13
- package/crypto/secp/test.f.js +12 -13
- package/crypto/sha2/module.f.d.ts +11 -5
- package/crypto/sha2/module.f.js +4 -3
- package/crypto/sha2/test.f.d.ts +4 -1
- package/crypto/sha2/test.f.js +41 -31
- package/crypto/sign/module.f.d.ts +17 -4
- package/crypto/sign/module.f.js +141 -46
- package/crypto/sign/test.f.d.ts +11 -1
- package/crypto/sign/test.f.js +631 -1
- package/dev/tf/all.test.js +9 -1
- package/djs/ast/module.f.d.ts +3 -3
- package/djs/ast/test.f.js +7 -8
- package/djs/parser/module.f.d.ts +3 -3
- package/djs/parser/module.f.js +4 -4
- package/djs/parser/test.f.js +76 -77
- package/djs/serializer/module.f.d.ts +8 -8
- package/djs/serializer/module.f.js +4 -7
- package/djs/serializer/test.f.js +8 -9
- package/djs/tokenizer/module.f.d.ts +2 -2
- package/djs/tokenizer/module.f.js +3 -5
- package/djs/tokenizer/test.f.js +8 -10
- package/djs/transpiler/module.f.d.ts +3 -3
- package/djs/transpiler/module.f.js +2 -0
- package/fsc/bnf.f.d.ts +1 -1
- package/fsc/bnf.f.js +39 -51
- package/fsc/json.f.d.ts +1 -1
- package/fsc/json.f.js +56 -81
- package/fsc/test.f.js +4 -6
- package/fsm/module.f.js +3 -3
- package/fsm/test.f.js +21 -25
- package/html/module.f.js +17 -4
- package/html/test.f.d.ts +7 -0
- package/html/test.f.js +37 -0
- package/issues/031-json.f.d.ts +1 -0
- package/js/tokenizer/module.f.d.ts +4 -4
- package/js/tokenizer/module.f.js +12 -17
- package/js/tokenizer/test.f.js +9 -11
- package/json/module.f.d.ts +6 -6
- package/json/module.f.js +5 -10
- package/json/parser/module.f.d.ts +4 -4
- package/json/parser/module.f.js +7 -4
- package/json/parser/test.f.js +47 -49
- package/json/serializer/module.f.d.ts +6 -6
- package/json/serializer/module.f.js +3 -2
- package/json/serializer/test.f.js +13 -13
- package/json/test.f.js +13 -15
- package/json/tokenizer/module.f.d.ts +4 -4
- package/json/tokenizer/module.f.js +6 -7
- package/json/tokenizer/test.f.js +7 -9
- package/nanvm-lib/tests/vm/test.f.js +1 -1
- package/package.json +5 -5
- package/path/module.f.d.ts +3 -2
- package/text/ascii/test.f.js +2 -2
- package/text/module.f.d.ts +3 -2
- package/text/module.f.js +2 -2
- package/text/test.f.js +3 -3
- package/text/utf16/test.f.js +2 -2
- package/text/utf8/test.f.js +2 -2
- package/types/array/test.f.js +2 -2
- package/types/bigint/module.f.d.ts +6 -3
- package/types/bigint/module.f.js +12 -11
- package/types/bigint/test.f.d.ts +2 -0
- package/types/bigint/test.f.js +21 -2
- package/types/bit_vec/module.f.d.ts +66 -34
- package/types/bit_vec/module.f.js +97 -32
- package/types/bit_vec/test.f.d.ts +7 -0
- package/types/bit_vec/test.f.js +283 -62
- package/types/btree/find/test.f.js +9 -8
- package/types/btree/remove/test.f.js +4 -4
- package/types/btree/set/test.f.js +4 -4
- package/types/btree/test.f.js +7 -7
- package/types/byte_set/test.f.js +2 -2
- package/types/function/compare/module.f.d.ts +15 -1
- package/types/function/compare/module.f.js +1 -1
- package/types/function/compare/test.f.js +37 -4
- package/types/list/test.f.js +93 -93
- package/types/monoid/module.f.d.ts +4 -4
- package/types/monoid/module.f.js +3 -3
- package/types/monoid/test.f.js +3 -3
- package/types/nominal/module.f.d.ts +5 -0
- package/types/nominal/module.f.js +4 -0
- package/types/nominal/test.f.d.ts +5 -0
- package/types/nominal/test.f.js +53 -0
- package/types/number/module.f.js +2 -2
- package/{crypto → types}/prime_field/module.f.d.ts +2 -2
- package/{crypto → types}/prime_field/module.f.js +5 -4
- package/{crypto → types}/prime_field/test.f.js +13 -13
- package/types/range_map/test.f.js +21 -21
- package/types/sorted_list/test.f.js +10 -10
- package/types/sorted_set/test.f.js +14 -14
- package/types/string/module.f.js +2 -2
- package/types/string_set/module.f.js +3 -3
- package/bnf/func/module.f.d.ts +0 -148
- package/bnf/func/module.f.js +0 -132
- package/bnf/func/test.f.d.ts +0 -12
- package/bnf/func/test.f.js +0 -171
- package/bnf/func/testlib.f.d.ts +0 -25
- package/bnf/func/testlib.f.js +0 -150
- /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
- /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
- /package/{crypto → types}/prime_field/test.f.d.ts +0 -0
|
@@ -58,21 +58,21 @@ export default {
|
|
|
58
58
|
},
|
|
59
59
|
pow: () => {
|
|
60
60
|
const test = a => {
|
|
61
|
-
if (f.pow(
|
|
61
|
+
if (f.pow(0n)(a) !== 1n) {
|
|
62
62
|
throw '**0';
|
|
63
63
|
}
|
|
64
|
-
if (f.pow(
|
|
64
|
+
if (f.pow(1n)(a) !== a) {
|
|
65
65
|
throw '**1';
|
|
66
66
|
}
|
|
67
67
|
// https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
|
|
68
68
|
// a^(p-1) % p = 1
|
|
69
|
-
if (f.abs(f.pow(
|
|
69
|
+
if (f.abs(f.pow(f.middle)(a)) !== 1n) {
|
|
70
70
|
throw '**middle';
|
|
71
71
|
}
|
|
72
|
-
if (f.pow(
|
|
72
|
+
if (f.pow(f.sub(f.max)(1n))(a) !== f.reciprocal(a)) {
|
|
73
73
|
throw '**(max-1)';
|
|
74
74
|
}
|
|
75
|
-
if (f.pow(
|
|
75
|
+
if (f.pow(f.max)(a) !== 1n) {
|
|
76
76
|
throw '**max';
|
|
77
77
|
}
|
|
78
78
|
};
|
|
@@ -80,7 +80,7 @@ export default {
|
|
|
80
80
|
if (f.pow(0n)(0n) !== 1n) {
|
|
81
81
|
throw '0**0';
|
|
82
82
|
}
|
|
83
|
-
if (f.pow(
|
|
83
|
+
if (f.pow(f.max)(0n) !== 0n) {
|
|
84
84
|
throw '0**max';
|
|
85
85
|
}
|
|
86
86
|
// 1
|
|
@@ -90,30 +90,30 @@ export default {
|
|
|
90
90
|
if (f.pow(2n)(2n) !== 4n) {
|
|
91
91
|
throw '2**2';
|
|
92
92
|
}
|
|
93
|
-
if (f.pow(
|
|
93
|
+
if (f.pow(3n)(2n) !== 8n) {
|
|
94
94
|
throw '2**3';
|
|
95
95
|
}
|
|
96
|
-
if (f.pow(
|
|
96
|
+
if (f.pow(128n)(2n) !== 1n << 128n) {
|
|
97
97
|
throw '2**128';
|
|
98
98
|
}
|
|
99
99
|
// 3
|
|
100
100
|
test(3n);
|
|
101
|
-
if (f.pow(
|
|
101
|
+
if (f.pow(2n)(3n) !== 9n) {
|
|
102
102
|
throw '3**2';
|
|
103
103
|
}
|
|
104
104
|
if (f.pow(3n)(3n) !== 27n) {
|
|
105
105
|
throw '3**3';
|
|
106
106
|
}
|
|
107
|
-
if (f.pow(
|
|
107
|
+
if (f.pow(100n)(3n) !== 3n ** 100n) {
|
|
108
108
|
throw '3**100';
|
|
109
109
|
}
|
|
110
|
-
if (f.pow(
|
|
110
|
+
if (f.pow(110n)(3n) !== 3n ** 110n) {
|
|
111
111
|
throw '3**110';
|
|
112
112
|
}
|
|
113
|
-
if (f.pow(
|
|
113
|
+
if (f.pow(120n)(3n) !== 3n ** 120n) {
|
|
114
114
|
throw '3**120';
|
|
115
115
|
}
|
|
116
|
-
if (f.pow(
|
|
116
|
+
if (f.pow(121n)(3n) !== 3n ** 121n) {
|
|
117
117
|
throw '3**121';
|
|
118
118
|
}
|
|
119
119
|
//
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { get, merge, fromRange, rangeMap } from "./module.f.js";
|
|
2
|
-
import {
|
|
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
|
|
8
|
-
|
|
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(
|
|
11
|
-
equal: equal(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
8
|
-
const
|
|
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 =
|
|
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 =
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 {
|
|
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
|
-
|
|
8
|
-
const
|
|
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 (
|
|
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 (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
}
|
package/types/string/module.f.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
26
|
+
export const cmp = uCmp;
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
* if (contains('banana')(mySet)) { throw '4' }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import
|
|
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 =
|
|
30
|
-
export const 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);
|
package/bnf/func/module.f.d.ts
DELETED
|
@@ -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 {};
|
package/bnf/func/module.f.js
DELETED
|
@@ -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
|
-
};
|