functionalscript 0.3.15 → 0.4.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.
Files changed (65) hide show
  1. package/bnf/djs/test.f.js +36 -41
  2. package/bnf/func/module.f.d.ts +12 -5
  3. package/bnf/func/module.f.js +27 -6
  4. package/bnf/func/test.f.js +25 -84
  5. package/bnf/tag/module.f.d.ts +30 -0
  6. package/bnf/tag/module.f.js +37 -0
  7. package/bnf/tag/test.f.d.ts +1 -0
  8. package/bnf/tag/test.f.js +138 -0
  9. package/fsc/bnf.f.d.ts +2 -0
  10. package/fsc/bnf.f.js +54 -0
  11. package/fsc/json.f.d.ts +7 -0
  12. package/fsc/json.f.js +89 -0
  13. package/package.json +2 -3
  14. package/types/array/module.f.d.ts +1 -0
  15. package/types/array/module.f.js +1 -0
  16. package/types/bigint/module.f.d.ts +6 -0
  17. package/types/bigint/module.f.js +27 -5
  18. package/types/bigint/test.f.d.ts +8 -5
  19. package/types/bigint/test.f.js +91 -19
  20. package/com/cpp/module.f.d.ts +0 -10
  21. package/com/cpp/module.f.js +0 -106
  22. package/com/cpp/test.f.d.ts +0 -2
  23. package/com/cpp/test.f.js +0 -40
  24. package/com/cpp/testlib.f.d.ts +0 -2
  25. package/com/cpp/testlib.f.js +0 -5
  26. package/com/cs/module.f.d.ts +0 -12
  27. package/com/cs/module.f.js +0 -79
  28. package/com/cs/test.f.d.ts +0 -2
  29. package/com/cs/test.f.js +0 -43
  30. package/com/cs/testlib.f.d.ts +0 -2
  31. package/com/cs/testlib.f.js +0 -5
  32. package/com/rust/module.f.d.ts +0 -15
  33. package/com/rust/module.f.js +0 -164
  34. package/com/rust/test.f.d.ts +0 -2
  35. package/com/rust/test.f.js +0 -123
  36. package/com/rust/testlib.f.d.ts +0 -2
  37. package/com/rust/testlib.f.js +0 -5
  38. package/com/test/build.f.d.ts +0 -20
  39. package/com/test/build.f.js +0 -58
  40. package/com/types/module.f.d.ts +0 -28
  41. package/com/types/module.f.js +0 -7
  42. package/com/types/testlib.f.d.ts +0 -44
  43. package/com/types/testlib.f.js +0 -28
  44. package/commonjs/build/module.f.d.ts +0 -6
  45. package/commonjs/build/module.f.js +0 -66
  46. package/commonjs/build/test.f.d.ts +0 -2
  47. package/commonjs/build/test.f.js +0 -92
  48. package/commonjs/module/function/module.f.d.ts +0 -8
  49. package/commonjs/module/function/module.f.js +0 -4
  50. package/commonjs/module/module.f.d.ts +0 -18
  51. package/commonjs/module/module.f.js +0 -11
  52. package/commonjs/module.f.d.ts +0 -6
  53. package/commonjs/module.f.js +0 -1
  54. package/commonjs/package/dependencies/module.f.d.ts +0 -7
  55. package/commonjs/package/dependencies/module.f.js +0 -13
  56. package/commonjs/package/dependencies/test.f.d.ts +0 -2
  57. package/commonjs/package/dependencies/test.f.js +0 -15
  58. package/commonjs/package/module.f.d.ts +0 -17
  59. package/commonjs/package/module.f.js +0 -18
  60. package/commonjs/package/test.f.d.ts +0 -2
  61. package/commonjs/package/test.f.js +0 -27
  62. package/commonjs/path/module.f.d.ts +0 -24
  63. package/commonjs/path/module.f.js +0 -112
  64. package/commonjs/path/test.f.d.ts +0 -25
  65. package/commonjs/path/test.f.js +0 -221
