1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Aether - 一个轻量级、可嵌入的领域特定语言
//!
//! 这个 crate 提供了 Aether 语言的完整实现,
//! 包括词法分析器、解析器、求值器和标准库。
//!
//! # 快速开始
//!
//! ## 作为 DSL(嵌入到您的应用程序中)
//!
//! 当将 Aether 作为 DSL 嵌入时,IO 操作**默认禁用**以确保安全性:
//!
//! ```
//! use aether::Aether;
//!
//! // 默认:IO 禁用(对用户脚本安全)
//! let mut engine = Aether::new();
//! let code = r#"
//! Set X 10
//! Set Y 20
//! (X + Y)
//! "#;
//!
//! match engine.eval(code) {
//! Ok(result) => println!("Result: {}", result),
//! Err(e) => eprintln!("Error: {}", e),
//! }
//! ```
//!
//! 仅在需要时启用 IO:
//!
//! ```
//! use aether::{Aether, IOPermissions};
//!
//! // 仅启用文件系统
//! let mut perms = IOPermissions::default();
//! perms.filesystem_enabled = true;
//! let mut engine = Aether::with_permissions(perms);
//!
//! // 或启用所有 IO
//! let mut engine = Aether::with_all_permissions();
//! ```
//!
//! ## 高性能引擎模式(新增!)
//!
//! 对于**高频、大规模 DSL 执行**,Aether 提供了三种优化的引擎模式:
//!
//! ### 1. GlobalEngine - 全局单例(最适合单线程)
//!
//! ```rust
//! use aether::engine::GlobalEngine;
//!
//! // 使用隔离环境执行(每次清除变量)
//! let result = GlobalEngine::eval_isolated("Set X 10\n(X + 20)").unwrap();
//! println!("Result: {}", result);
//!
//! // 优势:
//! // - ✅ 最大性能(引擎仅创建一次)
//! // - ✅ AST 缓存累积(高达 142 倍加速!)
//! // - ✅ 环境隔离(每次调用清除变量)
//! // - ⚠️ 单线程(使用 Mutex)
//! ```
//!
//! ### 2. EnginePool - 引擎池(最适合多线程)
//!
//! ```rust
//! use aether::engine::EnginePool;
//! use std::thread;
//!
//! // 一次性创建池(大小 = 推荐 2-4 倍 CPU 核心数)
//! let pool = EnginePool::new(8);
//!
//! // 跨线程使用
//! let handles: Vec<_> = (0..4).map(|i| {
//! let pool = pool.clone();
//! thread::spawn(move || {
//! let mut engine = pool.acquire(); // 自动获取
//! let code = format!("Set X {}\n(X * 2)", i);
//! engine.eval(&code)
//! }) // 作用域退出时自动返回
//! }).collect();
//!
//! // 优势:
//! // - ✅ 多线程安全(无锁队列)
//! // - ✅ RAII 模式(自动返回池)
//! // - ✅ 环境隔离(获取时清除)
//! // - ✅ 每个引擎的 AST 缓存
//! ```
//!
//! ### 3. ScopedEngine - 闭包风格(最适合简单性)
//!
//! ```rust
//! use aether::engine::ScopedEngine;
//!
//! // 闭包风格(类似 Py3o)
//! let result = ScopedEngine::with(|engine| {
//! engine.eval("Set X 10")?;
//! engine.eval("(X + 20)")
//! }).unwrap();
//!
//! // 或简化版本
//! let result = ScopedEngine::eval("Set X 10\n(X + 20)").unwrap();
//!
//! // 优势:
//! // - ✅ 完全隔离(每次新建引擎)
//! // - ✅ 简洁 API(自动生命周期管理)
//! // - ⚠️ 较低性能(无缓存重用)
//! ```
//!
//! ### 模式对比
//!
//! | 特性 | GlobalEngine | EnginePool | ScopedEngine |
//! |---------|-------------|------------|--------------|
//! | 性能 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
//! | 多线程 | ❌ | ✅ | ✅ |
//! | 隔离 | ✅ | ✅ | ✅ |
//! | AST 缓存 | ✅ | ✅ | ❌ |
//! | 使用场景 | 单线程高频 | 多线程 | 偶尔使用 |
//!
//! ### 选择性标准库加载(推荐用于 DSL)
//!
//! 为获得更好性能,仅加载您需要的 stdlib 模块:
//!
//! ```
//! use aether::Aether;
//!
//! // 仅加载字符串和数组工具
//! let mut engine = Aether::new()
//! .with_stdlib_string_utils()
//! .unwrap()
//! .with_stdlib_array_utils()
//! .unwrap();
//!
//! // 或加载数据结构
//! let mut engine2 = Aether::new()
//! .with_stdlib_set()
//! .unwrap()
//! .with_stdlib_queue()
//! .unwrap()
//! .with_stdlib_stack()
//! .unwrap();
//!
//! // 可用模块:
//! // - with_stdlib_string_utils()
//! // - with_stdlib_array_utils()
//! // - with_stdlib_validation()
//! // - with_stdlib_datetime()
//! // - with_stdlib_testing()
//! // - with_stdlib_set()
//! // - with_stdlib_queue()
//! // - with_stdlib_stack()
//! // - with_stdlib_heap()
//! // - with_stdlib_sorting()
//! // - with_stdlib_json()
//! // - with_stdlib_csv()
//! // - with_stdlib_functional()
//! // - with_stdlib_cli_utils()
//! // - with_stdlib_text_template()
//! // - with_stdlib_regex_utils()
//! ```
//!
//! ## 作为独立语言(命令行工具)
//!
//! `aether` 命令行工具自动启用所有 IO 权限,
//! 允许脚本自由使用文件和网络操作:
//!
//! ```bash
//! # 在 CLI 模式下,所有 IO 操作都有效
//! aether script.aether
//! ```
// FFI 和语言绑定
pub use Aether;
pub use *;