#![doc = include_str!("readme.md")]
#![warn(missing_docs)]
#![feature(new_range_api)]
use std::fs;
pub mod converter;
pub mod types;
pub mod type_checker;
use oak_idl::IdlRoot;
pub fn parse(idl: &str) -> Result<IdlRoot, String> {
oak_idl::parse(idl)
}
pub fn parse_file(file_path: &str) -> Result<IdlRoot, String> {
if file_path.is_empty() {
return Err("Empty file path".to_string());
}
match fs::read_to_string(file_path) {
Ok(content) => {
if content.trim().is_empty() {
return Err("Empty WebIDL file".to_string());
}
parse(&content)
}
Err(error) => {
let error_msg = format!("Failed to read file '{}': {}", file_path, error);
Err(error_msg)
}
}
}
pub fn convert_to_typescript(root: &IdlRoot) -> String {
converter::convert(root)
}