package/bnf/djs/test.f.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cp, range, remove, str } from "../func/module.f.js";
1
+ import { cp, range, remove, set, str } from "../func/module.f.js";
2
2
  import { parser, toRuleMap } from "./module.f.js";
3
3
  import { classic } from "../func/testlib.f.js";
4
4
  import * as j from "../../json/module.f.js";
@@ -114,14 +114,24 @@ const classicTest = () => {
114
114
  const result = map;
115
115
  return result;
116
116
  };
117
+ const repeat0Name = (v) => `${v}Repeat0`;
118
+ const repeat0Body = (v) => [
119
+ [],
120
+ [v, repeat0Name(v)]
121
+ ];
122
+ const repeat0 = (v) => {
123
+ const name = repeat0Name(v);
124
+ const body = repeat0Body(v);
125
+ return { [name]: body };
126
+ };
117
127
  const deterministic = () => {
118
128
  const map = {
119
129
  json: [
120
- ['ws', 'element']
130
+ ['wsRepeat0', 'element']
121
131
  ],
122
132
  value: [
123
- [cp('{'), 'ws', 'object', cp('}')],
124
- [cp('['), 'ws', 'array', cp(']')],
133
+ [cp('{'), 'wsRepeat0', 'object', cp('}')],
134
+ [cp('['), 'wsRepeat0', 'array', cp(']')],
125
135
  ['string'],
126
136
  ['number'],
127
137
  str('true'),
@@ -130,14 +140,14 @@ const deterministic = () => {
130
140
  ],
131
141
  object: [
132
142
  [],
133
- ['member', 'members'],
143
+ ['member', 'memberTailRepeat0'],
134
144
  ],
135
- members: [
136
- [],
137
- [cp(','), 'ws', 'member', 'members'],
145
+ memberTail: [
146
+ [cp(','), 'wsRepeat0', 'member']
138
147
  ],
148
+ ...repeat0('memberTail'),
139
149
  member: [
140
- ['string', 'ws', cp(':'), 'ws', 'element'],
150
+ ['string', 'wsRepeat0', cp(':'), 'wsRepeat0', 'element'],
141
151
  ],
142
152
  array: [
143
153
  [],
@@ -145,31 +155,21 @@ const deterministic = () => {
145
155
  ],
146
156
  elements: [
147
157
  [],
148
- [cp(','), 'ws', 'element', 'elements'],
158
+ [cp(','), 'wsRepeat0', 'element', 'elements'],
149
159
  ],
150
160
  element: [
151
- ['value', 'ws'],
161
+ ['value', 'wsRepeat0'],
152
162
  ],
153
163
  string: [
154
- [cp('"'), 'characters', cp('"')],
155
- ],
156
- characters: [
157
- [],
158
- ['character', 'characters'],
164
+ [cp('"'), 'characterRepeat0', cp('"')],
159
165
  ],
166
+ ...repeat0('character'),
160
167
  character: [
161
168
  ...remove([0x20, 0x10FFFF], [cp('"'), cp('\\')]),
162
169
  [cp('\\'), 'escape'], // 92
163
170
  ],
164
171
  escape: [
165
- [cp('"')],
166
- [cp('\\')],
167
- [cp('/')],
168
- [cp('b')],
169
- [cp('f')],
170
- [cp('n')],
171
- [cp('r')],
172
- [cp('t')],
172
+ ...set('"\\/bfnrt'),
173
173
  [cp('u'), 'hex', 'hex', 'hex', 'hex'],
174
174
  ],
175
175
  hex: [
@@ -177,18 +177,18 @@ const deterministic = () => {
177
177
  [range('AF')],
178
178
  [range('af')],
179
179
  ],
180
+ numberSign: [
181
+ [],
182
+ [cp('-')]
183
+ ],
180
184
  number: [
181
- ['integer', 'fraction', 'exponent'],
182
- [cp('-'), 'integer', 'fraction', 'exponent'],
185
+ ['numberSign', 'integer', 'fraction', 'exponent'],
183
186
  ],
184
187
  integer: [
185
188
  [cp('0')],
186
- ['onenine', 'digits'],
187
- ],
188
- digits: [
189
- [],
190
- ['digit', 'digits'],
189
+ ['onenine', 'digitRepeat0'],
191
190
  ],
191
+ ...repeat0('digit'),
192
192
  digit: [
193
193
  [cp('0')],
194
194
  ['onenine'],
@@ -198,25 +198,20 @@ const deterministic = () => {
198
198
  ],
199
199
  fraction: [
200
200
  [],
201
- [cp('.'), 'digit', 'digits'],
201
+ [cp('.'), 'digit', 'digitRepeat0'],
202
202
  ],
203
+ e: set('Ee'),
203
204
  exponent: [
204
205
  [],
205
- [cp('E'), 'sign', 'digit', 'digits'],
206
- [cp('e'), 'sign', 'digit', 'digits'],
206
+ ['e', 'sign', 'digit', 'digitRepeat0'],
207
207
  ],
208
208
  sign: [
209
209
  [],
210
210
  [cp('+')],
211
211
  [cp('-')],
212
212
  ],
213
- ws: [
214
- [],
215
- [cp(' '), 'ws'],
216
- [cp('\n'), 'ws'],
217
- [cp('\r'), 'ws'],
218
- [cp('\t'), 'ws'],
219
- ],
213
+ ws: set(' \n\r\t'),
214
+ ...repeat0('ws'),
220
215
  };
221
216
  const _map = map;
222
217
  return _map;
@@ -1,15 +1,13 @@
1
1
  /**
2
- * Types for defining language grammar using Backus-Naur Form (BNF).
3
- *
4
- * @module
5
- *
6
- * @description
2
+ * Types for defining language grammar using Backus-Naur Form (BNF).
7
3
  *
8
4
  * Utilities for serializing and deserializing BNF grammar
9
5
  * and creating a simple LL(1) parser.
10
6
  *
11
7
  * See [Backus-Naur form](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form).
12
8
  *
9
+ * @module
10
+ *
13
11
  * @example
14
12
  *
15
13
  * ```ts
@@ -124,6 +122,13 @@ type RangeSet = readonly TerminalRange[];
124
122
  * A set of terminal ranges compatible with the `Or` rule.
125
123
  */
126
124
  export type OrRangeSet = readonly (readonly [TerminalRange])[];
125
+ /**
126
+ * Convert a sequence of character into `OrRangeSet`
127
+ *
128
+ * @param s a set of code points
129
+ * @returns A set compatible with `Or`
130
+ */
131
+ export declare const set: (s: string) => OrRangeSet;
127
132
  /**
128
133
  * Removes a terminal range from a set of ranges.
129
134
  *
@@ -138,4 +143,6 @@ export type OrRangeSet = readonly (readonly [TerminalRange])[];
138
143
  * ```
139
144
  */
140
145
  export declare const remove: (range: TerminalRange, removeSet: RangeSet) => OrRangeSet;
146
+ export declare const repeat0: (rule: Rule) => Rule;
147
+ export declare const join0: (rule: Rule, separator: Rule) => Rule;
141
148
  export {};
@@ -1,15 +1,13 @@
1
1
  /**
2
- * Types for defining language grammar using Backus-Naur Form (BNF).
3
- *
4
- * @module
5
- *
6
- * @description
2
+ * Types for defining language grammar using Backus-Naur Form (BNF).
7
3
  *
8
4
  * Utilities for serializing and deserializing BNF grammar
9
5
  * and creating a simple LL(1) parser.
10
6
  *
11
7
  * See [Backus-Naur form](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form).
12
8
  *
9
+ * @module
10
+ *
13
11
  * @example
14
12
  *
15
13
  * ```ts
@@ -73,6 +71,14 @@ export const range = (ab) => {
73
71
  // deno-lint-ignore no-explicit-any
74
72
  return a;
75
73
  };
74
+ const toOr = (r) => r.map(v => [v]);
75
+ /**
76
+ * Convert a sequence of character into `OrRangeSet`
77
+ *
78
+ * @param s a set of code points
79
+ * @returns A set compatible with `Or`
80
+ */
81
+ export const set = (s) => toOr(str(s));
76
82
  const removeOne = (set, [a, b]) => {
77
83
  let result = [];
78
84
  for (const [a0, b0] of set) {
@@ -107,5 +113,20 @@ export const remove = (range, removeSet) => {
107
113
  for (const r of removeSet) {
108
114
  result = removeOne(result, r);
109
115
  }
110
- return result.map(v => [v]);
116
+ return toOr(result);
117
+ };
118
+ export const repeat0 = (rule) => {
119
+ const result = () => [
120
+ [],
121
+ [rule, result],
122
+ ];
123
+ return result;
124
+ };
125
+ export const join0 = (rule, separator) => {
126
+ const tail = repeat0(() => [[separator, rule]]);
127
+ const result = () => [
128
+ [],
129
+ [rule, tail],
130
+ ];
131
+ return result;
111
132
  };
@@ -1,20 +1,14 @@
1
1
  import { stringify } from "../../json/module.f.js";
2
2
  import { sort } from "../../types/object/module.f.js";
3
- import { cp, str, range, remove, } from "./module.f.js";
3
+ import { cp, str, range, remove, set, repeat0, join0, } from "./module.f.js";
4
4
  const deterministic = () => {
5
+ const wsSet = () => set('\t\n\r '); // 9,10,13,32
5
6
  // {"empty":true,"map":[[false,8],[true,10],[false,12],[true,13],[false,31],[true,32]]}
6
- const ws = () => [
7
- [],
8
- [cp('\t'), ws], // 9
9
- [cp('\n'), ws], // 10
10
- [cp('\r'), ws], // 13
11
- [cp(' '), ws], // 32
12
- ];
7
+ const ws = repeat0(wsSet);
13
8
  // {"empty":true,"map":[[false,42],[true,43],[false,44],[true,45]]}
14
9
  const sign = () => [
15
10
  [],
16
- str('+'), // 43
17
- str('-'), // 45
11
+ ...set('+-'), // 43
18
12
  ];
19
13
  // {"empty":false,"map":[[false,48],[true,57]]}
20
14
  const onenine = () => [
@@ -26,34 +20,31 @@ const deterministic = () => {
26
20
  [onenine],
27
21
  ];
28
22
  // {"empty":true,"map":[[false,47],[true,57]]}
29
- const digits1 = () => [
30
- [],
31
- [digit, digits1]
32
- ];
23
+ const digits0 = repeat0(digit);
33
24
  // {"empty":false,"map":[[false,47],[true,57]]}
34
- const digits = () => [
35
- [digit, digits1]
25
+ const digits1 = () => [
26
+ [digit, digits0]
36
27
  ];
28
+ const e = () => set('Ee'); // 69, 101
37
29
  // {"empty":true,"map":[[false,68],[true,69],[false,100],[true,101]]}
38
30
  const exponent = () => [
39
31
  [],
40
- [cp('E'), sign, digits], // 69
41
- [cp('e'), sign, digits], // 101
32
+ [e, sign, digits1], // 69 | 101
42
33
  ];
43
34
  // {"empty":true,"map":[[false,45],[true,46]]}
44
35
  const fraction = () => [
45
36
  [],
46
- [cp('.'), digits] // 46
37
+ [cp('.'), digits1] // 46
47
38
  ];
48
39
  // {"empty":false,"map":[[false,47],[true,57]]}
49
- const integer1 = () => [
40
+ const unsignedInteger = () => [
50
41
  str('0'), // 48
51
- [onenine, digits1], // 49-57
42
+ [onenine, digits0], // 49-57
52
43
  ];
53
44
  // {"empty":false,"map":[[false,44],[true,45],[false,47],[true,57]]}
54
45
  const integer = () => [
55
- [integer1], // 48-57
56
- [cp('-'), integer1], // 45
46
+ [unsignedInteger], // 48-57
47
+ [cp('-'), unsignedInteger], // 45
57
48
  ];
58
49
  // {"empty":false,"map":[[false,44],[true,45],[false,47],[true,57]]}
59
50
  const number = () => [
@@ -67,14 +58,7 @@ const deterministic = () => {
67
58
  ];
68
59
  // {"empty":false,"map":[[false,33],[true,34],[false,46],[true,47],[false,91],[true,92],[false,97],[true,98],[false,101],[true,102],[false,109],[true,110],[false,113],[true,114],[false,115],[true,117]]}
69
60
  const escape = () => [
70
- str('"'), // 34
71
- str('/'), // 47
72
- str('\\'), // 92
73
- str('b'), // 98
74
- str('f'), // 102
75
- str('n'), // 110
76
- str('r'), // 114
77
- str('t'), // 116
61
+ ...set('"\\/bfnrt'),
78
62
  [cp('u'), hex, hex, hex, hex] // 117
79
63
  ];
80
64
  // {"empty":false,"map":[[false,31],[true,33],[false,34],[true,1114111]]}
@@ -83,70 +67,27 @@ const deterministic = () => {
83
67
  [cp('\\'), escape], // 92
84
68
  ];
85
69
  // {"empty":true,"map":[[false,31],[true,33],[false,34],[true,1114111]]}
86
- const characters = () => [
87
- [],
88
- [character, characters]
89
- ];
70
+ const characters = repeat0(character);
90
71
  // {"empty":false,"map":[[false,33],[true,34]]}
91
72
  const string = () => [
92
73
  [cp('"'), characters, cp('"')]
93
74
  ];
75
+ const comma = () => [[cp(','), ws]];
94
76
  // {"empty":false,"map":[[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
95
- const element1 = () => [
96
- [value, ws]
97
- ];
98
- // {"empty":false,"map":[[false,8],[true,10],[false,12],[true,13],[false,31],[true,32],[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
99
77
  const element = () => [
100
- [ws, element1]
101
- ];
102
- // {"empty":true,"map":[[false,43],[true,44]]}
103
- const elements2 = () => [
104
- [],
105
- [cp(','), elements] // 44
106
- ];
107
- // {"empty":false,"map":[[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
108
- const elements1 = () => [
109
- [element1, elements2]
110
- ];
111
- // {"empty":false,"map":[[false,8],[true,10],[false,12],[true,13],[false,31],[true,32],[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
112
- const elements = () => [
113
- [ws, elements1]
78
+ [value, ws]
114
79
  ];
115
- // {"empty":false,"map":[[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,92],[true,93],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
116
- const array1 = () => [
117
- str(']'), // 93
118
- [elements1, cp(']')],
80
+ const list = (open, rule, close) => () => [
81
+ [cp(open), ws, join0(rule, comma), cp(close)]
119
82
  ];
120
83
  // {"empty":false,"map":[[false,90],[true,91]]}
121
- const array = () => [
122
- [cp('['), ws, array1]
123
- ];
84
+ const array = list('[', element, ']');
124
85
  // {"empty":false,"map":[[false,33],[true,34]]}
125
- const member1 = () => [
126
- [string, ws, cp(':'), element]
127
- ];
128
- // {"empty":true,"map":[[false,43],[true,44]]}
129
- const members2 = () => [
130
- [],
131
- [cp(','), members], // 44
132
- ];
133
- // {"empty":false,"map":[[false,33],[true,34]]}
134
- const members1 = () => [
135
- [member1, members2]
136
- ];
137
- // {"empty":false,"map":[[false,8],[true,10],[false,12],[true,13],[false,31],[true,32],[false,33],[true,34]]}
138
- const members = () => [
139
- [ws, members1]
140
- ];
141
- // {"empty":false,"map":[[false,33],[true,34],[false,124],[true,125]]}
142
- const object1 = () => [
143
- str('}'), // 125
144
- [members1, cp('}')],
86
+ const member = () => [
87
+ [string, ws, cp(':'), ws, element]
145
88
  ];
146
89
  // {"empty":false,"map":[[false,122],[true,123]]}
147
- const object = () => [
148
- [cp('{'), ws, object1]
149
- ];
90
+ const object = list('{', member, '}');
150
91
  // {"empty":false,"map":[[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
151
92
  const value = () => [
152
93
  [object], // 123
@@ -158,7 +99,7 @@ const deterministic = () => {
158
99
  str('null'), // 110
159
100
  ];
160
101
  // {"empty":false,"map":[[false,8],[true,10],[false,12],[true,13],[false,31],[true,32],[false,33],[true,34],[false,44],[true,45],[false,47],[true,57],[false,90],[true,91],[false,101],[true,102],[false,109],[true,110],[false,115],[true,116],[false,122],[true,123]]}
161
- const json = element;
102
+ const json = [ws, element];
162
103
  const _ = json;
163
104
  };
164
105
  //
@@ -0,0 +1,30 @@
1
+ import { type Array2 } from '../../types/array/module.f.ts';
2
+ export type Range = bigint;
3
+ export type Sequence = readonly Rule[];
4
+ export type Or = {
5
+ readonly [k in string]: Rule;
6
+ };
7
+ export type DataRule = Or | Sequence | Range | string;
8
+ export type LazyRule = () => DataRule;
9
+ export type Rule = DataRule | LazyRule;
10
+ export declare const rangeEncode: (a: number, b: number) => Range;
11
+ export declare const oneEncode: (a: number) => Range;
12
+ export declare const rangeDecode: (r: bigint) => Array2<number>;
13
+ export declare const str: (s: string) => readonly Range[] | Range;
14
+ export declare const set: (s: string) => Or;
15
+ export declare const range: (ab: string) => Range;
16
+ export type None = readonly [];
17
+ export declare const none: None;
18
+ export type Option<S> = {
19
+ none: None;
20
+ some: S;
21
+ };
22
+ export declare const option: <S extends Rule>(some: S) => Option<S>;
23
+ export type Repeat0<T> = () => Option<readonly [T, Repeat0<T>]>;
24
+ export declare const repeat0: <T extends Rule>(some: T) => Repeat0<T>;
25
+ export type Repeat1<T> = readonly [T, Repeat0<T>];
26
+ export declare const repeat1: <T extends Rule>(some: T) => Repeat1<T>;
27
+ export type Join1<T, S> = readonly [T, Repeat0<readonly [S, T]>];
28
+ export declare const join1: <T extends Rule, S extends Rule>(some: T, separator: S) => Join1<T, S>;
29
+ export type Join0<T, S> = Option<readonly [T, Repeat0<readonly [S, T]>]>;
30
+ export declare const join0: <T extends Rule, S extends Rule>(some: T, separator: S) => Rule;
@@ -0,0 +1,37 @@
1
+ import { stringToCodePointList } from "../../text/utf16/module.f.js";
2
+ import { isArray2 } from "../../types/array/module.f.js";
3
+ import { map, toArray } from "../../types/list/module.f.js";
4
+ //
5
+ const { fromEntries } = Object;
6
+ const { fromCodePoint } = String;
7
+ const offset = 24n;
8
+ const mask = (1n << offset) - 1n;
9
+ export const rangeEncode = (a, b) => (BigInt(a) << offset) | BigInt(b);
10
+ export const oneEncode = (a) => rangeEncode(a, a);
11
+ export const rangeDecode = (r) => [Number(r >> offset), Number(r & mask)];
12
+ const mapOneEncode = map(oneEncode);
13
+ export const str = (s) => {
14
+ const x = toArray(mapOneEncode(stringToCodePointList(s)));
15
+ return x.length === 1 ? x[0] : x;
16
+ };
17
+ const mapEntry = map((v) => [fromCodePoint(v), oneEncode(v)]);
18
+ export const set = (s) => fromEntries(toArray(mapEntry(stringToCodePointList(s))));
19
+ export const range = (ab) => {
20
+ const a = toArray(stringToCodePointList(ab));
21
+ if (!isArray2(a)) {
22
+ throw `Invalid range ${ab}.`;
23
+ }
24
+ return rangeEncode(...a);
25
+ };
26
+ export const none = [];
27
+ export const option = (some) => ({
28
+ none,
29
+ some,
30
+ });
31
+ export const repeat0 = (some) => {
32
+ const f = () => option([some, f]);
33
+ return f;
34
+ };
35
+ export const repeat1 = (some) => [some, repeat0(some)];
36
+ export const join1 = (some, separator) => [some, repeat0([separator, some])];
37
+ export const join0 = (some, separator) => option(join1(some, separator));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,138 @@
1
+ import { join0, none, option, range, repeat0, set } from "./module.f.js";
2
+ const _classic = () => {
3
+ const json = () => [element];
4
+ const value = () => ({
5
+ object,
6
+ array,
7
+ string,
8
+ number,
9
+ true: 'true',
10
+ false: 'false',
11
+ null: 'null'
12
+ });
13
+ const object = () => ({
14
+ ws: ['{', ws, '}'],
15
+ members: ['{', members, '}'],
16
+ });
17
+ const members = () => ({
18
+ member,
19
+ members: [member, ',', members],
20
+ });
21
+ const member = () => [ws, string, ws, ':', element];
22
+ const array = () => ({
23
+ ws: ['[', ws, ']'],
24
+ elements: ['[', elements, ']'],
25
+ });
26
+ const elements = () => ({
27
+ element,
28
+ elements: [element, ',', elements],
29
+ });
30
+ const element = () => [ws, value, ws];
31
+ const string = () => ['"', characters, '"'];
32
+ const characters = () => ({
33
+ none,
34
+ characters: [character, characters],
35
+ });
36
+ const character = () => ({
37
+ 0: 0x20000021n,
38
+ 1: 0x2300005bn,
39
+ 2: 0x5d10ffffn,
40
+ escape: ['\\', escape],
41
+ });
42
+ const escape = () => ({
43
+ ...set('"\\/bfnrt'),
44
+ u: ['u', hex, hex, hex, hex],
45
+ });
46
+ const hex = () => ({
47
+ digit,
48
+ AF: range('AF'),
49
+ af: range('af'),
50
+ });
51
+ const number = () => [integer, fraction, exponent];
52
+ const integer = () => ({
53
+ digit,
54
+ onenine: [onenine, digits],
55
+ negDigit: ['-', digit],
56
+ negOnenine: ['-', onenine, digits],
57
+ });
58
+ const digits = () => ({
59
+ digit,
60
+ digits: [digit, digits],
61
+ });
62
+ const digit = () => ({
63
+ '0': '0',
64
+ onenine,
65
+ });
66
+ const onenine = range('12');
67
+ const fraction = () => ({
68
+ none,
69
+ digits: ['.', digits],
70
+ });
71
+ const exponent = () => ({
72
+ none,
73
+ E: ['E', sign, digits],
74
+ e: ['e', sign, digits],
75
+ });
76
+ const sign = {
77
+ none,
78
+ ...set('+-'),
79
+ };
80
+ const ws = () => ({
81
+ none,
82
+ ' ': [' ', ws],
83
+ '\n': ['\n', ws],
84
+ '\r': ['\r', ws],
85
+ '\t': ['\t', ws],
86
+ });
87
+ return json;
88
+ };
89
+ const _deterministic = () => {
90
+ const onenine = range('12');
91
+ const digit = {
92
+ '0': '0',
93
+ onenine,
94
+ };
95
+ const hex = {
96
+ digit,
97
+ AF: range('AF'),
98
+ af: range('af'),
99
+ };
100
+ const escape = {
101
+ ...set('"\\/bfnrt'),
102
+ u: ['u', hex, hex, hex, hex],
103
+ };
104
+ const character = {
105
+ 0: 0x20000021n,
106
+ 1: 0x2300005bn,
107
+ 2: 0x5d10ffffn,
108
+ escape: ['\\', escape],
109
+ };
110
+ const characters = repeat0(character);
111
+ const string = ['"', characters, '"'];
112
+ const digits0 = repeat0(digit);
113
+ const digits = [digit, digits0];
114
+ const integer = [option('-'), {
115
+ '0': '0',
116
+ onenine: [onenine, digits0],
117
+ }];
118
+ const fraction = option(['.', digits]);
119
+ const sign = option(set('+-'));
120
+ const exponent = option([set('Ee'), sign, digits]);
121
+ const number = [integer, fraction, exponent];
122
+ const ws = repeat0(set(' \n\r\t'));
123
+ const value = () => ({
124
+ object,
125
+ array,
126
+ string,
127
+ number,
128
+ true: 'true',
129
+ false: 'false',
130
+ null: 'null'
131
+ });
132
+ const commaJoin0 = ([open, close], a) => [open, ws, join0([a, ws], [',', ws]), close];
133
+ const array = commaJoin0('[]', value);
134
+ const member = [string, ws, ':', ws, value];
135
+ const object = commaJoin0('{}', member);
136
+ const json = [ws, value, ws];
137
+ return json;
138
+ };
package/fsc/bnf.f.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { type Rule } from '../bnf/func/module.f.ts';
2
+ export declare const wsModule: Rule;
package/fsc/bnf.f.js ADDED
@@ -0,0 +1,54 @@
1
+ import { cp, range, remove, set, str } from "../bnf/func/module.f.js";
2
+ import { digit, json, unicode, ws0, ws1, wsNoNewLine0 } from "./json.f.js";
3
+ export const wsModule = () => [[ws0, module]];
4
+ const module = () => [
5
+ [json, ws0],
6
+ [fjs],
7
+ ];
8
+ const fjs = () => [
9
+ [],
10
+ [...str('const'), ws1, id, ws0, cp('='), ws0, json, wsNoNewLine0, fjsTail],
11
+ [...str('export'), ws1, ...str('default'), ws1, json],
12
+ ];
13
+ const fjsTail = () => [
14
+ [],
15
+ [cp('\n'), ws0, fjs],
16
+ ];
17
+ // line comment
18
+ const lineItem = () => remove(unicode, [cp('\n')]);
19
+ const line = () => [
20
+ [],
21
+ [lineItem, line]
22
+ ];
23
+ const lineComment = () => [
24
+ [cp('/'), commentTail, cp('\n')]
25
+ ];
26
+ const multiLineSkip = () => remove(unicode, [cp('/')]);
27
+ const multiLineItem = () => remove(unicode, [cp('*')]);
28
+ const multiLine = () => [
29
+ [cp('*'), multiLineTail],
30
+ [multiLineItem, multiLine]
31
+ ];
32
+ const multiLineTail = () => [
33
+ [cp('/')],
34
+ [multiLineSkip, multiLine]
35
+ ];
36
+ const commentTail = () => [
37
+ [cp('/'), lineComment],
38
+ [cp('*'), multiLine],
39
+ ];
40
+ // id
41
+ const id = () => [[alpha, idTail0]];
42
+ const alpha = () => [
43
+ [range('AZ')],
44
+ [range('az')],
45
+ ...set('_$'),
46
+ ];
47
+ const idTail0 = () => [
48
+ [],
49
+ [alphaDigit, idTail0],
50
+ ];
51
+ const alphaDigit = () => [
52
+ [alpha],
53
+ [digit],
54
+ ];