functionalscript 0.9.1 → 0.9.2
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/README.md +3 -3
- package/bnf/module.f.d.ts +6 -2
- package/bnf/module.f.js +8 -9
- package/cas/module.f.d.ts +14 -13
- package/cas/module.f.js +78 -60
- package/ci/module.f.d.ts +3 -2
- package/ci/module.f.js +6 -6
- package/ci/module.js +3 -3
- package/dev/module.f.d.ts +1 -1
- package/dev/module.f.js +13 -6
- package/dev/version/module.f.d.ts +2 -11
- package/dev/version/module.f.js +17 -15
- package/dev/version/test.f.d.ts +3 -1
- package/dev/version/test.f.js +26 -11
- package/djs/parser-new/module.f.d.ts +3 -0
- package/djs/parser-new/module.f.js +150 -0
- package/djs/parser-new/test.f.d.ts +5 -0
- package/djs/parser-new/test.f.js +201 -0
- package/djs/serializer/module.f.js +6 -6
- package/fjs/module.f.d.ts +1 -1
- package/fjs/module.f.js +3 -2
- package/fsc/module.f.js +1 -1
- package/io/module.d.ts +4 -0
- package/io/module.f.d.ts +10 -4
- package/io/module.f.js +21 -0
- package/io/module.js +7 -1
- package/json/module.f.js +3 -3
- package/package.json +3 -2
- package/path/module.f.d.ts +1 -0
- package/path/module.f.js +6 -3
- package/text/utf16/module.f.js +1 -1
- package/types/bit_vec/module.f.d.ts +1 -0
- package/types/bit_vec/module.f.js +1 -0
- package/types/effect/mock/module.f.d.ts +5 -0
- package/types/effect/mock/module.f.js +14 -0
- package/types/effect/module.d.ts +2 -0
- package/types/effect/module.f.d.ts +23 -0
- package/types/effect/module.f.js +14 -0
- package/types/effect/module.js +11 -0
- package/types/effect/node/module.f.d.ts +52 -0
- package/types/effect/node/module.f.js +7 -0
- package/types/effect/node/test.f.d.ts +27 -0
- package/types/effect/node/test.f.js +259 -0
- package/types/effect/node/virtual/module.f.d.ts +13 -0
- package/types/effect/node/virtual/module.f.js +98 -0
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/test.f.js +1 -1
- package/types/list/module.f.js +4 -4
- package/website/module.d.ts +1 -0
- package/website/module.f.d.ts +3 -0
- package/website/module.f.js +9 -0
- package/website/module.js +3 -0
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ This repository is a [monorepo](https://en.wikipedia.org/wiki/Monorepo) and dist
|
|
|
26
26
|
Install FunctionalScript via npm:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npm install functionalscript
|
|
29
|
+
npm install -g functionalscript
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
The FunctionalScript compiler command (`fjs compile`) currently supports:
|
|
@@ -39,9 +39,9 @@ It does **not** yet support functions or complex expressions.
|
|
|
39
39
|
Example usage with `fjs`:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
|
|
42
|
+
fjs compile example.f.js output.json
|
|
43
43
|
# or
|
|
44
|
-
|
|
44
|
+
fjs compile example.f.js output.f.js
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
FunctionalScript code can be compiled directly into either JSON or JavaScript without imports.
|
package/bnf/module.f.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { type Array2 } from '../types/array/module.f.ts';
|
|
|
7
7
|
* - 0xEEEEEE is the last symbol (24 bits)
|
|
8
8
|
*/
|
|
9
9
|
export type TerminalRange = number;
|
|
10
|
+
export declare const fullRange: TerminalRange;
|
|
11
|
+
export declare const unicodeRange: TerminalRange;
|
|
12
|
+
export declare const eof = 1114112;
|
|
10
13
|
/** A sequence of rules. */
|
|
11
14
|
export type Sequence = readonly Rule[];
|
|
12
15
|
/** A variant */
|
|
@@ -30,8 +33,9 @@ export declare const range: (ab: string) => TerminalRange;
|
|
|
30
33
|
export type RangeVariant = {
|
|
31
34
|
readonly [k in string]: TerminalRange;
|
|
32
35
|
};
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
36
|
+
export declare const remove: (range: TerminalRange, v: RangeVariant) => RangeVariant;
|
|
37
|
+
export declare const not: (v: RangeVariant) => RangeVariant;
|
|
38
|
+
export declare const notSet: (s: string) => RangeVariant;
|
|
35
39
|
export type None = readonly [];
|
|
36
40
|
export declare const none: None;
|
|
37
41
|
export type Option<S> = {
|
package/bnf/module.f.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { codePointListToString, stringToCodePointList } from "../text/utf16/module.f.js";
|
|
2
2
|
import { isArray2 } from "../types/array/module.f.js";
|
|
3
3
|
import { map, toArray, repeat as listRepeat } from "../types/list/module.f.js";
|
|
4
|
+
export const fullRange = 0x000000_FFFFFF;
|
|
5
|
+
export const unicodeRange = 0x000000_10FFFF;
|
|
6
|
+
export const eof = 0x110000;
|
|
4
7
|
// Internals:
|
|
5
8
|
const { fromEntries, values } = Object;
|
|
6
9
|
const { fromCodePoint } = String;
|
|
@@ -34,13 +37,7 @@ export const range = (ab) => {
|
|
|
34
37
|
}
|
|
35
38
|
return rangeEncode(...a);
|
|
36
39
|
};
|
|
37
|
-
|
|
38
|
-
const ab = rangeDecode(r);
|
|
39
|
-
const [a, b] = ab;
|
|
40
|
-
const cp = a === b ? [a] : ab;
|
|
41
|
-
return fromCodePoint(...cp);
|
|
42
|
-
};
|
|
43
|
-
const rangeToEntry = (r) => [rangeToId(r), r];
|
|
40
|
+
const rangeToEntry = (r) => ['0x' + r.toString(16), r];
|
|
44
41
|
const toVariantRangeSet = (r) => fromEntries(r.map(rangeToEntry));
|
|
45
42
|
const removeOne = (list, ab) => {
|
|
46
43
|
const [a, b] = rangeDecode(ab);
|
|
@@ -60,13 +57,15 @@ const removeOne = (list, ab) => {
|
|
|
60
57
|
}
|
|
61
58
|
return result;
|
|
62
59
|
};
|
|
63
|
-
export const remove = (range,
|
|
60
|
+
export const remove = (range, v) => {
|
|
64
61
|
let result = [range];
|
|
65
|
-
for (const r of values(
|
|
62
|
+
for (const r of values(v)) {
|
|
66
63
|
result = removeOne(result, r);
|
|
67
64
|
}
|
|
68
65
|
return toVariantRangeSet(result);
|
|
69
66
|
};
|
|
67
|
+
export const not = (v) => remove(fullRange, v);
|
|
68
|
+
export const notSet = (s) => not(set(s));
|
|
70
69
|
export const none = [];
|
|
71
70
|
export const option = (some) => ({
|
|
72
71
|
some,
|
package/cas/module.f.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { type Sha2 } from "../crypto/sha2/module.f.ts";
|
|
2
|
-
import type {
|
|
3
|
-
import { type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
2
|
+
import type { Vec } from "../types/bit_vec/module.f.ts";
|
|
3
|
+
import { type Effect, type Operations } from "../types/effect/module.f.ts";
|
|
4
|
+
import { type Fs, type NodeOperations } from "../types/effect/node/module.f.ts";
|
|
5
|
+
export type KvStore<O extends Operations> = {
|
|
6
|
+
readonly read: (key: Vec) => Effect<O, Vec | undefined>;
|
|
7
|
+
readonly write: (key: Vec, value: Vec) => Effect<O, void>;
|
|
8
|
+
readonly list: () => Effect<O, readonly Vec[]>;
|
|
8
9
|
};
|
|
9
10
|
export type Kv = readonly [Vec, Vec];
|
|
10
|
-
export declare const
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly list: () => Promise<Iterable<Vec>>;
|
|
11
|
+
export declare const fileKvStore: (path: string) => KvStore<Fs>;
|
|
12
|
+
export type Cas<O extends Operations> = {
|
|
13
|
+
readonly read: (key: Vec) => Effect<O, Vec | undefined>;
|
|
14
|
+
readonly write: (value: Vec) => Effect<O, Vec>;
|
|
15
|
+
readonly list: () => Effect<O, readonly Vec[]>;
|
|
16
16
|
};
|
|
17
|
-
export declare const cas: (sha2: Sha2) => (
|
|
17
|
+
export declare const cas: (sha2: Sha2) => <O extends Operations>(_: KvStore<O>) => Cas<O>;
|
|
18
|
+
export declare const main: (args: readonly string[]) => Effect<NodeOperations, number>;
|
package/cas/module.f.js
CHANGED
|
@@ -1,77 +1,95 @@
|
|
|
1
|
-
import { computeSync } from "../crypto/sha2/module.f.js";
|
|
2
|
-
import {
|
|
3
|
-
import {} from "../types/bit_vec/module.f.js";
|
|
1
|
+
import { computeSync, sha256 } from "../crypto/sha2/module.f.js";
|
|
2
|
+
import { parse } from "../path/module.f.js";
|
|
4
3
|
import { cBase32ToVec, vecToCBase32 } from "../types/cbase32/module.f.js";
|
|
5
|
-
import {
|
|
4
|
+
import { pure } from "../types/effect/module.f.js";
|
|
5
|
+
import { error, log, mkdir, readdir, readFile, writeFile } from "../types/effect/node/module.f.js";
|
|
6
6
|
import { toOption } from "../types/nullable/module.f.js";
|
|
7
|
-
import {
|
|
8
|
-
export const memKvStore = () => {
|
|
9
|
-
const create = (...i) => {
|
|
10
|
-
const store = new Map(i);
|
|
11
|
-
return {
|
|
12
|
-
read: async (key) => store.get(key),
|
|
13
|
-
write: async (...kv) => create(...store, kv),
|
|
14
|
-
list: async () => store.keys(),
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
return create();
|
|
18
|
-
};
|
|
7
|
+
import { unwrap } from "../types/result/module.f.js";
|
|
19
8
|
const o = { withFileTypes: true };
|
|
20
9
|
const split = (s) => [s.substring(0, 2), s.substring(2)];
|
|
10
|
+
const prefix = '.cas';
|
|
21
11
|
const toPath = (key) => {
|
|
22
12
|
const s = vecToCBase32(key);
|
|
23
13
|
const [a, bc] = split(s);
|
|
24
14
|
const [b, c] = split(bc);
|
|
25
|
-
return `${a}/${b}/${c}`;
|
|
26
|
-
};
|
|
27
|
-
export const fileKvStore = (io) => (path) => {
|
|
28
|
-
const { readdir, readFile, writeFile } = io.fs.promises;
|
|
29
|
-
const { asyncTryCatch } = io;
|
|
30
|
-
const result = {
|
|
31
|
-
read: async (key) => {
|
|
32
|
-
const p = toPath(key);
|
|
33
|
-
const [s, v] = await asyncTryCatch(() => readFile(`${path}/${p}`));
|
|
34
|
-
if (s === 'error') {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return toVec(v);
|
|
38
|
-
},
|
|
39
|
-
write: async (key, value) => {
|
|
40
|
-
const p = toPath(key);
|
|
41
|
-
await writeFile(`${path}/${p}`, fromVec(value));
|
|
42
|
-
return result;
|
|
43
|
-
},
|
|
44
|
-
list: async () => {
|
|
45
|
-
const f = async (p) => {
|
|
46
|
-
const dir = await readdir(p, o);
|
|
47
|
-
let result = [];
|
|
48
|
-
for (const entry of dir) {
|
|
49
|
-
const { name } = entry;
|
|
50
|
-
if (entry.isFile()) {
|
|
51
|
-
result = [...result, name];
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
// directory
|
|
55
|
-
const sub = await f(`${p}/${name}`);
|
|
56
|
-
result = [...result, ...sub.map(x => `${name}${x}`)];
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
const all = await f(path);
|
|
61
|
-
return all.flatMap(compose(cBase32ToVec)(toOption));
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
return result;
|
|
15
|
+
return `${prefix}/${a}/${b}/${c}`;
|
|
65
16
|
};
|
|
17
|
+
export const fileKvStore = (path) => ({
|
|
18
|
+
read: (key) => readFile(toPath(key))
|
|
19
|
+
.map(([status, data]) => status === 'error' ? undefined : data),
|
|
20
|
+
write: (key, value) => {
|
|
21
|
+
const p = toPath(key);
|
|
22
|
+
const parts = parse(p);
|
|
23
|
+
const dir = `${path}/${parts.slice(0, -1).join('/')}`;
|
|
24
|
+
// TODO: error handling
|
|
25
|
+
return mkdir(dir, { recursive: true })
|
|
26
|
+
.pipe(() => writeFile(`${path}/${p}`, value))
|
|
27
|
+
.map(() => undefined);
|
|
28
|
+
},
|
|
29
|
+
list: () => readdir('.cas', { recursive: true })
|
|
30
|
+
// TODO: remove unwrap
|
|
31
|
+
.map(r => unwrap(r).flatMap(({ name, parentPath, isFile }) => toOption(isFile ? cBase32ToVec(parentPath.substring(prefix.length).replaceAll('/', '') + name) : null))),
|
|
32
|
+
});
|
|
66
33
|
export const cas = (sha2) => {
|
|
67
34
|
const compute = computeSync(sha2);
|
|
68
|
-
|
|
35
|
+
return ({ read, write, list }) => ({
|
|
69
36
|
read,
|
|
70
|
-
write:
|
|
37
|
+
write: (value) => {
|
|
71
38
|
const hash = compute([value]);
|
|
72
|
-
return
|
|
39
|
+
return write(hash, value)
|
|
40
|
+
.map(() => hash);
|
|
73
41
|
},
|
|
74
42
|
list,
|
|
75
43
|
});
|
|
76
|
-
|
|
44
|
+
};
|
|
45
|
+
const e = (s) => error(s).map(() => 1);
|
|
46
|
+
export const main = (args) => {
|
|
47
|
+
const c = cas(sha256)(fileKvStore('.'));
|
|
48
|
+
const [cmd, ...options] = args;
|
|
49
|
+
switch (cmd) {
|
|
50
|
+
case 'add': {
|
|
51
|
+
if (options.length !== 1) {
|
|
52
|
+
return e("'cas add' expects one parameter");
|
|
53
|
+
}
|
|
54
|
+
const [path] = options;
|
|
55
|
+
return readFile(path)
|
|
56
|
+
.pipe(v => c.write(unwrap(v)))
|
|
57
|
+
.pipe(hash => log(vecToCBase32(hash)))
|
|
58
|
+
.map(() => 0);
|
|
59
|
+
}
|
|
60
|
+
case 'get': {
|
|
61
|
+
if (options.length !== 2) {
|
|
62
|
+
return e("'cas get' expects two parameters");
|
|
63
|
+
}
|
|
64
|
+
const [hashCBase32, path] = options;
|
|
65
|
+
const hash = cBase32ToVec(hashCBase32);
|
|
66
|
+
if (hash === null) {
|
|
67
|
+
return e(`invalid hash format: ${hashCBase32}`);
|
|
68
|
+
}
|
|
69
|
+
return c.read(hash)
|
|
70
|
+
.pipe(v => {
|
|
71
|
+
const result = v === undefined
|
|
72
|
+
? e(`no such hash: ${hashCBase32}`)
|
|
73
|
+
: writeFile(path, v).map(() => 0);
|
|
74
|
+
return result;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
case 'list': {
|
|
78
|
+
return c.list()
|
|
79
|
+
.pipe(v => {
|
|
80
|
+
// TODO: make it lazy.
|
|
81
|
+
let i = pure(undefined);
|
|
82
|
+
for (const j of v) {
|
|
83
|
+
i = i.pipe(() => log(vecToCBase32(j)));
|
|
84
|
+
}
|
|
85
|
+
return i;
|
|
86
|
+
})
|
|
87
|
+
.map(() => 0);
|
|
88
|
+
}
|
|
89
|
+
case undefined: {
|
|
90
|
+
return e('Error: CAS command requires subcommand');
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
return e(`Error: Unknown CAS subcommand "${args[0]}"`);
|
|
94
|
+
}
|
|
77
95
|
};
|
package/ci/module.f.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
declare const
|
|
1
|
+
import { type NodeEffect } from '../types/effect/node/module.f.ts';
|
|
2
|
+
export declare const effect: NodeEffect<number>;
|
|
3
|
+
declare const _default: () => NodeEffect<number>;
|
|
3
4
|
export default _default;
|
package/ci/module.f.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { utf8 } from "../text/module.f.js";
|
|
2
|
+
import { writeFile } from "../types/effect/node/module.f.js";
|
|
2
3
|
const os = ['ubuntu', 'macos', 'windows'];
|
|
3
4
|
const architecture = ['intel', 'arm'];
|
|
4
5
|
// https://docs.github.com/en/actions/reference/runners/github-hosted-runners#standard-github-hosted-runners-for-public-repositories
|
|
@@ -74,7 +75,7 @@ const toSteps = (m) => {
|
|
|
74
75
|
...(rust ? [{
|
|
75
76
|
// wasm32-wasip1-threads doesn't work on Rust 1.91 in the release mode.
|
|
76
77
|
// See https://github.com/sergey-shandar/wasmtime-crash
|
|
77
|
-
uses: 'dtolnay/rust-toolchain@1.
|
|
78
|
+
uses: 'dtolnay/rust-toolchain@1.93.0',
|
|
78
79
|
with: {
|
|
79
80
|
components: 'rustfmt,clippy',
|
|
80
81
|
targets
|
|
@@ -165,7 +166,6 @@ const gha = {
|
|
|
165
166
|
on: { pull_request: {} },
|
|
166
167
|
jobs,
|
|
167
168
|
};
|
|
168
|
-
export
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
169
|
+
export const effect = writeFile('.github/workflows/ci.yml', utf8(JSON.stringify(gha, null, ' ')))
|
|
170
|
+
.map(() => 0);
|
|
171
|
+
export default () => effect;
|
package/ci/module.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
await
|
|
1
|
+
import { nodeRun } from "../io/module.js";
|
|
2
|
+
import run from "./module.f.js";
|
|
3
|
+
await nodeRun(run);
|
package/dev/module.f.d.ts
CHANGED
package/dev/module.f.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { fromIo } from "../io/module.f.js";
|
|
1
2
|
import { updateVersion } from "./version/module.f.js";
|
|
2
3
|
import { decodeUtf8, encodeUtf8 } from "../types/uint8array/module.f.js";
|
|
4
|
+
import { readFile } from "../types/effect/node/module.f.js";
|
|
5
|
+
import { utf8ToString } from "../text/module.f.js";
|
|
6
|
+
import { unwrap } from "../types/result/module.f.js";
|
|
3
7
|
export const todo = () => { throw 'not implemented'; };
|
|
4
8
|
const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
|
|
5
9
|
export const env = ({ process: { env } }) => a => {
|
|
@@ -9,7 +13,7 @@ export const env = ({ process: { env } }) => a => {
|
|
|
9
13
|
r.value;
|
|
10
14
|
};
|
|
11
15
|
export const allFiles = (io) => (s) => {
|
|
12
|
-
const { fs: { promises: { readdir } }
|
|
16
|
+
const { fs: { promises: { readdir } } } = io;
|
|
13
17
|
const load = async (p) => {
|
|
14
18
|
let result = [];
|
|
15
19
|
for (const i of await readdir(p, { withFileTypes: true })) {
|
|
@@ -47,18 +51,21 @@ export const loadModuleMap = async (io) => {
|
|
|
47
51
|
}
|
|
48
52
|
return Object.fromEntries(map.toSorted(cmp));
|
|
49
53
|
};
|
|
54
|
+
const denoJson = './deno.json';
|
|
55
|
+
const index2 = updateVersion
|
|
56
|
+
.pipe(() => readFile(denoJson))
|
|
57
|
+
.map(v => JSON.parse(utf8ToString(unwrap(v))));
|
|
50
58
|
export const index = async (io) => {
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const jsr_json = JSON.parse(decodeUtf8(await io.fs.promises.readFile(jj)));
|
|
59
|
+
const runner = fromIo(io);
|
|
60
|
+
const jsr_json = await runner(index2);
|
|
54
61
|
const list = (await allFiles(io)('.')).filter(v => v.endsWith('/module.f.ts') || v.endsWith('/module.ts'));
|
|
55
|
-
//console.log(list)
|
|
62
|
+
// console.log(list)
|
|
56
63
|
const exportsA = list.map(v => [v, `./${v.substring(2)}`]);
|
|
57
64
|
// console.log(exportsA)
|
|
58
65
|
const exports = Object.fromEntries(exportsA);
|
|
59
66
|
// console.log(exports)
|
|
60
67
|
const json = JSON.stringify({ ...jsr_json, exports }, null, 2);
|
|
61
68
|
// console.log(json)
|
|
62
|
-
await io.fs.promises.writeFile(
|
|
69
|
+
await io.fs.promises.writeFile(denoJson, encodeUtf8(json));
|
|
63
70
|
return 0;
|
|
64
71
|
};
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly readFileSync: (name: string) => Uint8Array;
|
|
4
|
-
readonly writeFileSync: (name: string, content: Uint8Array) => T;
|
|
5
|
-
};
|
|
6
|
-
export type Node<T> = {
|
|
7
|
-
readonly fs: Fs<T>;
|
|
8
|
-
};
|
|
9
|
-
export declare const getVersion: <T>(fs: Fs<T>) => string;
|
|
10
|
-
export declare const updateVersion: <T>(node: Node<T>) => readonly [T, T];
|
|
11
|
-
export {};
|
|
1
|
+
import { type NodeEffect } from "../../types/effect/node/module.f.ts";
|
|
2
|
+
export declare const updateVersion: NodeEffect<number>;
|
package/dev/version/module.f.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { utf8, utf8ToString } from "../../text/module.f.js";
|
|
2
|
+
import { all } from "../../types/effect/module.f.js";
|
|
3
|
+
import { readFile, writeFile } from "../../types/effect/node/module.f.js";
|
|
4
|
+
import { unwrap } from "../../types/result/module.f.js";
|
|
2
5
|
const { stringify, parse } = JSON;
|
|
3
|
-
export const getVersion = fs => readJson(fs)('package').version;
|
|
4
6
|
const jsonFile = (jsonFile) => `${jsonFile}.json`;
|
|
5
|
-
const readJson =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const readJson = (name) => readFile(jsonFile(name))
|
|
8
|
+
.map(v => parse(utf8ToString(unwrap(v))));
|
|
9
|
+
const writeVersion = (version) => (name) => readJson(name)
|
|
10
|
+
.pipe(json => writeFile(jsonFile(name), utf8(stringify({
|
|
11
|
+
...json,
|
|
12
|
+
version,
|
|
13
|
+
}, null, 2))));
|
|
14
|
+
export const updateVersion = readJson('package')
|
|
15
|
+
.pipe(p => {
|
|
16
|
+
const w = writeVersion(p.version);
|
|
17
|
+
return all([w('package'), w('deno')]);
|
|
18
|
+
})
|
|
19
|
+
.map(() => 0);
|
package/dev/version/test.f.d.ts
CHANGED
package/dev/version/test.f.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { utf8, utf8ToString } from "../../text/module.f.js";
|
|
2
|
+
import { isVec } from "../../types/bit_vec/module.f.js";
|
|
3
|
+
import { run } from "../../types/effect/mock/module.f.js";
|
|
4
|
+
import { all } from "../../types/effect/module.f.js";
|
|
5
|
+
import { writeFile } from "../../types/effect/node/module.f.js";
|
|
6
|
+
import { emptyState, virtual } from "../../types/effect/node/virtual/module.f.js";
|
|
7
|
+
import { updateVersion } from "./module.f.js";
|
|
3
8
|
const version = '0.3.0';
|
|
4
9
|
const x = {
|
|
5
10
|
'package.json': {
|
|
@@ -74,15 +79,25 @@ const e = '{\n' +
|
|
|
74
79
|
' "typescript": "^4.7.4"\n' +
|
|
75
80
|
' }\n' +
|
|
76
81
|
'}';
|
|
77
|
-
export default
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
export default {
|
|
83
|
+
new: () => {
|
|
84
|
+
const rv = run(virtual);
|
|
85
|
+
const w = (name) => {
|
|
86
|
+
const fn = `${name}.json`;
|
|
87
|
+
return writeFile(fn, utf8(JSON.stringify(x[fn])));
|
|
88
|
+
};
|
|
89
|
+
const [state] = rv(emptyState)(all([w('package'), w('deno')]));
|
|
90
|
+
const [newState, result] = rv(state)(updateVersion);
|
|
91
|
+
if (result !== 0) {
|
|
92
|
+
throw result;
|
|
93
|
+
}
|
|
94
|
+
const vec = newState.root['package.json'];
|
|
95
|
+
if (!isVec(vec)) {
|
|
96
|
+
throw vec;
|
|
97
|
+
}
|
|
98
|
+
const n = utf8ToString(vec);
|
|
99
|
+
if (n !== e) {
|
|
100
|
+
throw [n, e];
|
|
82
101
|
}
|
|
83
|
-
};
|
|
84
|
-
const [n, d] = _.updateVersion(node);
|
|
85
|
-
if (n !== e) {
|
|
86
|
-
throw [n, e];
|
|
87
102
|
}
|
|
88
103
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { descentParser } from "../../bnf/data/module.f.js";
|
|
2
|
+
import { eof, join0Plus, max, none, not, notSet, oneEncode, option, range, remove, repeat, repeat0Plus, repeat1Plus, set, unicodeRange } from "../../bnf/module.f.js";
|
|
3
|
+
import { todo } from "../../dev/module.f.js";
|
|
4
|
+
export const parse = (input) => {
|
|
5
|
+
const m = descentParser(jsGrammar());
|
|
6
|
+
return todo();
|
|
7
|
+
};
|
|
8
|
+
export const jsGrammar = () => {
|
|
9
|
+
const onenine = range('19');
|
|
10
|
+
const digit = range('09');
|
|
11
|
+
const string = [
|
|
12
|
+
'"',
|
|
13
|
+
repeat0Plus({
|
|
14
|
+
...remove(range(` ${max}`), set('"\\')),
|
|
15
|
+
escape: [
|
|
16
|
+
'\\',
|
|
17
|
+
{
|
|
18
|
+
...set('"\\/bfnrt'),
|
|
19
|
+
u: [
|
|
20
|
+
'u',
|
|
21
|
+
...repeat(4)({
|
|
22
|
+
digit,
|
|
23
|
+
AF: range('AF'),
|
|
24
|
+
af: range('af'),
|
|
25
|
+
})
|
|
26
|
+
],
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
'"'
|
|
31
|
+
];
|
|
32
|
+
const digits0 = repeat0Plus(digit);
|
|
33
|
+
const digits = [digit, digits0];
|
|
34
|
+
const number = [
|
|
35
|
+
{
|
|
36
|
+
0: '0',
|
|
37
|
+
onenine: [onenine, digits0],
|
|
38
|
+
},
|
|
39
|
+
option({
|
|
40
|
+
bigint: 'n',
|
|
41
|
+
frac: [
|
|
42
|
+
option(['.', digits]),
|
|
43
|
+
option([set('Ee'), option(set('+-')), digits])
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
const ws = set(' \t');
|
|
48
|
+
const newLine = set('\n\r');
|
|
49
|
+
const idStart = {
|
|
50
|
+
smallLetter: range('az'),
|
|
51
|
+
bigLetter: range('AZ'),
|
|
52
|
+
lowLine: '_',
|
|
53
|
+
dollarSign: '$'
|
|
54
|
+
};
|
|
55
|
+
const idChar = {
|
|
56
|
+
...idStart,
|
|
57
|
+
digit
|
|
58
|
+
};
|
|
59
|
+
const id = [idStart, repeat0Plus(idChar)];
|
|
60
|
+
const operator = {
|
|
61
|
+
'.': '.',
|
|
62
|
+
'=>': '=>',
|
|
63
|
+
'===': '===',
|
|
64
|
+
'==': '==',
|
|
65
|
+
'=': '=',
|
|
66
|
+
'!==': '!==',
|
|
67
|
+
'!=': '!=',
|
|
68
|
+
'!': '!',
|
|
69
|
+
'>>>=': '>>>=',
|
|
70
|
+
'>>>': '>>>',
|
|
71
|
+
'>>=': '>>=',
|
|
72
|
+
'>>': '>>',
|
|
73
|
+
'>=': '>=',
|
|
74
|
+
'>': '>',
|
|
75
|
+
'<<<<=': '<<<=',
|
|
76
|
+
'<<<': '<<<',
|
|
77
|
+
'<<=': '<<=',
|
|
78
|
+
'<<': '<<',
|
|
79
|
+
'<=': '<=',
|
|
80
|
+
'<': '<',
|
|
81
|
+
'+=': '+=',
|
|
82
|
+
'++': '++',
|
|
83
|
+
'+': '+',
|
|
84
|
+
'-=': '-=',
|
|
85
|
+
'--': '--',
|
|
86
|
+
'-': '-',
|
|
87
|
+
'**=': '**=',
|
|
88
|
+
'**': '**',
|
|
89
|
+
'*=': '*=',
|
|
90
|
+
'*': '*',
|
|
91
|
+
'/=': '/=',
|
|
92
|
+
'/': '/',
|
|
93
|
+
'%=': '%=',
|
|
94
|
+
'%': '%',
|
|
95
|
+
'&&=': '&&=',
|
|
96
|
+
'&&': '&&',
|
|
97
|
+
'&=': '&=',
|
|
98
|
+
'&': '&',
|
|
99
|
+
'||=': '||=',
|
|
100
|
+
'||': '||',
|
|
101
|
+
'|=': '|=',
|
|
102
|
+
'|': '|',
|
|
103
|
+
'^=': '^=',
|
|
104
|
+
'^': '^',
|
|
105
|
+
'~': '~',
|
|
106
|
+
'??=': '??=',
|
|
107
|
+
'??': '??',
|
|
108
|
+
'?.': '?.',
|
|
109
|
+
'?': '?',
|
|
110
|
+
'[': '[',
|
|
111
|
+
']': ']',
|
|
112
|
+
'{': '{',
|
|
113
|
+
'}': '}',
|
|
114
|
+
'(': '(',
|
|
115
|
+
')': ')',
|
|
116
|
+
',': ',',
|
|
117
|
+
':': ':'
|
|
118
|
+
};
|
|
119
|
+
const commentEnd = {
|
|
120
|
+
...newLine,
|
|
121
|
+
eof
|
|
122
|
+
};
|
|
123
|
+
const comment = ['/', {
|
|
124
|
+
// TODO: investigate why `not(commentEnd)` instead of `remove(unicodeRange, newLine)` fail tests.
|
|
125
|
+
// TODO: should it be `repeat0Plus(not(commentEnd))` instead of `option(remove(unicodeRange, newLine))`.
|
|
126
|
+
oneline: ['/', option(remove(unicodeRange, newLine)), commentEnd],
|
|
127
|
+
multiline: [
|
|
128
|
+
'*',
|
|
129
|
+
repeat0Plus({
|
|
130
|
+
na: notSet('*'),
|
|
131
|
+
a: ['*', notSet('/')]
|
|
132
|
+
}),
|
|
133
|
+
'*/'
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
const endOfFile = oneEncode(eof);
|
|
138
|
+
const token = {
|
|
139
|
+
number,
|
|
140
|
+
string,
|
|
141
|
+
id,
|
|
142
|
+
comment,
|
|
143
|
+
operator,
|
|
144
|
+
ws,
|
|
145
|
+
newLine,
|
|
146
|
+
//endOfFile
|
|
147
|
+
};
|
|
148
|
+
const tokens = repeat0Plus(token);
|
|
149
|
+
return tokens;
|
|
150
|
+
};
|