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
package/doc/LANGUAGE.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# FunctionalScript Programming Language
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Principles:
|
|
4
|
+
|
|
5
|
+
- FunctionalScript VM should behaves the same way as a JavaScript VM,
|
|
5
6
|
- Any unsupported feature should be reported at compile-time.
|
|
6
7
|
|
|
7
8
|
## 1. Module Ecosystem
|
|
8
9
|
|
|
9
|
-
FunctionalScript uses
|
|
10
|
+
FunctionalScript uses ESM conventions as a module ecosystem. For example,
|
|
10
11
|
|
|
11
12
|
```js
|
|
12
|
-
|
|
13
|
+
import thirdPartyModule from 'third-party-package/module'
|
|
13
14
|
|
|
14
15
|
const result = thirdPartyModule.someFunction('hello')
|
|
15
16
|
```
|
|
@@ -39,10 +40,10 @@ npm install -S github:functionalscript/functionalscript
|
|
|
39
40
|
|
|
40
41
|
A module is a file with the `.js` extension. It contains three parts: references to other modules, definitions, and exports. For example
|
|
41
42
|
|
|
42
|
-
`./first.
|
|
43
|
+
`./first.f.mjs`
|
|
43
44
|
```js
|
|
44
45
|
// 1. references
|
|
45
|
-
|
|
46
|
+
import math from 'math'
|
|
46
47
|
|
|
47
48
|
// 2. definitions
|
|
48
49
|
const myConst = 42
|
|
@@ -52,35 +53,35 @@ const add42 = addition(42)
|
|
|
52
53
|
const _10digitsOfPi = math.calculatePi(10)
|
|
53
54
|
|
|
54
55
|
// 3. exports
|
|
55
|
-
|
|
56
|
+
export default {
|
|
56
57
|
addition,
|
|
57
58
|
add42,
|
|
58
59
|
_10digitsOfPi,
|
|
59
60
|
}
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
`./second.
|
|
63
|
+
`./second.f.mjs`
|
|
63
64
|
```js
|
|
64
65
|
// 1. references
|
|
65
|
-
|
|
66
|
+
import first from './first.f.mjs'
|
|
66
67
|
|
|
67
68
|
// 2. definitions
|
|
68
69
|
const _42plus7 = first.add42(7)
|
|
69
70
|
|
|
70
71
|
// 3. exports
|
|
71
|
-
|
|
72
|
+
export default {
|
|
72
73
|
_42plus7,
|
|
73
74
|
}
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
## 4. References To Other Modules
|
|
77
78
|
|
|
78
|
-
The format of references is `
|
|
79
|
+
The format of references is `import ANYNAME from 'PATH_TO_A_MODULE'`. For example,
|
|
79
80
|
|
|
80
81
|
```js
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
import math from 'math'
|
|
83
|
+
import algebra from 'math/algebra'
|
|
84
|
+
import localFile from '../some-directory/some-file.f.mjs'
|
|
84
85
|
```
|
|
85
86
|
|
|
86
87
|
## 5. Definitions
|
|
@@ -107,11 +108,11 @@ See [Expressions](#7-Expressions).
|
|
|
107
108
|
|
|
108
109
|
### 6. Exports
|
|
109
110
|
|
|
110
|
-
The format of exports is `
|
|
111
|
+
The format of exports is `export default { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `export default` at
|
|
111
112
|
the end of a FunctionalScript file. For example,
|
|
112
113
|
|
|
113
114
|
```js
|
|
114
|
-
|
|
115
|
+
export default {
|
|
115
116
|
nestedStructure,
|
|
116
117
|
array,
|
|
117
118
|
structure,
|
package/doc/README.md
CHANGED
|
@@ -1,76 +1,40 @@
|
|
|
1
1
|
# Documentation
|
|
2
2
|
|
|
3
|
-
FunctionalScript files have `.f.
|
|
4
|
-
ESM support when we have the first parser working. See
|
|
5
|
-
[ESM. Resolver Algorithm Specification](https://nodejs.org/api/esm.html#resolver-algorithm-specification)
|
|
6
|
-
and [ESM. Enabling](https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_enabling).
|
|
3
|
+
FunctionalScript files have `.f.mjs` file extensions because it's using the ES module system.
|
|
7
4
|
|
|
8
|
-
## 1.
|
|
5
|
+
## 1. Language
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## 1.1. Creating From Scratch
|
|
13
|
-
|
|
14
|
-
Prerequisites:
|
|
15
|
-
|
|
16
|
-
- [Git](https://git-scm.com/).
|
|
17
|
-
- [Node.js](https://nodejs.org/en/).
|
|
18
|
-
- GitHub account.
|
|
19
|
-
|
|
20
|
-
Creating a new GitHub repository
|
|
21
|
-
|
|
22
|
-
1. Create a public git repository on GitHub using Node template.
|
|
23
|
-
2. Clone the repository.
|
|
24
|
-
3. Go to the root directory of the cloned repository.
|
|
25
|
-
4. Run `npm init`. It should create `package.json` file.
|
|
26
|
-
5. Create a `main.f.cjs` file in the repository root directory.
|
|
27
|
-
6. Edit the `main.f.cjs` file. For example
|
|
28
|
-
```js
|
|
29
|
-
module.exports = "Hello world!"
|
|
30
|
-
```
|
|
31
|
-
11. Go to [functionalscript.com](https://functionalscript.com) and enter `github:YOUR_GITHUB_NAME/YOUR_REPOSITORY_NAME`. Press `Build`.
|
|
32
|
-
|
|
33
|
-
### 1.1. Optional
|
|
34
|
-
|
|
35
|
-
1. Install [Visual Studio Code](https://code.visualstudio.com/).
|
|
36
|
-
2. Add [TypeScript](https://www.typescriptlang.org/) to your repository for static type checking.
|
|
37
|
-
1. Run `npm install -D typescript`.
|
|
38
|
-
2. Run `npx tsc --init`. It should create `tsconfig.json` file.
|
|
39
|
-
3. Uncomment `"allowJs": true,` and `"checkJs": true` in the `tsconfig.json` file.
|
|
40
|
-
|
|
41
|
-
## 2. Language
|
|
42
|
-
|
|
43
|
-
### 2.1. Exports
|
|
7
|
+
### 1.1. Exports
|
|
44
8
|
|
|
45
9
|
```js
|
|
46
|
-
|
|
10
|
+
export default 'Hello world!'
|
|
47
11
|
```
|
|
48
12
|
|
|
49
13
|
```js
|
|
50
|
-
|
|
14
|
+
export default { a: 'hello', b: 42 }
|
|
51
15
|
```
|
|
52
16
|
|
|
53
17
|
```js
|
|
54
|
-
|
|
18
|
+
export default x => x * x
|
|
55
19
|
```
|
|
56
20
|
|
|
57
|
-
###
|
|
21
|
+
### 1.2. Reference Another Module
|
|
58
22
|
|
|
59
|
-
####
|
|
23
|
+
#### 1.2.1. Local File
|
|
60
24
|
|
|
61
25
|
```js
|
|
62
|
-
|
|
26
|
+
import x from './folder/main.f.mjs'
|
|
63
27
|
```
|
|
64
28
|
|
|
65
|
-
###
|
|
29
|
+
### 1.2.2. External Module
|
|
66
30
|
|
|
67
31
|
Run `npm install -D github:USER/REPO`
|
|
68
32
|
|
|
69
33
|
```js
|
|
70
|
-
|
|
34
|
+
import x from `REPO/DIR/FILE.f.mjs`
|
|
71
35
|
```
|
|
72
36
|
|
|
73
|
-
###
|
|
37
|
+
### 1.3. Functions
|
|
74
38
|
|
|
75
39
|
```js
|
|
76
40
|
const f = x => x * x
|
|
@@ -83,9 +47,9 @@ const sum = ar => ar.reduce((a, i) => a + i, 0)
|
|
|
83
47
|
const sumResult = sum([1, 2, 3])
|
|
84
48
|
```
|
|
85
49
|
|
|
86
|
-
##
|
|
50
|
+
## 2. Advanced
|
|
87
51
|
|
|
88
|
-
###
|
|
52
|
+
### 2.1. Generators
|
|
89
53
|
|
|
90
54
|
```js
|
|
91
55
|
const range5 = {*[System.iterator]() {
|
package/fsc/README.md
CHANGED
|
@@ -76,7 +76,6 @@
|
|
|
76
76
|
- `do` ?
|
|
77
77
|
- `else`
|
|
78
78
|
- `export`
|
|
79
|
-
- `exports` <= non-standard
|
|
80
79
|
- `false`
|
|
81
80
|
- `function` ?
|
|
82
81
|
- `globalThis` ?
|
|
@@ -86,11 +85,9 @@
|
|
|
86
85
|
- `in`
|
|
87
86
|
- `instanceof`
|
|
88
87
|
- `let`
|
|
89
|
-
- `module` <= non-standard
|
|
90
88
|
- `new` ?
|
|
91
89
|
- `null`
|
|
92
90
|
- `of`
|
|
93
|
-
- `require` <= non-standard
|
|
94
91
|
- `return`
|
|
95
92
|
- `super`
|
|
96
93
|
- `switch`
|
package/fsc/module.f.d.mts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { init };
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
1
|
+
export const terminal: -1;
|
|
2
|
+
export const init: ToResult;
|
|
6
3
|
export type Result = readonly [readonly string[], ToResult];
|
|
7
4
|
export type ToResult = (codePoint: number) => Result;
|
|
8
5
|
export type CreateToResult<T> = (state: T) => ToResult;
|
|
9
|
-
export type State<T> =
|
|
10
|
-
|
|
11
|
-
declare const init: ToResult;
|
|
12
|
-
import * as RM from '../types/range_map/module.f.mjs';
|
|
6
|
+
export type State<T> = rangeMap.RangeMapArray<CreateToResult<T>>;
|
|
7
|
+
import * as rangeMap from '../types/range_map/module.f.mjs';
|
package/fsc/module.f.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import operator from '../types/function/operator/module.f.mjs'
|
|
3
|
-
import
|
|
4
|
-
const { merge: rangeMapMerge, fromRange, get } =
|
|
5
|
-
import
|
|
2
|
+
import * as operator from '../types/function/operator/module.f.mjs'
|
|
3
|
+
import * as rangeMap from '../types/range_map/module.f.mjs'
|
|
4
|
+
const { merge: rangeMapMerge, fromRange, get } = rangeMap
|
|
5
|
+
import * as list from '../types/list/module.f.mjs'
|
|
6
6
|
const { reduce: listReduce } = list
|
|
7
|
-
import ascii from '../text/ascii/module.f.mjs'
|
|
7
|
+
import * as ascii from '../text/ascii/module.f.mjs'
|
|
8
8
|
const { range: asciiRange } = ascii
|
|
9
9
|
const { fromCharCode } = String
|
|
10
|
-
import f from '../types/function/module.f.mjs'
|
|
10
|
+
import * as f from '../types/function/module.f.mjs'
|
|
11
11
|
const { fn } = f
|
|
12
|
-
import
|
|
12
|
+
import * as _range from '../types/range/module.f.mjs'
|
|
13
13
|
const { one } = _range
|
|
14
14
|
const { toArray, map } = list
|
|
15
15
|
|
|
@@ -24,7 +24,7 @@ const { toArray, map } = list
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @template T
|
|
27
|
-
* @typedef {
|
|
27
|
+
* @typedef {rangeMap.RangeMapArray<CreateToResult<T>>} State
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
/** @type {ToResult} */
|
|
@@ -43,10 +43,10 @@ const union = a => b => {
|
|
|
43
43
|
/** @type {readonly never[]} */
|
|
44
44
|
const empty = []
|
|
45
45
|
|
|
46
|
-
/** @type {<T>(a:
|
|
46
|
+
/** @type {<T>(a: list.List<State<T>>) => State<T>} */
|
|
47
47
|
const reduce = a => {
|
|
48
|
-
/** @typedef {typeof a extends
|
|
49
|
-
/** @type {
|
|
48
|
+
/** @typedef {typeof a extends list.List<State<infer T>> ? T : never} T */
|
|
49
|
+
/** @type {rangeMap.RangeMerge<CreateToResult<T>>} */
|
|
50
50
|
const merge = rangeMapMerge({
|
|
51
51
|
union,
|
|
52
52
|
equal: operator.strictEqual,
|
|
@@ -61,28 +61,28 @@ const range = fn(asciiRange).then(codePointRange).result
|
|
|
61
61
|
/** @type {(l: readonly string[]) => <T>(f: CreateToResult<T>) => State<T>} */
|
|
62
62
|
const rangeSet = l => f => {
|
|
63
63
|
/** @typedef {typeof f extends CreateToResult<infer T> ? T : never} T */
|
|
64
|
-
/** @type {(a:
|
|
64
|
+
/** @type {(a: _range.Range) => (f: CreateToResult<T>) => State<T>} */
|
|
65
65
|
const codePointRange = fromRange(def)
|
|
66
66
|
/** @type {(r: string) => State<T>} */
|
|
67
67
|
const g = r => codePointRange(asciiRange(r))(f)
|
|
68
68
|
return reduce(map(g)(l))
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/** @type {<T>(a:
|
|
71
|
+
/** @type {<T>(a: list.List<State<T>>) => CreateToResult<T>} */
|
|
72
72
|
const create = a => {
|
|
73
|
-
/** @typedef {typeof a extends
|
|
73
|
+
/** @typedef {typeof a extends list.List<State<infer T>> ? T : never} T */
|
|
74
74
|
const i = reduce(a)
|
|
75
75
|
/** @type {(v: number) => (i: State<T>) => (v: T) => ToResult} */
|
|
76
76
|
const x = get(def)
|
|
77
77
|
return v => c => x(c)(i)(v)(c)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const terminal = -1
|
|
80
|
+
export const terminal = -1
|
|
81
81
|
|
|
82
82
|
/** @type {() => ToResult} */
|
|
83
83
|
const toInit = () => () => [[], init]
|
|
84
84
|
|
|
85
|
-
const init = create([
|
|
85
|
+
export const init = create([
|
|
86
86
|
codePointRange(one(terminal))(toInit),
|
|
87
87
|
rangeSet(['\t', ' ', '\n', '\r'])(toInit),
|
|
88
88
|
range('!')(() => () => [['!'], unexpectedSymbol]),
|
|
@@ -114,11 +114,4 @@ const init = create([
|
|
|
114
114
|
range('|')(() => () => [['|'], unexpectedSymbol]),
|
|
115
115
|
range('}')(() => () => [['}'], unexpectedSymbol]),
|
|
116
116
|
range('~')(() => () => [['~'], unexpectedSymbol]),
|
|
117
|
-
])(
|
|
118
|
-
|
|
119
|
-
export default {
|
|
120
|
-
/** @readonly */
|
|
121
|
-
terminal,
|
|
122
|
-
/** @readonly */
|
|
123
|
-
init,
|
|
124
|
-
}
|
|
117
|
+
])(undefined)
|
package/fsc/test.f.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _ from './module.f.mjs'
|
|
2
|
-
import ascii from '../text/ascii/module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
|
+
import * as ascii from '../text/ascii/module.f.mjs'
|
|
3
3
|
const { one } = ascii
|
|
4
|
-
import j from '../json/module.f.mjs'
|
|
4
|
+
import * as j from '../json/module.f.mjs'
|
|
5
5
|
const { stringify } = j
|
|
6
6
|
const s = stringify(i => i)
|
|
7
7
|
|
package/fsm/README.md
CHANGED
|
@@ -107,7 +107,7 @@ const b = { ...a, z: 7 }
|
|
|
107
107
|
## How to Add a Property # 2
|
|
108
108
|
|
|
109
109
|
```js
|
|
110
|
-
|
|
110
|
+
import map from './types/map/module.f.mjs'
|
|
111
111
|
const a = map.fromEntries(Object.entries({ x: 5, y: 6 }))
|
|
112
112
|
const b = map.setReplace('z')(7)(a)
|
|
113
113
|
```
|
package/fsm/module.f.d.mts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { toUnion };
|
|
6
|
-
}
|
|
7
|
-
export default _default;
|
|
8
|
-
export type Rule = readonly [string, byteSetT.ByteSet, string];
|
|
9
|
-
export type Grammar = List.List<Rule>;
|
|
10
|
-
export type Dfa = { readonly [state in string]: RM.RangeMapArray<string>; };
|
|
1
|
+
/** @type {(s: string) => byteSet.ByteSet} */
|
|
2
|
+
export const toRange: (s: string) => byteSet.ByteSet;
|
|
3
|
+
/** @type {(s: string) => byteSet.ByteSet} */
|
|
4
|
+
export const toUnion: (s: string) => byteSet.ByteSet;
|
|
11
5
|
/** @type {(grammar: Grammar) => Dfa} */
|
|
12
|
-
|
|
13
|
-
/** @type {(dfa: Dfa) => (input:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import * as
|
|
20
|
-
import * as
|
|
21
|
-
import * as RM from '../types/range_map/module.f.mjs';
|
|
6
|
+
export const dfa: (grammar: Grammar) => Dfa;
|
|
7
|
+
/** @type {(dfa: Dfa) => (input: list.List<number>) => list.List<string>} */
|
|
8
|
+
export const run: (dfa: Dfa) => (input: list.List<number>) => list.List<string>;
|
|
9
|
+
export type Rule = readonly [string, byteSet.ByteSet, string];
|
|
10
|
+
export type Grammar = list.List<Rule>;
|
|
11
|
+
export type Dfa = { readonly [state in string]: rangeMap.RangeMapArray<string>; };
|
|
12
|
+
import * as byteSet from '../types/byte_set/module.f.mjs';
|
|
13
|
+
import * as list from '../types/list/module.f.mjs';
|
|
14
|
+
import * as rangeMap from '../types/range_map/module.f.mjs';
|
package/fsm/module.f.mjs
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
2
|
+
import * as list from '../types/list/module.f.mjs'
|
|
3
3
|
const { equal, isEmpty, fold, toArray, scan, foldScan, empty: emptyList } = list
|
|
4
|
-
import
|
|
4
|
+
import * as byteSet from '../types/byte_set/module.f.mjs'
|
|
5
5
|
const { toRangeMap, union: byteSetUnion, one, empty } = byteSet
|
|
6
|
-
import
|
|
6
|
+
import * as sortedSet from '../types/sorted_set/module.f.mjs'
|
|
7
7
|
const { intersect, union: sortedSetUnion } = sortedSet
|
|
8
|
-
import
|
|
8
|
+
import * as rangeMap from '../types/range_map/module.f.mjs'
|
|
9
9
|
const { merge } = rangeMap
|
|
10
|
-
import cmp from '../types/function/compare/module.f.mjs'
|
|
10
|
+
import * as cmp from '../types/function/compare/module.f.mjs'
|
|
11
11
|
const { unsafeCmp } = cmp
|
|
12
|
-
import
|
|
12
|
+
import * as operator from '../types/function/operator/module.f.mjs'
|
|
13
13
|
const { strictEqual } = operator
|
|
14
|
-
import j from '../json/module.f.mjs'
|
|
14
|
+
import * as j from '../json/module.f.mjs'
|
|
15
15
|
const { stringify } = j
|
|
16
|
-
import f from '../types/function/module.f.mjs'
|
|
16
|
+
import * as f from '../types/function/module.f.mjs'
|
|
17
17
|
const { identity } = f
|
|
18
|
-
import utf16 from '../text/utf16/module.f.mjs'
|
|
18
|
+
import * as utf16 from '../text/utf16/module.f.mjs'
|
|
19
19
|
const { stringToList } = utf16
|
|
20
20
|
|
|
21
|
-
/** @typedef {readonly[string,
|
|
21
|
+
/** @typedef {readonly[string, byteSet.ByteSet, string]} Rule */
|
|
22
22
|
|
|
23
|
-
/** @typedef {
|
|
23
|
+
/** @typedef {list.List<Rule>} Grammar */
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {{
|
|
27
|
-
* readonly[state in string]:
|
|
27
|
+
* readonly[state in string]: rangeMap.RangeMapArray<string>
|
|
28
28
|
* }} Dfa
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
const stringifyIdentity = stringify(identity)
|
|
32
32
|
|
|
33
|
-
/** @type {(s: string) =>
|
|
34
|
-
const toRange = s => {
|
|
33
|
+
/** @type {(s: string) => byteSet.ByteSet} */
|
|
34
|
+
export const toRange = s => {
|
|
35
35
|
const [b, e] = toArray(stringToList(s))
|
|
36
36
|
return byteSet.range([b, e])
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** @type {
|
|
39
|
+
/** @type {operator.Fold<number, byteSet.ByteSet>} */
|
|
40
40
|
const toUnionOp = i => bs => byteSetUnion(bs)(one(i))
|
|
41
41
|
|
|
42
|
-
/** @type {(s: string) =>
|
|
43
|
-
const toUnion = s => {
|
|
42
|
+
/** @type {(s: string) => byteSet.ByteSet} */
|
|
43
|
+
export const toUnion = s => {
|
|
44
44
|
const codePoints = stringToList(s)
|
|
45
45
|
return fold(toUnionOp)(empty)(codePoints)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** @type {
|
|
48
|
+
/** @type {rangeMap.Operators<sortedSet.SortedSet<string>>} */
|
|
49
49
|
const mergeOp = { union: sortedSetUnion(unsafeCmp), equal: equal(strictEqual) }
|
|
50
50
|
|
|
51
|
-
/** @type {(s: string) => (set:
|
|
51
|
+
/** @type {(s: string) => (set: sortedSet.SortedSet<string>) => boolean} */
|
|
52
52
|
const hasState = s => set => !isEmpty(intersect(unsafeCmp)([s])(set))
|
|
53
53
|
|
|
54
|
-
/** @type {(set:
|
|
54
|
+
/** @type {(set: sortedSet.SortedSet<string>) => operator.Fold<Rule, rangeMap.RangeMap<sortedSet.SortedSet<string>>>} */
|
|
55
55
|
const foldOp = set => ([ruleIn, bs, ruleOut]) => rm => {
|
|
56
56
|
if (hasState(ruleIn)(set)) { return merge(mergeOp)(rm)(toRangeMap(bs)(ruleOut)) }
|
|
57
57
|
return rm
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/** @type {
|
|
60
|
+
/** @type {operator.Scan<rangeMap.Entry<sortedSet.SortedSet<string>>, rangeMap.Entry<string>>} */
|
|
61
61
|
const stringifyOp = ([sortedSet, max]) => [[stringifyIdentity(sortedSet), max], stringifyOp]
|
|
62
62
|
|
|
63
63
|
const scanStringify = scan(stringifyOp)
|
|
64
64
|
|
|
65
|
-
/** @type {
|
|
65
|
+
/** @type {operator.Scan<rangeMap.Entry<sortedSet.SortedSet<string>>, sortedSet.SortedSet<string>>} */
|
|
66
66
|
const fetchOp = ([item, _]) => [item, fetchOp]
|
|
67
67
|
|
|
68
68
|
const scanFetch = scan(fetchOp)
|
|
69
69
|
|
|
70
|
-
/** @type {(grammar: Grammar) =>
|
|
70
|
+
/** @type {(grammar: Grammar) => operator.Fold<sortedSet.SortedSet<string>, Dfa>} */
|
|
71
71
|
const addEntry = grammar => set => dfa => {
|
|
72
72
|
const s = stringifyIdentity(set)
|
|
73
73
|
if (s in dfa) { return dfa }
|
|
@@ -88,23 +88,12 @@ const initialState = ['']
|
|
|
88
88
|
const initialStateStringify = stringifyIdentity(initialState)
|
|
89
89
|
|
|
90
90
|
/** @type {(grammar: Grammar) => Dfa} */
|
|
91
|
-
const dfa = grammar => addEntry(grammar)(initialState)({})
|
|
91
|
+
export const dfa = grammar => addEntry(grammar)(initialState)({})
|
|
92
92
|
|
|
93
93
|
const get = rangeMap.get(emptyStateStringify)
|
|
94
94
|
|
|
95
|
-
/** @type {(dfa: Dfa) =>
|
|
95
|
+
/** @type {(dfa: Dfa) => operator.Fold<number, string>} */
|
|
96
96
|
const runOp = dfa => input => s => get(input)(dfa[s])
|
|
97
97
|
|
|
98
|
-
/** @type {(dfa: Dfa) => (input:
|
|
99
|
-
const run = dfa => input => foldScan(runOp(dfa))(initialStateStringify)(input)
|
|
100
|
-
|
|
101
|
-
export default {
|
|
102
|
-
/** @readonly */
|
|
103
|
-
dfa,
|
|
104
|
-
/** @readonly */
|
|
105
|
-
run,
|
|
106
|
-
/** @readonly */
|
|
107
|
-
toRange,
|
|
108
|
-
/** @readonly */
|
|
109
|
-
toUnion
|
|
110
|
-
}
|
|
98
|
+
/** @type {(dfa: Dfa) => (input: list.List<number>) => list.List<string>} */
|
|
99
|
+
export const run = dfa => input => foldScan(runOp(dfa))(initialStateStringify)(input)
|
package/fsm/test.f.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import byteSet from '../types/byte_set/module.f.mjs'
|
|
3
|
-
import o from '../types/object/module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
|
+
import * as byteSet from '../types/byte_set/module.f.mjs'
|
|
3
|
+
import * as o from '../types/object/module.f.mjs'
|
|
4
4
|
const { sort, fromEntries } = o
|
|
5
|
-
import json from '../json/module.f.mjs'
|
|
6
|
-
import f from '../types/function/module.f.mjs'
|
|
5
|
+
import * as json from '../json/module.f.mjs'
|
|
6
|
+
import * as f from '../types/function/module.f.mjs'
|
|
7
7
|
const { identity } = f
|
|
8
|
-
import list from '../types/list/module.f.mjs'
|
|
8
|
+
import * as list from '../types/list/module.f.mjs'
|
|
9
9
|
const { toArray } = list
|
|
10
|
-
import utf16 from '../text/utf16/module.f.mjs'
|
|
10
|
+
import * as utf16 from '../text/utf16/module.f.mjs'
|
|
11
11
|
const { stringToList } = utf16
|
|
12
12
|
|
|
13
13
|
const stringifyIdentity = json.stringify(identity)
|
|
@@ -22,7 +22,7 @@ const buildDfa = () => {
|
|
|
22
22
|
const idNext = byteSet.union(idBegin)(digit)
|
|
23
23
|
const dot = _.toUnion('.')
|
|
24
24
|
|
|
25
|
-
/** @type {
|
|
25
|
+
/** @type {_.Grammar} */
|
|
26
26
|
const grammar = [
|
|
27
27
|
['', digit, 'int'],
|
|
28
28
|
['int', digit, 'int'],
|
package/html/README.md
CHANGED
|
@@ -5,3 +5,27 @@
|
|
|
5
5
|
|`<br>` |`['br']` |
|
|
6
6
|
|`<img src="https://example.com/image.jpg">` |`['img',{src:'https://example.com/image.jpg'}]` |
|
|
7
7
|
|`<a href="https://example.com/">Example</a>`|`['a',{href:'https://example.com/'},['Example']]`|
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<html>
|
|
13
|
+
<head>
|
|
14
|
+
<title>Page</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<a href="https://example.com/">Example</a>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
['html', [
|
|
24
|
+
['head', [
|
|
25
|
+
['title', ['Page']]
|
|
26
|
+
]]
|
|
27
|
+
['body', [
|
|
28
|
+
['a', { href: 'https://example.com/' }, ['Example']]
|
|
29
|
+
]]
|
|
30
|
+
]]
|
|
31
|
+
```
|
package/html/module.f.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export default _default;
|
|
1
|
+
/** @type {(element: Element) => list.List<string>} */
|
|
2
|
+
export const element: (element: Element) => list.List<string>;
|
|
3
|
+
export const html: f.Func<Element, list.List<string>>;
|
|
4
|
+
export const htmlToString: f.Func<Element, string>;
|
|
7
5
|
export type Tag = string;
|
|
8
6
|
export type Element1 = readonly [Tag];
|
|
9
7
|
export type Element2A = readonly [Tag, Attributes];
|
|
@@ -11,10 +9,7 @@ export type Element2N = readonly [Tag, readonly Node[]];
|
|
|
11
9
|
export type Element3 = readonly [Tag, Attributes, Nodes];
|
|
12
10
|
export type Element = Element1 | Element2A | Element2N | Element3;
|
|
13
11
|
export type Attributes = { readonly [k in string]: string; };
|
|
14
|
-
export type Nodes =
|
|
12
|
+
export type Nodes = list.List<Node>;
|
|
15
13
|
export type Node = Element | string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
declare const html: import("../types/function/module.f.mjs").Func<Element, List.List<string>>;
|
|
19
|
-
declare const htmlToString: import("../types/function/module.f.mjs").Func<Element, string>;
|
|
20
|
-
import * as List from '../types/list/module.f.mjs';
|
|
14
|
+
import * as list from '../types/list/module.f.mjs';
|
|
15
|
+
import * as f from '../types/function/module.f.mjs';
|