functionalscript 0.7.0 → 0.8.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.
- package/LICENSE +21 -661
- package/README.md +3 -2
- package/bnf/data/module.f.d.ts +10 -6
- package/bnf/data/module.f.js +62 -23
- package/bnf/data/test.f.d.ts +3 -0
- package/bnf/data/test.f.js +323 -14
- package/bnf/module.f.d.ts +5 -4
- package/bnf/module.f.js +1 -1
- package/bnf/testlib.f.js +1 -1
- package/fsc/test.f.d.ts +5 -0
- package/fsc/test.f.js +65 -1
- package/nanvm-lib/tests/vm/test.f.d.ts +25 -0
- package/nanvm-lib/tests/vm/test.f.js +105 -0
- package/package.json +6 -6
- package/bnf/djs/module.f.d.ts +0 -77
- package/bnf/djs/module.f.js +0 -207
- package/bnf/djs/test.f.d.ts +0 -8
- package/bnf/djs/test.f.js +0 -277
package/bnf/djs/test.f.js
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { cp, range, remove, set, str } from "../func/module.f.js";
|
|
2
|
-
import { parser, toRuleMap } from "./module.f.js";
|
|
3
|
-
import { classic } from "../func/testlib.f.js";
|
|
4
|
-
import * as j from "../../json/module.f.js";
|
|
5
|
-
import { sort } from "../../types/object/module.f.js";
|
|
6
|
-
import { stringToCodePointList } from "../../text/utf16/module.f.js";
|
|
7
|
-
import { toArray } from "../../types/list/module.f.js";
|
|
8
|
-
const stringify = j.stringify(sort);
|
|
9
|
-
const classicTest = () => {
|
|
10
|
-
const map = {
|
|
11
|
-
json: [
|
|
12
|
-
['element']
|
|
13
|
-
],
|
|
14
|
-
value: [
|
|
15
|
-
['object'],
|
|
16
|
-
['array'],
|
|
17
|
-
['string'],
|
|
18
|
-
['number'],
|
|
19
|
-
str('true'),
|
|
20
|
-
str('false'),
|
|
21
|
-
str('null'),
|
|
22
|
-
],
|
|
23
|
-
object: [
|
|
24
|
-
[cp('{'), 'ws', cp('}')],
|
|
25
|
-
[cp('{'), 'members', cp('}')],
|
|
26
|
-
],
|
|
27
|
-
members: [
|
|
28
|
-
['member'],
|
|
29
|
-
['member', cp(','), 'members'],
|
|
30
|
-
],
|
|
31
|
-
member: [
|
|
32
|
-
['ws', 'string', 'ws', cp(':'), 'element'],
|
|
33
|
-
],
|
|
34
|
-
array: [
|
|
35
|
-
[cp('['), 'ws', cp(']')],
|
|
36
|
-
[cp('['), 'elements', cp(']')],
|
|
37
|
-
],
|
|
38
|
-
elements: [
|
|
39
|
-
['element'],
|
|
40
|
-
['element', cp(','), 'elements'],
|
|
41
|
-
],
|
|
42
|
-
element: [
|
|
43
|
-
['ws', 'value', 'ws'],
|
|
44
|
-
],
|
|
45
|
-
string: [
|
|
46
|
-
[cp('"'), 'characters', cp('"')],
|
|
47
|
-
],
|
|
48
|
-
characters: [
|
|
49
|
-
[],
|
|
50
|
-
['character', 'characters'],
|
|
51
|
-
],
|
|
52
|
-
character: [
|
|
53
|
-
...remove([0x20, 0x10FFFF], [cp('"'), cp('\\')]),
|
|
54
|
-
[cp('\\'), 'escape'], // 92
|
|
55
|
-
],
|
|
56
|
-
escape: [
|
|
57
|
-
str('"'),
|
|
58
|
-
str('\\'),
|
|
59
|
-
str('/'),
|
|
60
|
-
str('b'),
|
|
61
|
-
str('f'),
|
|
62
|
-
str('n'),
|
|
63
|
-
str('r'),
|
|
64
|
-
str('t'),
|
|
65
|
-
[cp('u'), 'hex', 'hex', 'hex', 'hex'],
|
|
66
|
-
],
|
|
67
|
-
hex: [
|
|
68
|
-
['digit'],
|
|
69
|
-
[range('AF')], // A-F
|
|
70
|
-
[range('af')], // a-f
|
|
71
|
-
],
|
|
72
|
-
number: [
|
|
73
|
-
['integer', 'fraction', 'exponent'],
|
|
74
|
-
],
|
|
75
|
-
integer: [
|
|
76
|
-
['digit'],
|
|
77
|
-
['onenine', 'digits'],
|
|
78
|
-
[cp('-'), 'digit'],
|
|
79
|
-
[cp('-'), 'onenine', 'digits'],
|
|
80
|
-
],
|
|
81
|
-
digits: [
|
|
82
|
-
['digit'],
|
|
83
|
-
['digit', 'digits'],
|
|
84
|
-
],
|
|
85
|
-
digit: [
|
|
86
|
-
[cp('0')],
|
|
87
|
-
['onenine'],
|
|
88
|
-
],
|
|
89
|
-
onenine: [
|
|
90
|
-
[range('19')],
|
|
91
|
-
],
|
|
92
|
-
fraction: [
|
|
93
|
-
[],
|
|
94
|
-
[cp('.'), 'digits'],
|
|
95
|
-
],
|
|
96
|
-
exponent: [
|
|
97
|
-
[],
|
|
98
|
-
[cp('E'), 'sign', 'digits'],
|
|
99
|
-
[cp('e'), 'sign', 'digits'],
|
|
100
|
-
],
|
|
101
|
-
sign: [
|
|
102
|
-
[],
|
|
103
|
-
[cp('+')],
|
|
104
|
-
[cp('-')],
|
|
105
|
-
],
|
|
106
|
-
ws: [
|
|
107
|
-
[],
|
|
108
|
-
[cp(' '), 'ws'],
|
|
109
|
-
[cp('\n'), 'ws'],
|
|
110
|
-
[cp('\r'), 'ws'],
|
|
111
|
-
[cp('\t'), 'ws'],
|
|
112
|
-
],
|
|
113
|
-
};
|
|
114
|
-
const result = map;
|
|
115
|
-
return result;
|
|
116
|
-
};
|
|
117
|
-
const repeat0Name = (v) => `${v}Repeat0`;
|
|
118
|
-
const repeat0Body = (v) => [
|
|
119
|
-
[],
|
|
120
|
-
[v, repeat0Name(v)]
|
|
121
|
-
];
|
|
122
|
-
const repeat0 = (v) => {
|
|
123
|
-
const name = repeat0Name(v);
|
|
124
|
-
const body = repeat0Body(v);
|
|
125
|
-
return { [name]: body };
|
|
126
|
-
};
|
|
127
|
-
const deterministic = () => {
|
|
128
|
-
const map = {
|
|
129
|
-
json: [
|
|
130
|
-
['wsRepeat0', 'element']
|
|
131
|
-
],
|
|
132
|
-
value: [
|
|
133
|
-
[cp('{'), 'wsRepeat0', 'object', cp('}')],
|
|
134
|
-
[cp('['), 'wsRepeat0', 'array', cp(']')],
|
|
135
|
-
['string'],
|
|
136
|
-
['number'],
|
|
137
|
-
str('true'),
|
|
138
|
-
str('false'),
|
|
139
|
-
str('null'),
|
|
140
|
-
],
|
|
141
|
-
object: [
|
|
142
|
-
[],
|
|
143
|
-
['member', 'memberTailRepeat0'],
|
|
144
|
-
],
|
|
145
|
-
memberTail: [
|
|
146
|
-
[cp(','), 'wsRepeat0', 'member']
|
|
147
|
-
],
|
|
148
|
-
...repeat0('memberTail'),
|
|
149
|
-
member: [
|
|
150
|
-
['string', 'wsRepeat0', cp(':'), 'wsRepeat0', 'element'],
|
|
151
|
-
],
|
|
152
|
-
array: [
|
|
153
|
-
[],
|
|
154
|
-
['element', 'elements'],
|
|
155
|
-
],
|
|
156
|
-
elements: [
|
|
157
|
-
[],
|
|
158
|
-
[cp(','), 'wsRepeat0', 'element', 'elements'],
|
|
159
|
-
],
|
|
160
|
-
element: [
|
|
161
|
-
['value', 'wsRepeat0'],
|
|
162
|
-
],
|
|
163
|
-
string: [
|
|
164
|
-
[cp('"'), 'characterRepeat0', cp('"')],
|
|
165
|
-
],
|
|
166
|
-
...repeat0('character'),
|
|
167
|
-
character: [
|
|
168
|
-
...remove([0x20, 0x10FFFF], [cp('"'), cp('\\')]),
|
|
169
|
-
[cp('\\'), 'escape'], // 92
|
|
170
|
-
],
|
|
171
|
-
escape: [
|
|
172
|
-
...set('"\\/bfnrt'),
|
|
173
|
-
[cp('u'), 'hex', 'hex', 'hex', 'hex'],
|
|
174
|
-
],
|
|
175
|
-
hex: [
|
|
176
|
-
['digit'],
|
|
177
|
-
[range('AF')],
|
|
178
|
-
[range('af')],
|
|
179
|
-
],
|
|
180
|
-
numberSign: [
|
|
181
|
-
[],
|
|
182
|
-
[cp('-')]
|
|
183
|
-
],
|
|
184
|
-
number: [
|
|
185
|
-
['numberSign', 'integer', 'fraction', 'exponent'],
|
|
186
|
-
],
|
|
187
|
-
integer: [
|
|
188
|
-
[cp('0')],
|
|
189
|
-
['onenine', 'digitRepeat0'],
|
|
190
|
-
],
|
|
191
|
-
...repeat0('digit'),
|
|
192
|
-
digit: [
|
|
193
|
-
[cp('0')],
|
|
194
|
-
['onenine'],
|
|
195
|
-
],
|
|
196
|
-
onenine: [
|
|
197
|
-
[range('19')],
|
|
198
|
-
],
|
|
199
|
-
fraction: [
|
|
200
|
-
[],
|
|
201
|
-
[cp('.'), 'digit', 'digitRepeat0'],
|
|
202
|
-
],
|
|
203
|
-
e: set('Ee'),
|
|
204
|
-
exponent: [
|
|
205
|
-
[],
|
|
206
|
-
['e', 'sign', 'digit', 'digitRepeat0'],
|
|
207
|
-
],
|
|
208
|
-
sign: [
|
|
209
|
-
[],
|
|
210
|
-
[cp('+')],
|
|
211
|
-
[cp('-')],
|
|
212
|
-
],
|
|
213
|
-
ws: set(' \n\r\t'),
|
|
214
|
-
...repeat0('ws'),
|
|
215
|
-
};
|
|
216
|
-
const _map = map;
|
|
217
|
-
return _map;
|
|
218
|
-
};
|
|
219
|
-
export default {
|
|
220
|
-
example: {
|
|
221
|
-
module: () => {
|
|
222
|
-
// Define a simple grammar
|
|
223
|
-
const grammar = () => [
|
|
224
|
-
[range('AZ')], // 'A-Z'
|
|
225
|
-
[range('az'), grammar], // 'a-z' followed by more grammar
|
|
226
|
-
];
|
|
227
|
-
const ruleMap = toRuleMap(grammar);
|
|
228
|
-
const parse = parser(ruleMap);
|
|
229
|
-
// Parse an input
|
|
230
|
-
const input = toArray(stringToCodePointList('abcdefgA'));
|
|
231
|
-
const result = parse(grammar.name, input);
|
|
232
|
-
if (result === null) {
|
|
233
|
-
throw result;
|
|
234
|
-
}
|
|
235
|
-
const [, b] = result;
|
|
236
|
-
if (b?.length !== 0) {
|
|
237
|
-
throw b;
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
classic: () => {
|
|
242
|
-
const c = classic();
|
|
243
|
-
const json = stringify(toRuleMap(c.json));
|
|
244
|
-
const jsonE = stringify(classicTest());
|
|
245
|
-
if (json !== jsonE) {
|
|
246
|
-
//console.error(json)
|
|
247
|
-
//console.error(jsonE)
|
|
248
|
-
throw [json, jsonE];
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
map: () => {
|
|
252
|
-
const f = parser(deterministic());
|
|
253
|
-
// console.error(stringify(x))
|
|
254
|
-
//
|
|
255
|
-
const isSuccess = (s) => s?.length === 0;
|
|
256
|
-
const expect = (s, success) => {
|
|
257
|
-
const [a, r] = f('json', toArray(stringToCodePointList(s)));
|
|
258
|
-
if (isSuccess(r) !== success) {
|
|
259
|
-
throw r;
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
//
|
|
263
|
-
expect(' true ', true);
|
|
264
|
-
expect(' tr2ue ', false);
|
|
265
|
-
expect(' true" ', false);
|
|
266
|
-
expect(' "Hello" ', true);
|
|
267
|
-
expect(' "Hello ', false);
|
|
268
|
-
expect(' "Hello\\n\\r\\"" ', true);
|
|
269
|
-
expect(' -56.7e+5 ', true);
|
|
270
|
-
expect(' h-56.7e+5 ', false);
|
|
271
|
-
expect(' -56.7e+5 3', false);
|
|
272
|
-
expect(' [ 12, false, "a"] ', true);
|
|
273
|
-
expect(' [ 12, false2, "a"] ', false);
|
|
274
|
-
expect(' { "q": [ 12, false, [{}], "a"] } ', true);
|
|
275
|
-
expect(' { "q": [ 12, false, [}], "a"] } ', false);
|
|
276
|
-
}
|
|
277
|
-
};
|