functionalscript 0.8.0 → 0.8.1
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/bnf/data/module.f.d.ts +6 -0
- package/bnf/data/module.f.js +57 -4
- package/bnf/data/test.f.d.ts +1 -0
- package/bnf/data/test.f.js +67 -1
- package/ci/module.f.d.ts +3 -0
- package/ci/module.f.js +169 -0
- package/ci/module.js +3 -0
- package/crypto/hmac/module.f.d.ts +5 -4
- package/crypto/hmac/module.f.js +9 -18
- package/crypto/hmac/test.f.d.ts +1 -0
- package/crypto/hmac/test.f.js +16 -8
- package/crypto/prime_field/module.f.d.ts +1 -1
- package/crypto/prime_field/module.f.js +4 -3
- package/crypto/prime_field/test.f.js +13 -13
- package/crypto/rfc6979/module.f.d.ts +15 -0
- package/crypto/rfc6979/module.f.js +98 -0
- package/crypto/rfc6979/test.f.d.ts +10 -0
- package/crypto/rfc6979/test.f.js +490 -0
- package/crypto/secp/module.f.d.ts +4 -4
- package/crypto/secp/module.f.js +1 -1
- package/crypto/secp/test.f.js +8 -8
- package/crypto/sha2/module.f.d.ts +11 -5
- package/crypto/sha2/module.f.js +4 -3
- package/crypto/sha2/test.f.d.ts +4 -1
- package/crypto/sha2/test.f.js +41 -31
- package/crypto/sign/module.f.d.ts +1 -1
- package/crypto/sign/module.f.js +3 -2
- package/dev/tf/all.test.js +9 -1
- package/djs/ast/module.f.d.ts +3 -3
- package/djs/ast/test.f.js +7 -8
- package/djs/parser/module.f.d.ts +3 -3
- package/djs/parser/module.f.js +4 -4
- package/djs/parser/test.f.js +76 -77
- package/djs/serializer/module.f.d.ts +8 -8
- package/djs/serializer/module.f.js +4 -7
- package/djs/serializer/test.f.js +8 -9
- package/djs/tokenizer/module.f.d.ts +2 -2
- package/djs/tokenizer/module.f.js +3 -5
- package/djs/tokenizer/test.f.js +8 -10
- package/djs/transpiler/module.f.d.ts +3 -3
- package/djs/transpiler/module.f.js +2 -0
- package/fsc/bnf.f.d.ts +1 -1
- package/fsc/bnf.f.js +39 -51
- package/fsc/json.f.d.ts +1 -1
- package/fsc/json.f.js +56 -81
- package/fsc/test.f.js +4 -6
- package/fsm/module.f.js +3 -3
- package/fsm/test.f.js +21 -25
- package/html/module.f.js +17 -4
- package/html/test.f.d.ts +7 -0
- package/html/test.f.js +37 -0
- package/issues/031-json.f.d.ts +1 -0
- package/js/tokenizer/module.f.d.ts +4 -4
- package/js/tokenizer/module.f.js +12 -17
- package/js/tokenizer/test.f.js +9 -11
- package/json/module.f.d.ts +6 -6
- package/json/module.f.js +5 -10
- package/json/parser/module.f.d.ts +4 -4
- package/json/parser/module.f.js +7 -4
- package/json/parser/test.f.js +47 -49
- package/json/serializer/module.f.d.ts +6 -6
- package/json/serializer/module.f.js +3 -2
- package/json/serializer/test.f.js +13 -13
- package/json/test.f.js +13 -15
- package/json/tokenizer/module.f.d.ts +4 -4
- package/json/tokenizer/module.f.js +6 -7
- package/json/tokenizer/test.f.js +7 -9
- package/package.json +5 -5
- package/text/ascii/test.f.js +2 -2
- package/text/module.f.d.ts +3 -2
- package/text/module.f.js +2 -2
- package/text/test.f.js +3 -3
- package/text/utf16/test.f.js +2 -2
- package/text/utf8/test.f.js +2 -2
- package/types/array/test.f.js +2 -2
- package/types/bigint/module.f.d.ts +6 -3
- package/types/bigint/module.f.js +12 -11
- package/types/bigint/test.f.d.ts +2 -0
- package/types/bigint/test.f.js +21 -2
- package/types/bit_vec/module.f.d.ts +66 -34
- package/types/bit_vec/module.f.js +97 -32
- package/types/bit_vec/test.f.d.ts +7 -0
- package/types/bit_vec/test.f.js +283 -62
- package/types/btree/find/test.f.js +9 -8
- package/types/btree/remove/test.f.js +4 -4
- package/types/btree/set/test.f.js +4 -4
- package/types/btree/test.f.js +7 -7
- package/types/byte_set/test.f.js +2 -2
- package/types/function/compare/module.f.d.ts +15 -1
- package/types/function/compare/module.f.js +1 -1
- package/types/function/compare/test.f.js +37 -4
- package/types/list/test.f.js +93 -93
- package/types/monoid/module.f.d.ts +4 -4
- package/types/monoid/module.f.js +3 -3
- package/types/monoid/test.f.js +3 -3
- package/types/nominal/module.f.d.ts +5 -0
- package/types/nominal/module.f.js +4 -0
- package/types/nominal/test.f.d.ts +5 -0
- package/types/nominal/test.f.js +53 -0
- package/types/number/module.f.js +2 -2
- package/types/range_map/test.f.js +21 -21
- package/types/sorted_list/test.f.js +10 -10
- package/types/sorted_set/test.f.js +14 -14
- package/types/string/module.f.js +2 -2
- package/types/string_set/module.f.js +3 -3
- package/bnf/func/module.f.d.ts +0 -148
- package/bnf/func/module.f.js +0 -132
- package/bnf/func/test.f.d.ts +0 -12
- package/bnf/func/test.f.js +0 -171
- package/bnf/func/testlib.f.d.ts +0 -25
- package/bnf/func/testlib.f.js +0 -150
- /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
- /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
package/djs/serializer/test.f.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { countRefs, stringify, stringifyAsTree } from "./module.f.js";
|
|
2
|
-
import
|
|
3
|
-
const { sort } = list;
|
|
2
|
+
import { sort } from "../../types/object/module.f.js";
|
|
4
3
|
import { identity } from "../../types/function/module.f.js";
|
|
5
|
-
import
|
|
4
|
+
import { setProperty } from "../../json/module.f.js";
|
|
6
5
|
export default {
|
|
7
6
|
stringify: [
|
|
8
7
|
{
|
|
@@ -83,14 +82,14 @@ export default {
|
|
|
83
82
|
stringifyAsTree: [
|
|
84
83
|
{
|
|
85
84
|
sort: () => {
|
|
86
|
-
const r =
|
|
85
|
+
const r = setProperty("Hello")(['a'])({});
|
|
87
86
|
const x = stringifyAsTree(sort)(r);
|
|
88
87
|
if (x !== '{"a":"Hello"}') {
|
|
89
88
|
throw x;
|
|
90
89
|
}
|
|
91
90
|
},
|
|
92
91
|
identity: () => {
|
|
93
|
-
const x = stringifyAsTree(identity)(
|
|
92
|
+
const x = stringifyAsTree(identity)(setProperty("Hello")(['a'])({}));
|
|
94
93
|
if (x !== '{"a":"Hello"}') {
|
|
95
94
|
throw x;
|
|
96
95
|
}
|
|
@@ -98,13 +97,13 @@ export default {
|
|
|
98
97
|
},
|
|
99
98
|
{
|
|
100
99
|
sort: () => {
|
|
101
|
-
const x = stringifyAsTree(sort)(
|
|
100
|
+
const x = stringifyAsTree(sort)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
|
|
102
101
|
if (x !== '{"a":"Hello","b":12,"c":[]}') {
|
|
103
102
|
throw x;
|
|
104
103
|
}
|
|
105
104
|
},
|
|
106
105
|
identity: () => {
|
|
107
|
-
const x = stringifyAsTree(identity)(
|
|
106
|
+
const x = stringifyAsTree(identity)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
|
|
108
107
|
if (x !== '{"c":[],"b":12,"a":"Hello"}') {
|
|
109
108
|
throw x;
|
|
110
109
|
}
|
|
@@ -113,7 +112,7 @@ export default {
|
|
|
113
112
|
{
|
|
114
113
|
sort: () => {
|
|
115
114
|
const _0 = { a: { y: [24] }, c: [], b: 12 };
|
|
116
|
-
const _1 =
|
|
115
|
+
const _1 = setProperty("Hello")(['a', 'x'])(_0);
|
|
117
116
|
const _2 = stringifyAsTree(sort)(_1);
|
|
118
117
|
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') {
|
|
119
118
|
throw _2;
|
|
@@ -121,7 +120,7 @@ export default {
|
|
|
121
120
|
},
|
|
122
121
|
identity: () => {
|
|
123
122
|
const _0 = { a: { y: [24] }, c: [], b: 12 };
|
|
124
|
-
const _1 =
|
|
123
|
+
const _1 = setProperty("Hello")(['a', 'x'])(_0);
|
|
125
124
|
const _2 = stringifyAsTree(identity)(_1);
|
|
126
125
|
if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') {
|
|
127
126
|
throw _2;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type List } from '../../types/list/module.f.ts';
|
|
2
2
|
import * as jsTokenizer from '../../js/tokenizer/module.f.ts';
|
|
3
3
|
export type DjsToken = {
|
|
4
4
|
readonly kind: 'true' | 'false' | 'null' | 'undefined';
|
|
@@ -9,4 +9,4 @@ export type DjsTokenWithMetadata = {
|
|
|
9
9
|
readonly token: DjsToken;
|
|
10
10
|
readonly metadata: jsTokenizer.TokenMetadata;
|
|
11
11
|
};
|
|
12
|
-
export declare const tokenize: (input:
|
|
12
|
+
export declare const tokenize: (input: List<number>) => (path: string) => List<DjsTokenWithMetadata>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as bf from "../../types/bigfloat/module.f.js";
|
|
4
|
-
const { multiply } = bf;
|
|
1
|
+
import { empty, flat, map, stateScan } from "../../types/list/module.f.js";
|
|
2
|
+
import { multiply } from "../../types/bigfloat/module.f.js";
|
|
5
3
|
import * as jsTokenizer from "../../js/tokenizer/module.f.js";
|
|
6
4
|
const mapToken = input => {
|
|
7
5
|
switch (input.kind) {
|
|
@@ -55,7 +53,7 @@ const scanToken = state => input => {
|
|
|
55
53
|
const mapTokenWithMetadata = metadata => token => { return { token, metadata }; };
|
|
56
54
|
const scanTokenWithMetadata = state => (input) => {
|
|
57
55
|
const [djsTokens, newState] = scanToken(state)(input.token);
|
|
58
|
-
const djsTokensWithMetadata =
|
|
56
|
+
const djsTokensWithMetadata = map(mapTokenWithMetadata(input.metadata))(djsTokens);
|
|
59
57
|
return [djsTokensWithMetadata, newState];
|
|
60
58
|
};
|
|
61
59
|
export const tokenize = input => path => {
|
package/djs/tokenizer/test.f.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const tokenizeStringWithMetadata = s => toArray(tokenizer.tokenize(encoding.stringToList(s))(''));
|
|
10
|
-
const stringify = serializer.stringifyAsTree(sort);
|
|
1
|
+
import { tokenize } from "./module.f.js";
|
|
2
|
+
import { map, toArray } from "../../types/list/module.f.js";
|
|
3
|
+
import { stringifyAsTree } from "../serializer/module.f.js";
|
|
4
|
+
import { sort } from "../../types/object/module.f.js";
|
|
5
|
+
import { stringToList } from "../../text/utf16/module.f.js";
|
|
6
|
+
const tokenizeString = s => toArray(map(withoutMetada)(tokenize(stringToList(s))('')));
|
|
7
|
+
const tokenizeStringWithMetadata = s => toArray(tokenize(stringToList(s))(''));
|
|
8
|
+
const stringify = stringifyAsTree(sort);
|
|
11
9
|
const withoutMetada = tokenWithMetada => { return tokenWithMetada.token; };
|
|
12
10
|
export default {
|
|
13
11
|
djs: [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Unknown } from '../module.f.ts';
|
|
2
2
|
import { type Result } from '../../types/result/module.f.ts';
|
|
3
3
|
import { type List } from '../../types/list/module.f.ts';
|
|
4
4
|
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
@@ -11,6 +11,6 @@ export type ParseContext = {
|
|
|
11
11
|
readonly error: ParseError | null;
|
|
12
12
|
};
|
|
13
13
|
export type djsResult = {
|
|
14
|
-
djs:
|
|
14
|
+
djs: Unknown;
|
|
15
15
|
};
|
|
16
|
-
export declare const transpile: (fs: Fs) => (path: string) => Result<
|
|
16
|
+
export declare const transpile: (fs: Fs) => (path: string) => Result<Unknown, ParseError>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {} from "../module.f.js";
|
|
1
2
|
import { error, ok } from "../../types/result/module.f.js";
|
|
2
3
|
import { fold, drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
|
|
4
|
+
import {} from "../../types/function/operator/module.f.js";
|
|
3
5
|
import { tokenize } from "../tokenizer/module.f.js";
|
|
4
6
|
import { setReplace, at } from "../../types/ordered_map/module.f.js";
|
|
5
7
|
import { stringToList } from "../../text/utf16/module.f.js";
|
package/fsc/bnf.f.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type Rule } from '../bnf/
|
|
1
|
+
import { type Rule } from '../bnf/module.f.ts';
|
|
2
2
|
export declare const wsModule: Rule;
|
package/fsc/bnf.f.js
CHANGED
|
@@ -1,54 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { range, remove, set, option } from "../bnf/module.f.js";
|
|
2
2
|
import { digit, json, unicode, ws0, ws1, wsNoNewLine0 } from "./json.f.js";
|
|
3
|
-
export const wsModule = () => [
|
|
4
|
-
const module = () =>
|
|
5
|
-
[json, ws0],
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fjs = () =>
|
|
9
|
-
[],
|
|
10
|
-
[
|
|
11
|
-
|
|
12
|
-
];
|
|
13
|
-
const fjsTail = () => [
|
|
14
|
-
[],
|
|
15
|
-
[cp('\n'), ws0, fjs],
|
|
16
|
-
];
|
|
3
|
+
export const wsModule = () => [ws0, module];
|
|
4
|
+
const module = () => ({
|
|
5
|
+
json: [json, ws0],
|
|
6
|
+
fjs,
|
|
7
|
+
});
|
|
8
|
+
const fjs = () => option({
|
|
9
|
+
const: ['const', ws1, id, ws0, '=', ws0, json, wsNoNewLine0, fjsTail],
|
|
10
|
+
export: ['export', ws1, 'default', ws1, json],
|
|
11
|
+
});
|
|
12
|
+
const fjsTail = option(['\n', ws0, fjs]);
|
|
17
13
|
// line comment
|
|
18
|
-
const lineItem =
|
|
19
|
-
const line = () => [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
[
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[
|
|
34
|
-
|
|
35
|
-
];
|
|
36
|
-
const commentTail = () => [
|
|
37
|
-
[cp('/'), lineComment],
|
|
38
|
-
[cp('*'), multiLine],
|
|
39
|
-
];
|
|
14
|
+
const lineItem = remove(unicode, set('\n'));
|
|
15
|
+
const line = () => option([lineItem, line]);
|
|
16
|
+
const lineComment = () => ['/', commentTail, '\n'];
|
|
17
|
+
const multiLineSkip = remove(unicode, set('/'));
|
|
18
|
+
const multiLineItem = remove(unicode, set('*'));
|
|
19
|
+
const multiLine = () => ({
|
|
20
|
+
'*': ['*', multiLineTail],
|
|
21
|
+
'_': [multiLineItem, multiLine]
|
|
22
|
+
});
|
|
23
|
+
const multiLineTail = {
|
|
24
|
+
'/': '/',
|
|
25
|
+
'_': [multiLineSkip, multiLine]
|
|
26
|
+
};
|
|
27
|
+
const commentTail = {
|
|
28
|
+
'/': ['/', lineComment],
|
|
29
|
+
'*': ['*', multiLine],
|
|
30
|
+
};
|
|
40
31
|
// id
|
|
41
|
-
const id = () => [
|
|
42
|
-
const alpha =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const idTail0 = () => [
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
[alpha],
|
|
53
|
-
[digit],
|
|
54
|
-
];
|
|
32
|
+
const id = () => [alpha, idTail0];
|
|
33
|
+
const alpha = {
|
|
34
|
+
upper: range('AZ'),
|
|
35
|
+
lower: range('az'),
|
|
36
|
+
_: set('_$'),
|
|
37
|
+
};
|
|
38
|
+
const idTail0 = () => option([alphaDigit, idTail0]);
|
|
39
|
+
const alphaDigit = {
|
|
40
|
+
alpha,
|
|
41
|
+
digit,
|
|
42
|
+
};
|
package/fsc/json.f.d.ts
CHANGED
package/fsc/json.f.js
CHANGED
|
@@ -1,89 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join0Plus, rangeEncode, range, remove, repeat0Plus, set, option } from "../bnf/module.f.js";
|
|
2
2
|
// space
|
|
3
|
-
const wsNoNewLineItem =
|
|
4
|
-
export const wsNoNewLine0 = ()
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
];
|
|
12
|
-
export const ws0 = () => [
|
|
13
|
-
[],
|
|
14
|
-
[ws1],
|
|
15
|
-
];
|
|
16
|
-
export const ws1 = () => [
|
|
17
|
-
[wsItem, ws0]
|
|
18
|
-
];
|
|
3
|
+
const wsNoNewLineItem = set(' \t\r');
|
|
4
|
+
export const wsNoNewLine0 = repeat0Plus(wsNoNewLineItem);
|
|
5
|
+
const wsItem = {
|
|
6
|
+
wsNoNewLineItem,
|
|
7
|
+
n: '\n',
|
|
8
|
+
};
|
|
9
|
+
export const ws0 = () => option(ws1);
|
|
10
|
+
export const ws1 = [wsItem, ws0];
|
|
19
11
|
//
|
|
20
|
-
export const json = () =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
export const json = () => ({
|
|
13
|
+
object,
|
|
14
|
+
array,
|
|
15
|
+
number,
|
|
16
|
+
string,
|
|
17
|
+
true: 'true',
|
|
18
|
+
false: 'false',
|
|
19
|
+
null: 'null',
|
|
20
|
+
});
|
|
29
21
|
//
|
|
30
|
-
const separator =
|
|
22
|
+
const separator = [',', ws0];
|
|
31
23
|
// object
|
|
32
|
-
const member = () => [
|
|
33
|
-
const object = ()
|
|
34
|
-
[cp('{'), ws0, join0(member, separator), cp('}')]
|
|
35
|
-
];
|
|
24
|
+
const member = () => [string, ws0, ':', ws0, json, ws0];
|
|
25
|
+
const object = ['{', ws0, join0Plus(member, separator), '}'];
|
|
36
26
|
// array
|
|
37
|
-
const element =
|
|
38
|
-
|
|
39
|
-
];
|
|
40
|
-
const array = () => [
|
|
41
|
-
[cp('['), ws0, join0(element, separator), cp(']')]
|
|
42
|
-
];
|
|
27
|
+
const element = [json, ws0];
|
|
28
|
+
const array = ['[', ws0, join0Plus(element, separator), ']'];
|
|
43
29
|
// string
|
|
44
|
-
const character = () =>
|
|
45
|
-
...remove(unicode,
|
|
46
|
-
[
|
|
47
|
-
|
|
48
|
-
const string =
|
|
49
|
-
export const unicode =
|
|
50
|
-
const escape = () =>
|
|
30
|
+
const character = () => ({
|
|
31
|
+
...remove(unicode, set('"\\')),
|
|
32
|
+
'\\': ['\\', escape],
|
|
33
|
+
});
|
|
34
|
+
const string = ['"', repeat0Plus(character), '"'];
|
|
35
|
+
export const unicode = rangeEncode(0x20, 0x10FFFF);
|
|
36
|
+
const escape = () => ({
|
|
51
37
|
...set('"\\/bfnrt'),
|
|
52
|
-
[
|
|
53
|
-
|
|
54
|
-
const hex = () =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
'u': ['u', hex, hex, hex, hex] // 117
|
|
39
|
+
});
|
|
40
|
+
const hex = () => ({
|
|
41
|
+
digit,
|
|
42
|
+
upper: range('AF'),
|
|
43
|
+
lower: range('af'),
|
|
44
|
+
});
|
|
59
45
|
// number
|
|
60
|
-
const number = () =>
|
|
61
|
-
|
|
62
|
-
[
|
|
63
|
-
|
|
64
|
-
const uNumber = () => [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
];
|
|
80
|
-
const exponent0 = () => [
|
|
81
|
-
[],
|
|
82
|
-
[e, sign, digits1],
|
|
83
|
-
];
|
|
84
|
-
const e = () => set('eE');
|
|
85
|
-
const sign = () => [
|
|
86
|
-
[],
|
|
87
|
-
[cp('+')],
|
|
88
|
-
[cp('-')],
|
|
89
|
-
];
|
|
46
|
+
const number = () => ({
|
|
47
|
+
uNumber,
|
|
48
|
+
minus: ['-', uNumber],
|
|
49
|
+
});
|
|
50
|
+
const uNumber = () => [uint, fraction0, exponent0];
|
|
51
|
+
const uint = () => ({
|
|
52
|
+
'0': '0',
|
|
53
|
+
'19': [range('19'), digits0]
|
|
54
|
+
});
|
|
55
|
+
export const digit = range('09');
|
|
56
|
+
const digits0 = repeat0Plus(digit);
|
|
57
|
+
const digits1 = [digit, digits0];
|
|
58
|
+
const fraction0 = option(['.', digits1]);
|
|
59
|
+
const exponent0 = () => option([e, sign, digits1]);
|
|
60
|
+
const e = set('eE');
|
|
61
|
+
const sign = option({
|
|
62
|
+
'+': '+',
|
|
63
|
+
'-': '-',
|
|
64
|
+
});
|
package/fsc/test.f.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import * as j from "../json/module.f.js";
|
|
5
|
-
const { stringify } = j;
|
|
1
|
+
import { init } from "./module.f.js";
|
|
2
|
+
import { one } from "../text/ascii/module.f.js";
|
|
3
|
+
import { stringify } from "../json/module.f.js";
|
|
6
4
|
const s = stringify(i => i);
|
|
7
5
|
const f = v => {
|
|
8
6
|
const n = one(v);
|
|
9
|
-
return s(
|
|
7
|
+
return s(init(n)[0]);
|
|
10
8
|
};
|
|
11
9
|
// this doesn't change a name of the function
|
|
12
10
|
const fn = (f, name) => ({ [name]: f }[name]);
|
package/fsm/module.f.js
CHANGED
|
@@ -2,11 +2,11 @@ import { equal, isEmpty, fold, toArray, scan, foldScan, empty as emptyList } fro
|
|
|
2
2
|
import { toRangeMap, union as byteSetUnion, one, empty, range } from "../types/byte_set/module.f.js";
|
|
3
3
|
import { intersect, union as sortedSetUnion } from "../types/sorted_set/module.f.js";
|
|
4
4
|
import { merge, get as rangeMapGet } from "../types/range_map/module.f.js";
|
|
5
|
-
import { unsafeCmp } from "../types/function/compare/module.f.js";
|
|
6
5
|
import { strictEqual } from "../types/function/operator/module.f.js";
|
|
7
6
|
import { stringify } from "../json/module.f.js";
|
|
8
7
|
import { identity } from "../types/function/module.f.js";
|
|
9
8
|
import { stringToList } from "../text/utf16/module.f.js";
|
|
9
|
+
import { cmp } from "../types/string/module.f.js";
|
|
10
10
|
const stringifyIdentity = stringify(identity);
|
|
11
11
|
export const toRange = s => {
|
|
12
12
|
const [b, e] = toArray(stringToList(s));
|
|
@@ -17,8 +17,8 @@ export const toUnion = s => {
|
|
|
17
17
|
const codePoints = stringToList(s);
|
|
18
18
|
return fold(toUnionOp)(empty)(codePoints);
|
|
19
19
|
};
|
|
20
|
-
const mergeOp = { union: sortedSetUnion(
|
|
21
|
-
const hasState = s => set => !isEmpty(intersect(
|
|
20
|
+
const mergeOp = { union: sortedSetUnion(cmp), equal: equal(strictEqual), def: [] };
|
|
21
|
+
const hasState = s => set => !isEmpty(intersect(cmp)([s])(set));
|
|
22
22
|
const foldOp = set => ([ruleIn, bs, ruleOut]) => rm => {
|
|
23
23
|
if (hasState(ruleIn)(set)) {
|
|
24
24
|
return merge(mergeOp)(rm)(toRangeMap(bs)(ruleOut));
|
package/fsm/test.f.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { toArray } = list;
|
|
10
|
-
import * as utf16 from "../text/utf16/module.f.js";
|
|
11
|
-
const { stringToList } = utf16;
|
|
12
|
-
const stringifyIdentity = json.stringify(identity);
|
|
1
|
+
import { dfa, run, toRange, toUnion } from "./module.f.js";
|
|
2
|
+
import { union } from "../types/byte_set/module.f.js";
|
|
3
|
+
import { sort, fromEntries } from "../types/object/module.f.js";
|
|
4
|
+
import { stringify } from "../json/module.f.js";
|
|
5
|
+
import { identity } from "../types/function/module.f.js";
|
|
6
|
+
import { toArray } from "../types/list/module.f.js";
|
|
7
|
+
import { stringToList } from "../text/utf16/module.f.js";
|
|
8
|
+
const stringifyIdentity = stringify(identity);
|
|
13
9
|
const buildDfa = () => {
|
|
14
|
-
const lowercaseAlpha =
|
|
15
|
-
const uppercaseAlpha =
|
|
16
|
-
const alpha =
|
|
17
|
-
const idSymbol =
|
|
18
|
-
const idBegin =
|
|
19
|
-
const digit =
|
|
20
|
-
const idNext =
|
|
21
|
-
const dot =
|
|
10
|
+
const lowercaseAlpha = toRange('az');
|
|
11
|
+
const uppercaseAlpha = toRange('AZ');
|
|
12
|
+
const alpha = union(lowercaseAlpha)(uppercaseAlpha);
|
|
13
|
+
const idSymbol = toUnion('_$');
|
|
14
|
+
const idBegin = union(alpha)(idSymbol);
|
|
15
|
+
const digit = toRange('09');
|
|
16
|
+
const idNext = union(idBegin)(digit);
|
|
17
|
+
const dot = toUnion('.');
|
|
22
18
|
const grammar = [
|
|
23
19
|
['', digit, 'int'],
|
|
24
20
|
['int', digit, 'int'],
|
|
@@ -30,7 +26,7 @@ const buildDfa = () => {
|
|
|
30
26
|
['', idBegin, 'id'],
|
|
31
27
|
['id', idNext, 'id']
|
|
32
28
|
];
|
|
33
|
-
return
|
|
29
|
+
return dfa(grammar);
|
|
34
30
|
};
|
|
35
31
|
export default {
|
|
36
32
|
dfa: () => {
|
|
@@ -83,7 +79,7 @@ export default {
|
|
|
83
79
|
() => {
|
|
84
80
|
const dfa = buildDfa();
|
|
85
81
|
const input = stringToList('a1');
|
|
86
|
-
const result = stringifyIdentity(toArray(
|
|
82
|
+
const result = stringifyIdentity(toArray(run(dfa)(input)));
|
|
87
83
|
const expectedOutput = [
|
|
88
84
|
'["id"]',
|
|
89
85
|
'["id"]'
|
|
@@ -96,7 +92,7 @@ export default {
|
|
|
96
92
|
() => {
|
|
97
93
|
const dfa = buildDfa();
|
|
98
94
|
const input = stringToList('0.1');
|
|
99
|
-
const result = stringifyIdentity(toArray(
|
|
95
|
+
const result = stringifyIdentity(toArray(run(dfa)(input)));
|
|
100
96
|
const expectedOutput = [
|
|
101
97
|
'["floatBegin","int"]',
|
|
102
98
|
'["floatDot"]',
|
|
@@ -110,7 +106,7 @@ export default {
|
|
|
110
106
|
() => {
|
|
111
107
|
const dfa = buildDfa();
|
|
112
108
|
const input = stringToList('//');
|
|
113
|
-
const result = stringifyIdentity(toArray(
|
|
109
|
+
const result = stringifyIdentity(toArray(run(dfa)(input)));
|
|
114
110
|
const expectedOutput = [
|
|
115
111
|
'[]',
|
|
116
112
|
'[]'
|
|
@@ -123,7 +119,7 @@ export default {
|
|
|
123
119
|
() => {
|
|
124
120
|
const dfa = buildDfa();
|
|
125
121
|
const input = stringToList('::');
|
|
126
|
-
const result = stringifyIdentity(toArray(
|
|
122
|
+
const result = stringifyIdentity(toArray(run(dfa)(input)));
|
|
127
123
|
const expectedOutput = [
|
|
128
124
|
'[]',
|
|
129
125
|
'[]'
|
package/html/module.f.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { map, flatMap, flat, concat as listConcat } from "../types/list/module.f.js";
|
|
2
|
-
import { concat as stringConcat } from "../types/string/module.f.js";
|
|
2
|
+
import { concat, concat as stringConcat } from "../types/string/module.f.js";
|
|
3
3
|
import { compose } from "../types/function/module.f.js";
|
|
4
4
|
import { stringToList } from "../text/utf16/module.f.js";
|
|
5
5
|
const { fromCharCode } = String;
|
|
@@ -25,6 +25,14 @@ const voidTagList = [
|
|
|
25
25
|
'track',
|
|
26
26
|
'wbr',
|
|
27
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script
|
|
30
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/style
|
|
31
|
+
*/
|
|
32
|
+
const rawText = [
|
|
33
|
+
'script',
|
|
34
|
+
'style'
|
|
35
|
+
];
|
|
28
36
|
/**
|
|
29
37
|
* https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-in-html
|
|
30
38
|
*/
|
|
@@ -40,6 +48,10 @@ const escapeCharCode = (code) => {
|
|
|
40
48
|
const escape = compose(stringToList)(map(escapeCharCode));
|
|
41
49
|
const node = (n) => typeof n === 'string' ? escape(n) : element(n);
|
|
42
50
|
const nodes = flatMap(node);
|
|
51
|
+
const raw = (n) => typeof n === 'string' ? n : '';
|
|
52
|
+
const mr = map(raw);
|
|
53
|
+
// Escape closing tags in raw text elements
|
|
54
|
+
const rawMap = (n) => concat(mr(n)).replaceAll('</', '<\\/');
|
|
43
55
|
const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']]);
|
|
44
56
|
const attributes = compose(entries)(flatMap(attribute));
|
|
45
57
|
const parseElement = (e) => {
|
|
@@ -53,9 +65,10 @@ const parseElement = (e) => {
|
|
|
53
65
|
export const element = (e) => {
|
|
54
66
|
const [tag, a, n] = parseElement(e);
|
|
55
67
|
const open = flat([[`<`, tag], attributes(a), [`>`]]);
|
|
56
|
-
|
|
57
|
-
open
|
|
58
|
-
|
|
68
|
+
if (voidTagList.includes(tag)) {
|
|
69
|
+
return open;
|
|
70
|
+
}
|
|
71
|
+
return flat([open, rawText.includes(tag) ? [rawMap(n)] : nodes(n), ['</', tag, '>']]);
|
|
59
72
|
};
|
|
60
73
|
export const html = compose(element)(listConcat(['<!DOCTYPE html>']));
|
|
61
74
|
export const htmlToString = compose(html)(stringConcat);
|
package/html/test.f.d.ts
CHANGED
package/html/test.f.js
CHANGED
|
@@ -38,5 +38,42 @@ export default {
|
|
|
38
38
|
if (s !== '<!DOCTYPE html><div><br id="5"><div>&amp;</div><a href="hello""></a></div>') {
|
|
39
39
|
throw s;
|
|
40
40
|
}
|
|
41
|
+
},
|
|
42
|
+
raw: {
|
|
43
|
+
script: () => {
|
|
44
|
+
const x = ['script', { id: 'a<' }, 'const a = ', 'a<b>c'];
|
|
45
|
+
const s = htmlToString(x);
|
|
46
|
+
if (s !== '<!DOCTYPE html><script id="a<">const a = a<b>c</script>') {
|
|
47
|
+
throw s;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
scriptEsc: () => {
|
|
51
|
+
const x = ['script', { id: 'a<' }, '<', '/script>'];
|
|
52
|
+
const s = htmlToString(x);
|
|
53
|
+
if (s !== '<!DOCTYPE html><script id="a<"><\\/script></script>') {
|
|
54
|
+
throw s;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
style: () => {
|
|
58
|
+
const x = ['style', { id: 'a<' }, 'const a = ', 'a<b>c'];
|
|
59
|
+
const s = htmlToString(x);
|
|
60
|
+
if (s !== '<!DOCTYPE html><style id="a<">const a = a<b>c</style>') {
|
|
61
|
+
throw s;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
styleEsc: () => {
|
|
65
|
+
const x = ['style', { id: 'a<' }, '</', 'stYle>'];
|
|
66
|
+
const s = htmlToString(x);
|
|
67
|
+
if (s !== '<!DOCTYPE html><style id="a<"><\\/stYle></style>') {
|
|
68
|
+
throw s;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
noRaw: () => {
|
|
72
|
+
const x = ['div', { id: 'a<' }, 'const a = ', 'a<b>c'];
|
|
73
|
+
const s = htmlToString(x);
|
|
74
|
+
if (s !== '<!DOCTYPE html><div id="a<">const a = a<b>c</div>') {
|
|
75
|
+
throw s;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
41
78
|
}
|
|
42
79
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|