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.
Files changed (222) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Cargo.lock +4 -0
  3. package/Cargo.toml +4 -2
  4. package/README.md +1 -1
  5. package/com/cpp/module.f.d.mts +4 -8
  6. package/com/cpp/module.f.mjs +20 -25
  7. package/com/cpp/testlib.f.mjs +3 -4
  8. package/com/cs/module.f.d.mts +4 -8
  9. package/com/cs/module.f.mjs +18 -23
  10. package/com/cs/testlib.f.mjs +3 -5
  11. package/com/rust/module.f.d.mts +3 -7
  12. package/com/rust/module.f.mjs +25 -30
  13. package/com/rust/nanocom/src/cobject.rs +1 -1
  14. package/com/rust/testlib.f.mjs +3 -5
  15. package/com/test/build.f.d.mts +2 -2
  16. package/com/test/build.f.mjs +2 -2
  17. package/com/test/build.mjs +4 -4
  18. package/com/test/rust/src/lib.rs +4 -4
  19. package/com/types/module.f.d.mts +5 -10
  20. package/com/types/module.f.mjs +5 -12
  21. package/commonjs/build/module.f.d.mts +13 -17
  22. package/commonjs/build/module.f.mjs +23 -28
  23. package/commonjs/build/test.f.mjs +4 -4
  24. package/commonjs/module/function/module.f.d.mts +0 -2
  25. package/commonjs/module/function/module.f.mjs +0 -2
  26. package/commonjs/module/module.f.d.mts +16 -21
  27. package/commonjs/module/module.f.mjs +2 -9
  28. package/commonjs/module.d.mts +1 -5
  29. package/commonjs/module.f.d.mts +0 -2
  30. package/commonjs/module.f.mjs +0 -2
  31. package/commonjs/module.mjs +2 -7
  32. package/commonjs/package/dependencies/module.f.d.mts +3 -7
  33. package/commonjs/package/dependencies/module.f.mjs +5 -10
  34. package/commonjs/package/dependencies/test.f.mjs +1 -1
  35. package/commonjs/package/module.f.d.mts +12 -18
  36. package/commonjs/package/module.f.mjs +6 -13
  37. package/commonjs/package/test.f.mjs +1 -1
  38. package/commonjs/path/module.f.d.mts +25 -32
  39. package/commonjs/path/module.f.mjs +12 -23
  40. package/commonjs/path/test.f.mjs +11 -11
  41. package/commonjs/test.mjs +1 -1
  42. package/dev/module.f.d.mts +1 -4
  43. package/dev/module.f.mjs +1 -4
  44. package/dev/module.mjs +1 -1
  45. package/dev/test/module.f.d.mts +2 -3
  46. package/dev/test/module.f.mjs +5 -7
  47. package/djs/module.f.d.mts +13 -18
  48. package/djs/module.f.mjs +12 -19
  49. package/djs/parser/module.f.d.mts +53 -37
  50. package/djs/parser/module.f.mjs +278 -131
  51. package/djs/parser/test.f.d.mts +4 -0
  52. package/djs/parser/test.f.mjs +186 -70
  53. package/djs/test.f.mjs +4 -4
  54. package/djs/tokenizer/module.f.d.mts +6 -10
  55. package/djs/tokenizer/module.f.mjs +19 -22
  56. package/djs/tokenizer/test.f.mjs +7 -7
  57. package/doc/LANGUAGE.md +17 -16
  58. package/doc/README.md +14 -50
  59. package/fsc/README.md +0 -3
  60. package/fsc/module.f.d.mts +4 -9
  61. package/fsc/module.f.mjs +17 -24
  62. package/fsc/test.f.mjs +3 -3
  63. package/fsm/README.md +1 -1
  64. package/fsm/module.f.d.mts +13 -20
  65. package/fsm/module.f.mjs +27 -38
  66. package/fsm/test.f.mjs +8 -8
  67. package/html/README.md +24 -0
  68. package/html/module.f.d.mts +7 -12
  69. package/html/module.f.mjs +14 -23
  70. package/html/test.f.mjs +4 -4
  71. package/issues/01-test-debug.md +3 -0
  72. package/issues/{publish.md → 05-publish.md} +8 -8
  73. package/issues/17-djs-extension.md +6 -0
  74. package/issues/README.md +20 -13
  75. package/issues/lang/1000-json.md +38 -0
  76. package/issues/lang/2110-default-export.md +2 -2
  77. package/issues/lang/2310-undefined.md +1 -1
  78. package/issues/lang/2330-property-accessor.md +225 -0
  79. package/issues/lang/2360-built-in.md +54 -47
  80. package/issues/lang/3240-export.md +44 -0
  81. package/issues/lang/README.md +64 -22
  82. package/issues/test.f.d.mts +16 -0
  83. package/issues/test.f.mjs +57 -0
  84. package/js/tokenizer/module.f.d.mts +18 -17
  85. package/js/tokenizer/module.f.mjs +80 -61
  86. package/js/tokenizer/test.f.mjs +15 -12
  87. package/json/module.f.d.mts +18 -26
  88. package/json/module.f.mjs +18 -31
  89. package/json/parser/module.f.d.mts +9 -13
  90. package/json/parser/module.f.mjs +9 -14
  91. package/json/parser/test.f.mjs +7 -7
  92. package/json/serializer/module.f.d.mts +11 -20
  93. package/json/serializer/module.f.mjs +14 -29
  94. package/json/serializer/test.f.mjs +2 -2
  95. package/json/test.f.mjs +3 -3
  96. package/json/tokenizer/module.f.d.mts +6 -10
  97. package/json/tokenizer/module.f.mjs +16 -20
  98. package/json/tokenizer/test.f.mjs +6 -6
  99. package/jsr.json +1 -1
  100. package/nanvm-lib/Cargo.toml +6 -0
  101. package/nanvm-lib/src/extension.rs +119 -0
  102. package/nanvm-lib/src/interface.rs +136 -0
  103. package/nanvm-lib/src/lib.rs +7 -0
  104. package/nanvm-lib/src/naive.rs +229 -0
  105. package/nanvm-lib/src/nanenum.rs +230 -0
  106. package/nanvm-lib/src/nullish.rs +7 -0
  107. package/nanvm-lib/src/sign.rs +5 -0
  108. package/nanvm-lib/src/simple.rs +32 -0
  109. package/nanvm-lib/tests/test.f.d.mts +36 -0
  110. package/nanvm-lib/tests/test.f.mjs +79 -0
  111. package/nanvm-lib/tests/test.rs +108 -0
  112. package/nodejs/version/main.mjs +1 -1
  113. package/nodejs/version/module.f.d.mts +4 -9
  114. package/nodejs/version/module.f.mjs +2 -7
  115. package/nodejs/version/test.f.mjs +3 -3
  116. package/package.json +1 -1
  117. package/prime_field/module.f.d.mts +20 -23
  118. package/prime_field/module.f.mjs +9 -12
  119. package/prime_field/test.f.mjs +1 -1
  120. package/secp/module.f.d.mts +27 -28
  121. package/secp/module.f.mjs +38 -39
  122. package/secp/test.f.mjs +4 -4
  123. package/sha2/module.f.d.mts +8 -16
  124. package/sha2/module.f.mjs +7 -20
  125. package/sha2/test.f.mjs +4 -4
  126. package/text/README.md +2 -2
  127. package/text/ascii/module.f.d.mts +69 -72
  128. package/text/ascii/module.f.mjs +5 -10
  129. package/text/ascii/test.f.mjs +3 -3
  130. package/text/module.f.d.mts +9 -14
  131. package/text/module.f.mjs +7 -14
  132. package/text/sgr/module.f.d.mts +7 -9
  133. package/text/sgr/module.f.mjs +2 -4
  134. package/text/test.f.mjs +3 -3
  135. package/text/utf16/module.f.d.mts +8 -15
  136. package/text/utf16/module.f.mjs +17 -28
  137. package/text/utf16/test.f.mjs +5 -5
  138. package/text/utf8/module.f.d.mts +4 -9
  139. package/text/utf8/module.f.mjs +9 -16
  140. package/text/utf8/test.f.mjs +4 -4
  141. package/types/array/module.f.d.mts +14 -24
  142. package/types/array/module.f.mjs +8 -25
  143. package/types/array/test.f.mjs +3 -3
  144. package/types/bigfloat/module.f.d.mts +4 -9
  145. package/types/bigfloat/module.f.mjs +3 -10
  146. package/types/bigfloat/test.f.mjs +1 -1
  147. package/types/bigint/module.f.d.mts +16 -64
  148. package/types/bigint/module.f.mjs +11 -30
  149. package/types/bigint/test.f.mjs +1 -1
  150. package/types/btree/find/module.f.d.mts +20 -26
  151. package/types/btree/find/module.f.mjs +8 -17
  152. package/types/btree/find/test.f.mjs +7 -7
  153. package/types/btree/module.f.d.mts +4 -8
  154. package/types/btree/module.f.mjs +6 -11
  155. package/types/btree/remove/module.f.d.mts +7 -12
  156. package/types/btree/remove/module.f.mjs +10 -17
  157. package/types/btree/remove/test.f.mjs +5 -5
  158. package/types/btree/set/module.f.d.mts +3 -7
  159. package/types/btree/set/module.f.mjs +4 -9
  160. package/types/btree/set/test.f.mjs +4 -4
  161. package/types/btree/test.f.mjs +9 -9
  162. package/types/btree/types/module.f.d.mts +0 -2
  163. package/types/btree/types/module.f.mjs +0 -2
  164. package/types/byte_set/module.f.d.mts +16 -29
  165. package/types/byte_set/module.f.mjs +14 -39
  166. package/types/byte_set/test.f.mjs +5 -5
  167. package/types/function/compare/module.f.d.mts +9 -15
  168. package/types/function/compare/module.f.mjs +3 -12
  169. package/types/function/compare/test.f.mjs +1 -1
  170. package/types/function/module.f.d.mts +20 -27
  171. package/types/function/module.f.mjs +4 -15
  172. package/types/function/operator/module.f.d.mts +28 -43
  173. package/types/function/operator/module.f.mjs +14 -41
  174. package/types/function/test.f.mjs +1 -1
  175. package/types/list/module.f.d.mts +56 -91
  176. package/types/list/module.f.mjs +45 -114
  177. package/types/list/test.f.mjs +10 -10
  178. package/types/map/module.f.d.mts +15 -24
  179. package/types/map/module.f.mjs +15 -30
  180. package/types/map/test.f.mjs +2 -2
  181. package/types/nibble_set/module.f.d.mts +10 -20
  182. package/types/nibble_set/module.f.mjs +7 -24
  183. package/types/nibble_set/test.f.mjs +2 -2
  184. package/types/nullable/module.f.d.mts +3 -8
  185. package/types/nullable/module.f.mjs +2 -9
  186. package/types/nullable/test.f.mjs +1 -1
  187. package/types/number/module.f.d.mts +7 -13
  188. package/types/number/module.f.mjs +8 -19
  189. package/types/number/test.f.mjs +1 -1
  190. package/types/object/module.f.d.mts +11 -18
  191. package/types/object/module.f.mjs +9 -20
  192. package/types/object/test.f.mjs +1 -1
  193. package/types/range/module.f.d.mts +3 -8
  194. package/types/range/module.f.mjs +2 -9
  195. package/types/range/test.f.mjs +1 -1
  196. package/types/range_map/module.f.d.mts +9 -15
  197. package/types/range_map/module.f.mjs +9 -18
  198. package/types/range_map/test.f.mjs +32 -32
  199. package/types/result/module.d.mts +3 -3
  200. package/types/result/module.f.d.mts +6 -12
  201. package/types/result/module.f.mjs +3 -12
  202. package/types/result/module.mjs +2 -2
  203. package/types/sorted_list/module.f.d.mts +22 -28
  204. package/types/sorted_list/module.f.mjs +10 -19
  205. package/types/sorted_list/test.f.mjs +7 -7
  206. package/types/sorted_set/module.f.d.mts +6 -12
  207. package/types/sorted_set/module.f.mjs +7 -16
  208. package/types/sorted_set/test.f.mjs +7 -7
  209. package/types/string/module.f.d.mts +8 -14
  210. package/types/string/module.f.mjs +10 -21
  211. package/types/string/test.f.mjs +2 -2
  212. package/types/string_set/module.f.d.mts +8 -16
  213. package/types/string_set/module.f.mjs +12 -27
  214. package/types/string_set/test.f.mjs +1 -1
  215. package/issues/lang/2351-property-accessor.md +0 -44
  216. package/issues/lang/2352-property-call.md +0 -43
  217. package/issues/lang/2353-property-at.md +0 -19
  218. package/issues/test-debug.md +0 -12
  219. /package/issues/{esm.md → 02-esm.md} +0 -0
  220. /package/issues/{djs.md → 03-djs.md} +0 -0
  221. /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
  222. /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
