@shd101wyy/yo 0.1.12 → 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.
Files changed (164) hide show
  1. package/README.md +10 -1
  2. package/out/cjs/index.cjs +578 -572
  3. package/out/cjs/yo-cli.cjs +1413 -592
  4. package/out/esm/index.mjs +434 -428
  5. package/out/types/src/build-runner.d.ts +1 -1
  6. package/out/types/src/doc/builder.d.ts +21 -0
  7. package/out/types/src/doc/builder.test.d.ts +1 -0
  8. package/out/types/src/doc/extractor.d.ts +27 -0
  9. package/out/types/src/doc/extractor.test.d.ts +1 -0
  10. package/out/types/src/doc/model.d.ts +87 -0
  11. package/out/types/src/doc/render-html.d.ts +23 -0
  12. package/out/types/src/doc/render-html.test.d.ts +1 -0
  13. package/out/types/src/doc/render-json.d.ts +7 -0
  14. package/out/types/src/doc/render-json.test.d.ts +1 -0
  15. package/out/types/src/doc/render-markdown.d.ts +13 -0
  16. package/out/types/src/doc/render-markdown.test.d.ts +1 -0
  17. package/out/types/src/doc/sections.d.ts +7 -0
  18. package/out/types/src/doc/sections.test.d.ts +1 -0
  19. package/out/types/src/doc-command.d.ts +10 -0
  20. package/out/types/src/env.d.ts +1 -0
  21. package/out/types/src/evaluator/builtins/build.d.ts +17 -0
  22. package/out/types/src/evaluator/context.d.ts +1 -0
  23. package/out/types/src/expr.d.ts +2 -1
  24. package/out/types/src/token.d.ts +4 -0
  25. package/out/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +2 -1
  27. package/scripts/build-site.ts +461 -0
  28. package/std/alg/hash.yo +12 -24
  29. package/std/allocator.yo +21 -29
  30. package/std/async.yo +4 -2
  31. package/std/build.yo +188 -42
  32. package/std/cli/arg_parser.yo +37 -1
  33. package/std/collections/array_list.yo +8 -20
  34. package/std/collections/btree_map.yo +15 -20
  35. package/std/collections/deque.yo +13 -15
  36. package/std/collections/hash_map.yo +15 -54
  37. package/std/collections/hash_set.yo +14 -50
  38. package/std/collections/linked_list.yo +6 -23
  39. package/std/collections/priority_queue.yo +15 -17
  40. package/std/crypto/md5.yo +10 -9
  41. package/std/crypto/random.yo +14 -12
  42. package/std/crypto/sha256.yo +9 -8
  43. package/std/encoding/base64.yo +13 -15
  44. package/std/encoding/hex.yo +14 -10
  45. package/std/encoding/html.yo +14 -11
  46. package/std/encoding/html_char_utils.yo +14 -11
  47. package/std/encoding/html_entities.yo +7 -8
  48. package/std/encoding/json.yo +36 -19
  49. package/std/encoding/punycode.yo +21 -18
  50. package/std/encoding/toml.yo +23 -9
  51. package/std/encoding/utf16.yo +16 -9
  52. package/std/error.yo +10 -23
  53. package/std/fmt/display.yo +15 -17
  54. package/std/fmt/index.yo +6 -27
  55. package/std/fmt/to_string.yo +4 -10
  56. package/std/fmt/writer.yo +33 -34
  57. package/std/fs/dir.yo +37 -30
  58. package/std/fs/file.yo +77 -75
  59. package/std/fs/metadata.yo +25 -25
  60. package/std/fs/temp.yo +21 -27
  61. package/std/fs/types.yo +20 -23
  62. package/std/fs/walker.yo +26 -31
  63. package/std/gc.yo +5 -0
  64. package/std/glob/index.yo +3 -0
  65. package/std/http/client.yo +25 -11
  66. package/std/http/http.yo +20 -0
  67. package/std/http/index.yo +1 -0
  68. package/std/io/reader.yo +4 -8
  69. package/std/io/writer.yo +4 -7
  70. package/std/libc/assert.yo +2 -2
  71. package/std/libc/ctype.yo +1 -2
  72. package/std/libc/dirent.yo +1 -2
  73. package/std/libc/errno.yo +1 -2
  74. package/std/libc/fcntl.yo +2 -2
  75. package/std/libc/float.yo +1 -2
  76. package/std/libc/limits.yo +1 -2
  77. package/std/libc/math.yo +2 -0
  78. package/std/libc/signal.yo +1 -2
  79. package/std/libc/stdatomic.yo +1 -2
  80. package/std/libc/stdint.yo +4 -3
  81. package/std/libc/stdio.yo +2 -0
  82. package/std/libc/stdlib.yo +2 -0
  83. package/std/libc/string.yo +2 -0
  84. package/std/libc/sys/stat.yo +1 -2
  85. package/std/libc/time.yo +2 -2
  86. package/std/libc/unistd.yo +2 -0
  87. package/std/libc/wctype.yo +1 -2
  88. package/std/libc/windows.yo +2 -2
  89. package/std/log/index.yo +11 -26
  90. package/std/net/addr.yo +18 -11
  91. package/std/net/dns.yo +3 -2
  92. package/std/net/errors.yo +16 -2
  93. package/std/net/tcp.yo +25 -22
  94. package/std/net/udp.yo +14 -12
  95. package/std/os/env.yo +23 -18
  96. package/std/os/signal.yo +31 -19
  97. package/std/path.yo +23 -74
  98. package/std/prelude.yo +284 -113
  99. package/std/process.yo +23 -37
  100. package/std/regex/compiler.yo +3 -5
  101. package/std/regex/flags.yo +11 -11
  102. package/std/regex/index.yo +2 -13
  103. package/std/regex/match.yo +3 -5
  104. package/std/regex/node.yo +6 -6
  105. package/std/regex/parser.yo +2 -4
  106. package/std/regex/unicode.yo +5 -5
  107. package/std/regex/vm.yo +5 -5
  108. package/std/string/index.yo +2 -1
  109. package/std/string/rune.yo +25 -1
  110. package/std/string/string.yo +31 -19
  111. package/std/string/unicode.yo +14 -15
  112. package/std/sync/channel.yo +18 -28
  113. package/std/sync/cond.yo +4 -0
  114. package/std/sync/mutex.yo +4 -1
  115. package/std/sync/once.yo +17 -19
  116. package/std/sync/rwlock.yo +19 -22
  117. package/std/sync/waitgroup.yo +21 -23
  118. package/std/sys/advise.yo +4 -4
  119. package/std/sys/bufio/buf_reader.yo +19 -16
  120. package/std/sys/bufio/buf_writer.yo +14 -11
  121. package/std/sys/clock.yo +4 -4
  122. package/std/sys/constants.yo +5 -5
  123. package/std/sys/copy.yo +9 -8
  124. package/std/sys/dir.yo +9 -8
  125. package/std/sys/dns.yo +8 -8
  126. package/std/sys/errors.yo +35 -6
  127. package/std/sys/events.yo +3 -3
  128. package/std/sys/externs.yo +3 -3
  129. package/std/sys/fallocate.yo +4 -4
  130. package/std/sys/fcntl.yo +8 -6
  131. package/std/sys/file.yo +7 -8
  132. package/std/sys/future.yo +1 -3
  133. package/std/sys/iov.yo +4 -4
  134. package/std/sys/lock.yo +7 -7
  135. package/std/sys/mmap.yo +7 -8
  136. package/std/sys/path.yo +4 -7
  137. package/std/sys/perm.yo +8 -8
  138. package/std/sys/pipe.yo +9 -8
  139. package/std/sys/process.yo +8 -8
  140. package/std/sys/seek.yo +4 -4
  141. package/std/sys/signal.yo +4 -4
  142. package/std/sys/signals.yo +4 -4
  143. package/std/sys/socket.yo +4 -4
  144. package/std/sys/socketpair.yo +4 -4
  145. package/std/sys/sockinfo.yo +4 -4
  146. package/std/sys/statfs.yo +8 -8
  147. package/std/sys/statx.yo +4 -4
  148. package/std/sys/sysinfo.yo +4 -4
  149. package/std/sys/tcp.yo +8 -8
  150. package/std/sys/temp.yo +9 -8
  151. package/std/sys/time.yo +8 -8
  152. package/std/sys/timer.yo +7 -8
  153. package/std/sys/tty.yo +13 -10
  154. package/std/sys/udp.yo +8 -8
  155. package/std/sys/umask.yo +4 -4
  156. package/std/sys/unix.yo +5 -5
  157. package/std/testing/bench.yo +21 -10
  158. package/std/thread.yo +18 -9
  159. package/std/time/datetime.yo +12 -14
  160. package/std/time/duration.yo +12 -14
  161. package/std/time/instant.yo +13 -16
  162. package/std/time/sleep.yo +9 -8
  163. package/std/url/index.yo +3 -19
  164. package/std/worker.yo +10 -18
