spydecy_python/
lib.rs

1//! Python transpiler - converts Python AST to Spydecy HIR
2//!
3//! This module uses PyO3 to parse Python code into AST, then converts
4//! it to Spydecy's Unified HIR for cross-layer optimization.
5//!
6//! # Sprint 2 Deliverables
7//!
8//! - Python AST parser (PyO3)
9//! - Type hint extraction
10//! - Python → HIR conversion
11//! - First debugger feature: `spydecy debug visualize python-ast`
12
13#![warn(missing_docs, clippy::all, clippy::pedantic)]
14#![deny(unsafe_code)]
15#![allow(
16    clippy::doc_markdown,
17    clippy::single_match_else,
18    clippy::single_match,
19    clippy::module_name_repetitions,
20    clippy::str_to_string,
21    clippy::unwrap_used,
22    clippy::panic
23)]
24
25pub mod hir_converter;
26pub mod parser;
27pub mod type_extractor;
28
29use anyhow::Result;
30use spydecy_hir::python::PythonHIR;
31
32/// Parse Python source code into HIR
33///
34/// # Errors
35///
36/// Returns an error if the Python code cannot be parsed or converted to HIR
37pub fn parse_python(source: &str, filename: &str) -> Result<PythonHIR> {
38    let ast = parser::parse(source, filename)?;
39    hir_converter::convert_to_hir(&ast)
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_parse_simple_function() {
48        let source = r"
49def my_len(x):
50    return len(x)
51";
52        let result = parse_python(source, "test.py");
53        assert!(result.is_ok());
54    }
55}