feat: IDE支持 — workspace拆分、LSP服务器、VS Code扩展
**Workspace 拆分** - aster-core: 纯库,zero-dependency,包含 lexer/parser/ast/interpreter/error/analysis - aster: REPL 二进制,薄封装 aster-core - aster-lsp: LSP 语言服务器 **VS Code 扩展 (vscode-ext/)** - TextMate 语法高亮 (.ast 文件) - 语言配置 (注释切换、括号配对、自动缩进) - LSP 客户端 (extension.js) **LSP 服务端功能** - Diagnostics: 实时显示 lex/parse 错误红色波浪线 - Completion: 关键字 + 内置函数 + 用户定义符号补全 - Hover: 悬停显示变量/函数信息 - Signature Help: 函数参数提示 - Goto Definition: Ctrl+Click 跳转到声明处 - Find References: 查找所有引用位置 - Rename: F2 重命名符号 **新增 analysis 模块** - collect_symbols: AST 遍历收集符号 - find_declaration/find_all_references: Token 扫描定位声明和引用
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//! 内置函数模块:按功能分组注册,便于扩展和维护。
|
||||
|
||||
mod core;
|
||||
mod io;
|
||||
mod os;
|
||||
pub mod string;
|
||||
|
||||
use crate::interpreter::{Env, Value};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// 向全局环境注册所有标准库(io、os 等)
|
||||
pub fn register_all(env: &Rc<RefCell<Env>>) {
|
||||
let mut e = env.borrow_mut();
|
||||
|
||||
// io
|
||||
let mut io = HashMap::new();
|
||||
io.insert("print".into(), Value::NativeFunction(Rc::new(io::print)));
|
||||
io.insert("input".into(), Value::NativeFunction(Rc::new(io::input)));
|
||||
e.define("io".into(), Value::Object(Rc::new(RefCell::new(io))), true);
|
||||
// input and print can be used as global functions for convenience
|
||||
e.define("print".into(), Value::NativeFunction(Rc::new(io::print)), true);
|
||||
e.define("input".into(), Value::NativeFunction(Rc::new(io::input)), true);
|
||||
|
||||
// os
|
||||
let mut os = HashMap::new();
|
||||
os.insert("clock".into(), Value::NativeFunction(Rc::new(os::clock)));
|
||||
e.define("os".into(), Value::Object(Rc::new(RefCell::new(os))), true);
|
||||
// clock can also be used as a global function for convenience
|
||||
e.define("clock".into(), Value::NativeFunction(Rc::new(os::clock)), true);
|
||||
|
||||
// core — len, typeof, push, pop
|
||||
e.define("len".into(), Value::NativeFunction(Rc::new(core::len)), true);
|
||||
e.define("typeof".into(), Value::NativeFunction(Rc::new(core::typeof_fn)), true);
|
||||
e.define("push".into(), Value::NativeFunction(Rc::new(core::push)), true);
|
||||
e.define("pop".into(), Value::NativeFunction(Rc::new(core::pop)), true);
|
||||
|
||||
// require — module loader
|
||||
e.define("require".into(), Value::NativeFunction(Rc::new(super::module::require_fn)), true);
|
||||
|
||||
// string — split, trim, substring, replace, contains, upper, lower, starts_with, ends_with
|
||||
e.define("split".into(), Value::NativeFunction(Rc::new(string::split)), true);
|
||||
e.define("trim".into(), Value::NativeFunction(Rc::new(string::trim)), true);
|
||||
e.define("substring".into(), Value::NativeFunction(Rc::new(string::substring)), true);
|
||||
e.define("replace".into(), Value::NativeFunction(Rc::new(string::replace)), true);
|
||||
e.define("contains".into(), Value::NativeFunction(Rc::new(string::contains)), true);
|
||||
e.define("upper".into(), Value::NativeFunction(Rc::new(string::upper)), true);
|
||||
e.define("lower".into(), Value::NativeFunction(Rc::new(string::lower)), true);
|
||||
e.define("starts_with".into(), Value::NativeFunction(Rc::new(string::starts_with)), true);
|
||||
e.define("ends_with".into(), Value::NativeFunction(Rc::new(string::ends_with)), true);
|
||||
}
|
||||
Reference in New Issue
Block a user