@shd101wyy/yo 0.0.28 → 0.0.30

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 (48) hide show
  1. package/README.md +20 -1
  2. package/out/cjs/index.cjs +7554 -7826
  3. package/out/cjs/yo-cli.cjs +7604 -7876
  4. package/out/esm/index.mjs +7453 -7725
  5. package/out/types/src/codegen/async/runtime-core.d.ts +2 -1
  6. package/out/types/src/codegen/async/runtime-io-common.d.ts +3 -1
  7. package/out/types/src/codegen/async/runtime-io-linux.d.ts +1 -0
  8. package/out/types/src/codegen/async/runtime-io-macos.d.ts +1 -0
  9. package/out/types/src/codegen/async/runtime-io-windows.d.ts +1 -0
  10. package/out/types/src/codegen/async/runtime.d.ts +2 -1
  11. package/out/types/src/codegen/async/state-machine.d.ts +18 -2
  12. package/out/types/src/codegen/functions/context.d.ts +5 -0
  13. package/out/types/src/codegen/parallelism/runtime.d.ts +2 -1
  14. package/out/types/src/codegen/utils/index.d.ts +2 -0
  15. package/out/types/src/target.d.ts +1 -0
  16. package/out/types/tsconfig.tsbuildinfo +1 -1
  17. package/package.json +1 -1
  18. package/std/cli/arg_parser.yo +365 -0
  19. package/std/collections/array_list.yo +108 -0
  20. package/std/collections/hash_map.yo +1 -1
  21. package/std/collections/hash_set.yo +7 -7
  22. package/std/collections/linked_list.yo +1 -1
  23. package/std/encoding/base64.yo +73 -0
  24. package/std/fs/file.yo +113 -6
  25. package/std/fs/types.yo +21 -0
  26. package/std/glob/glob.yo +206 -0
  27. package/std/http/http.yo +196 -0
  28. package/std/io/reader.yo +17 -0
  29. package/std/io/writer.yo +19 -0
  30. package/std/net/tcp.yo +1 -1
  31. package/std/prelude.yo +69 -0
  32. package/std/regex/compiler.yo +355 -0
  33. package/std/regex/flags.yo +104 -0
  34. package/std/regex/match.yo +83 -0
  35. package/std/regex/node.yo +283 -0
  36. package/std/regex/parser.yo +847 -0
  37. package/std/regex/regex.yo +714 -0
  38. package/std/regex/unicode.yo +365 -0
  39. package/std/regex/vm.yo +737 -0
  40. package/std/string/string.yo +398 -4
  41. package/std/sync/cond.yo +19 -19
  42. package/std/sync/mutex.yo +16 -16
  43. package/std/sys/bufio/buf_reader.yo +2 -2
  44. package/std/sys/future.yo +3 -3
  45. package/std/time/sleep.yo +18 -0
  46. package/std/toml/toml.yo +179 -0
  47. package/std/testing/assert.yo +0 -173
  48. package/std/time.yo +0 -13
