functionalscript 0.1.608 → 0.2.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/CHANGELOG.md +10 -0
- package/Cargo.lock +4 -0
- package/Cargo.toml +4 -2
- package/README.md +1 -1
- package/com/cpp/module.f.d.mts +4 -8
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.d.mts +4 -8
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.d.mts +3 -7
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/nanocom/src/cobject.rs +1 -1
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.d.mts +2 -2
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/test/rust/src/lib.rs +4 -4
- package/com/types/module.f.d.mts +5 -10
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.d.mts +13 -17
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.d.mts +0 -2
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.d.mts +16 -21
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.d.mts +1 -5
- package/commonjs/module.f.d.mts +0 -2
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.d.mts +3 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.d.mts +12 -18
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.d.mts +25 -32
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.d.mts +1 -4
- package/dev/module.f.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.d.mts +2 -3
- package/dev/test/module.f.mjs +5 -7
- package/djs/module.f.d.mts +13 -18
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.d.mts +53 -37
- package/djs/parser/module.f.mjs +278 -131
- package/djs/parser/test.f.d.mts +4 -0
- package/djs/parser/test.f.mjs +186 -70
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.d.mts +6 -10
- package/djs/tokenizer/module.f.mjs +19 -22
- package/djs/tokenizer/test.f.mjs +7 -7
- package/doc/LANGUAGE.md +17 -16
- package/doc/README.md +14 -50
- package/fsc/README.md +0 -3
- package/fsc/module.f.d.mts +4 -9
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/README.md +1 -1
- package/fsm/module.f.d.mts +13 -20
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/README.md +24 -0
- package/html/module.f.d.mts +7 -12
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/issues/01-test-debug.md +3 -0
- package/issues/{publish.md → 05-publish.md} +8 -8
- package/issues/17-djs-extension.md +6 -0
- package/issues/README.md +20 -13
- package/issues/lang/1000-json.md +38 -0
- package/issues/lang/2110-default-export.md +2 -2
- package/issues/lang/2310-undefined.md +1 -1
- package/issues/lang/2330-property-accessor.md +225 -0
- package/issues/lang/2360-built-in.md +54 -47
- package/issues/lang/3240-export.md +44 -0
- package/issues/lang/README.md +64 -22
- package/issues/test.f.d.mts +16 -0
- package/issues/test.f.mjs +57 -0
- package/js/tokenizer/module.f.d.mts +18 -17
- package/js/tokenizer/module.f.mjs +80 -61
- package/js/tokenizer/test.f.mjs +15 -12
- package/json/module.f.d.mts +18 -26
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.d.mts +9 -13
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.d.mts +11 -20
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.d.mts +6 -10
- package/json/tokenizer/module.f.mjs +16 -20
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +1 -1
- package/nanvm-lib/Cargo.toml +6 -0
- package/nanvm-lib/src/extension.rs +119 -0
- package/nanvm-lib/src/interface.rs +136 -0
- package/nanvm-lib/src/lib.rs +7 -0
- package/nanvm-lib/src/naive.rs +229 -0
- package/nanvm-lib/src/nanenum.rs +230 -0
- package/nanvm-lib/src/nullish.rs +7 -0
- package/nanvm-lib/src/sign.rs +5 -0
- package/nanvm-lib/src/simple.rs +32 -0
- package/nanvm-lib/tests/test.f.d.mts +36 -0
- package/nanvm-lib/tests/test.f.mjs +79 -0
- package/nanvm-lib/tests/test.rs +108 -0
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.d.mts +4 -9
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/package.json +1 -1
- package/prime_field/module.f.d.mts +20 -23
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.d.mts +27 -28
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.d.mts +8 -16
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/README.md +2 -2
- package/text/ascii/module.f.d.mts +69 -72
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.d.mts +9 -14
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.d.mts +7 -9
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.d.mts +8 -15
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.d.mts +4 -9
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/types/array/module.f.d.mts +14 -24
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.d.mts +4 -9
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.d.mts +16 -64
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.d.mts +20 -26
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.d.mts +4 -8
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.d.mts +7 -12
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.d.mts +3 -7
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.d.mts +0 -2
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.d.mts +16 -29
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.d.mts +9 -15
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.d.mts +20 -27
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.d.mts +28 -43
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.d.mts +56 -91
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.d.mts +15 -24
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.d.mts +10 -20
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.d.mts +3 -8
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.d.mts +7 -13
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.d.mts +11 -18
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.d.mts +3 -8
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.d.mts +9 -15
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.d.mts +3 -3
- package/types/result/module.f.d.mts +6 -12
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.d.mts +22 -28
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.d.mts +6 -12
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.d.mts +8 -14
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.d.mts +8 -16
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/issues/lang/2351-property-accessor.md +0 -44
- package/issues/lang/2352-property-call.md +0 -43
- package/issues/lang/2353-property-at.md +0 -19
- package/issues/test-debug.md +0 -12
- /package/issues/{esm.md → 02-esm.md} +0 -0
- /package/issues/{djs.md → 03-djs.md} +0 -0
- /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
- /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export default _default;
|
|
1
|
+
/** @type {(tokenList: list.List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>} */
|
|
2
|
+
export const parse: (tokenList: list.List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>;
|
|
5
3
|
export type JsonObject = {
|
|
6
4
|
readonly kind: "object";
|
|
7
|
-
readonly values:
|
|
5
|
+
readonly values: map.Map<Json.Unknown>;
|
|
8
6
|
readonly key: string;
|
|
9
7
|
};
|
|
10
8
|
export type JsonArray = {
|
|
11
9
|
readonly kind: "array";
|
|
12
|
-
readonly values:
|
|
10
|
+
readonly values: list.List<Json.Unknown>;
|
|
13
11
|
};
|
|
14
12
|
export type JsonStackElement = JsonObject | JsonArray;
|
|
15
|
-
export type JsonStack =
|
|
13
|
+
export type JsonStack = list.List<JsonStackElement>;
|
|
16
14
|
export type StateParse = {
|
|
17
15
|
readonly status: "" | "[" | "[v" | "[," | "{" | "{k" | "{:" | "{v" | "{,";
|
|
18
16
|
readonly top: JsonStackElement | null;
|
|
@@ -27,10 +25,8 @@ export type StateError = {
|
|
|
27
25
|
readonly message: string;
|
|
28
26
|
};
|
|
29
27
|
export type JsonState = StateParse | StateResult | StateError;
|
|
30
|
-
|
|
31
|
-
declare const parse: (tokenList: List.List<Tokenizer.JsonToken>) => Result.Result<Json.Unknown, string>;
|
|
32
|
-
import * as Map from '../../types/map/module.f.mjs';
|
|
33
|
-
import * as Json from '../module.f.mjs';
|
|
34
|
-
import * as List from '../../types/list/module.f.mjs';
|
|
28
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
35
29
|
import * as Tokenizer from '../tokenizer/module.f.mjs';
|
|
36
|
-
import * as
|
|
30
|
+
import * as result from '../../types/result/module.f.mjs';
|
|
31
|
+
import * as Json from '../module.f.mjs';
|
|
32
|
+
import * as map from '../../types/map/module.f.mjs';
|
package/json/parser/module.f.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as result from '../../types/result/module.f.mjs'
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { fold, first, drop, toArray } = list
|
|
5
5
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
6
6
|
import * as Tokenizer from '../tokenizer/module.f.mjs'
|
|
7
|
-
import
|
|
7
|
+
import * as map from '../../types/map/module.f.mjs'
|
|
8
8
|
const { setReplace } = map
|
|
9
9
|
import * as Json from '../module.f.mjs'
|
|
10
|
-
import o from '../../types/object/module.f.mjs'
|
|
10
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
11
11
|
const { fromMap } = o
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {{
|
|
16
16
|
* readonly kind: 'object'
|
|
17
|
-
* readonly values:
|
|
17
|
+
* readonly values: map.Map<Json.Unknown>
|
|
18
18
|
* readonly key: string
|
|
19
19
|
* }} JsonObject
|
|
20
20
|
* */
|
|
@@ -22,7 +22,7 @@ const { fromMap } = o
|
|
|
22
22
|
/**
|
|
23
23
|
* @typedef {{
|
|
24
24
|
* readonly kind: 'array'
|
|
25
|
-
* readonly values:
|
|
25
|
+
* readonly values: list.List<Json.Unknown>
|
|
26
26
|
* }} JsonArray
|
|
27
27
|
* */
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ const { fromMap } = o
|
|
|
33
33
|
* } JsonStackElement
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
-
/** @typedef {
|
|
36
|
+
/** @typedef {list.List<JsonStackElement>} JsonStack */
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @typedef {{
|
|
@@ -206,8 +206,8 @@ const foldOp = token => state => {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
/** @type {(tokenList:
|
|
210
|
-
const parse = tokenList => {
|
|
209
|
+
/** @type {(tokenList: list.List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>} */
|
|
210
|
+
export const parse = tokenList => {
|
|
211
211
|
const state = fold(foldOp)({ status: '', top: null, stack: null })(tokenList)
|
|
212
212
|
switch (state.status) {
|
|
213
213
|
case 'result': return result.ok(state.value)
|
|
@@ -215,8 +215,3 @@ const parse = tokenList => {
|
|
|
215
215
|
default: return result.error('unexpected end')
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
export default {
|
|
220
|
-
/** @readonly */
|
|
221
|
-
parse
|
|
222
|
-
}
|
package/json/parser/test.f.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import parser from './module.f.mjs'
|
|
2
|
-
import
|
|
3
|
-
import list from '../../types/list/module.f.mjs'
|
|
1
|
+
import * as parser from './module.f.mjs'
|
|
2
|
+
import * as tokenizer from '../tokenizer/module.f.mjs'
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { toArray } = list
|
|
5
|
-
import json from '../module.f.mjs'
|
|
6
|
-
import o from '../../types/object/module.f.mjs'
|
|
5
|
+
import * as json from '../module.f.mjs'
|
|
6
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
7
7
|
const { sort } = o
|
|
8
|
-
import encoding from '../../text/utf16/module.f.mjs'
|
|
8
|
+
import * as encoding from '../../text/utf16/module.f.mjs'
|
|
9
9
|
|
|
10
|
-
/** @type {(s: string) => readonly
|
|
10
|
+
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
11
11
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
|
|
12
12
|
|
|
13
13
|
const stringify = json.stringify(sort)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
1
|
+
/** @type {(_: string) => list.List<string>} */
|
|
2
|
+
export const stringSerialize: (_: string) => list.List<string>;
|
|
3
|
+
/** @type {(_: number) => list.List<string>} */
|
|
4
|
+
export const numberSerialize: (_: number) => list.List<string>;
|
|
5
|
+
export const nullSerialize: string[];
|
|
6
|
+
/** @type {(_: boolean) => list.List<string>} */
|
|
7
|
+
export const boolSerialize: (_: boolean) => list.List<string>;
|
|
8
|
+
export const objectWrap: (input: list.List<list.List<string>>) => list.List<string>;
|
|
9
|
+
export const arrayWrap: (input: list.List<list.List<string>>) => list.List<string>;
|
|
10
10
|
/**
|
|
11
11
|
* <T>
|
|
12
12
|
*/
|
|
@@ -27,19 +27,10 @@ export type Entry<T> = O.Entry<Unknown<T>>;
|
|
|
27
27
|
/**
|
|
28
28
|
* <T>
|
|
29
29
|
*/
|
|
30
|
-
export type Entries<T> = (
|
|
30
|
+
export type Entries<T> = (list.List<Entry<T>>);
|
|
31
31
|
/**
|
|
32
32
|
* <T>
|
|
33
33
|
*/
|
|
34
34
|
export type MapEntries<T> = (entries: Entries<T>) => Entries<T>;
|
|
35
|
-
|
|
36
|
-
declare const arrayWrap: (input: List.List<List.List<string>>) => List.List<string>;
|
|
37
|
-
/** @type {(_: string) => List.List<string>} */
|
|
38
|
-
declare const stringSerialize: (_: string) => List.List<string>;
|
|
39
|
-
/** @type {(_: number) => List.List<string>} */
|
|
40
|
-
declare const numberSerialize: (_: number) => List.List<string>;
|
|
41
|
-
declare const nullSerialize: string[];
|
|
42
|
-
/** @type {(_: boolean) => List.List<string>} */
|
|
43
|
-
declare const boolSerialize: (_: boolean) => List.List<string>;
|
|
35
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
44
36
|
import * as O from '../../types/object/module.f.mjs';
|
|
45
|
-
import * as List from '../../types/list/module.f.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
2
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
3
3
|
const { flat, reduce, empty } = list
|
|
4
4
|
import * as O from '../../types/object/module.f.mjs'
|
|
5
5
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
@@ -37,39 +37,39 @@ import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
|
37
37
|
|
|
38
38
|
const jsonStringify = JSON.stringify
|
|
39
39
|
|
|
40
|
-
/** @type {(_: string) =>
|
|
41
|
-
const stringSerialize = input => [jsonStringify(input)]
|
|
40
|
+
/** @type {(_: string) => list.List<string>} */
|
|
41
|
+
export const stringSerialize = input => [jsonStringify(input)]
|
|
42
42
|
|
|
43
|
-
/** @type {(_: number) =>
|
|
44
|
-
const numberSerialize = input => [jsonStringify(input)]
|
|
43
|
+
/** @type {(_: number) => list.List<string>} */
|
|
44
|
+
export const numberSerialize = input => [jsonStringify(input)]
|
|
45
45
|
|
|
46
|
-
const nullSerialize = ['null']
|
|
46
|
+
export const nullSerialize = ['null']
|
|
47
47
|
|
|
48
48
|
const trueSerialize = ['true']
|
|
49
49
|
|
|
50
50
|
const falseSerialize = ['false']
|
|
51
51
|
|
|
52
|
-
/** @type {(_: boolean) =>
|
|
53
|
-
const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
52
|
+
/** @type {(_: boolean) => list.List<string>} */
|
|
53
|
+
export const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
54
54
|
|
|
55
55
|
const comma = [',']
|
|
56
56
|
|
|
57
|
-
/** @type {Operator.Reduce<
|
|
57
|
+
/** @type {Operator.Reduce<list.List<string>>} */
|
|
58
58
|
const joinOp = b => prior => flat([prior, comma, b])
|
|
59
59
|
|
|
60
|
-
/** @type {(input:
|
|
60
|
+
/** @type {(input: list.List<list.List<string>>) => list.List<string>} */
|
|
61
61
|
const join = reduce(joinOp)(empty)
|
|
62
62
|
|
|
63
|
-
/** @type {(open: string) => (close: string) => (input:
|
|
63
|
+
/** @type {(open: string) => (close: string) => (input: list.List<list.List<string>>) => list.List<string>} */
|
|
64
64
|
const wrap = open => close => {
|
|
65
65
|
const seqOpen = [open]
|
|
66
66
|
const seqClose = [close]
|
|
67
67
|
return input => flat([seqOpen, join(input), seqClose])
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const objectWrap = wrap('{')('}')
|
|
70
|
+
export const objectWrap = wrap('{')('}')
|
|
71
71
|
|
|
72
|
-
const arrayWrap = wrap('[')(']')
|
|
72
|
+
export const arrayWrap = wrap('[')(']')
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* @template T
|
|
@@ -78,25 +78,10 @@ const arrayWrap = wrap('[')(']')
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @template T
|
|
81
|
-
* @typedef {(
|
|
81
|
+
* @typedef {(list.List<Entry<T>>)} Entries<T>
|
|
82
82
|
*/
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* @template T
|
|
86
86
|
* @typedef {(entries: Entries<T>) => Entries<T>} MapEntries<T>
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
export default {
|
|
90
|
-
/** @readonly */
|
|
91
|
-
objectWrap,
|
|
92
|
-
/** @readonly */
|
|
93
|
-
arrayWrap,
|
|
94
|
-
/** @readonly */
|
|
95
|
-
stringSerialize,
|
|
96
|
-
/** @readonly */
|
|
97
|
-
numberSerialize,
|
|
98
|
-
/** @readonly */
|
|
99
|
-
nullSerialize,
|
|
100
|
-
/** @readonly */
|
|
101
|
-
boolSerialize,
|
|
102
|
-
}
|
package/json/test.f.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import json from './module.f.mjs'
|
|
2
|
-
import o from '../types/object/module.f.mjs'
|
|
1
|
+
import * as json from './module.f.mjs'
|
|
2
|
+
import * as o from '../types/object/module.f.mjs'
|
|
3
3
|
const { sort } = o
|
|
4
|
-
import f from '../types/function/module.f.mjs'
|
|
4
|
+
import * as f from '../types/function/module.f.mjs'
|
|
5
5
|
const { identity } = f
|
|
6
6
|
|
|
7
7
|
export default {
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export default _default;
|
|
1
|
+
/** @type {(input: list.List<number>) => list.List<JsonToken>} */
|
|
2
|
+
export const tokenize: (input: list.List<number>) => list.List<JsonToken>;
|
|
5
3
|
export type JsonToken = {
|
|
6
4
|
readonly kind: "true" | "false" | "null";
|
|
7
5
|
} | {
|
|
8
6
|
readonly kind: "{" | "}" | ":" | "," | "[" | "]";
|
|
9
|
-
} |
|
|
7
|
+
} | jsTokenizer.StringToken | jsTokenizer.NumberToken | jsTokenizer.ErrorToken;
|
|
10
8
|
export type ScanState = {
|
|
11
9
|
readonly kind: "def" | "-";
|
|
12
10
|
};
|
|
13
|
-
export type ScanInput =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import * as JsTokenizer from '../../js/tokenizer/module.f.mjs';
|
|
17
|
-
import * as List from '../../types/list/module.f.mjs';
|
|
11
|
+
export type ScanInput = jsTokenizer.JsToken | null;
|
|
12
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
13
|
+
import * as jsTokenizer from '../../js/tokenizer/module.f.mjs';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
3
|
-
import
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { empty, flat, stateScan } = list
|
|
5
|
-
import bf from '../../types/bigfloat/module.f.mjs'
|
|
5
|
+
import * as bf from '../../types/bigfloat/module.f.mjs'
|
|
6
6
|
const { multiply } = bf
|
|
7
|
-
import
|
|
7
|
+
import * as jsTokenizer from '../../js/tokenizer/module.f.mjs'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {|
|
|
11
11
|
* {readonly kind: 'true' | 'false' | 'null' } |
|
|
12
12
|
* {readonly kind: '{' | '}' | ':' | ',' | '[' | ']' } |
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* jsTokenizer.StringToken |
|
|
14
|
+
* jsTokenizer.NumberToken |
|
|
15
|
+
* jsTokenizer.ErrorToken
|
|
16
16
|
* } JsonToken
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -24,11 +24,11 @@ import jsTokenizer, * as JsTokenizer from '../../js/tokenizer/module.f.mjs'
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {|
|
|
27
|
-
*
|
|
27
|
+
* jsTokenizer.JsToken | null
|
|
28
28
|
* } ScanInput
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
/** @type {(input:
|
|
31
|
+
/** @type {(input: jsTokenizer.JsToken) => list.List<JsonToken>} */
|
|
32
32
|
const mapToken = input =>
|
|
33
33
|
{
|
|
34
34
|
switch(input.kind)
|
|
@@ -45,12 +45,13 @@ const mapToken = input =>
|
|
|
45
45
|
case 'string':
|
|
46
46
|
case 'number':
|
|
47
47
|
case 'error': return [input]
|
|
48
|
-
case 'ws':
|
|
48
|
+
case 'ws':
|
|
49
|
+
case 'nl': return empty
|
|
49
50
|
default: return [{ kind: 'error', message: 'invalid token' }]
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/** @type {(input: ScanInput) => readonly [
|
|
54
|
+
/** @type {(input: ScanInput) => readonly [list.List<JsonToken>, ScanState]} */
|
|
54
55
|
const parseDefaultState = input =>
|
|
55
56
|
{
|
|
56
57
|
if (input === null) return [empty, { kind: 'def'}]
|
|
@@ -61,7 +62,7 @@ const parseDefaultState = input =>
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
/** @type {(input: ScanInput) => readonly [
|
|
65
|
+
/** @type {(input: ScanInput) => readonly [list.List<JsonToken>, ScanState]} */
|
|
65
66
|
const parseMinusState = input =>
|
|
66
67
|
{
|
|
67
68
|
if (input === null) return [[{ kind: 'error', message: 'invalid token' }], { kind: 'def'}]
|
|
@@ -73,7 +74,7 @@ const parseMinusState = input =>
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
/** @type {Operator.StateScan<ScanInput, ScanState,
|
|
77
|
+
/** @type {Operator.StateScan<ScanInput, ScanState, list.List<JsonToken>>} */
|
|
77
78
|
const scanToken = state => input => {
|
|
78
79
|
switch(state.kind)
|
|
79
80
|
{
|
|
@@ -82,15 +83,10 @@ const scanToken = state => input => {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
/** @type {(input:
|
|
86
|
-
const tokenize = input =>
|
|
86
|
+
/** @type {(input: list.List<number>) => list.List<JsonToken>} */
|
|
87
|
+
export const tokenize = input =>
|
|
87
88
|
{
|
|
88
|
-
/** @type {
|
|
89
|
+
/** @type {list.List<ScanInput>} */
|
|
89
90
|
const jsTokens = jsTokenizer.tokenize(input)
|
|
90
91
|
return flat(stateScan(scanToken)({ kind: 'def' })(list.concat(jsTokens)([null])))
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
export default {
|
|
94
|
-
/** @readonly */
|
|
95
|
-
tokenize
|
|
96
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import list from '../../types/list/module.f.mjs'
|
|
1
|
+
import * as tokenizer from './module.f.mjs'
|
|
2
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
3
3
|
const { toArray } = list
|
|
4
|
-
import djs from '../../djs/module.f.mjs'
|
|
5
|
-
import o from '../../types/object/module.f.mjs'
|
|
4
|
+
import * as djs from '../../djs/module.f.mjs'
|
|
5
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
6
6
|
const { sort } = o
|
|
7
|
-
import encoding from '../../text/utf16/module.f.mjs'
|
|
7
|
+
import * as encoding from '../../text/utf16/module.f.mjs'
|
|
8
8
|
|
|
9
|
-
/** @type {(s: string) => readonly
|
|
9
|
+
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
10
10
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
|
|
11
11
|
|
|
12
12
|
const stringify = djs.stringify(sort)
|
package/jsr.json
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
use crate::{interface::{Any, Container, Extension, Unpacked}, nullish::Nullish::*, simple::Simple};
|
|
2
|
+
|
|
3
|
+
pub trait AnyExtension: Any {
|
|
4
|
+
fn string(c: &str) -> Self::String16 {
|
|
5
|
+
c.encode_utf16().into_iter().to_complex()
|
|
6
|
+
}
|
|
7
|
+
fn to_string(self) -> Self::String16 {
|
|
8
|
+
match self.unpack() {
|
|
9
|
+
Unpacked::Nullish(v) => Self::string(match v {
|
|
10
|
+
Null => "null",
|
|
11
|
+
Undefined => "undefined",
|
|
12
|
+
}),
|
|
13
|
+
Unpacked::Bool(v) => Self::string(match v {
|
|
14
|
+
true => "true",
|
|
15
|
+
false => "false",
|
|
16
|
+
}),
|
|
17
|
+
Unpacked::Number(_) => todo!(),
|
|
18
|
+
Unpacked::String16(v) => v,
|
|
19
|
+
Unpacked::BigInt(_) => todo!(),
|
|
20
|
+
Unpacked::Array(_) => [].to_complex(),
|
|
21
|
+
Unpacked::Object(_) => Self::string("[object Object"),
|
|
22
|
+
Unpacked::Function(_) => todo!(),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
fn own_property(self, i: Self) -> Self {
|
|
26
|
+
match self.unpack() {
|
|
27
|
+
Unpacked::Nullish(_) => panic!("own_property(\"nullish\")"),
|
|
28
|
+
Unpacked::Bool(_) => Simple::Nullish(Undefined).to_unknown(),
|
|
29
|
+
Unpacked::Number(_) => todo!(),
|
|
30
|
+
Unpacked::String16(_) => todo!(),
|
|
31
|
+
Unpacked::BigInt(_) => todo!(),
|
|
32
|
+
Unpacked::Array(_) => match i.unpack() {
|
|
33
|
+
Unpacked::Nullish(_) => todo!(),
|
|
34
|
+
Unpacked::Bool(_) => todo!(),
|
|
35
|
+
Unpacked::Number(_) => todo!(),
|
|
36
|
+
Unpacked::String16(_) => todo!(),
|
|
37
|
+
Unpacked::BigInt(_) => todo!(),
|
|
38
|
+
Unpacked::Array(_) => todo!(),
|
|
39
|
+
Unpacked::Object(_) => todo!(),
|
|
40
|
+
Unpacked::Function(_) => todo!(),
|
|
41
|
+
},
|
|
42
|
+
Unpacked::Object(_) => todo!(),
|
|
43
|
+
Unpacked::Function(_) => todo!(),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl<T: Any> AnyExtension for T {}
|
|
49
|
+
|
|
50
|
+
#[cfg(test)]
|
|
51
|
+
mod test {
|
|
52
|
+
mod to_string {
|
|
53
|
+
use crate::{
|
|
54
|
+
extension::AnyExtension, interface::{Complex, Extension}, naive::{Any, Array, Object}, nullish::Nullish::*, simple::Simple
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
fn test_string() {
|
|
59
|
+
let s = Any::string("Hello world!");
|
|
60
|
+
let xs: Any = s.clone().to_unknown();
|
|
61
|
+
let sxs = xs.to_string();
|
|
62
|
+
assert_eq!(s, sxs);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[test]
|
|
66
|
+
fn test_nullish() {
|
|
67
|
+
{
|
|
68
|
+
let x: Any = Simple::Nullish(Null).to_unknown();
|
|
69
|
+
assert_eq!(Any::string("null"), x.to_string());
|
|
70
|
+
}
|
|
71
|
+
{
|
|
72
|
+
let x: Any = Simple::Nullish(Undefined).to_unknown();
|
|
73
|
+
assert_eq!(Any::string("undefined"), x.to_string());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#[test]
|
|
78
|
+
fn test_boolean() {
|
|
79
|
+
{
|
|
80
|
+
let x: Any = Simple::Boolean(true).to_unknown();
|
|
81
|
+
assert_eq!(Any::string("true"), x.to_string());
|
|
82
|
+
}
|
|
83
|
+
{
|
|
84
|
+
let x: Any = Simple::Boolean(false).to_unknown();
|
|
85
|
+
assert_eq!(Any::string("false"), x.to_string());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[test]
|
|
90
|
+
fn test_object() {
|
|
91
|
+
let x: Any = [].to_object_unknown();
|
|
92
|
+
assert_eq!(Any::string("[object Object"), x.to_string());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[test]
|
|
96
|
+
fn test_array() {
|
|
97
|
+
let x: Any = [].to_array_unknown();
|
|
98
|
+
assert_eq!(Any::string(""), x.to_string());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
mod own_property {
|
|
103
|
+
use crate::{extension::AnyExtension, interface::Complex, naive::Any, nullish::Nullish::*, simple::Simple};
|
|
104
|
+
|
|
105
|
+
#[test]
|
|
106
|
+
#[should_panic]
|
|
107
|
+
fn test_own_property_null() {
|
|
108
|
+
let x: Any = Simple::Nullish(Null).to_unknown();
|
|
109
|
+
x.own_property(Any::string("hello").to_unknown());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#[test]
|
|
113
|
+
fn test_own_property_bool() {
|
|
114
|
+
let x: Any = Simple::Boolean(true).to_unknown();
|
|
115
|
+
let undefined: Any = Simple::Nullish(Undefined).to_unknown();
|
|
116
|
+
assert_eq!(undefined, x.own_property(Any::string("hello").to_unknown()));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|