nomen-lang 0.6.1 → 0.6.3
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/core/System/List.nm +12 -0
- package/core/System/StringBuilder.nm +12 -4
- package/core/System/Text/Regex.nm +704 -77
- package/core/docs/System/Text/Regex.md +1 -1
- package/dist/index.mjs +1362 -362
- package/package.json +1 -1
- package/src/index.ts +8 -56
- package/src/init.ts +12 -3
- package/src/test.ts +57 -3
package/core/System/List.nm
CHANGED
|
@@ -61,6 +61,18 @@ pub struct List<T>: Viewable {
|
|
|
61
61
|
self.items.replace(i, value)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
// Bounds-checked write that traps when i is outside [0, self.length) —
|
|
65
|
+
// for indices that can't be proven at compile time (cross-module calls
|
|
66
|
+
// can never discharge `set`'s parameter constraint) and out-of-range is
|
|
67
|
+
// a bug, not a case.
|
|
68
|
+
pub func set_or_panic = (ref self, int i, move T value) {
|
|
69
|
+
if i >= 0 && i < self.length {
|
|
70
|
+
self.set(i, value)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
panic("index out of range")
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
// A deep copy: a fresh List<T> with an independent copy of every element.
|
|
65
77
|
// For owning element types (strings, owning value structs) each slot in the
|
|
66
78
|
// copy owns its own heap data (Buffer deep-copies on store), so the source
|
|
@@ -16,7 +16,9 @@ pub struct StringBuilder {
|
|
|
16
16
|
// Ensure capacity for at least `needed` bytes. Grows geometrically.
|
|
17
17
|
// Plain Nomen + the memory externs — no pointer arithmetic needed, so
|
|
18
18
|
// this doesn't even require an unsafe context.
|
|
19
|
-
|
|
19
|
+
// `internal`: capacity plumbing for the builder's own appenders; not
|
|
20
|
+
// part of the user surface.
|
|
21
|
+
internal func ensure = (ref self, int needed) {
|
|
20
22
|
if self.cap >= needed {
|
|
21
23
|
return
|
|
22
24
|
}
|
|
@@ -84,7 +86,10 @@ pub struct StringBuilder {
|
|
|
84
86
|
// Append a null-terminated string. `unsafe` Nomen single-sourced for
|
|
85
87
|
// both backends: the fat pair's pointer half feeds memcpy directly, and
|
|
86
88
|
// the tracked length replaces the strlen the old C body paid.
|
|
87
|
-
|
|
89
|
+
// `internal`: a library-implementation append — user code appends with
|
|
90
|
+
// `append_char` / `append_string_view`; the library's own structs (Json,
|
|
91
|
+
// Regex) are on the trusted side of the boundary.
|
|
92
|
+
internal func append_string = (ref self, string s) {
|
|
88
93
|
unsafe {
|
|
89
94
|
var int sl = s.length
|
|
90
95
|
self.ensure(self.len + sl + 1)
|
|
@@ -175,7 +180,7 @@ pub struct StringBuilder {
|
|
|
175
180
|
// to [0, len]; the returned string is always an independent allocation.
|
|
176
181
|
// (`move out string` — the raw body mallocs the result, so the caller
|
|
177
182
|
// owns it by signature, like `Console.read_line`.)
|
|
178
|
-
func take_since = (ref self, int mark, move out string) {
|
|
183
|
+
pub func take_since = (ref self, int mark, move out string) {
|
|
179
184
|
```
|
|
180
185
|
#arch: c
|
|
181
186
|
int start = mark;
|
|
@@ -237,7 +242,10 @@ pub struct StringBuilder {
|
|
|
237
242
|
|
|
238
243
|
// Finalize: null-terminate, return the byte buffer as a string, and
|
|
239
244
|
// release ownership (sets `data` to 0 so the destructor won't free it).
|
|
240
|
-
|
|
245
|
+
// Explicitly `pub`: struct members default to pub, but this is the
|
|
246
|
+
// builder's primary read-back — the contract should not depend on the
|
|
247
|
+
// default.
|
|
248
|
+
pub func to_string = (ref self, out string) {
|
|
241
249
|
```
|
|
242
250
|
#arch: c
|
|
243
251
|
int idx = self->len;
|