@@ -0,0 +1,179 @@
1
+ // std/toml/toml.yo - Basic TOML parser
2
+ //
3
+ // Parses a subset of TOML into a TomlValue tree.
4
+ // Supports: strings, integers, booleans, table sections, comments.
5
+
6
+ open import "../string";
7
+ { ArrayList } :: import "../collections/array_list";
8
+
9
+ TomlValue :: enum(
10
+ Str(value: String),
11
+ Int(value: i64),
12
+ Bool(value: bool),
13
+ Table(keys: ArrayList(String), values: ArrayList(Self))
14
+ );
15
+
16
+ impl(TomlValue,
17
+ new_table : (fn() -> Self)(
18
+ Self.Table(keys: ArrayList(String).new(), values: ArrayList(TomlValue).new())
19
+ ),
20
+
21
+ get : (fn(self: Self, key: String) -> Option(TomlValue))(
22
+ match(self,
23
+ .Table(keys, values) => {
24
+ i := usize(0);
25
+ while (i < keys.len()), (i = (i + usize(1))), {
26
+ cond(
27
+ (keys.get(i).unwrap() == key) => {
28
+ return .Some(values.get(i).unwrap());
29
+ },
30
+ true => ()
31
+ );
32
+ };
33
+ .None
34
+ },
35
+ _ => .None
36
+ )
37
+ ),
38
+
39
+ has_key : (fn(self: Self, key: String) -> bool)(
40
+ self.get(key).is_some()
41
+ ),
42
+
43
+ set : (fn(self: Self, key: String, value: TomlValue) -> unit)(
44
+ match(self,
45
+ .Table(keys, values) => {
46
+ i := usize(0);
47
+ len := keys.len();
48
+ found := false;
49
+ while (i < len), (i = (i + usize(1))), {
50
+ cond(
51
+ (keys.get(i).unwrap() == key) => {
52
+ values.set(i, value);
53
+ found = true;
54
+ },
55
+ true => ()
56
+ );
57
+ };
58
+ cond(
59
+ (!(found)) => {
60
+ keys.push(key);
61
+ values.push(value);
62
+ },
63
+ true => ()
64
+ );
65
+ },
66
+ _ => ()
67
+ )
68
+ ),
69
+
70
+ table_len : (fn(self: Self) -> usize)(
71
+ match(self,
72
+ .Table(keys, _) => keys.len(),
73
+ _ => usize(0)
74
+ )
75
+ ),
76
+
77
+ as_string : (fn(self: Self) -> Option(String))(
78
+ match(self, .Str(s) => .Some(s), _ => .None)
79
+ ),
80
+
81
+ as_int : (fn(self: Self) -> Option(i64))(
82
+ match(self, .Int(n) => .Some(n), _ => .None)
83
+ ),
84
+
85
+ as_bool : (fn(self: Self) -> Option(bool))(
86
+ match(self, .Bool(b) => .Some(b), _ => .None)
87
+ )
88
+ );
89
+
90
+ _parse_toml_value :: (fn(raw: String) -> Result(TomlValue, String))({
91
+ trimmed := raw.trim();
92
+ cond(
93
+ trimmed.is_empty() => { return .Err(`Empty value`); },
94
+ true => ()
95
+ );
96
+
97
+ // Quoted string: starts and ends with "
98
+ cond(
99
+ (trimmed.starts_with(`"`) && trimmed.ends_with(`"`)) => {
100
+ len := trimmed.len();
101
+ cond(
102
+ (len < usize(2)) => { return .Err(`Unterminated string`); },
103
+ true => {
104
+ return .Ok(.Str(trimmed.substring(usize(1), (len - usize(1)))));
105
+ }
106
+ );
107
+ },
108
+ true => ()
109
+ );
110
+
111
+ // Booleans
112
+ cond(
113
+ (trimmed == `true`) => { return .Ok(.Bool(true)); },
114
+ (trimmed == `false`) => { return .Ok(.Bool(false)); },
115
+ true => ()
116
+ );
117
+
118
+ // Integer
119
+ match(trimmed.parse_i64(),
120
+ .Some(n) => { return .Ok(.Int(n)); },
121
+ .None => ()
122
+ );
123
+
124
+ .Err(`Unknown value: ${trimmed}`)
125
+ });
126
+
127
+ toml_parse :: (fn(input: String) -> Result(TomlValue, String))({
128
+ root_keys := ArrayList(String).new();
129
+ root_vals := ArrayList(TomlValue).new();
130
+ cur_keys := root_keys;
131
+ cur_vals := root_vals;
132
+ lines := input.split(`\n`);
133
+ i := usize(0);
134
+ line_count := lines.len();
135
+
136
+ while (i < line_count), (i = (i + usize(1))), {
137
+ match(lines.get(i),
138
+ .Some(raw_line) => {
139
+ line := raw_line.trim();
140
+ cond(
141
+ line.is_empty() => (),
142
+ line.starts_with(`#`) => (),
143
+ // Table header: [name]
144
+ (line.starts_with(`[`) && line.ends_with(`]`)) => {
145
+ table_name := line.substring(usize(1), (line.len() - usize(1))).trim();
146
+ new_keys := ArrayList(String).new();
147
+ new_vals := ArrayList(TomlValue).new();
148
+ root_keys.push(table_name);
149
+ root_vals.push(.Table(keys: new_keys, values: new_vals));
150
+ cur_keys = new_keys;
151
+ cur_vals = new_vals;
152
+ },
153
+ // Key = value
154
+ true => {
155
+ match(line.index_of(`=`),
156
+ .Some(pos) => {
157
+ key := line.substring(usize(0), pos).trim();
158
+ val_str := line.substring((pos + usize(1)), line.len()).trim();
159
+ match(_parse_toml_value(val_str),
160
+ .Ok(val) => {
161
+ cur_keys.push(key);
162
+ cur_vals.push(val);
163
+ },
164
+ .Err(e) => { return .Err(e); }
165
+ );
166
+ },
167
+ .None => ()
168
+ );
169
+ }
170
+ );
171
+ },
172
+ .None => ()
173
+ );
174
+ };
175
+
176
+ .Ok(.Table(keys: root_keys, values: root_vals))
177
+ });
178
+
179
+ export TomlValue, toml_parse;
@@ -1,173 +0,0 @@
1
- // std/testing/assert.yo - Rich test assertions
2
- //
3
- // Provides typed assertion helpers that print a diff-friendly failure message.
4
- //
5
- // Example:
6
- // { assert_eq, assert_approx } :: import "std/testing/assert";
7
- //
8
- // assert_eq(result, expected, "values should match");
9
- // assert_approx(3.14159, PI, 0.00001, "PI check");
10
-
11
- open import "../string";
12
- { ToString } :: import "../fmt";
13
-
14
- // ============================================================================
15
- // Assertions
16
- // ============================================================================
17
-
18
- // Assert two values are equal.
19
- assert_eq :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Eq(T), T <: ToString)) -> unit)({
20
- cond(
21
- (actual != expected) => {
22
- a_s := actual.to_string();
23
- e_s := expected.to_string();
24
- panic(`assert_eq failed: ${msg} — actual=${a_s} expected=${e_s}`);
25
- },
26
- true => ()
27
- );
28
- });
29
-
30
- // Assert two values are not equal.
31
- assert_ne :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Eq(T), T <: ToString)) -> unit)({
32
- cond(
33
- (actual == expected) => {
34
- a_s := actual.to_string();
35
- panic(`assert_ne failed: ${msg} — both equal to ${a_s}`);
36
- },
37
- true => ()
38
- );
39
- });
40
-
41
- // Assert actual > expected.
42
- assert_gt :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Ord(T), T <: ToString)) -> unit)({
43
- cond(
44
- (actual <= expected) => {
45
- a_s := actual.to_string();
46
- e_s := expected.to_string();
47
- panic(`assert_gt failed: ${msg} — actual=${a_s} expected=${e_s}`);
48
- },
49
- true => ()
50
- );
51
- });
52
-
53
- // Assert actual < expected.
54
- assert_lt :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Ord(T), T <: ToString)) -> unit)({
55
- cond(
56
- (actual >= expected) => {
57
- a_s := actual.to_string();
58
- e_s := expected.to_string();
59
- panic(`assert_lt failed: ${msg} — actual=${a_s} expected=${e_s}`);
60
- },
61
- true => ()
62
- );
63
- });
64
-
65
- // Assert actual >= expected.
66
- assert_ge :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Ord(T), T <: ToString)) -> unit)({
67
- cond(
68
- (actual < expected) => {
69
- a_s := actual.to_string();
70
- e_s := expected.to_string();
71
- panic(`assert_ge failed: ${msg} — actual=${a_s} expected=${e_s}`);
72
- },
73
- true => ()
74
- );
75
- });
76
-
77
- // Assert actual <= expected.
78
- assert_le :: (fn(forall(T : Type), actual: T, expected: T, msg: str, where(T <: Ord(T), T <: ToString)) -> unit)({
79
- cond(
80
- (actual > expected) => {
81
- a_s := actual.to_string();
82
- e_s := expected.to_string();
83
- panic(`assert_le failed: ${msg} — actual=${a_s} expected=${e_s}`);
84
- },
85
- true => ()
86
- );
87
- });
88
-
89
- // Assert that `haystack` contains `needle`.
90
- assert_contains :: (fn(haystack: str, needle: str, msg: str) -> unit)({
91
- found := false;
92
- cond(
93
- (needle.len() == usize(0)) => { found = true; },
94
- (haystack.len() < needle.len()) => (),
95
- true => {
96
- limit := ((haystack.len() - needle.len()) + usize(1));
97
- i := usize(0);
98
- while (i < limit), (i = (i + usize(1))), {
99
- match_ok := true;
100
- j := usize(0);
101
- while (j < needle.len()), (j = (j + usize(1))), {
102
- cond(
103
- (haystack.bytes((i + j)) != needle.bytes(j)) => {
104
- match_ok = false;
105
- break;
106
- },
107
- true => ()
108
- );
109
- };
110
- cond(
111
- match_ok => {
112
- found = true;
113
- break;
114
- },
115
- true => ()
116
- );
117
- };
118
- }
119
- );
120
- cond(
121
- (!found) => {
122
- panic(`assert_contains failed: ${msg}`);
123
- },
124
- true => ()
125
- );
126
- });
127
-
128
- // Assert that `s` starts with `prefix`.
129
- assert_starts_with :: (fn(s: str, prefix: str, msg: str) -> unit)({
130
- ok := cond(
131
- (s.len() < prefix.len()) => false,
132
- true => {
133
- result := true;
134
- i := usize(0);
135
- while (i < prefix.len()), (i = (i + usize(1))), {
136
- cond(
137
- (s.bytes(i) != prefix.bytes(i)) => {
138
- result = false;
139
- break;
140
- },
141
- true => ()
142
- );
143
- };
144
- result
145
- }
146
- );
147
- cond(
148
- (!ok) => {
149
- panic(`assert_starts_with failed: ${msg}`);
150
- },
151
- true => ()
152
- );
153
- });
154
-
155
- // Assert that two f64 values are within `epsilon` of each other.
156
- assert_approx :: (fn(actual: f64, expected: f64, epsilon: f64, msg: str) -> unit)({
157
- diff := cond(
158
- (actual >= expected) => (actual - expected),
159
- true => (expected - actual)
160
- );
161
- cond(
162
- (diff > epsilon) => {
163
- panic(`assert_approx failed: ${msg}`);
164
- },
165
- true => ()
166
- );
167
- });
168
-
169
- export
170
- assert_eq, assert_ne,
171
- assert_gt, assert_lt, assert_ge, assert_le,
172
- assert_contains, assert_starts_with,
173
- assert_approx;
package/std/time.yo DELETED
@@ -1,13 +0,0 @@
1
- extern "Yo",
2
- __yo_ms_sleep : (fn(ms: usize) -> unit)
3
- ;
4
-
5
- Time :: impl {
6
- sleep :: __yo_ms_sleep;
7
-
8
- export sleep;
9
- };
10
-
11
- export
12
- Time
13
- ;