use typescript_types::{TsError, TsValue};
use typescript_webidl::{convert_to_typescript, parse};
pub struct WebIdlProcessor {
pub typescript_definitions: String,
}
impl WebIdlProcessor {
pub fn new() -> Self {
Self { typescript_definitions: String::new() }
}
pub fn process_webidl(&mut self, idl: &str) -> Result<(), TsError> {
match parse(idl) {
Ok(root) => {
self.typescript_definitions = convert_to_typescript(&root);
Ok(())
}
Err(error) => Err(TsError::SyntaxError(format!("WebIDL parse error: {}", error))),
}
}
pub fn process_webidl_file(&mut self, path: &std::path::Path) -> Result<(), TsError> {
use std::fs::read_to_string;
let idl = read_to_string(path).map_err(|e| TsError::Other(format!("Failed to read WebIDL file: {}", e)))?;
self.process_webidl(&idl)
}
pub fn get_typescript_definitions(&self) -> &str {
&self.typescript_definitions
}
}