functionalscript 0.0.523 → 0.0.525

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.
@@ -0,0 +1,354 @@
1
+ const tokenizer = require('./module.f.cjs')
2
+ const { toArray, countdown } = require('../../types/list/module.f.cjs')
3
+ const fjson = require('../../fjson/module.f.cjs')
4
+ const { sort } = require('../../types/object/module.f.cjs')
5
+ const encoding = require('../../text/utf16/module.f.cjs');
6
+
7
+ /** @type {(s: string) => readonly tokenizer.JsToken[]} */
8
+ const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
9
+
10
+ const stringify = fjson.stringify(sort)
11
+
12
+ module.exports = {
13
+ fjson: [
14
+ () => {
15
+ const result = tokenizeString('')
16
+ if (result.length !== 0) { throw result }
17
+ },
18
+ () => {
19
+ const result = stringify(tokenizeString('{'))
20
+ if (result !== '[{"kind":"{"}]') { throw result }
21
+ },
22
+ () => {
23
+ const result = stringify(tokenizeString('}'))
24
+ if (result !== '[{"kind":"}"}]') { throw result }
25
+ },
26
+ () => {
27
+ const result = stringify(tokenizeString(':'))
28
+ if (result !== '[{"kind":":"}]') { throw result }
29
+ },
30
+ () => {
31
+ const result = stringify(tokenizeString(','))
32
+ if (result !== '[{"kind":","}]') { throw result }
33
+ },
34
+ () => {
35
+ const result = stringify(tokenizeString('['))
36
+ if (result !== '[{"kind":"["}]') { throw result }
37
+ },
38
+ () => {
39
+ const result = stringify(tokenizeString(']'))
40
+ if (result !== '[{"kind":"]"}]') { throw result }
41
+ },
42
+ () => {
43
+ const result = stringify(tokenizeString('ᄑ'))
44
+ if (result !== '[{"kind":"error","message":"unexpected character"}]') { throw result }
45
+ },
46
+ () => {
47
+ const result = stringify(tokenizeString('err'))
48
+ if (result !== '[{"kind":"id","value":"err"}]') { throw result }
49
+ },
50
+ () => {
51
+ const result = stringify(tokenizeString('{e}'))
52
+ if (result !== '[{"kind":"{"},{"kind":"id","value":"e"},{"kind":"}"}]') { throw result }
53
+ },
54
+ () => {
55
+ const result = stringify(tokenizeString('{ \t\n\r}'))
56
+ if (result !== '[{"kind":"{"},{"kind":"}"}]') { throw result }
57
+ },
58
+ () => {
59
+ const result = stringify(tokenizeString('true'))
60
+ if (result !== '[{"kind":"true"}]') { throw result }
61
+ },
62
+ () => {
63
+ const result = stringify(tokenizeString('tru'))
64
+ if (result !== '[{"kind":"id","value":"tru"}]') { throw result }
65
+ },
66
+ () => {
67
+ const result = stringify(tokenizeString('false'))
68
+ if (result !== '[{"kind":"false"}]') { throw result }
69
+ },
70
+ () => {
71
+ const result = stringify(tokenizeString('null'))
72
+ if (result !== '[{"kind":"null"}]') { throw result }
73
+ },
74
+ () => {
75
+ const result = stringify(tokenizeString('[null]'))
76
+ if (result !== '[{"kind":"["},{"kind":"null"},{"kind":"]"}]') { throw result }
77
+ },
78
+ () => {
79
+ const result = stringify(tokenizeString('""'))
80
+ if (result !== '[{"kind":"string","value":""}]') { throw result }
81
+ },
82
+ () => {
83
+ const result = stringify(tokenizeString('"value"'))
84
+ if (result !== '[{"kind":"string","value":"value"}]') { throw result }
85
+ },
86
+ () => {
87
+ const result = stringify(tokenizeString('"value'))
88
+ if (result !== '[{"kind":"error","message":"\\" are missing"}]') { throw result }
89
+ },
90
+ () => {
91
+ const result = stringify(tokenizeString('"value1" "value2"'))
92
+ if (result !== '[{"kind":"string","value":"value1"},{"kind":"string","value":"value2"}]') { throw result }
93
+ },
94
+ () => {
95
+ const result = stringify(tokenizeString('"'))
96
+ if (result !== '[{"kind":"error","message":"\\" are missing"}]') { throw result }
97
+ },
98
+ () => {
99
+ const result = stringify(tokenizeString('"\\\\"'))
100
+ if (result !== '[{"kind":"string","value":"\\\\"}]') { throw result }
101
+ },
102
+ () => {
103
+ const result = stringify(tokenizeString('"\\""'))
104
+ if (result !== '[{"kind":"string","value":"\\""}]') { throw result }
105
+ },
106
+ () => {
107
+ const result = stringify(tokenizeString('"\\/"'))
108
+ if (result !== '[{"kind":"string","value":"/"}]') { throw result }
109
+ },
110
+ () => {
111
+ const result = stringify(tokenizeString('"\\x"'))
112
+ if (result !== '[{"kind":"error","message":"unescaped character"},{"kind":"string","value":"x"}]') { throw result }
113
+ },
114
+ () => {
115
+ const result = stringify(tokenizeString('"\\'))
116
+ if (result !== '[{"kind":"error","message":"\\" are missing"}]') { throw result }
117
+ },
118
+ () => {
119
+ const result = stringify(tokenizeString('"\\b\\f\\n\\r\\t"'))
120
+ if (result !== '[{"kind":"string","value":"\\b\\f\\n\\r\\t"}]') { throw result }
121
+ },
122
+ () => {
123
+ const result = stringify(tokenizeString('"\\u1234"'))
124
+ if (result !== '[{"kind":"string","value":"ሴ"}]') { throw result }
125
+ },
126
+ () => {
127
+ const result = stringify(tokenizeString('"\\uaBcDEeFf"'))
128
+ if (result !== '[{"kind":"string","value":"ꯍEeFf"}]') { throw result }
129
+ },
130
+ () => {
131
+ const result = stringify(tokenizeString('"\\uEeFg"'))
132
+ if (result !== '[{"kind":"error","message":"invalid hex value"},{"kind":"string","value":"g"}]') { throw result }
133
+ },
134
+ () => {
135
+ const result = stringify(tokenizeString('0'))
136
+ if (result !== '[{"bf":[0n,0],"kind":"number","value":"0"}]') { throw result }
137
+ },
138
+ () => {
139
+ const result = stringify(tokenizeString('[0]'))
140
+ if (result !== '[{"kind":"["},{"bf":[0n,0],"kind":"number","value":"0"},{"kind":"]"}]') { throw result }
141
+ },
142
+ () => {
143
+ const result = stringify(tokenizeString('00'))
144
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
145
+ },
146
+ () => {
147
+ const result = stringify(tokenizeString('0abc,'))
148
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"abc"},{"kind":","}]') { throw result }
149
+ },
150
+ () => {
151
+ const result = stringify(tokenizeString('123456789012345678901234567890'))
152
+ if (result !== '[{"bf":[123456789012345678901234567890n,0],"kind":"number","value":"123456789012345678901234567890"}]') { throw result }
153
+ },
154
+ () => {
155
+ const result = stringify(tokenizeString('{90}'))
156
+ if (result !== '[{"kind":"{"},{"bf":[90n,0],"kind":"number","value":"90"},{"kind":"}"}]') { throw result }
157
+ },
158
+ () => {
159
+ const result = stringify(tokenizeString('1 2'))
160
+ if (result !== '[{"bf":[1n,0],"kind":"number","value":"1"},{"bf":[2n,0],"kind":"number","value":"2"}]') { throw result }
161
+ },
162
+ () => {
163
+ const result = stringify(tokenizeString('0. 2'))
164
+ if (result !== '[{"kind":"error","message":"invalid number"},{"bf":[2n,0],"kind":"number","value":"2"}]') { throw result }
165
+ },
166
+ () => {
167
+ const result = stringify(tokenizeString('10-0'))
168
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
169
+ },
170
+ () => {
171
+ const result = stringify(tokenizeString('9a:'))
172
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"a"},{"kind":":"}]') { throw result }
173
+ },
174
+ () => {
175
+ const result = stringify(tokenizeString('-10'))
176
+ if (result !== '[{"bf":[-10n,0],"kind":"number","value":"-10"}]') { throw result }
177
+ },
178
+ () => {
179
+ const result = stringify(tokenizeString('-0'))
180
+ if (result !== '[{"bf":[0n,0],"kind":"number","value":"-0"}]') { throw result }
181
+ },
182
+ () => {
183
+ const result = stringify(tokenizeString('-00'))
184
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
185
+ },
186
+ () => {
187
+ const result = stringify(tokenizeString('-.123'))
188
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
189
+ },
190
+ () => {
191
+ const result = stringify(tokenizeString('0.01'))
192
+ if (result !== '[{"bf":[1n,-2],"kind":"number","value":"0.01"}]') { throw result }
193
+ },
194
+ () => {
195
+ const result = stringify(tokenizeString('-0.9'))
196
+ if (result !== '[{"bf":[-9n,-1],"kind":"number","value":"-0.9"}]') { throw result }
197
+ },
198
+ () => {
199
+ const result = stringify(tokenizeString('-0.'))
200
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
201
+ },
202
+ () => {
203
+ const result = stringify(tokenizeString('-0.]'))
204
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"]"}]') { throw result }
205
+ },
206
+ () => {
207
+ const result = stringify(tokenizeString('12.34'))
208
+ if (result !== '[{"bf":[1234n,-2],"kind":"number","value":"12.34"}]') { throw result }
209
+ },
210
+ () => {
211
+ const result = stringify(tokenizeString('-12.00'))
212
+ if (result !== '[{"bf":[-1200n,-2],"kind":"number","value":"-12.00"}]') { throw result }
213
+ },
214
+ () => {
215
+ const result = stringify(tokenizeString('-12.'))
216
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
217
+ },
218
+ () => {
219
+ const result = stringify(tokenizeString('12.]'))
220
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"]"}]') { throw result }
221
+ },
222
+ () => {
223
+ const result = stringify(tokenizeString('0e1'))
224
+ if (result !== '[{"bf":[0n,1],"kind":"number","value":"0e1"}]') { throw result }
225
+ },
226
+ () => {
227
+ const result = stringify(tokenizeString('0e+2'))
228
+ if (result !== '[{"bf":[0n,2],"kind":"number","value":"0e+2"}]') { throw result }
229
+ },
230
+ () => {
231
+ const result = stringify(tokenizeString('0e-0'))
232
+ if (result !== '[{"bf":[0n,0],"kind":"number","value":"0e-0"}]') { throw result }
233
+ },
234
+ () => {
235
+ const result = stringify(tokenizeString('12e0000'))
236
+ if (result !== '[{"bf":[12n,0],"kind":"number","value":"12e0000"}]') { throw result }
237
+ },
238
+ () => {
239
+ const result = stringify(tokenizeString('-12e-0001'))
240
+ if (result !== '[{"bf":[-12n,-1],"kind":"number","value":"-12e-0001"}]') { throw result }
241
+ },
242
+ () => {
243
+ const result = stringify(tokenizeString('-12.34e1234'))
244
+ if (result !== '[{"bf":[-1234n,1232],"kind":"number","value":"-12.34e1234"}]') { throw result }
245
+ },
246
+ () => {
247
+ const result = stringify(tokenizeString('0e'))
248
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
249
+ },
250
+ () => {
251
+ const result = stringify(tokenizeString('0e-'))
252
+ if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
253
+ },
254
+ () => {
255
+ const result = stringify(tokenizeString('ABCdef1234567890$_'))
256
+ if (result !== '[{"kind":"id","value":"ABCdef1234567890$_"}]') { throw result }
257
+ },
258
+ () => {
259
+ const result = stringify(tokenizeString('{ABCdef1234567890$_}'))
260
+ if (result !== '[{"kind":"{"},{"kind":"id","value":"ABCdef1234567890$_"},{"kind":"}"}]') { throw result }
261
+ },
262
+ () => {
263
+ const result = stringify(tokenizeString('123 _123'))
264
+ if (result !== '[{"bf":[123n,0],"kind":"number","value":"123"},{"kind":"id","value":"_123"}]') { throw result }
265
+ },
266
+ () => {
267
+ const result = stringify(tokenizeString('123 $123'))
268
+ if (result !== '[{"bf":[123n,0],"kind":"number","value":"123"},{"kind":"id","value":"$123"}]') { throw result }
269
+ },
270
+ () => {
271
+ const result = stringify(tokenizeString('123_123'))
272
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"_123"}]') { throw result }
273
+ },
274
+ () => {
275
+ const result = stringify(tokenizeString('123$123'))
276
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"$123"}]') { throw result }
277
+ },
278
+ () => {
279
+ const result = stringify(tokenizeString('1234567890n'))
280
+ if (result !== '[{"kind":"bigint","value":1234567890n}]') { throw result }
281
+ },
282
+ () => {
283
+ const result = stringify(tokenizeString('0n'))
284
+ if (result !== '[{"kind":"bigint","value":0n}]') { throw result }
285
+ },
286
+ () => {
287
+ const result = stringify(tokenizeString('[-1234567890n]'))
288
+ if (result !== '[{"kind":"["},{"kind":"bigint","value":-1234567890n},{"kind":"]"}]') { throw result }
289
+ },
290
+ () => {
291
+ const result = stringify(tokenizeString('123.456n'))
292
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"}]') { throw result }
293
+ },
294
+ () => {
295
+ const result = stringify(tokenizeString('123e456n'))
296
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"}]') { throw result }
297
+ },
298
+ () => {
299
+ const result = stringify(tokenizeString('1234567890na'))
300
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"a"}]') { throw result }
301
+ },
302
+ () => {
303
+ const result = stringify(tokenizeString('1234567890nn'))
304
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"id","value":"n"}]') { throw result }
305
+ },
306
+ ],
307
+ operators:
308
+ [
309
+ () => {
310
+ const result = stringify(tokenizeString('='))
311
+ if (result !== '[{"kind":"="}]') { throw result }
312
+ },
313
+ () => {
314
+ const result = stringify(tokenizeString('=a'))
315
+ if (result !== '[{"kind":"="},{"kind":"id","value":"a"}]') { throw result }
316
+ },
317
+ () => {
318
+ const result = stringify(tokenizeString('-'))
319
+ if (result !== '[{"kind":"-"}]') { throw result }
320
+ },
321
+ () => {
322
+ const result = stringify(tokenizeString('== != === !== > >= < <='))
323
+ if (result !== '[{"kind":"=="},{"kind":"!="},{"kind":"==="},{"kind":"!=="},{"kind":">"},{"kind":">="},{"kind":"<"},{"kind":"<="}]') { throw result }
324
+ },
325
+ () => {
326
+ const result = stringify(tokenizeString('+ - * / % ++ -- **'))
327
+ if (result !== '[{"kind":"+"},{"kind":"-"},{"kind":"*"},{"kind":"/"},{"kind":"%"},{"kind":"++"},{"kind":"--"},{"kind":"**"}]') { throw result }
328
+ },
329
+ () => {
330
+ const result = stringify(tokenizeString('= += -= *= /= %= **='))
331
+ if (result !== '[{"kind":"="},{"kind":"+="},{"kind":"-="},{"kind":"*="},{"kind":"/="},{"kind":"%="},{"kind":"**="}]') { throw result }
332
+ },
333
+ () => {
334
+ const result = stringify(tokenizeString('& | ^ ~ << >> >>>'))
335
+ if (result !== '[{"kind":"&"},{"kind":"|"},{"kind":"^"},{"kind":"~"},{"kind":"<<"},{"kind":">>"},{"kind":">>>"}]') { throw result }
336
+ },
337
+ () => {
338
+ const result = stringify(tokenizeString('&= |= ^= <<= >>= >>>='))
339
+ if (result !== '[{"kind":"&="},{"kind":"|="},{"kind":"^="},{"kind":"<<="},{"kind":">>="},{"kind":">>>="}]') { throw result }
340
+ },
341
+ () => {
342
+ const result = stringify(tokenizeString('&& || ! ??'))
343
+ if (result !== '[{"kind":"&&"},{"kind":"||"},{"kind":"!"},{"kind":"??"}]') { throw result }
344
+ },
345
+ () => {
346
+ const result = stringify(tokenizeString('&&= ||= ??='))
347
+ if (result !== '[{"kind":"&&="},{"kind":"||="},{"kind":"??="}]') { throw result }
348
+ },
349
+ () => {
350
+ const result = stringify(tokenizeString('? ?. . =>'))
351
+ if (result !== '[{"kind":"?"},{"kind":"?."},{"kind":"."},{"kind":"=>"}]') { throw result }
352
+ },
353
+ ]
354
+ }
@@ -1,16 +1,16 @@
1
1
  const list = require('../../types/list/module.f.cjs')
