1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod ast;
mod generators;
#[cfg(feature = "_bin")]
mod options;
mod parser;
mod helper;

pub use helper::update_types;

pub use parser::{
    parse, parse_file, parse_file_raw, parse_file_with_namespace, parse_raw, ParseError,
};
pub use ssd_data::{
    Attribute, DataType, Dependency, Enum, EnumValue, Event, Function, Import, Namespace,
    OrderedMap, Parameter, Service, SsdModule, TypeName,
};

#[cfg(feature = "_web")]
pub use generators::rhai::generate_web;

#[cfg(feature = "_python")]
mod python {
    use std::path::Path;

    use pyo3::exceptions::PyException;
    use pyo3::prelude::*;
    use pyo3::Python;

    use ssd_data::Namespace;
    use ssd_data::SsdModule;

    #[pyfunction]
    pub fn parse(content: &str, namespace: &str) -> PyResult<SsdModule> {
        crate::parse(content, Namespace::new(namespace))
            .map_err(|e| PyException::new_err(e.to_string()))
    }

    #[pyfunction]
    pub fn parse_file(base: &str, path: &str) -> PyResult<SsdModule> {
        crate::parse_file(&Path::new(base), &Path::new(path))
            .map_err(|e| PyException::new_err(e.to_string()))
    }

    #[pyfunction]
    pub fn parse_file_with_namespace(path: &str, namespace: &str) -> PyResult<SsdModule> {
        crate::parse_file_with_namespace(Path::new(path), Namespace::new(namespace))
            .map_err(|e| PyException::new_err(e.to_string()))
    }

    #[pymodule]
    fn py_ssd(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
        m.add_function(wrap_pyfunction!(parse, m)?)?;
        m.add_function(wrap_pyfunction!(parse_file, m)?)?;
        m.add_function(wrap_pyfunction!(parse_file_with_namespace, m)?)?;
        Ok(())
    }
}