//! The Lotus interpreter library. use pest::Parser; /// The interpreter module, which contains the interpreter for the Lotus language. pub mod parser; /// The transpiler module, which transpiles Lotus code to vanilla Lua mod transpiler; /// The Lua runner module, which runs Lua code mod lua_runner; /// Runs a string of Lotus source code. /// /// # Arguments /// - `source_code` - The Lotus source code to run. /// /// # Errors /// - If the source code is not valid Lotus or if a runtime error occurs. /// /// # Safety /// This function is inherently unsafe because it runs arbitrary Lua code, including loading and using /// arbitrary C libraries. #[allow(clippy::missing_panics_doc)] // this doesn't panic? besides what's covered in # Safety pub unsafe fn run_lotus(source_code: &str) -> anyhow::Result<()> { let mut lotus_pairs = crate::parser::LotusParser::parse(crate::parser::Rule::program, source_code)?; let lotus_ast = crate::transpiler::pair_to_lotus_node(lotus_pairs.next().unwrap())?; let lua_ast: crate::transpiler::LuaAstNode = lotus_ast.into_lua_node()?; let lua_code = lua_ast.to_lua_code(); crate::lua_runner::run(&lua_code)?; Ok(()) }