2
- const fjsonTokenizer = require('../../fjson/tokenizer/module.f.cjs')
2
+ const jsTokenizer = require('../../js/tokenizer/module.f.cjs')
3
3
 
4
4
  /**
5
5
  * @typedef {|
6
- * fjsonTokenizer.SimpleToken |
7
- * fjsonTokenizer.StringToken |
8
- * fjsonTokenizer.NumberToken |
9
- * fjsonTokenizer.ErrorToken
6
+ * jsTokenizer.SimpleToken |
7
+ * jsTokenizer.StringToken |
8
+ * jsTokenizer.NumberToken |
9
+ * jsTokenizer.ErrorToken
10
10
  * } JsonToken
11
11
  */
12
12
 
13
- /** @type {(input: fjsonTokenizer.FjsonToken) => JsonToken} */
13
+ /** @type {(input: jsTokenizer.JsToken) => JsonToken} */
14
14
  const mapToken = input =>
15
15
  {
16
16
  switch(input.kind)
@@ -32,7 +32,7 @@ const mapToken = input =>
32
32
  }
33
33
 
34
34
  /** @type {(input: list.List<number>) => list.List<JsonToken>} */
35
- const tokenize = input => list.map(mapToken)(fjsonTokenizer.tokenize(input))
35
+ const tokenize = input => list.map(mapToken)(jsTokenizer.tokenize(input))
36
36
 
37
37
  module.exports = {
38
38
  /** @readonly */
@@ -10,7 +10,7 @@ const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s))
10
10
  const stringify = fjson.stringify(sort)
11
11
 
12
12
  module.exports = {
13
- testing: [
13
+ json: [
14
14
  () => {
15
15
  const result = tokenizeString('')
16
16
  if (result.length !== 0) { throw result }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.523",
3
+ "version": "0.0.525",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {