Skip to main content

ruby_tools/
lib.rs

1//! Ruby Tools 库
2//! 提供 Ruby 语言相关的工具链
3
4#![warn(missing_docs)]
5
6use oak_ruby::{ast::RubyRoot, RubyBuilder, RubyLanguage};
7use oak_core::{Builder, TextEdit, builder::BuildOutput};
8
9/// Rusty Ruby 前端
10pub struct RustyRubyFrontend {
11    language: RubyLanguage,
12}
13
14impl Default for RustyRubyFrontend {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl RustyRubyFrontend {
21    /// 创建新的前端实例
22    pub fn new() -> Self {
23        Self {
24            language: RubyLanguage::new(),
25        }
26    }
27
28    /// 解析 Ruby 代码
29    pub fn parse(&self, source: &str) -> Result<RubyRoot, String> {
30        let builder = RubyBuilder::new(&self.language);
31        let edits: &[TextEdit] = &[];
32        let mut cache = oak_core::parser::ParseSession::default();
33        let output: BuildOutput<RubyLanguage> = builder.build(source, edits, &mut cache);
34        output.result.map_err(|e| e.to_string())
35    }
36}