1pub const STRING_UTILS: &str = include_str!("../stdlib/string_utils.aether");
8
9pub const ARRAY_UTILS: &str = include_str!("../stdlib/array_utils.aether");
11
12pub const VALIDATION: &str = include_str!("../stdlib/validation.aether");
14
15pub const DATETIME: &str = include_str!("../stdlib/datetime.aether");
17
18pub const TESTING: &str = include_str!("../stdlib/testing.aether");
20
21pub const SET: &str = include_str!("../stdlib/set.aether");
23
24pub const QUEUE: &str = include_str!("../stdlib/queue.aether");
26
27pub const STACK: &str = include_str!("../stdlib/stack.aether");
29
30pub const HEAP: &str = include_str!("../stdlib/heap.aether");
32
33pub const SORTING: &str = include_str!("../stdlib/sorting.aether");
35
36pub const JSON: &str = include_str!("../stdlib/json.aether");
38
39pub const CSV: &str = include_str!("../stdlib/csv.aether");
41
42pub const FUNCTIONAL: &str = include_str!("../stdlib/functional.aether");
44
45pub const CLI_UTILS: &str = include_str!("../stdlib/cli_utils.aether");
47
48pub const TEXT_TEMPLATE: &str = include_str!("../stdlib/text_template.aether");
50
51pub const REGEX_UTILS: &str = include_str!("../stdlib/regex_utils.aether");
53
54pub const ALL_MODULES: &[(&str, &str)] = &[
56 ("string_utils", STRING_UTILS),
57 ("array_utils", ARRAY_UTILS),
58 ("validation", VALIDATION),
59 ("datetime", DATETIME),
60 ("testing", TESTING),
61 ("set", SET),
62 ("queue", QUEUE),
63 ("stack", STACK),
64 ("heap", HEAP),
65 ("sorting", SORTING),
66 ("json", JSON),
67 ("csv", CSV),
68 ("functional", FUNCTIONAL),
69 ("cli_utils", CLI_UTILS),
70 ("text_template", TEXT_TEMPLATE),
71 ("regex_utils", REGEX_UTILS),
72];
73
74pub fn get_module(name: &str) -> Option<&'static str> {
76 match name {
77 "string_utils" => Some(STRING_UTILS),
78 "array_utils" => Some(ARRAY_UTILS),
79 "validation" => Some(VALIDATION),
80 "datetime" => Some(DATETIME),
81 "testing" => Some(TESTING),
82 "set" => Some(SET),
83 "queue" => Some(QUEUE),
84 "stack" => Some(STACK),
85 "heap" => Some(HEAP),
86 "sorting" => Some(SORTING),
87 "json" => Some(JSON),
88 "csv" => Some(CSV),
89 "functional" => Some(FUNCTIONAL),
90 "cli_utils" => Some(CLI_UTILS),
91 "text_template" => Some(TEXT_TEMPLATE),
92 "regex_utils" => Some(REGEX_UTILS),
93 _ => None,
94 }
95}
96
97pub fn get_all_stdlib() -> String {
99 let mut result = String::new();
100 result.push_str("// Aether Standard Library - Auto-loaded\n\n");
101
102 for (name, code) in ALL_MODULES {
103 result.push_str(&format!("// ========== {} ==========\n", name));
104 result.push_str(code);
105 result.push_str("\n\n");
106 }
107
108 result
109}
110
111pub fn preload_stdlib(engine: &mut crate::Aether) -> Result<(), String> {
115 for (name, code) in ALL_MODULES {
116 engine
117 .eval(code)
118 .map_err(|e| format!("Failed to load stdlib module '{}': {}", name, e))?;
119 }
120 Ok(())
121}
122
123#[cfg(test)]
124mod tests {
125 use super::*;
126
127 #[test]
128 fn test_module_exists() {
129 assert!(STRING_UTILS.len() > 0);
130 assert!(ARRAY_UTILS.len() > 0);
131 assert!(VALIDATION.len() > 0);
132 assert!(DATETIME.len() > 0);
133 assert!(TESTING.len() > 0);
134 assert!(SET.len() > 0);
135 assert!(QUEUE.len() > 0);
136 assert!(STACK.len() > 0);
137 assert!(HEAP.len() > 0);
138 assert!(SORTING.len() > 0);
139 }
140
141 #[test]
142 fn test_get_module() {
143 assert!(get_module("string_utils").is_some());
144 assert!(get_module("array_utils").is_some());
145 assert!(get_module("set").is_some());
146 assert!(get_module("queue").is_some());
147 assert!(get_module("stack").is_some());
148 assert!(get_module("heap").is_some());
149 assert!(get_module("sorting").is_some());
150 assert!(get_module("unknown").is_none());
151 }
152}