@@ -1,22 +1,20 @@
1
- // std/collections/deque.yo - Double-ended queue (ring buffer)
2
- //
3
- // A Deque supports O(1) push/pop at both ends using a circular buffer.
4
- //
5
- // Example:
6
- // { Deque } :: import "std/collections/deque";
7
- //
8
- // d := Deque(i32).new();
9
- // d.push_back(1);
10
- // d.push_front(0);
11
- // x := d.pop_front().unwrap(); // 0
1
+ //! Double-ended queue (ring buffer) with O(1) push/pop at both ends.
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```rust
6
+ //! { Deque } :: import "std/collections/deque";
7
+ //!
8
+ //! d := Deque(i32).new();
9
+ //! d.push_back(1);
10
+ //! d.push_front(0);
11
+ //! x := d.pop_front().unwrap(); // 0
12
+ //! ```
12
13
 
13
14
  { GlobalAllocator, AllocError } :: import "../allocator";
14
15
  { malloc, realloc, free } :: GlobalAllocator;
15
16
 
16
- // ============================================================================
17
- // Deque
18
- // ============================================================================
19
-
17
+ /// Circular buffer supporting efficient push/pop at both front and back.
20
18
  Deque :: (fn(comptime(T) : Type) -> comptime(Type))(
21
19
  object(
22
20
  _buf : ?*(T),
@@ -1,59 +1,31 @@
1
- /**
2
- * HashMap - A high-performance hash map implementation using SwissTable algorithm
3
- *
4
- * SwissTable is a state-of-the-art hash table design developed by Google for Abseil.
5
- * Key features:
6
- * - SIMD-accelerated lookup using control bytes
7
- * - Quadratic probing for collision resolution
8
- * - 7/8 max load factor for good performance
9
- * - Compact memory layout with metadata array
10
- *
11
- * Memory layout:
12
- * - ctrl: Array of control bytes (metadata), one per bucket
13
- * - data: Array of key-value pairs
14
- *
15
- * Control byte values:
16
- * - 0xFF (EMPTY): Bucket is empty and never used
17
- * - 0xFE (DELETED): Bucket was used but is now deleted
18
- * - 0x00-0x7F: Lower 7 bits of hash (H2 hash), indicates occupied bucket
19
- *
20
- * Hash function splits hash into two parts:
21
- * - H1: Upper bits used to find bucket group
22
- * - H2: Lower 7 bits stored in control byte for fast SIMD comparison
23
- */
1
+ //! Hash map using SwissTable algorithm with SIMD-accelerated lookup.
2
+
24
3
  { GlobalAllocator, AllocError } :: import "../allocator.yo";
25
4
  { malloc, calloc, realloc, free } :: GlobalAllocator;
26
5
 
27
- /**
28
- * HashMap error types
29
- */
6
+ /// Error variants for HashMap operations.
30
7
  HashMapError :: enum(
8
+ /// Memory allocation failed.
31
9
  AllocError(error : AllocError),
10
+ /// The requested key was not found.
32
11
  KeyNotFound,
12
+ /// Capacity calculation overflowed.
33
13
  CapacityOverflow
34
14
  );
35
15
 
36
- /**
37
- * Control byte constants for SwissTable
38
- */
16
+ /// Control byte for an empty bucket (never used).
39
17
  CTRL_EMPTY :: u8(255);
18
+ /// Control byte for a deleted bucket (tombstone).
40
19
  CTRL_DELETED :: u8(254);
41
20
 
42
- /**
43
- * Default initial capacity (must be power of 2)
44
- */
21
+ /// Default initial capacity (must be power of 2).
45
22
  DEFAULT_CAPACITY :: usize(16);
46
23
 
47
- /**
48
- * Maximum load factor: 7/8 = 0.875
49
- * We resize when: size > capacity * 7 / 8
50
- */
24
+ /// Maximum load factor numerator (7/8 = 0.875). Resize when `size > capacity * 7 / 8`.
51
25
  MAX_LOAD_FACTOR_NUMERATOR :: usize(7);
52
26
  MAX_LOAD_FACTOR_DENOMINATOR :: usize(8);
53
27
 
54
- /**
55
- * Bucket - Internal structure to store key-value pairs
56
- */
28
+ /// Key-value pair stored in a hash map bucket.
57
29
  Bucket :: (fn(comptime(K): Type, comptime(V): Type) -> comptime(Type))
58
30
  struct(
59
31
  key : K,
@@ -61,29 +33,18 @@ Bucket :: (fn(comptime(K): Type, comptime(V): Type) -> comptime(Type))
61
33
  )
62
34
  ;
63
35
 
64
- /**
65
- * Extract H2 hash (lower 7 bits) from full hash
66
- */
36
+ /// Extract H2 hash (lower 7 bits) from full hash for control byte comparison.
67
37
  h2_hash :: (fn(hash: u64) -> u8)
68
38
  u8(hash & u64(127))
69
39
  ;
70
40
 
71
- /**
72
- * Extract H1 hash (upper bits) for bucket index
73
- */
41
+ /// Extract H1 hash (upper bits) for bucket index calculation.
74
42
  h1_hash :: (fn(hash: u64, capacity: usize) -> usize)
75
43
  (usize((hash >> u64(7))) % capacity)
76
44
  ;
77
45
 
78
- /**
79
- * HashMap type - high-performance hash table using SwissTable
80
- *
81
- * Memory layout:
82
- * - ctrl: Pointer to control bytes array (length = capacity)
83
- * - data: Pointer to buckets array (length = capacity)
84
- * - capacity: Total number of buckets (always power of 2)
85
- * - size: Current number of occupied buckets
86
- */
46
+ /// High-performance hash map using SwissTable algorithm.
47
+ /// Keys must implement `Eq` and `Hash`. Provides O(1) average lookup, insert, and delete.
87
48
  HashMap :: (fn(
88
49
  comptime(K): Type,
89
50
  comptime(V): Type,
@@ -1,78 +1,42 @@
1
- /**
2
- * HashSet - A high-performance hash set implementation using SwissTable algorithm
3
- *
4
- * This implementation uses the same SwissTable design as HashMap, providing:
5
- * - SIMD-accelerated lookup using control bytes
6
- * - Quadratic probing for collision resolution
7
- * - 7/8 max load factor for optimal performance
8
- * - Compact memory layout with metadata array
9
- *
10
- * Memory layout:
11
- * - ctrl: Array of control bytes (metadata), one per slot
12
- * - data: Array of elements
13
- *
14
- * Control byte values:
15
- * - 0xFF (EMPTY): Slot is empty and never used
16
- * - 0xFE (DELETED): Slot was used but is now deleted
17
- * - 0x00-0x7F: Lower 7 bits of hash (H2 hash), indicates occupied slot
18
- *
19
- * Hash function splits hash into two parts:
20
- * - H1: Upper bits used to find slot group
21
- * - H2: Lower 7 bits stored in control byte for fast SIMD comparison
22
- */
1
+ //! Hash set using SwissTable algorithm with set-theoretic operations.
2
+
23
3
  { GlobalAllocator, AllocError } :: import "../allocator.yo";
24
4
  { malloc, calloc, realloc, free } :: GlobalAllocator;
25
5
 
26
- /**
27
- * HashSet error types
28
- */
6
+ /// Error variants for HashSet operations.
29
7
  HashSetError :: enum(
8
+ /// Memory allocation failed.
30
9
  AllocError(error : AllocError),
10
+ /// The element was not found in the set.
31
11
  ElementNotFound,
12
+ /// Capacity calculation overflowed.
32
13
  CapacityOverflow
33
14
  );
34
15
 
35
- /**
36
- * Control byte constants for SwissTable
37
- */
16
+ /// Control byte for an empty slot.
38
17
  CTRL_EMPTY :: u8(255);
18
+ /// Control byte for a deleted slot (tombstone).
39
19
  CTRL_DELETED :: u8(254);
40
20
 
41
- /**
42
- * Default initial capacity (must be power of 2)
43
- */
21
+ /// Default initial capacity (must be power of 2).
44
22
  DEFAULT_CAPACITY :: usize(16);
45
23
 
46
- /**
47
- * Maximum load factor: 7/8 = 0.875
48
- * We resize when: size > capacity * 7 / 8
49
- */
24
+ /// Maximum load factor numerator (7/8 = 0.875).
50
25
  MAX_LOAD_FACTOR_NUMERATOR :: usize(7);
51
26
  MAX_LOAD_FACTOR_DENOMINATOR :: usize(8);
52
27
 
53
- /**
54
- * Extract H2 hash (lower 7 bits) from full hash
55
- */
28
+ /// Extract H2 hash (lower 7 bits) from full hash.
56
29
  h2_hash :: (fn(hash: u64) -> u8)
57
30
  (u8((hash & u64(127))))
58
31
  ;
59
32
 
60
- /**
61
- * Extract H1 hash (upper bits) for slot index
62
- */
33
+ /// Extract H1 hash (upper bits) for slot index.
63
34
  h1_hash :: (fn(hash: u64, capacity: usize) -> usize)
64
35
  ((usize((hash >> u64(7))) % capacity))
65
36
  ;
66
37
 
67
- /**
68
- * HashSet type - high-performance set using SwissTable
69
- *
70
- * Memory layout:
71
- * - ctrl: Pointer to control bytes array (length = capacity)
72
- * - data: Pointer to elements array (length = capacity)
73
- * - capacity: Total number of slots (always power of 2)
74
- * - size: Current number of occupied slots
75
- */
38
+ /// High-performance hash set using SwissTable algorithm.
39
+ /// Elements must implement `Eq` and `Hash`. Provides O(1) average lookup and insert.
76
40
  HashSet :: (fn(
77
41
  comptime(T): Type,
78
42
  where(T <: (Eq(T), Hash))
@@ -1,29 +1,14 @@
1
- /**
2
- * LinkedList - A doubly-linked list implementation for Yo language
3
- *
4
- * Features:
5
- * - O(1) push/pop from front and back
6
- * - O(1) insertion/removal at known positions (with node reference)
7
- * - RAII for automatic cleanup
8
- * - True linked list using object indirection
9
- *
10
- * Memory layout:
11
- * - Each node is an object (reference-counted)
12
- * - Nodes contain: value, optional next node, optional prev node
13
- */
1
+ //! Doubly-linked list with O(1) push/pop at both ends.
14
2
 
15
- /**
16
- * LinkedList error types
17
- */
3
+ /// Error variants for LinkedList operations.
18
4
  LinkedListError :: enum(
5
+ /// Index is out of bounds for the current length.
19
6
  IndexOutOfBounds(index: usize, length: usize),
7
+ /// Attempted to access an element from an empty list.
20
8
  EmptyList
21
9
  );
22
10
 
23
- /**
24
- * Node - Internal structure for linked list nodes
25
- * Since Node is an object (reference-counted), no Box needed
26
- */
11
+ /// Internal node for the linked list. Reference-counted via `object`.
27
12
  Node :: (fn(comptime(T): Type) -> comptime(Type))
28
13
  object(
29
14
  value : T,
@@ -32,9 +17,7 @@ Node :: (fn(comptime(T): Type) -> comptime(Type))
32
17
  )
33
18
  ;
34
19
 
35
- /**
36
- * LinkedList - Doubly-linked list with O(1) operations at both ends
37
- */
20
+ /// Doubly-linked list with O(1) push/pop at both ends.
38
21
  LinkedList :: (fn(comptime(T): Type) -> comptime(Type))
39
22
  object(
40
23
  head : Option(Node(T)),
@@ -1,23 +1,21 @@
1
- // std/collections/priority_queue.yo - Binary min-heap (priority queue)
2
- //
3
- // PriorityQueue keeps elements in ascending order (smallest first).
4
- // Use a negated key to get a max-heap.
5
- //
6
- // Example:
7
- // { PriorityQueue } :: import "std/collections/priority_queue";
8
- //
9
- // pq := PriorityQueue(i32).new();
10
- // pq.push(5);
11
- // pq.push(1);
12
- // pq.push(3);
13
- // x := pq.pop().unwrap(); // 1
1
+ //! Binary min-heap priority queue.
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```rust
6
+ //! { PriorityQueue } :: import "std/collections/priority_queue";
7
+ //!
8
+ //! pq := PriorityQueue(i32).new();
9
+ //! pq.push(5);
10
+ //! pq.push(1);
11
+ //! pq.push(3);
12
+ //! x := pq.pop().unwrap(); // 1
13
+ //! ```
14
14
 
15
15
  { ArrayList } :: import "./array_list";
16
16
 
17
- // ============================================================================
18
- // PriorityQueue min-heap backed by ArrayList
19
- // ============================================================================
20
-
17
+ /// Min-heap backed by an ArrayList.
18
+ /// Elements are ordered ascending (smallest first). Negate keys for max-heap behavior.
21
19
  PriorityQueue :: (fn(comptime(T) : Type) -> comptime(Type))(
22
20
  object(
23
21
  _data : ArrayList(T)
package/std/crypto/md5.yo CHANGED
@@ -1,12 +1,13 @@
1
- // std/crypto/md5.yo - MD5 hash function
2
- //
3
- // Pure-Yo implementation of MD5 (RFC 1321).
4
- // MD5 is considered cryptographically broken — use SHA-256 for security.
5
- //
6
- // Example:
7
- // { md5_hex } :: import "std/crypto/md5";
8
- //
9
- // digest := md5_hex(data); // "5d41402abc4b2a76b9719d911017c592"
1
+ //! MD5 hash function (RFC 1321), pure Yo implementation.
2
+ //! MD5 is considered cryptographically broken — use SHA-256 for security.
3
+ //!
4
+ //! # Example
5
+ //!
6
+ //! ```rust
7
+ //! { md5_hex } :: import "std/crypto/md5";
8
+ //!
9
+ //! digest := md5_hex(data); // "5d41402abc4b2a76b9719d911017c592"
10
+ //! ```
10
11
 
11
12
  { ArrayList } :: import "../collections/array_list";
12
13
  { hex_encode } :: import "../encoding/hex";
@@ -1,15 +1,14 @@
1
- // std/crypto/random.yo - Cryptographically secure random number generation
2
- //
3
- // Uses OS entropy sources:
4
- // Linux/others: getrandom()
5
- // macOS: arc4random_buf()
6
- // Windows: BCryptGenRandom()
7
- // WASI/WASM: getentropy()
8
- //
9
- // Example:
10
- // { random_u64, uuid_v4 } :: import "std/crypto/random";
11
- //
12
- // id := uuid_v4(); // "550e8400-e29b-41d4-a716-446655440000"
1
+ //! Cryptographically secure random number generation.
2
+ //! Uses OS entropy sources (getrandom on Linux, arc4random_buf on macOS,
3
+ //! BCryptGenRandom on Windows, getentropy on WASI).
4
+ //!
5
+ //! # Example
6
+ //!
7
+ //! ```rust
8
+ //! { random_u64, uuid_v4 } :: import "std/crypto/random";
9
+ //!
10
+ //! id := uuid_v4(); // "550e8400-e29b-41d4-a716-446655440000"
11
+ //! ```
13
12
 
14
13
  { ArrayList } :: import "../collections/array_list";
15
14
  { platform, Platform } :: import "../process";
@@ -23,8 +22,11 @@ open import "../string";
23
22
  // Error type
24
23
  // ============================================================================
25
24
 
25
+ /// Errors that can occur during cryptographic random operations.
26
26
  CryptoError :: enum(
27
+ /// Platform does not support secure random generation.
27
28
  Unavailable,
29
+ /// Other platform-specific error.
28
30
  Other(msg: String)
29
31
  );
30
32
 
@@ -1,11 +1,12 @@
1
- // std/crypto/sha256.yo - SHA-256 hash function
2
- //
3
- // Pure-Yo implementation of SHA-256 (FIPS 180-4).
4
- //
5
- // Example:
6
- // { sha256_hex } :: import "std/crypto/sha256";
7
- //
8
- // digest := sha256_hex(data); // "2cf24dba..."
1
+ //! SHA-256 hash function (FIPS 180-4), pure Yo implementation.
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```rust
6
+ //! { sha256_hex } :: import "std/crypto/sha256";
7
+ //!
8
+ //! digest := sha256_hex(data); // "2cf24dba..."
9
+ //! ```
9
10
 
10
11
  { ArrayList } :: import "../collections/array_list";
11
12
  { hex_encode } :: import "../encoding/hex";
@@ -1,12 +1,10 @@
1
- // std/encoding/base64.yo - Base64 encoding/decoding
2
- //
3
- // Standard (RFC 4648) and URL-safe base64 variants.
4
- //
5
- // Example:
6
- // { base64_encode, base64_decode } :: import "std/encoding/base64";
7
- //
8
- // s := base64_encode(data);
9
- // b := base64_decode(s.to_str()).unwrap();
1
+ //! Base64 encoding and decoding (RFC 4648) with standard and URL-safe variants.
2
+ //!
3
+ //! Example:
4
+ //! { base64_encode, base64_decode } :: import "std/encoding/base64";
5
+ //!
6
+ //! s := base64_encode(data);
7
+ //! b := base64_decode(s.to_str()).unwrap();
10
8
 
11
9
  open import "../string";
12
10
  { ArrayList } :: import "../collections/array_list";
@@ -58,12 +56,12 @@ _encode_with :: (fn(data: ArrayList(u8), alpha: str, pad: bool) -> String)({
58
56
  String.from_bytes(out)
59
57
  });
60
58
 
61
- // Encode bytes as standard base64.
59
+ /// Encode bytes as standard base64 with padding.
62
60
  base64_encode :: (fn(data: ArrayList(u8)) -> String)(
63
61
  _encode_with(data, _STD_ALPHA, true)
64
62
  );
65
63
 
66
- // Encode bytes as URL-safe base64 (no padding).
64
+ /// Encode bytes as URL-safe base64 without padding.
67
65
  base64_encode_url :: (fn(data: ArrayList(u8)) -> String)(
68
66
  _encode_with(data, _URL_ALPHA, false)
69
67
  );
@@ -116,12 +114,12 @@ _decode_with :: (fn(s: str, alpha: str, using(exn : Exception)) -> ArrayList(u8)
116
114
  out
117
115
  });
118
116
 
119
- // Decode standard base64.
117
+ /// Decode a standard base64 string to bytes. Throws via `Exception` on invalid input.
120
118
  base64_decode :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))(
121
119
  _decode_with(s, _STD_ALPHA)
122
120
  );
123
121
 
124
- // Decode URL-safe base64.
122
+ /// Decode a URL-safe base64 string to bytes. Throws via `Exception` on invalid input.
125
123
  base64_decode_url :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))(
126
124
  _decode_with(s, _URL_ALPHA)
127
125
  );
@@ -132,7 +130,7 @@ export base64_decode, base64_decode_url;
132
130
  // String-level convenience API
133
131
  // ============================================================================
134
132
 
135
- // Encode a String to standard base64.
133
+ /// Encode a `String` to standard base64.
136
134
  base64_encode_string :: (fn(input: String) -> String)(
137
135
  _encode_with(input.as_bytes(), _STD_ALPHA, true)
138
136
  );
@@ -150,7 +148,7 @@ _base64_index :: (fn(c: u8) -> i32)({
150
148
  i32(-1)
151
149
  });
152
150
 
153
- // Decode a base64 String, ignoring whitespace. Returns Result.
151
+ /// Decode a base64 `String`, ignoring whitespace. Returns `Result(String, String)`.
154
152
  base64_decode_string :: (fn(input: String) -> Result(String, String))({
155
153
  raw := input.as_str();
156
154
  cleaned := ArrayList(u8).new();
@@ -1,12 +1,12 @@
1
- // std/encoding/hex.yo - Hexadecimal encoding/decoding
2
- //
3
- // Converts between raw bytes (ArrayList(u8)) and hex strings.
4
- //
5
- // Example:
6
- // { hex_encode, hex_decode } :: import "std/encoding/hex";
7
- //
8
- // s := hex_encode(data); // "deadbeef"
9
- // b := hex_decode("deadbeef");
1
+ //! Hexadecimal encoding and decoding.
2
+ //!
3
+ //! Converts between raw bytes (`ArrayList(u8)`) and hex strings.
4
+ //!
5
+ //! Example:
6
+ //! { hex_encode, hex_decode } :: import "std/encoding/hex";
7
+ //!
8
+ //! s := hex_encode(data); // "deadbeef"
9
+ //! b := hex_decode("deadbeef");
10
10
 
11
11
  open import "../string";
12
12
  { ArrayList } :: import "../collections/array_list";
@@ -17,8 +17,11 @@ open import "../string";
17
17
  // Error type
18
18
  // ============================================================================
19
19
 
20
+ /// Encoding/decoding error type.
20
21
  EncodingError :: enum(
22
+ /// Invalid character encountered during decoding.
21
23
  InvalidChar(ch: u8),
24
+ /// Input string has odd length (hex requires even length).
22
25
  OddLength
23
26
  );
24
27
 
@@ -55,6 +58,7 @@ _hex_encode_impl :: (fn(data: ArrayList(u8), hex_chars: str) -> String)({
55
58
  String.from_bytes(out)
56
59
  });
57
60
 
61
+ /// Encode bytes as a lowercase hexadecimal string.
58
62
  hex_encode :: (fn(data: ArrayList(u8)) -> String)(
59
63
  _hex_encode_impl(data, _HEX_CHARS)
60
64
  );
@@ -74,7 +78,7 @@ _hex_nibble :: (fn(c: u8, using(exn : Exception)) -> u8)(
74
78
  )
75
79
  );
76
80
 
77
- // Decode a hexadecimal string into bytes.
81
+ /// Decode a hexadecimal string to bytes. Throws via `Exception` on invalid input.
78
82
  hex_decode :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))({
79
83
  cond(
80
84
  (((s.len() % usize(2)) != usize(0))) => {
@@ -1,13 +1,13 @@
1
- // HTML entity decoding
2
- //
3
- // Decodes named (&amp;), decimal (&#38;), and hex (&#x26;) HTML character references.
4
- // Uses Legacy mode — entities without trailing semicolon are also decoded.
5
- //
6
- // Example:
7
- // { decode_html } :: import "std/encoding/html";
8
- //
9
- // result := decode_html(`&amp; &lt; &#38; &#x26;`);
10
- // assert((result == `& < & &`), "decoded entities");
1
+ //! HTML entity decoding — named, decimal, and hexadecimal character references.
2
+ //!
3
+ //! Decodes named (&amp;), decimal (&#38;), and hex (&#x26;) HTML character references.
4
+ //! Uses Legacy mode — entities without trailing semicolon are also decoded.
5
+ //!
6
+ //! Example:
7
+ //! { decode_html } :: import "std/encoding/html";
8
+ //!
9
+ //! result := decode_html(`&amp; &lt; &#38; &#x26;`);
10
+ //! assert((result == `& < & &`), "decoded entities");
11
11
 
12
12
  open import "../string";
13
13
  { HashMap } :: import "../collections/hash_map";
@@ -64,7 +64,10 @@ _is_alpha_numeric :: (fn(c: rune) -> bool)(
64
64
  ((((c >= rune(u32('a'))) && (c <= rune(u32('z')))) || ((c >= rune(u32('A'))) && (c <= rune(u32('Z'))))) || ((c >= rune(u32('0'))) && (c <= rune(u32('9')))))
65
65
  );
66
66
 
67
- // Decode HTML entities in a string (Legacy mode — entities without ; are also decoded).
67
+ /// Decode HTML entities in a string.
68
+ ///
69
+ /// Supports named (`&amp;`), decimal (`&#38;`), and hexadecimal (`&#x26;`) character
70
+ /// references. Legacy mode — entities without trailing semicolons are also decoded.
68
71
  decode_html :: (fn(input: String) -> String)({
69
72
  _ensure_init();
70
73
 
@@ -1,16 +1,19 @@
1
- // HTML character utility functions
2
- //
3
- // Provides Unicode codepoint validation and conversion for HTML entity processing.
4
- //
5
- // Example:
6
- // { is_valid_entity_code, from_code_point } :: import "std/encoding/html_char_utils";
7
- //
8
- // assert(is_valid_entity_code(i32(65)), "A is valid");
9
- // s := from_code_point(i32(65)); // "A"
1
+ //! HTML character utility functions.
2
+ //!
3
+ //! Provides Unicode codepoint validation and conversion for HTML entity processing.
4
+ //!
5
+ //! # Example
6
+ //!
7
+ //! ```rust
8
+ //! { is_valid_entity_code, from_code_point } :: import "std/encoding/html_char_utils";
9
+ //!
10
+ //! assert(is_valid_entity_code(i32(65)), "A is valid");
11
+ //! s := from_code_point(i32(65)); // "A"
12
+ //! ```
10
13
 
11
14
  open import "../string";
12
15
 
13
- // Check if a Unicode codepoint is a valid HTML entity value.
16
+ /// Check if a Unicode codepoint is a valid HTML entity value.
14
17
  is_valid_entity_code :: (fn(c: i32) -> bool)(
15
18
  cond(
16
19
  ((c >= i32(0xD800)) && (c <= i32(0xDFFF))) => false,
@@ -25,7 +28,7 @@ is_valid_entity_code :: (fn(c: i32) -> bool)(
25
28
  )
26
29
  );
27
30
 
28
- // Convert a Unicode codepoint to a String.
31
+ /// Convert a Unicode codepoint to a `String`.
29
32
  from_code_point :: (fn(c: i32) -> String)(
30
33
  {
31
34
  (r : rune) = rune(u32(c));
@@ -1,17 +1,16 @@
1
- // HTML5 named character references data
2
- //
3
- // Auto-generated from https://html.spec.whatwg.org/entities.json
4
- // Total: 2125 entities
5
- //
6
- // This module provides the entity name-to-string mapping used by decode_html.
7
- // Import: { _build_entity_map, _build_legacy_set } :: import "std/encoding/html_entities";
1
+ //! HTML5 named character references data.
2
+ //!
3
+ //! Auto-generated from <https://html.spec.whatwg.org/entities.json>.
4
+ //! Total: 2125 entities.
5
+ //!
6
+ //! This module provides the entity name-to-string mapping used by `decode_html`.
8
7
 
9
8
  open import "../string";
10
9
  { HashMap } :: import "../collections/hash_map";
11
10
  { HashSet } :: import "../collections/hash_set";
12
11
  { from_code_point } :: import "./html_char_utils";
13
12
 
14
- // Returns a HashMap mapping entity names (without & and ;) to decoded strings.
13
+ /// Returns a `HashMap` mapping entity names (without `&` and `;`) to decoded strings.
15
14
  _build_entity_map :: (fn() -> HashMap(String, String))(
16
15
  {
17
16
  (m : HashMap(String, String)) = HashMap(String, String).new();