@fraczak/k 6.1.0 → 6.1.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.
@@ -44,6 +44,32 @@ assert.deepEqual(decodedMerged.pattern, INT_PATTERN);
44
44
  const identityResult = k.compile("()")(withPattern(two, INT_PATTERN));
45
45
  assert.deepEqual(identityResult.pattern, INT_PATTERN);
46
46
 
47
+ const wrappedFloatPattern = [
48
+ ["closed-product", [["result", 1], ["flags", 6]]],
49
+ ["closed-product", [["sign", 2], ["exponent", 3], ["fraction", 4]]],
50
+ ["closed-union", [["+", 5], ["-", 5]]],
51
+ ["closed-product", [["0", 2]]],
52
+ ["closed-product", [["0", 2]]],
53
+ ["closed-product", []],
54
+ ["closed-union", [["inexact", 5]]]
55
+ ];
56
+ const wrappedFloat = new Product({
57
+ result: new Product({
58
+ sign: new Variant("+", new Product({})),
59
+ exponent: new Product({ 0: new Variant("1", new Product({})) }),
60
+ fraction: new Product({ 0: new Variant("0", new Product({})) })
61
+ }),
62
+ flags: new Variant("inexact", new Product({}))
63
+ });
64
+ const resultProjection = k.compile(".result")(withPattern(wrappedFloat, wrappedFloatPattern));
65
+ assert.deepEqual(resultProjection.pattern, [
66
+ ["closed-product", [["sign", 1], ["exponent", 3], ["fraction", 4]]],
67
+ ["closed-union", [["+", 2], ["-", 2]]],
68
+ ["closed-product", []],
69
+ ["closed-product", [["0", 1]]],
70
+ ["closed-product", [["0", 1]]]
71
+ ]);
72
+
47
73
  assert.throws(
48
74
  () => k.compile(".x")(withPattern(two, INT_PATTERN)),
49
75
  /Type Error in 'comp'.*Value envelope does not intersect expression input pattern/s
package/DOCS/REPL.md CHANGED
@@ -45,6 +45,9 @@ complete.
45
45
  | `:C name` | Show canonical code definition |
46
46
  | `:codes` | List type aliases |
47
47
  | `:rels` | List relation aliases |
48
+ | `:codec load file` | Load an importable REPL codec module |
49
+ | `:codec list` | List loaded REPL codecs |
50
+ | `:input type [codec]` | Read the next line as codec input for a singleton type |
48
51
  | `:load [--no-alias] file` | Load `.k` source or `.klib` into the current state |
49
52
  | `:klib file` | Export current state as a `.klib` library |
50
53
  | `:ko file expr` | Export a `.ko` executable with `expr` as main |
@@ -133,6 +136,10 @@ Tab completion covers:
133
136
 
134
137
  Type aliases also complete in `$name` position inside raw k input.
135
138
 
139
+ For codec commands, completion covers `:codec load`, `:codec list`, file paths
140
+ after `:codec load`, singleton type names after `:input`, and loaded codec names
141
+ after the input type.
142
+
136
143
  ## Loading
137
144
 
138
145
  ### `:load [--no-alias] file.k`
@@ -147,6 +154,32 @@ Reads the plain-JSON library file and merges its codes, relations, aliases, and
147
154
  metadata into the session. Aliases are recovered from `meta[hash].origins[]`
148
155
  unless `--no-alias` is used.
149
156
 
157
+ ## Codecs
158
+
159
+ REPL codecs are keyed by canonical singleton code hashes. Open filters are not
160
+ used for codec dispatch.
161
+
162
+ ### `:codec load file`
163
+
164
+ Loads an importable ES module that exports a codec shape:
165
+
166
+ ```js
167
+ export const name = "utf8";
168
+ export const codes = ["@..."];
169
+ export function parse(text) { /* text -> Value */ }
170
+ export function print(value) { /* Value -> text */ }
171
+ ```
172
+
173
+ A codec may export `patterns` instead of `codes`; each pattern must be a
174
+ singleton closed property-list pattern, and its code hash is recalculated by the
175
+ REPL.
176
+
177
+ ### `:input type [codec]`
178
+
179
+ Resolves `type` to a canonical singleton code, selects the registered codec,
180
+ and consumes the next line verbatim as codec input. The parsed value is validated
181
+ against that code before becoming the current value.
182
+
150
183
  ## Export
151
184
 
152
185
  ### `:klib file`
@@ -0,0 +1,140 @@
1
+ <h1 id="project-dependency-graph">Project Dependency Graph</h1>
2
+ <p><em>Auto-generated by scripts/generate-dependency-graph.mjs.</em></p>
3
+ <pre class="mermaid"><code>graph TD
4
+ classDef default fill:#fff,stroke:#333,stroke-width:2px,color:#000;
5
+
6
+ Graph_mjs[&quot;Graph.mjs (1.9 KB)&lt;br/&gt;██&quot;]
7
+ TypeGraph_mjs[&quot;TypeGraph.mjs (1.1 KB)&lt;br/&gt;█&quot;]
8
+ TypePatternGraph_mjs[&quot;TypePatternGraph.mjs (8.0 KB)&lt;br/&gt;████████&quot;]
9
+ Value_mjs[&quot;Value.mjs (5.4 KB)&lt;br/&gt;█████&quot;]
10
+ augmentation_mjs[&quot;augmentation.mjs (6.9 KB)&lt;br/&gt;███████&quot;]
11
+ codecs_example_pipeline_mjs[&quot;codecs/example-pipeline.mjs (5.1 KB)&lt;br/&gt;█████&quot;]
12
+ codecs_ieee_mjs[&quot;codecs/ieee.mjs (4.3 KB)&lt;br/&gt;████&quot;]
13
+ codecs_int_mjs[&quot;codecs/int.mjs (3.5 KB)&lt;br/&gt;████&quot;]
14
+ codecs_json_codec_mjs[&quot;codecs/json-codec.mjs (6.2 KB)&lt;br/&gt;██████&quot;]
15
+ codecs_json_mjs[&quot;codecs/json.mjs (1.5 KB)&lt;br/&gt;██&quot;]
16
+ codecs_k_parse_mjs[&quot;codecs/k-parse.mjs (3.0 KB)&lt;br/&gt;███&quot;]
17
+ codecs_k_print_mjs[&quot;codecs/k-print.mjs (1.5 KB)&lt;br/&gt;██&quot;]
18
+ codecs_runtime_codec_mjs[&quot;codecs/runtime/codec.mjs (25.7 KB)&lt;br/&gt;████████████████████&quot;]
19
+ codecs_runtime_ieee_pattern_mjs[&quot;codecs/runtime/ieee-pattern.mjs (1.1 KB)&lt;br/&gt;█&quot;]
20
+ codecs_runtime_pattern_json_mjs[&quot;codecs/runtime/pattern-json.mjs (3.5 KB)&lt;br/&gt;███&quot;]
21
+ codecs_runtime_prefix_codec_mjs[&quot;codecs/runtime/prefix-codec.mjs (13.7 KB)&lt;br/&gt;██████████████&quot;]
22
+ codecs_runtime_show_value_mjs[&quot;codecs/runtime/show-value.mjs (2.1 KB)&lt;br/&gt;██&quot;]
23
+ codecs_runtime_test_codec_mjs[&quot;codecs/runtime/test-codec.mjs (3.0 KB)&lt;br/&gt;███&quot;]
24
+ codecs_runtime_typeFromValue_mjs[&quot;codecs/runtime/typeFromValue.mjs (0.9 KB)&lt;br/&gt;█&quot;]
25
+ codecs_runtime_unicode_string_mjs[&quot;codecs/runtime/unicode-string.mjs (7.5 KB)&lt;br/&gt;████████&quot;]
26
+ codecs_show_mjs[&quot;codecs/show.mjs (1.5 KB)&lt;br/&gt;██&quot;]
27
+ codecs_string_codec_mjs[&quot;codecs/string-codec.mjs (4.5 KB)&lt;br/&gt;█████&quot;]
28
+ codecs_unit_mjs[&quot;codecs/unit.mjs (1.6 KB)&lt;br/&gt;██&quot;]
29
+ codecs_utf16_mjs[&quot;codecs/utf16.mjs (2.2 KB)&lt;br/&gt;██&quot;]
30
+ codecs_utf8_mjs[&quot;codecs/utf8.mjs (1.3 KB)&lt;br/&gt;█&quot;]
31
+ codes_mjs[&quot;codes.mjs (9.9 KB)&lt;br/&gt;██████████&quot;]
32
+ compiler_mjs[&quot;compiler.mjs (3.9 KB)&lt;br/&gt;████&quot;]
33
+ convergence_mjs[&quot;convergence.mjs (6.5 KB)&lt;br/&gt;██████&quot;]
34
+ export_mjs[&quot;export.mjs (5.2 KB)&lt;br/&gt;█████&quot;]
35
+ hash_mjs[&quot;hash.mjs (1.1 KB)&lt;br/&gt;█&quot;]
36
+ index_mjs[&quot;index.mjs (1.9 KB)&lt;br/&gt;██&quot;]
37
+ k_mjs[&quot;k.mjs (2.7 KB)&lt;br/&gt;███&quot;]
38
+ object_mjs[&quot;object.mjs (26.3 KB)&lt;br/&gt;████████████████████&quot;]
39
+ pretty_mjs[&quot;pretty.mjs (5.6 KB)&lt;br/&gt;██████&quot;]
40
+ repl_mjs[&quot;repl.mjs (29.3 KB)&lt;br/&gt;████████████████████&quot;]
41
+ run_mjs[&quot;run.mjs (14.4 KB)&lt;br/&gt;██████████████&quot;]
42
+ symbol_table_mjs[&quot;symbol-table.mjs (2.7 KB)&lt;br/&gt;███&quot;]
43
+ typing_mjs[&quot;typing.mjs (4.9 KB)&lt;br/&gt;█████&quot;]
44
+ unification_mjs[&quot;unification.mjs (5.4 KB)&lt;br/&gt;█████&quot;]
45
+ valueIO_mjs[&quot;valueIO.mjs (1.8 KB)&lt;br/&gt;██&quot;]
46
+
47
+ TypePatternGraph_mjs --&gt; Graph_mjs
48
+ TypePatternGraph_mjs --&gt; unification_mjs
49
+ TypePatternGraph_mjs --&gt; TypeGraph_mjs
50
+ augmentation_mjs --&gt; codes_mjs
51
+ codecs_example_pipeline_mjs --&gt; codecs_runtime_codec_mjs
52
+ codecs_example_pipeline_mjs --&gt; codecs_runtime_prefix_codec_mjs
53
+ codecs_example_pipeline_mjs --&gt; codecs_runtime_pattern_json_mjs
54
+ codecs_example_pipeline_mjs --&gt; Value_mjs
55
+ codecs_example_pipeline_mjs --&gt; hash_mjs
56
+ codecs_ieee_mjs --&gt; Value_mjs
57
+ codecs_ieee_mjs --&gt; codecs_runtime_prefix_codec_mjs
58
+ codecs_ieee_mjs --&gt; codecs_runtime_ieee_pattern_mjs
59
+ codecs_int_mjs --&gt; Value_mjs
60
+ codecs_int_mjs --&gt; codecs_runtime_prefix_codec_mjs
61
+ codecs_json_codec_mjs --&gt; Value_mjs
62
+ codecs_json_codec_mjs --&gt; codecs_string_codec_mjs
63
+ codecs_json_codec_mjs --&gt; codecs_runtime_ieee_pattern_mjs
64
+ codecs_json_mjs --&gt; codecs_runtime_prefix_codec_mjs
65
+ codecs_json_mjs --&gt; codecs_json_codec_mjs
66
+ codecs_k_parse_mjs --&gt; index_mjs
67
+ codecs_k_parse_mjs --&gt; valueIO_mjs
68
+ codecs_k_parse_mjs --&gt; codecs_runtime_codec_mjs
69
+ codecs_k_parse_mjs --&gt; codecs_runtime_pattern_json_mjs
70
+ codecs_k_parse_mjs --&gt; codecs_runtime_prefix_codec_mjs
71
+ codecs_k_print_mjs --&gt; codecs_runtime_prefix_codec_mjs
72
+ codecs_runtime_codec_mjs --&gt; Value_mjs
73
+ codecs_runtime_codec_mjs --&gt; TypePatternGraph_mjs
74
+ codecs_runtime_codec_mjs --&gt; typing_mjs
75
+ codecs_runtime_codec_mjs --&gt; codes_mjs
76
+ codecs_runtime_codec_mjs --&gt; codecs_runtime_pattern_json_mjs
77
+ codecs_runtime_ieee_pattern_mjs --&gt; codes_mjs
78
+ codecs_runtime_ieee_pattern_mjs --&gt; codecs_runtime_codec_mjs
79
+ codecs_runtime_ieee_pattern_mjs --&gt; codecs_runtime_pattern_json_mjs
80
+ codecs_runtime_prefix_codec_mjs --&gt; Value_mjs
81
+ codecs_runtime_prefix_codec_mjs --&gt; codecs_runtime_codec_mjs
82
+ codecs_runtime_prefix_codec_mjs --&gt; codecs_runtime_pattern_json_mjs
83
+ codecs_runtime_prefix_codec_mjs --&gt; codecs_runtime_unicode_string_mjs
84
+ codecs_runtime_show_value_mjs --&gt; Value_mjs
85
+ codecs_runtime_test_codec_mjs --&gt; codecs_runtime_codec_mjs
86
+ codecs_runtime_test_codec_mjs --&gt; codecs_runtime_prefix_codec_mjs
87
+ codecs_runtime_test_codec_mjs --&gt; codecs_runtime_pattern_json_mjs
88
+ codecs_runtime_test_codec_mjs --&gt; Value_mjs
89
+ codecs_runtime_test_codec_mjs --&gt; hash_mjs
90
+ codecs_runtime_typeFromValue_mjs --&gt; Value_mjs
91
+ codecs_runtime_unicode_string_mjs --&gt; Value_mjs
92
+ codecs_show_mjs --&gt; codecs_runtime_prefix_codec_mjs
93
+ codecs_show_mjs --&gt; codecs_runtime_show_value_mjs
94
+ codecs_string_codec_mjs --&gt; codecs_runtime_codec_mjs
95
+ codecs_string_codec_mjs --&gt; codecs_runtime_prefix_codec_mjs
96
+ codecs_string_codec_mjs --&gt; codecs_runtime_pattern_json_mjs
97
+ codecs_string_codec_mjs --&gt; codecs_runtime_unicode_string_mjs
98
+ codecs_unit_mjs --&gt; Value_mjs
99
+ codecs_unit_mjs --&gt; codecs_runtime_prefix_codec_mjs
100
+ codecs_utf16_mjs --&gt; codecs_string_codec_mjs
101
+ codecs_utf8_mjs --&gt; codecs_string_codec_mjs
102
+ codes_mjs --&gt; hash_mjs
103
+ compiler_mjs --&gt; hash_mjs
104
+ compiler_mjs --&gt; TypePatternGraph_mjs
105
+ compiler_mjs --&gt; Graph_mjs
106
+ compiler_mjs --&gt; codes_mjs
107
+ compiler_mjs --&gt; augmentation_mjs
108
+ compiler_mjs --&gt; export_mjs
109
+ compiler_mjs --&gt; convergence_mjs
110
+ convergence_mjs --&gt; pretty_mjs
111
+ convergence_mjs --&gt; typing_mjs
112
+ export_mjs --&gt; hash_mjs
113
+ export_mjs --&gt; pretty_mjs
114
+ index_mjs --&gt; Value_mjs
115
+ index_mjs --&gt; valueIO_mjs
116
+ index_mjs --&gt; compiler_mjs
117
+ index_mjs --&gt; run_mjs
118
+ index_mjs --&gt; codes_mjs
119
+ k_mjs --&gt; index_mjs
120
+ k_mjs --&gt; codecs_runtime_prefix_codec_mjs
121
+ k_mjs --&gt; object_mjs
122
+ object_mjs --&gt; index_mjs
123
+ object_mjs --&gt; run_mjs
124
+ object_mjs --&gt; codes_mjs
125
+ object_mjs --&gt; TypePatternGraph_mjs
126
+ object_mjs --&gt; pretty_mjs
127
+ pretty_mjs --&gt; TypePatternGraph_mjs
128
+ repl_mjs --&gt; index_mjs
129
+ repl_mjs --&gt; run_mjs
130
+ repl_mjs --&gt; codes_mjs
131
+ repl_mjs --&gt; Value_mjs
132
+ repl_mjs --&gt; pretty_mjs
133
+ repl_mjs --&gt; object_mjs
134
+ repl_mjs --&gt; codecs_runtime_show_value_mjs
135
+ run_mjs --&gt; Value_mjs
136
+ run_mjs --&gt; codecs_runtime_codec_mjs
137
+ run_mjs --&gt; codecs_runtime_pattern_json_mjs
138
+ symbol_table_mjs --&gt; hash_mjs
139
+ typing_mjs --&gt; TypePatternGraph_mjs
140
+ valueIO_mjs --&gt; Value_mjs</code></pre>
@@ -0,0 +1,144 @@
1
+ # Project Dependency Graph
2
+
3
+ _Auto-generated by scripts/generate-dependency-graph.mjs._
4
+
5
+ ```mermaid
6
+ graph TD
7
+ classDef default fill:#fff,stroke:#333,stroke-width:2px,color:#000;
8
+
9
+ Graph_mjs["Graph.mjs (1.9 KB)<br/>██"]
10
+ TypeGraph_mjs["TypeGraph.mjs (1.1 KB)<br/>█"]
11
+ TypePatternGraph_mjs["TypePatternGraph.mjs (8.0 KB)<br/>████████"]
12
+ Value_mjs["Value.mjs (5.4 KB)<br/>█████"]
13
+ augmentation_mjs["augmentation.mjs (6.9 KB)<br/>███████"]
14
+ codecs_example_pipeline_mjs["codecs/example-pipeline.mjs (5.1 KB)<br/>█████"]
15
+ codecs_ieee_mjs["codecs/ieee.mjs (4.3 KB)<br/>████"]
16
+ codecs_int_mjs["codecs/int.mjs (3.5 KB)<br/>████"]
17
+ codecs_json_codec_mjs["codecs/json-codec.mjs (6.2 KB)<br/>██████"]
18
+ codecs_json_mjs["codecs/json.mjs (1.5 KB)<br/>██"]
19
+ codecs_k_parse_mjs["codecs/k-parse.mjs (3.0 KB)<br/>███"]
20
+ codecs_k_print_mjs["codecs/k-print.mjs (1.5 KB)<br/>██"]
21
+ codecs_runtime_codec_mjs["codecs/runtime/codec.mjs (25.7 KB)<br/>████████████████████"]
22
+ codecs_runtime_ieee_pattern_mjs["codecs/runtime/ieee-pattern.mjs (1.1 KB)<br/>█"]
23
+ codecs_runtime_pattern_json_mjs["codecs/runtime/pattern-json.mjs (3.5 KB)<br/>███"]
24
+ codecs_runtime_prefix_codec_mjs["codecs/runtime/prefix-codec.mjs (13.7 KB)<br/>██████████████"]
25
+ codecs_runtime_show_value_mjs["codecs/runtime/show-value.mjs (2.1 KB)<br/>██"]
26
+ codecs_runtime_test_codec_mjs["codecs/runtime/test-codec.mjs (3.0 KB)<br/>███"]
27
+ codecs_runtime_typeFromValue_mjs["codecs/runtime/typeFromValue.mjs (0.9 KB)<br/>█"]
28
+ codecs_runtime_unicode_string_mjs["codecs/runtime/unicode-string.mjs (7.5 KB)<br/>████████"]
29
+ codecs_show_mjs["codecs/show.mjs (1.5 KB)<br/>██"]
30
+ codecs_string_codec_mjs["codecs/string-codec.mjs (4.5 KB)<br/>█████"]
31
+ codecs_unit_mjs["codecs/unit.mjs (1.6 KB)<br/>██"]
32
+ codecs_utf16_mjs["codecs/utf16.mjs (2.2 KB)<br/>██"]
33
+ codecs_utf8_mjs["codecs/utf8.mjs (1.3 KB)<br/>█"]
34
+ codes_mjs["codes.mjs (9.9 KB)<br/>██████████"]
35
+ compiler_mjs["compiler.mjs (3.9 KB)<br/>████"]
36
+ convergence_mjs["convergence.mjs (6.5 KB)<br/>██████"]
37
+ export_mjs["export.mjs (5.2 KB)<br/>█████"]
38
+ hash_mjs["hash.mjs (1.1 KB)<br/>█"]
39
+ index_mjs["index.mjs (1.9 KB)<br/>██"]
40
+ k_mjs["k.mjs (2.7 KB)<br/>███"]
41
+ object_mjs["object.mjs (26.3 KB)<br/>████████████████████"]
42
+ pretty_mjs["pretty.mjs (5.6 KB)<br/>██████"]
43
+ repl_mjs["repl.mjs (29.3 KB)<br/>████████████████████"]
44
+ run_mjs["run.mjs (14.4 KB)<br/>██████████████"]
45
+ symbol_table_mjs["symbol-table.mjs (2.7 KB)<br/>███"]
46
+ typing_mjs["typing.mjs (4.9 KB)<br/>█████"]
47
+ unification_mjs["unification.mjs (5.4 KB)<br/>█████"]
48
+ valueIO_mjs["valueIO.mjs (1.8 KB)<br/>██"]
49
+
50
+ TypePatternGraph_mjs --> Graph_mjs
51
+ TypePatternGraph_mjs --> unification_mjs
52
+ TypePatternGraph_mjs --> TypeGraph_mjs
53
+ augmentation_mjs --> codes_mjs
54
+ codecs_example_pipeline_mjs --> codecs_runtime_codec_mjs
55
+ codecs_example_pipeline_mjs --> codecs_runtime_prefix_codec_mjs
56
+ codecs_example_pipeline_mjs --> codecs_runtime_pattern_json_mjs
57
+ codecs_example_pipeline_mjs --> Value_mjs
58
+ codecs_example_pipeline_mjs --> hash_mjs
59
+ codecs_ieee_mjs --> Value_mjs
60
+ codecs_ieee_mjs --> codecs_runtime_prefix_codec_mjs
61
+ codecs_ieee_mjs --> codecs_runtime_ieee_pattern_mjs
62
+ codecs_int_mjs --> Value_mjs
63
+ codecs_int_mjs --> codecs_runtime_prefix_codec_mjs
64
+ codecs_json_codec_mjs --> Value_mjs
65
+ codecs_json_codec_mjs --> codecs_string_codec_mjs
66
+ codecs_json_codec_mjs --> codecs_runtime_ieee_pattern_mjs
67
+ codecs_json_mjs --> codecs_runtime_prefix_codec_mjs
68
+ codecs_json_mjs --> codecs_json_codec_mjs
69
+ codecs_k_parse_mjs --> index_mjs
70
+ codecs_k_parse_mjs --> valueIO_mjs
71
+ codecs_k_parse_mjs --> codecs_runtime_codec_mjs
72
+ codecs_k_parse_mjs --> codecs_runtime_pattern_json_mjs
73
+ codecs_k_parse_mjs --> codecs_runtime_prefix_codec_mjs
74
+ codecs_k_print_mjs --> codecs_runtime_prefix_codec_mjs
75
+ codecs_runtime_codec_mjs --> Value_mjs
76
+ codecs_runtime_codec_mjs --> TypePatternGraph_mjs
77
+ codecs_runtime_codec_mjs --> typing_mjs
78
+ codecs_runtime_codec_mjs --> codes_mjs
79
+ codecs_runtime_codec_mjs --> codecs_runtime_pattern_json_mjs
80
+ codecs_runtime_ieee_pattern_mjs --> codes_mjs
81
+ codecs_runtime_ieee_pattern_mjs --> codecs_runtime_codec_mjs
82
+ codecs_runtime_ieee_pattern_mjs --> codecs_runtime_pattern_json_mjs
83
+ codecs_runtime_prefix_codec_mjs --> Value_mjs
84
+ codecs_runtime_prefix_codec_mjs --> codecs_runtime_codec_mjs
85
+ codecs_runtime_prefix_codec_mjs --> codecs_runtime_pattern_json_mjs
86
+ codecs_runtime_prefix_codec_mjs --> codecs_runtime_unicode_string_mjs
87
+ codecs_runtime_show_value_mjs --> Value_mjs
88
+ codecs_runtime_test_codec_mjs --> codecs_runtime_codec_mjs
89
+ codecs_runtime_test_codec_mjs --> codecs_runtime_prefix_codec_mjs
90
+ codecs_runtime_test_codec_mjs --> codecs_runtime_pattern_json_mjs
91
+ codecs_runtime_test_codec_mjs --> Value_mjs
92
+ codecs_runtime_test_codec_mjs --> hash_mjs
93
+ codecs_runtime_typeFromValue_mjs --> Value_mjs
94
+ codecs_runtime_unicode_string_mjs --> Value_mjs
95
+ codecs_show_mjs --> codecs_runtime_prefix_codec_mjs
96
+ codecs_show_mjs --> codecs_runtime_show_value_mjs
97
+ codecs_string_codec_mjs --> codecs_runtime_codec_mjs
98
+ codecs_string_codec_mjs --> codecs_runtime_prefix_codec_mjs
99
+ codecs_string_codec_mjs --> codecs_runtime_pattern_json_mjs
100
+ codecs_string_codec_mjs --> codecs_runtime_unicode_string_mjs
101
+ codecs_unit_mjs --> Value_mjs
102
+ codecs_unit_mjs --> codecs_runtime_prefix_codec_mjs
103
+ codecs_utf16_mjs --> codecs_string_codec_mjs
104
+ codecs_utf8_mjs --> codecs_string_codec_mjs
105
+ codes_mjs --> hash_mjs
106
+ compiler_mjs --> hash_mjs
107
+ compiler_mjs --> TypePatternGraph_mjs
108
+ compiler_mjs --> Graph_mjs
109
+ compiler_mjs --> codes_mjs
110
+ compiler_mjs --> augmentation_mjs
111
+ compiler_mjs --> export_mjs
112
+ compiler_mjs --> convergence_mjs
113
+ convergence_mjs --> pretty_mjs
114
+ convergence_mjs --> typing_mjs
115
+ export_mjs --> hash_mjs
116
+ export_mjs --> pretty_mjs
117
+ index_mjs --> Value_mjs
118
+ index_mjs --> valueIO_mjs
119
+ index_mjs --> compiler_mjs
120
+ index_mjs --> run_mjs
121
+ index_mjs --> codes_mjs
122
+ k_mjs --> index_mjs
123
+ k_mjs --> codecs_runtime_prefix_codec_mjs
124
+ k_mjs --> object_mjs
125
+ object_mjs --> index_mjs
126
+ object_mjs --> run_mjs
127
+ object_mjs --> codes_mjs
128
+ object_mjs --> TypePatternGraph_mjs
129
+ object_mjs --> pretty_mjs
130
+ pretty_mjs --> TypePatternGraph_mjs
131
+ repl_mjs --> index_mjs
132
+ repl_mjs --> run_mjs
133
+ repl_mjs --> codes_mjs
134
+ repl_mjs --> Value_mjs
135
+ repl_mjs --> pretty_mjs
136
+ repl_mjs --> object_mjs
137
+ repl_mjs --> codecs_runtime_show_value_mjs
138
+ run_mjs --> Value_mjs
139
+ run_mjs --> codecs_runtime_codec_mjs
140
+ run_mjs --> codecs_runtime_pattern_json_mjs
141
+ symbol_table_mjs --> hash_mjs
142
+ typing_mjs --> TypePatternGraph_mjs
143
+ valueIO_mjs --> Value_mjs
144
+ ```
package/codecs/ieee.mjs CHANGED
@@ -2,9 +2,12 @@
2
2
 
3
3
  import { stdin, stdout, argv, exit } from "node:process";
4
4
  import { Product, Variant } from "../Value.mjs";
5
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
6
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
6
7
  import { FLOAT64_PATTERN } from "./runtime/ieee-pattern.mjs";
7
8
  const UNIT = new Product({});
9
+ const name = "ieee";
10
+ const patterns = [FLOAT64_PATTERN];
8
11
 
9
12
  function usage(stream = console.error) {
10
13
  stream(`Usage: ${argv[1]} --parse | --print`);
@@ -112,6 +115,14 @@ function printFloatText(number) {
112
115
  return String(number);
113
116
  }
114
117
 
118
+ function parse(text) {
119
+ return encodeNumberToValue(parseFloatText(text));
120
+ }
121
+
122
+ function print(value) {
123
+ return printFloatText(decodeValueToNumber(value));
124
+ }
125
+
115
126
  function readAll(stream) {
116
127
  return new Promise((resolve, reject) => {
117
128
  const chunks = [];
@@ -144,7 +155,11 @@ async function main() {
144
155
  }
145
156
  }
146
157
 
147
- main().catch((error) => {
148
- console.error(error.message || String(error));
149
- exit(1);
150
- });
158
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
159
+ main().catch((error) => {
160
+ console.error(error.message || String(error));
161
+ exit(1);
162
+ });
163
+ }
164
+
165
+ export { FLOAT64_PATTERN, name, patterns, parse, print };
package/codecs/int.mjs CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  import { stdin, stdout, argv, exit } from "node:process";
17
17
  import { Product, Variant } from "../Value.mjs";
18
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
18
19
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
19
20
 
20
21
  function usage(stream = console.error) {
@@ -31,6 +32,8 @@ const INT_PATTERN = [
31
32
  ["closed-union", [["0", 1], ["1", 1], ["_", 2]]],
32
33
  ["closed-product", []]
33
34
  ];
35
+ const name = "int";
36
+ const patterns = [INT_PATTERN];
34
37
 
35
38
  function readAll(stream) {
36
39
  return new Promise((resolve, reject) => {
@@ -108,7 +111,11 @@ async function main() {
108
111
  }
109
112
  }
110
113
 
111
- main().catch(err => {
112
- console.error(err.message || String(err));
113
- exit(1);
114
- });
114
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
115
+ main().catch(err => {
116
+ console.error(err.message || String(err));
117
+ exit(1);
118
+ });
119
+ }
120
+
121
+ export { INT_PATTERN, name, patterns, parseIntStr as parse, printIntValue as print };
package/codecs/json.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { stdin, stdout, argv, exit } from "node:process";
4
4
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
5
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
6
  import { fromJsonValue, toJsonValue, patternFromJsonValue } from "./json-codec.mjs";
6
7
 
7
8
  function usage(stream = console.error) {
@@ -44,7 +45,9 @@ async function main() {
44
45
  }
45
46
  }
46
47
 
47
- main().catch((error) => {
48
- console.error(error.stack || error.message || String(error));
49
- exit(1);
50
- });
48
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
49
+ main().catch((error) => {
50
+ console.error(error.stack || error.message || String(error));
51
+ exit(1);
52
+ });
53
+ }
@@ -4,6 +4,7 @@ import fs from "node:fs";
4
4
  import { argv, stdin, exit, stdout } from "node:process";
5
5
  import k from "../index.mjs";
6
6
  import { parseValue } from "../valueIO.mjs";
7
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
7
8
  import { exportPatternGraph } from "./runtime/codec.mjs";
8
9
  import { patternToPropertyList } from "./runtime/pattern-json.mjs";
9
10
  import { encodeToWire } from "./runtime/prefix-codec.mjs";
@@ -89,7 +90,9 @@ async function main() {
89
90
  stdout.write(encodeToWire(value, propertyList));
90
91
  }
91
92
 
92
- main().catch((error) => {
93
- console.error(error.stack || error.message || String(error));
94
- process.exit(1);
95
- });
93
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
94
+ main().catch((error) => {
95
+ console.error(error.stack || error.message || String(error));
96
+ process.exit(1);
97
+ });
98
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  import fs from "node:fs";
4
4
  import { argv, stdin, stdout } from "node:process";
5
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
6
  import { decodeWire } from "./runtime/prefix-codec.mjs";
6
7
 
7
8
  function usage(stream = console.error) {
@@ -55,7 +56,9 @@ async function main() {
55
56
  stdout.write(`${JSON.stringify(value)}\n`);
56
57
  }
57
58
 
58
- main().catch((error) => {
59
- console.error(error.stack || error.message || String(error));
60
- process.exit(1);
61
- });
59
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
60
+ main().catch((error) => {
61
+ console.error(error.stack || error.message || String(error));
62
+ process.exit(1);
63
+ });
64
+ }
@@ -0,0 +1,13 @@
1
+ import fs from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ function isMainEntrypoint(metaUrl, entryArg) {
5
+ if (!entryArg) return false;
6
+ try {
7
+ return fs.realpathSync(entryArg) === fs.realpathSync(fileURLToPath(metaUrl));
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+
13
+ export { isMainEntrypoint };
package/codecs/show.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import fs from "node:fs";
4
4
  import { argv, stdin, stdout, stderr } from "node:process";
5
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
6
  import { decodeWire } from "./runtime/prefix-codec.mjs";
6
7
  import { propertyListToFilter, valueToK } from "./runtime/show-value.mjs";
7
8
 
@@ -49,7 +50,9 @@ async function main() {
49
50
  stderr.write(`${valueStr} ?${filterStr}\n`);
50
51
  }
51
52
 
52
- main().catch((error) => {
53
- console.error(error.stack || error.message || String(error));
54
- process.exit(1);
55
- });
53
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
54
+ main().catch((error) => {
55
+ console.error(error.stack || error.message || String(error));
56
+ process.exit(1);
57
+ });
58
+ }
package/codecs/unit.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { stdin, stdout, argv, exit } from "node:process";
4
4
  import { Product } from "../Value.mjs";
5
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
6
  import { decodeWire, encodeToWire } from "./runtime/prefix-codec.mjs";
6
7
 
7
8
  function usage(stream = console.error) {
@@ -14,6 +15,8 @@ function usage(stream = console.error) {
14
15
  const UNIT_PATTERN = [
15
16
  ["closed-product", []]
16
17
  ];
18
+ const name = "unit";
19
+ const patterns = [UNIT_PATTERN];
17
20
 
18
21
  function readAll(stream) {
19
22
  return new Promise((resolve, reject) => {
@@ -28,6 +31,17 @@ function unitEncoding() {
28
31
  return encodeToWire(new Product({}), UNIT_PATTERN);
29
32
  }
30
33
 
34
+ function parse() {
35
+ return new Product({});
36
+ }
37
+
38
+ function print(value) {
39
+ if (!(value instanceof Product) || Object.keys(value.product).length !== 0) {
40
+ throw new Error("Input is not a unit value");
41
+ }
42
+ return "{}";
43
+ }
44
+
31
45
  async function main() {
32
46
  const args = argv.slice(2);
33
47
  if (args.includes("-h") || args.includes("--help")) {
@@ -49,13 +63,14 @@ async function main() {
49
63
 
50
64
  const input = await readAll(stdin);
51
65
  const { value } = decodeWire(input);
52
- if (!(value instanceof Product) || Object.keys(value.product).length !== 0) {
53
- throw new Error("Input is not a unit value");
54
- }
55
- stdout.write("{}");
66
+ stdout.write(print(value));
67
+ }
68
+
69
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
70
+ main().catch((error) => {
71
+ console.error(error.message || String(error));
72
+ exit(1);
73
+ });
56
74
  }
57
75
 
58
- main().catch((error) => {
59
- console.error(error.message || String(error));
60
- exit(1);
61
- });
76
+ export { UNIT_PATTERN, name, patterns, parse, print };
package/codecs/utf16.mjs CHANGED
@@ -1,7 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { stdin, stdout, argv, exit } from "node:process";
4
- import { encodeText, decodeText } from "./string-codec.mjs";
4
+ import { isMainEntrypoint } from "./runtime/cli-entry.mjs";
5
+ import {
6
+ STRING_PATTERN_PROPERTY_LIST,
7
+ encodeText,
8
+ decodeText,
9
+ textToStringValue,
10
+ stringValueToText
11
+ } from "./string-codec.mjs";
12
+
13
+ const name = "utf16";
14
+ const patterns = [STRING_PATTERN_PROPERTY_LIST];
15
+
16
+ function parse(text) {
17
+ return textToStringValue(text);
18
+ }
19
+
20
+ function print(value) {
21
+ return stringValueToText(value);
22
+ }
5
23
 
6
24
  function usage(stream = console.error) {
7
25
  stream(`Usage: ${argv[1]} --parse | --print`);
@@ -70,7 +88,11 @@ async function main() {
70
88
  }
71
89
  }
72
90
 
73
- main().catch(err => {
74
- console.error(err.message || String(err));
75
- exit(1);
76
- });
91
+ if (isMainEntrypoint(import.meta.url, argv[1])) {
92
+ main().catch(err => {
93
+ console.error(err.message || String(err));
94
+ exit(1);
95
+ });
96
+ }
97
+
98
+ export { name, patterns, parse, print };