xdl_matlab/
lib.rs

1//! # XDL-MATLAB Compatibility Layer
2//!
3//! This crate provides MATLAB compatibility for XDL, allowing you to:
4//! - Load and execute .m files
5//! - Transpile MATLAB syntax to XDL
6//! - Map MATLAB functions to XDL equivalents
7
8pub mod function_map;
9pub mod lexer;
10pub mod transpiler;
11
12pub use function_map::MATLAB_FUNCTION_MAP;
13pub use transpiler::transpile_matlab_to_xdl;
14
15/// Load and transpile a MATLAB .m file to XDL code
16pub fn load_matlab_file(path: &std::path::Path) -> Result<String, String> {
17    let matlab_code =
18        std::fs::read_to_string(path).map_err(|e| format!("Failed to read file: {}", e))?;
19
20    transpile_matlab_to_xdl(&matlab_code)
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn test_simple_transpilation() {
29        let matlab = "x = zeros(10, 1);";
30        let result = transpile_matlab_to_xdl(matlab);
31        assert!(result.is_ok());
32    }
33}