- Principals:
4
- - FunctionalScript VM should behaves the same way as a JavaScript VM
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 [CommonJS](https://en.wikipedia.org/wiki/CommonJS) conventions as a module ecosystem. For example,
10
+ FunctionalScript uses ESM conventions as a module ecosystem. For example,
10
11
 
11
12
  ```js
12
- const thirdPartyModule = require('third-party-package/module')
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.js`
43
+ `./first.f.mjs`
43
44
  ```js
44
45
  // 1. references
45
- const math = require('math')
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
- module.exports = {
56
+ export default {
56
57
  addition,
57
58
  add42,
58
59
  _10digitsOfPi,
59
60
  }
60
61
  ```
61
62
 
62
- `./second.js`
63
+ `./second.f.mjs`
63
64
  ```js
64
65
  // 1. references
65
- const first = require('./first.js')
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
- module.exports = {
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 `const ANYNAME = require('PATH_TO_A_MODULE')`. For example,
79
+ The format of references is `import ANYNAME from 'PATH_TO_A_MODULE'`. For example,
79
80
 
80
81
  ```js
81
- const math = require('math')
82
- const algebra = require('math/algebra')
83
- const localFile = require('../some-directory/some-file.js')
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 `module.exports = { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `module.exports` at
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
- module.exports = {
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.cjs` file extensions because it's using a `Common.JS` module system. We plan to add
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. Creating a New Repository
5
+ ## 1. Language
9
6
 
10
- Creating from a template https://github.com/functionalscript/template/generate
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
- module.exports = 'Hello world!'
10
+ export default 'Hello world!'
47
11
  ```
48
12
 
49
13
  ```js
50
- module.exports = { a: 'hello', b: 42 }
14
+ export default { a: 'hello', b: 42 }
51
15
  ```
52
16
 
53
17
  ```js
54
- module.exports = x => x * x
18
+ export default x => x * x
55
19
  ```
56
20
 
57
- ### 2.2. Reference Another Module
21
+ ### 1.2. Reference Another Module
58
22
 
59
- #### 2.2.1. Local File
23
+ #### 1.2.1. Local File
60
24
 
61
25
  ```js
62
- const x = require('./folder/main.f.cjs')
26
+ import x from './folder/main.f.mjs'
63
27
  ```
64
28
 
65
- ### 2.2.2. External Module
29
+ ### 1.2.2. External Module
66
30
 
67
31
  Run `npm install -D github:USER/REPO`
68
32
 
69
33
  ```js
70
- const x = require(`REPO/DIR/FILE.f.cjs`)
34
+ import x from `REPO/DIR/FILE.f.mjs`
71
35
  ```
72
36
 
73
- ### 2.3. Functions
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
- ## 3. Advanced
50
+ ## 2. Advanced
87
51
 
88
- ### 3.1. Generators
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`
@@ -1,12 +1,7 @@
1
- declare namespace _default {
2
- export { terminal };
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> = RM.RangeMapArray<CreateToResult<T>>;
10
- declare const terminal: -1;
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 range_map, * as RM from '../types/range_map/module.f.mjs'
4
- const { merge: rangeMapMerge, fromRange, get } = range_map
5
- import list, * as List from '../types/list/module.f.mjs'
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 _range, * as Range from '../types/range/module.f.mjs'
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 {RM.RangeMapArray<CreateToResult<T>>} State
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: List.List<State<T>>) => State<T>} */
46
+ /** @type {<T>(a: list.List<State<T>>) => State<T>} */
47
47
  const reduce = a => {
48
- /** @typedef {typeof a extends List.List<State<infer T>> ? T : never} T */
49
- /** @type {RM.RangeMerge<CreateToResult<T>>} */
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: Range.Range) => (f: CreateToResult<T>) => State<T>} */
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: List.List<State<T>>) => CreateToResult<T>} */
71
+ /** @type {<T>(a: list.List<State<T>>) => CreateToResult<T>} */
72
72
  const create = a => {
73
- /** @typedef {typeof a extends List.List<State<infer T>> ? T : never} T */
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
- ])(void 0)
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
- const map = require('./types/map/module.f.js')
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
  ```
@@ -1,21 +1,14 @@
1
- declare namespace _default {
2
- export { dfa };
3
- export { run };
4
- export { toRange };
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
- declare const dfa: (grammar: Grammar) => Dfa;
13
- /** @type {(dfa: Dfa) => (input: List.List<number>) => List.List<string>} */
14
- declare const run: (dfa: Dfa) => (input: List.List<number>) => List.List<string>;
15
- /** @type {(s: string) => byteSetT.ByteSet} */
16
- declare const toRange: (s: string) => byteSetT.ByteSet;
17
- /** @type {(s: string) => byteSetT.ByteSet} */
18
- declare const toUnion: (s: string) => byteSetT.ByteSet;
19
- import * as byteSetT from '../types/byte_set/module.f.mjs';
20
- import * as List from '../types/list/module.f.mjs';
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 list, * as List from '../types/list/module.f.mjs'
2
+ import * as list from '../types/list/module.f.mjs'
3
3
  const { equal, isEmpty, fold, toArray, scan, foldScan, empty: emptyList } = list
4
- import byteSet, * as byteSetT from '../types/byte_set/module.f.mjs'
4
+ import * as byteSet from '../types/byte_set/module.f.mjs'
5
5
  const { toRangeMap, union: byteSetUnion, one, empty } = byteSet
6
- import sortedSet, * as SortedSet from '../types/sorted_set/module.f.mjs'
6
+ import * as sortedSet from '../types/sorted_set/module.f.mjs'
7
7
  const { intersect, union: sortedSetUnion } = sortedSet
8
- import rangeMap, * as RM from '../types/range_map/module.f.mjs'
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 operator, * as Operator from '../types/function/operator/module.f.mjs'
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, byteSetT.ByteSet, string]} Rule */
21
+ /** @typedef {readonly[string, byteSet.ByteSet, string]} Rule */
22
22
 
23
- /** @typedef {List.List<Rule>} Grammar */
23
+ /** @typedef {list.List<Rule>} Grammar */
24
24
 
25
25
  /**
26
26
  * @typedef {{
27
- * readonly[state in string]: RM.RangeMapArray<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) => byteSetT.ByteSet} */
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 {Operator.Fold<number, byteSetT.ByteSet>} */
39
+ /** @type {operator.Fold<number, byteSet.ByteSet>} */
40
40
  const toUnionOp = i => bs => byteSetUnion(bs)(one(i))
41
41
 
42
- /** @type {(s: string) => byteSetT.ByteSet} */
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 {RM.Operators<SortedSet.SortedSet<string>>} */
48
+ /** @type {rangeMap.Operators<sortedSet.SortedSet<string>>} */
49
49
  const mergeOp = { union: sortedSetUnion(unsafeCmp), equal: equal(strictEqual) }
50
50
 
51
- /** @type {(s: string) => (set: SortedSet.SortedSet<string>) => boolean} */
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: SortedSet.SortedSet<string>) => Operator.Fold<Rule, RM.RangeMap<SortedSet.SortedSet<string>>>} */
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 {Operator.Scan<RM.Entry<SortedSet.SortedSet<string>>, RM.Entry<string>>} */
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 {Operator.Scan<RM.Entry<SortedSet.SortedSet<string>>, SortedSet.SortedSet<string>>} */
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) => Operator.Fold<SortedSet.SortedSet<string>, Dfa>} */
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) => Operator.Fold<number, string>} */
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: List.List<number>) => List.List<string>} */
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 _, * as T from './module.f.mjs'
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 {T.Grammar} */
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
+ ```
@@ -1,9 +1,7 @@
1
- declare namespace _default {
2
- export { element };
3
- export { html };
4
- export { htmlToString };
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 = List.List<Node>;
12
+ export type Nodes = list.List<Node>;
15
13
  export type Node = Element | string;
16
- /** @type {(element: Element) => List.List<string>} */
17
- declare const element: (element: Element) => List.List<string>;
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';