@shd101wyy/yo 0.1.11 → 0.1.13
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 +10 -1
- package/out/cjs/index.cjs +579 -573
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +437 -431
- package/out/types/src/build-runner.d.ts +1 -1
- package/out/types/src/doc/builder.d.ts +21 -0
- package/out/types/src/doc/builder.test.d.ts +1 -0
- package/out/types/src/doc/extractor.d.ts +27 -0
- package/out/types/src/doc/extractor.test.d.ts +1 -0
- package/out/types/src/doc/model.d.ts +87 -0
- package/out/types/src/doc/render-html.d.ts +23 -0
- package/out/types/src/doc/render-html.test.d.ts +1 -0
- package/out/types/src/doc/render-json.d.ts +7 -0
- package/out/types/src/doc/render-json.test.d.ts +1 -0
- package/out/types/src/doc/render-markdown.d.ts +13 -0
- package/out/types/src/doc/render-markdown.test.d.ts +1 -0
- package/out/types/src/doc/sections.d.ts +7 -0
- package/out/types/src/doc/sections.test.d.ts +1 -0
- package/out/types/src/doc-command.d.ts +10 -0
- package/out/types/src/env.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +17 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/evaluator/exprs/import.d.ts +2 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/tests/import-path.test.d.ts +1 -0
- package/out/types/src/token.d.ts +4 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/build-site.ts +461 -0
- package/std/alg/hash.yo +12 -24
- package/std/allocator.yo +21 -29
- package/std/async.yo +4 -2
- package/std/build.yo +188 -42
- package/std/cli/arg_parser.yo +37 -1
- package/std/collections/array_list.yo +8 -20
- package/std/collections/btree_map.yo +15 -20
- package/std/collections/deque.yo +13 -15
- package/std/collections/hash_map.yo +15 -54
- package/std/collections/hash_set.yo +14 -50
- package/std/collections/linked_list.yo +6 -23
- package/std/collections/priority_queue.yo +15 -17
- package/std/crypto/md5.yo +10 -9
- package/std/crypto/random.yo +14 -12
- package/std/crypto/sha256.yo +9 -8
- package/std/encoding/base64.yo +13 -15
- package/std/encoding/hex.yo +14 -10
- package/std/encoding/html.yo +14 -11
- package/std/encoding/html_char_utils.yo +14 -11
- package/std/encoding/html_entities.yo +7 -8
- package/std/encoding/json.yo +36 -19
- package/std/encoding/punycode.yo +21 -18
- package/std/encoding/toml.yo +23 -9
- package/std/encoding/utf16.yo +16 -9
- package/std/error.yo +10 -23
- package/std/fmt/display.yo +15 -17
- package/std/fmt/index.yo +6 -27
- package/std/fmt/to_string.yo +4 -10
- package/std/fmt/writer.yo +33 -34
- package/std/fs/dir.yo +37 -30
- package/std/fs/file.yo +77 -75
- package/std/fs/metadata.yo +25 -25
- package/std/fs/temp.yo +21 -27
- package/std/fs/types.yo +20 -23
- package/std/fs/walker.yo +26 -31
- package/std/gc.yo +5 -0
- package/std/glob/index.yo +3 -0
- package/std/http/client.yo +25 -11
- package/std/http/http.yo +20 -0
- package/std/http/index.yo +1 -0
- package/std/io/reader.yo +4 -8
- package/std/io/writer.yo +4 -7
- package/std/libc/assert.yo +2 -2
- package/std/libc/ctype.yo +1 -2
- package/std/libc/dirent.yo +1 -2
- package/std/libc/errno.yo +1 -2
- package/std/libc/fcntl.yo +2 -2
- package/std/libc/float.yo +1 -2
- package/std/libc/limits.yo +1 -2
- package/std/libc/math.yo +2 -0
- package/std/libc/signal.yo +1 -2
- package/std/libc/stdatomic.yo +1 -2
- package/std/libc/stdint.yo +4 -3
- package/std/libc/stdio.yo +2 -0
- package/std/libc/stdlib.yo +2 -0
- package/std/libc/string.yo +2 -0
- package/std/libc/sys/stat.yo +1 -2
- package/std/libc/time.yo +2 -2
- package/std/libc/unistd.yo +2 -0
- package/std/libc/wctype.yo +1 -2
- package/std/libc/windows.yo +2 -2
- package/std/log/index.yo +11 -26
- package/std/net/addr.yo +18 -11
- package/std/net/dns.yo +3 -2
- package/std/net/errors.yo +16 -2
- package/std/net/tcp.yo +25 -22
- package/std/net/udp.yo +14 -12
- package/std/os/env.yo +23 -18
- package/std/os/signal.yo +31 -19
- package/std/path.yo +23 -74
- package/std/prelude.yo +284 -113
- package/std/process.yo +23 -37
- package/std/regex/compiler.yo +3 -5
- package/std/regex/flags.yo +11 -11
- package/std/regex/index.yo +2 -13
- package/std/regex/match.yo +3 -5
- package/std/regex/node.yo +6 -6
- package/std/regex/parser.yo +2 -4
- package/std/regex/unicode.yo +5 -5
- package/std/regex/vm.yo +5 -5
- package/std/string/index.yo +2 -1
- package/std/string/rune.yo +25 -1
- package/std/string/string.yo +31 -19
- package/std/string/unicode.yo +14 -15
- package/std/sync/channel.yo +18 -28
- package/std/sync/cond.yo +4 -0
- package/std/sync/mutex.yo +4 -1
- package/std/sync/once.yo +17 -19
- package/std/sync/rwlock.yo +19 -22
- package/std/sync/waitgroup.yo +21 -23
- package/std/sys/advise.yo +4 -4
- package/std/sys/bufio/buf_reader.yo +19 -16
- package/std/sys/bufio/buf_writer.yo +14 -11
- package/std/sys/clock.yo +4 -4
- package/std/sys/constants.yo +5 -5
- package/std/sys/copy.yo +9 -8
- package/std/sys/dir.yo +9 -8
- package/std/sys/dns.yo +8 -8
- package/std/sys/errors.yo +35 -6
- package/std/sys/events.yo +3 -3
- package/std/sys/externs.yo +3 -3
- package/std/sys/fallocate.yo +4 -4
- package/std/sys/fcntl.yo +8 -6
- package/std/sys/file.yo +7 -8
- package/std/sys/future.yo +1 -3
- package/std/sys/iov.yo +4 -4
- package/std/sys/lock.yo +7 -7
- package/std/sys/mmap.yo +7 -8
- package/std/sys/path.yo +4 -7
- package/std/sys/perm.yo +8 -8
- package/std/sys/pipe.yo +9 -8
- package/std/sys/process.yo +8 -8
- package/std/sys/seek.yo +4 -4
- package/std/sys/signal.yo +4 -4
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +4 -4
- package/std/sys/socketpair.yo +4 -4
- package/std/sys/sockinfo.yo +4 -4
- package/std/sys/statfs.yo +8 -8
- package/std/sys/statx.yo +4 -4
- package/std/sys/sysinfo.yo +4 -4
- package/std/sys/tcp.yo +8 -8
- package/std/sys/temp.yo +9 -8
- package/std/sys/time.yo +8 -8
- package/std/sys/timer.yo +7 -8
- package/std/sys/tty.yo +13 -10
- package/std/sys/udp.yo +8 -8
- package/std/sys/umask.yo +4 -4
- package/std/sys/unix.yo +5 -5
- package/std/testing/bench.yo +21 -10
- package/std/thread.yo +18 -9
- package/std/time/datetime.yo +12 -14
- package/std/time/duration.yo +12 -14
- package/std/time/instant.yo +13 -16
- package/std/time/sleep.yo +9 -8
- package/std/url/index.yo +3 -19
- package/std/worker.yo +10 -18
package/std/encoding/json.yo
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//! JSON parsing and serialization.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides a dynamically-typed JSON value tree.
|
|
4
|
+
//!
|
|
5
|
+
//! Example:
|
|
6
|
+
//! { json_parse, json_stringify, JsonValue } :: import "std/encoding/json";
|
|
7
|
+
//! { Exception } :: import "std/error";
|
|
8
|
+
//!
|
|
9
|
+
//! given(exn) := Exception(throw : ((err) -> { escape (); }));
|
|
10
|
+
//! v := json_parse(`{"x": 1}`);
|
|
11
|
+
//! println(json_stringify(v));
|
|
12
12
|
|
|
13
13
|
open import "../string";
|
|
14
14
|
{ ArrayList } :: import "../collections/array_list";
|
|
@@ -20,12 +20,19 @@ open import "../string";
|
|
|
20
20
|
// JsonError
|
|
21
21
|
// ============================================================================
|
|
22
22
|
|
|
23
|
+
/// JSON parsing error type.
|
|
23
24
|
JsonError :: enum(
|
|
25
|
+
/// Encountered an unexpected character at the given position.
|
|
24
26
|
UnexpectedChar(ch: u8, pos: usize),
|
|
27
|
+
/// Input ended unexpectedly.
|
|
25
28
|
UnexpectedEnd,
|
|
29
|
+
/// Failed to parse a numeric literal.
|
|
26
30
|
InvalidNumber,
|
|
31
|
+
/// Invalid escape sequence in a string.
|
|
27
32
|
InvalidEscape,
|
|
33
|
+
/// Invalid Unicode escape in a string.
|
|
28
34
|
InvalidUnicode,
|
|
35
|
+
/// Other error with a descriptive message.
|
|
29
36
|
Other(msg: String)
|
|
30
37
|
);
|
|
31
38
|
|
|
@@ -50,12 +57,19 @@ export JsonError;
|
|
|
50
57
|
// JsonValue
|
|
51
58
|
// ============================================================================
|
|
52
59
|
|
|
60
|
+
/// Dynamically-typed JSON value tree.
|
|
53
61
|
JsonValue :: enum(
|
|
62
|
+
/// JSON null.
|
|
54
63
|
Null,
|
|
64
|
+
/// JSON boolean.
|
|
55
65
|
Bool(value: bool),
|
|
66
|
+
/// JSON number (IEEE 754 double).
|
|
56
67
|
Number(value: f64),
|
|
68
|
+
/// JSON string.
|
|
57
69
|
Str(value: String),
|
|
70
|
+
/// JSON array of values.
|
|
58
71
|
Array(items: ArrayList(Self)),
|
|
72
|
+
/// JSON object with ordered key-value pairs.
|
|
59
73
|
Object(keys: ArrayList(String), values: ArrayList(Self))
|
|
60
74
|
);
|
|
61
75
|
|
|
@@ -63,13 +77,14 @@ JsonValue :: enum(
|
|
|
63
77
|
// JsonKV - key/value pair convenience struct for Object
|
|
64
78
|
// ============================================================================
|
|
65
79
|
|
|
80
|
+
/// Key-value pair for JSON object entries.
|
|
66
81
|
JsonKV :: struct(
|
|
67
82
|
key : String,
|
|
68
83
|
value : JsonValue
|
|
69
84
|
);
|
|
70
85
|
|
|
71
86
|
impl(JsonValue,
|
|
72
|
-
|
|
87
|
+
/// Get a field from an Object value by key. Returns `.None` if not an Object or key is missing.
|
|
73
88
|
get : (fn(self: Self, key: String) -> Option(JsonValue))(
|
|
74
89
|
match(self,
|
|
75
90
|
.Object(keys, values) => {
|
|
@@ -88,7 +103,7 @@ impl(JsonValue,
|
|
|
88
103
|
)
|
|
89
104
|
),
|
|
90
105
|
|
|
91
|
-
|
|
106
|
+
/// Get an element from an Array value by index.
|
|
92
107
|
at : (fn(self: Self, index: usize) -> Option(JsonValue))(
|
|
93
108
|
match(self,
|
|
94
109
|
.Array(items) => items.get(index),
|
|
@@ -96,7 +111,7 @@ impl(JsonValue,
|
|
|
96
111
|
)
|
|
97
112
|
),
|
|
98
113
|
|
|
99
|
-
|
|
114
|
+
/// Extract the boolean value, or `.None` if not a `Bool`.
|
|
100
115
|
as_bool : (fn(self: Self) -> Option(bool))(
|
|
101
116
|
match(self,
|
|
102
117
|
.Bool(b) => .Some(b),
|
|
@@ -104,7 +119,7 @@ impl(JsonValue,
|
|
|
104
119
|
)
|
|
105
120
|
),
|
|
106
121
|
|
|
107
|
-
|
|
122
|
+
/// Extract the numeric value, or `.None` if not a `Number`.
|
|
108
123
|
as_number : (fn(self: Self) -> Option(f64))(
|
|
109
124
|
match(self,
|
|
110
125
|
.Number(n) => .Some(n),
|
|
@@ -112,7 +127,7 @@ impl(JsonValue,
|
|
|
112
127
|
)
|
|
113
128
|
),
|
|
114
129
|
|
|
115
|
-
|
|
130
|
+
/// Extract the string value, or `.None` if not a `Str`.
|
|
116
131
|
as_string : (fn(self: Self) -> Option(String))(
|
|
117
132
|
match(self,
|
|
118
133
|
.Str(s) => .Some(s),
|
|
@@ -120,7 +135,7 @@ impl(JsonValue,
|
|
|
120
135
|
)
|
|
121
136
|
),
|
|
122
137
|
|
|
123
|
-
|
|
138
|
+
/// Extract the array items, or `.None` if not an `Array`.
|
|
124
139
|
as_array : (fn(self: Self) -> Option(ArrayList(JsonValue)))(
|
|
125
140
|
match(self,
|
|
126
141
|
.Array(items) => .Some(items),
|
|
@@ -128,7 +143,7 @@ impl(JsonValue,
|
|
|
128
143
|
)
|
|
129
144
|
),
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
/// Extract object entries as `ArrayList(JsonKV)`, or `.None` if not an `Object`.
|
|
132
147
|
as_object : (fn(self: Self) -> Option(ArrayList(JsonKV)))(
|
|
133
148
|
match(self,
|
|
134
149
|
.Object(keys, values) => {
|
|
@@ -468,6 +483,7 @@ _parse_value :: (fn(p: _Parser) -> Result(JsonValue, JsonError))({
|
|
|
468
483
|
// Public API
|
|
469
484
|
// ============================================================================
|
|
470
485
|
|
|
486
|
+
/// Parse a JSON string into a `JsonValue` tree. Throws via `Exception` on invalid input.
|
|
471
487
|
json_parse :: (fn(s: str, using(exn : Exception)) -> JsonValue)({
|
|
472
488
|
p := _Parser.new(s);
|
|
473
489
|
match(_parse_value(p),
|
|
@@ -558,13 +574,14 @@ _stringify_into :: (fn(value: JsonValue, out: ArrayList(u8)) -> unit)({
|
|
|
558
574
|
);
|
|
559
575
|
});
|
|
560
576
|
|
|
577
|
+
/// Serialize a `JsonValue` to a compact JSON string.
|
|
561
578
|
json_stringify :: (fn(value: JsonValue) -> String)({
|
|
562
579
|
out := ArrayList(u8).new();
|
|
563
580
|
_stringify_into(value, out);
|
|
564
581
|
String.from_bytes(out)
|
|
565
582
|
});
|
|
566
583
|
|
|
567
|
-
|
|
584
|
+
/// Serialize a `JsonValue` to a pretty-printed JSON string.
|
|
568
585
|
json_stringify_pretty :: (fn(value: JsonValue, _indent: usize) -> String)(
|
|
569
586
|
json_stringify(value)
|
|
570
587
|
);
|
package/std/encoding/punycode.yo
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//! Punycode encoding/decoding (RFC 3492) for internationalized domain names.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides punycode encoding/decoding and IDN hostname conversion.
|
|
4
|
+
//!
|
|
5
|
+
//! Example:
|
|
6
|
+
//! { punycode_decode, punycode_encode, to_unicode, to_ascii } :: import "std/encoding/punycode";
|
|
7
|
+
//!
|
|
8
|
+
//! encoded := punycode_encode(`München`);
|
|
9
|
+
//! decoded := punycode_decode(encoded);
|
|
10
|
+
//! ascii_domain := to_ascii(`münchen.de`); // "xn--mnchen-3ya.de"
|
|
11
|
+
//! unicode_domain := to_unicode(ascii_domain); // "münchen.de"
|
|
12
12
|
|
|
13
13
|
open import "../string";
|
|
14
14
|
{ ArrayList } :: import "../collections/array_list";
|
|
@@ -122,8 +122,9 @@ _string_to_codepoints :: (fn(s: String) -> ArrayList(i32))({
|
|
|
122
122
|
cps
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
/// Decode a punycode-encoded string (without the `xn--` prefix).
|
|
126
|
+
///
|
|
127
|
+
/// Returns `.Some(decoded)` on success, `.None` on invalid input.
|
|
127
128
|
punycode_decode :: (fn(input: String) -> Option(String))({
|
|
128
129
|
(bytes : ArrayList(u8)) = input.as_bytes();
|
|
129
130
|
(input_len : i32) = i32(bytes.len());
|
|
@@ -220,7 +221,7 @@ punycode_decode :: (fn(input: String) -> Option(String))({
|
|
|
220
221
|
.Some(String.from_bytes(result_bytes))
|
|
221
222
|
});
|
|
222
223
|
|
|
223
|
-
|
|
224
|
+
/// Encode a Unicode string to punycode (without the `xn--` prefix).
|
|
224
225
|
punycode_encode :: (fn(input: String) -> String)({
|
|
225
226
|
(cps : ArrayList(i32)) = _string_to_codepoints(input);
|
|
226
227
|
(cp_count : i32) = i32(cps.len());
|
|
@@ -300,8 +301,9 @@ punycode_encode :: (fn(input: String) -> String)({
|
|
|
300
301
|
String.from_bytes(out)
|
|
301
302
|
});
|
|
302
303
|
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
/// Convert an IDN hostname to Unicode display form.
|
|
305
|
+
///
|
|
306
|
+
/// Splits on `.`, decodes `xn--` labels via punycode, and keeps original labels on failure.
|
|
305
307
|
to_unicode :: (fn(hostname: String) -> String)({
|
|
306
308
|
(parts : ArrayList(String)) = hostname.split(`.`);
|
|
307
309
|
(result : String) = ``;
|
|
@@ -331,8 +333,9 @@ to_unicode :: (fn(hostname: String) -> String)({
|
|
|
331
333
|
result
|
|
332
334
|
});
|
|
333
335
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
+
/// Convert a Unicode hostname to ASCII-compatible encoding.
|
|
337
|
+
///
|
|
338
|
+
/// Non-ASCII labels are punycode-encoded with the `xn--` prefix.
|
|
336
339
|
to_ascii :: (fn(hostname: String) -> String)({
|
|
337
340
|
(parts : ArrayList(String)) = hostname.split(`.`);
|
|
338
341
|
(result : String) = ``;
|
package/std/encoding/toml.yo
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! Basic TOML parser for configuration files.
|
|
2
|
+
//!
|
|
3
|
+
//! Parses a subset of TOML into a `TomlValue` tree.
|
|
4
|
+
//! Supports: strings, integers, booleans, table sections, comments.
|
|
5
|
+
//!
|
|
6
|
+
//! Example:
|
|
7
|
+
//! { toml_parse, TomlValue } :: import "std/encoding/toml";
|
|
8
|
+
//! // Or via the encoding index:
|
|
9
|
+
//! { toml_parse, TomlValue } :: import "std/encoding";
|
|
10
10
|
|
|
11
11
|
open import "../string";
|
|
12
12
|
{ ArrayList } :: import "../collections/array_list";
|
|
13
13
|
|
|
14
|
+
/// TOML value type — the result of parsing a TOML document.
|
|
14
15
|
TomlValue :: enum(
|
|
16
|
+
/// A TOML string value.
|
|
15
17
|
Str(value: String),
|
|
18
|
+
/// A TOML integer value.
|
|
16
19
|
Int(value: i64),
|
|
20
|
+
/// A TOML boolean value.
|
|
17
21
|
Bool(value: bool),
|
|
22
|
+
/// A TOML table (ordered key-value map).
|
|
18
23
|
Table(keys: ArrayList(String), values: ArrayList(Self))
|
|
19
24
|
);
|
|
20
25
|
|
|
21
26
|
impl(TomlValue,
|
|
27
|
+
/// Create a new empty table.
|
|
22
28
|
new_table : (fn() -> Self)(
|
|
23
29
|
Self.Table(keys: ArrayList(String).new(), values: ArrayList(TomlValue).new())
|
|
24
30
|
),
|
|
25
31
|
|
|
32
|
+
/// Look up a value by key in a table. Returns `.None` if not a table or key is missing.
|
|
26
33
|
get : (fn(self: Self, key: String) -> Option(TomlValue))(
|
|
27
34
|
match(self,
|
|
28
35
|
.Table(keys, values) => {
|
|
@@ -41,10 +48,12 @@ impl(TomlValue,
|
|
|
41
48
|
)
|
|
42
49
|
),
|
|
43
50
|
|
|
51
|
+
/// Check whether the table contains the given key.
|
|
44
52
|
has_key : (fn(self: Self, key: String) -> bool)(
|
|
45
53
|
self.get(key).is_some()
|
|
46
54
|
),
|
|
47
55
|
|
|
56
|
+
/// Insert or update a key-value pair in the table.
|
|
48
57
|
set : (fn(self: Self, key: String, value: TomlValue) -> unit)(
|
|
49
58
|
match(self,
|
|
50
59
|
.Table(keys, values) => {
|
|
@@ -72,6 +81,7 @@ impl(TomlValue,
|
|
|
72
81
|
)
|
|
73
82
|
),
|
|
74
83
|
|
|
84
|
+
/// Return the number of keys in the table, or `0` if not a table.
|
|
75
85
|
table_len : (fn(self: Self) -> usize)(
|
|
76
86
|
match(self,
|
|
77
87
|
.Table(keys, _) => keys.len(),
|
|
@@ -79,14 +89,17 @@ impl(TomlValue,
|
|
|
79
89
|
)
|
|
80
90
|
),
|
|
81
91
|
|
|
92
|
+
/// Extract the string value, or `.None` if not a `Str`.
|
|
82
93
|
as_string : (fn(self: Self) -> Option(String))(
|
|
83
94
|
match(self, .Str(s) => .Some(s), _ => .None)
|
|
84
95
|
),
|
|
85
96
|
|
|
97
|
+
/// Extract the integer value, or `.None` if not an `Int`.
|
|
86
98
|
as_int : (fn(self: Self) -> Option(i64))(
|
|
87
99
|
match(self, .Int(n) => .Some(n), _ => .None)
|
|
88
100
|
),
|
|
89
101
|
|
|
102
|
+
/// Extract the boolean value, or `.None` if not a `Bool`.
|
|
90
103
|
as_bool : (fn(self: Self) -> Option(bool))(
|
|
91
104
|
match(self, .Bool(b) => .Some(b), _ => .None)
|
|
92
105
|
)
|
|
@@ -129,6 +142,7 @@ _parse_toml_value :: (fn(raw: String) -> Result(TomlValue, String))({
|
|
|
129
142
|
.Err(`Unknown value: ${trimmed}`)
|
|
130
143
|
});
|
|
131
144
|
|
|
145
|
+
/// Parse a TOML string into a `TomlValue` tree. Returns `Result(TomlValue, String)`.
|
|
132
146
|
toml_parse :: (fn(input: String) -> Result(TomlValue, String))({
|
|
133
147
|
root_keys := ArrayList(String).new();
|
|
134
148
|
root_vals := ArrayList(TomlValue).new();
|
package/std/encoding/utf16.yo
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! UTF-8 to UTF-16 conversion and vice versa.
|
|
2
|
+
//!
|
|
3
|
+
//! Converts between Yo's UTF-8 `str` and UTF-16 code units (`ArrayList(u16)`).
|
|
4
|
+
//!
|
|
5
|
+
//! Example:
|
|
6
|
+
//! { utf8_to_utf16, utf16_to_utf8 } :: import "std/encoding/utf16";
|
|
7
|
+
//!
|
|
8
|
+
//! words := utf8_to_utf16("hello");
|
|
9
|
+
//! s := utf16_to_utf8(words);
|
|
10
10
|
|
|
11
11
|
open import "../string";
|
|
12
12
|
{ ArrayList } :: import "../collections/array_list";
|
|
@@ -17,6 +17,9 @@ open import "../string";
|
|
|
17
17
|
// UTF-8 → UTF-16
|
|
18
18
|
// ============================================================================
|
|
19
19
|
|
|
20
|
+
/// Convert a UTF-8 string to an `ArrayList(u16)` of UTF-16 code units.
|
|
21
|
+
///
|
|
22
|
+
/// Handles BMP characters directly and encodes supplementary characters as surrogate pairs.
|
|
20
23
|
utf8_to_utf16 :: (fn(s: str) -> ArrayList(u16))({
|
|
21
24
|
out := ArrayList(u16).new();
|
|
22
25
|
i := usize(0);
|
|
@@ -64,6 +67,10 @@ export utf8_to_utf16;
|
|
|
64
67
|
// UTF-16 → UTF-8
|
|
65
68
|
// ============================================================================
|
|
66
69
|
|
|
70
|
+
/// Convert UTF-16 code units to a UTF-8 `String`.
|
|
71
|
+
///
|
|
72
|
+
/// Decodes surrogate pairs back into supplementary code points.
|
|
73
|
+
/// Throws via `Exception` on unpaired surrogates.
|
|
67
74
|
utf16_to_utf8 :: (fn(data: ArrayList(u16), using(exn : Exception)) -> String)({
|
|
68
75
|
out := ArrayList(u8).new();
|
|
69
76
|
i := usize(0);
|
package/std/error.yo
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// Provides a standard Error trait for typed error propagation.
|
|
4
|
-
// All error types in the standard library should implement this trait.
|
|
1
|
+
//! Standard error handling types and traits for Yo.
|
|
2
|
+
|
|
5
3
|
open import "./string";
|
|
6
4
|
open import "./fmt";
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// ============================================================================
|
|
11
|
-
|
|
6
|
+
/// Standard error trait for typed error propagation.
|
|
7
|
+
/// All error types should implement this trait along with `ToString`.
|
|
12
8
|
Error :: trait(
|
|
13
9
|
(source : (fn(self: *(Self)) -> Option(Dyn(SelfTrait)))) ?= ((self) -> .None),
|
|
14
10
|
|
|
@@ -16,32 +12,23 @@ Error :: trait(
|
|
|
16
12
|
);
|
|
17
13
|
export Error;
|
|
18
14
|
|
|
15
|
+
/// Type-erased dynamic error type. Wraps any type implementing `Error`.
|
|
19
16
|
AnyError :: Dyn(Error);
|
|
20
17
|
export AnyError;
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
// Error implementations for standard types
|
|
24
|
-
// ============================================================================
|
|
25
|
-
|
|
19
|
+
/// Allows using `String` directly as an error type.
|
|
26
20
|
impl(String, Error());
|
|
27
21
|
|
|
28
|
-
///
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
// Example (function that may throw):
|
|
32
|
-
//
|
|
33
|
-
// safe_div :: (fn(x: i32, y: i32, using(exn : Exception)) -> i32)(
|
|
34
|
-
// cond(
|
|
35
|
-
// (y == i32(0)) => exn.throw(dyn `division by zero`)),
|
|
36
|
-
// true => (x / y)
|
|
37
|
-
// )
|
|
38
|
-
// );
|
|
22
|
+
/// Non-resumable exception handling effect module.
|
|
23
|
+
/// Use `throw` to raise an `AnyError` and abort the current computation.
|
|
39
24
|
Exception :: module(
|
|
40
25
|
throw : (fn(forall(ResumeType : Type), error : AnyError) -> ResumeType)
|
|
41
26
|
);
|
|
42
27
|
export Exception;
|
|
43
28
|
|
|
44
29
|
|
|
30
|
+
/// Creates a resumable exception module parameterized by the resume type.
|
|
31
|
+
/// Unlike `Exception`, the handler can return a value to resume the computation.
|
|
45
32
|
ResumableException :: (fn(comptime(ResumeType) : Type) -> comptime(Module))(
|
|
46
33
|
module(
|
|
47
34
|
throw : (fn(error : AnyError) -> ResumeType)
|
package/std/fmt/display.yo
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// ));
|
|
1
|
+
//! Display trait for streaming formatted output to a Writer.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! impl(MyType, Display(
|
|
7
|
+
//! display : (fn(self: *(Self), writer: Writer) -> Writer)(
|
|
8
|
+
//! writer.write_str("MyType(").write_i64(i64(self.value)).write_str(")")
|
|
9
|
+
//! )
|
|
10
|
+
//! ));
|
|
11
|
+
//! ```
|
|
13
12
|
|
|
14
13
|
{ Writer } :: import "./writer";
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// ============================================================================
|
|
15
|
+
/// Trait for formatting values by writing to a `Writer` rather than allocating a `String`.
|
|
16
|
+
/// Complement to `ToString` for streaming output into an existing buffer.
|
|
19
17
|
|
|
20
|
-
Display :: (fn(comptime(T) : Type) -> comptime(
|
|
18
|
+
Display :: (fn(comptime(T) : Type) -> comptime(Trait))
|
|
21
19
|
trait(
|
|
22
|
-
display
|
|
20
|
+
display : (fn(self: *(T), writer: Writer) -> Writer)
|
|
23
21
|
)
|
|
24
22
|
;
|
|
25
23
|
|
package/std/fmt/index.yo
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
+
//! Formatted output to stdout and stderr.
|
|
2
|
+
|
|
1
3
|
{ fwrite, stdout, stderr } :: import "../libc/stdio";
|
|
2
4
|
{ String } :: import "../string";
|
|
3
5
|
{ ToString } :: import "./to_string.yo";
|
|
4
6
|
|
|
5
7
|
export ToString;
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
* Print a value that implements ToString to stdout, with a newline.
|
|
9
|
-
*
|
|
10
|
-
* Example:
|
|
11
|
-
* println(42); // prints "42\n"
|
|
12
|
-
* println("hello"); // prints "hello\n"
|
|
13
|
-
*/
|
|
9
|
+
/// Print a value that implements `ToString` to stdout, followed by a newline.
|
|
14
10
|
println :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
15
11
|
s := v.to_string();
|
|
16
12
|
str_bytes := s.as_bytes();
|
|
@@ -26,13 +22,7 @@ println :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
|
26
22
|
});
|
|
27
23
|
export println;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
* Print a value that implements ToString to stdout, without a newline.
|
|
31
|
-
*
|
|
32
|
-
* Example:
|
|
33
|
-
* print("hello ");
|
|
34
|
-
* print("world"); // prints "hello world"
|
|
35
|
-
*/
|
|
25
|
+
/// Print a value that implements `ToString` to stdout, without a trailing newline.
|
|
36
26
|
print :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
37
27
|
s := v.to_string();
|
|
38
28
|
str_bytes := s.as_bytes();
|
|
@@ -47,12 +37,7 @@ print :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
|
47
37
|
});
|
|
48
38
|
export print;
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
* Print a value that implements ToString to stderr, with a newline.
|
|
52
|
-
*
|
|
53
|
-
* Example:
|
|
54
|
-
* eprintln("Error: something went wrong");
|
|
55
|
-
*/
|
|
40
|
+
/// Print a value that implements `ToString` to stderr, followed by a newline.
|
|
56
41
|
eprintln :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
57
42
|
s := v.to_string();
|
|
58
43
|
str_bytes := s.as_bytes();
|
|
@@ -68,13 +53,7 @@ eprintln :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
|
68
53
|
});
|
|
69
54
|
export eprintln;
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
* Print a value that implements ToString to stderr, without a newline.
|
|
73
|
-
*
|
|
74
|
-
* Example:
|
|
75
|
-
* eprint("Warning: ");
|
|
76
|
-
* eprintln("be careful");
|
|
77
|
-
*/
|
|
56
|
+
/// Print a value that implements `ToString` to stderr, without a trailing newline.
|
|
78
57
|
eprint :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
|
|
79
58
|
s := v.to_string();
|
|
80
59
|
str_bytes := s.as_bytes();
|
package/std/fmt/to_string.yo
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
+
//! ToString trait and implementations for all primitive types.
|
|
2
|
+
|
|
1
3
|
{ String, rune } :: import "../string";
|
|
2
4
|
{ snprintf } :: import "../libc/stdio";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* This is similar to:
|
|
8
|
-
* - Rust's `std::fmt::Display` / `ToString` trait
|
|
9
|
-
* - Go's `fmt.Stringer` interface
|
|
10
|
-
* - Java's `Object.toString()` method
|
|
11
|
-
*
|
|
12
|
-
* Types implementing this trait can be used with `println`, `print`, and `format`.
|
|
13
|
-
*/
|
|
6
|
+
/// Trait for converting values to their `String` representation.
|
|
7
|
+
/// Types implementing this trait can be used with `println`, `print`, and template strings.
|
|
14
8
|
ToString :: trait(
|
|
15
9
|
to_string : (fn(self: *(Self)) -> String)
|
|
16
10
|
);
|