1#![doc = include_str!("readme.md")]
2#![warn(missing_docs)]
3#![feature(new_range_api)]
4
5use std::fs;
6
7pub mod converter;
9
10pub mod types;
12
13pub mod type_checker;
15
16use oak_idl::IdlRoot;
18
19pub fn parse(idl: &str) -> Result<IdlRoot, String> {
28 oak_idl::parse(idl)
29}
30
31pub fn parse_file(file_path: &str) -> Result<IdlRoot, String> {
40 if file_path.is_empty() {
41 return Err("Empty file path".to_string());
42 }
43
44 match fs::read_to_string(file_path) {
45 Ok(content) => {
46 if content.trim().is_empty() {
47 return Err("Empty WebIDL file".to_string());
48 }
49 parse(&content)
50 }
51 Err(error) => {
52 let error_msg = format!("Failed to read file '{}': {}", file_path, error);
53 Err(error_msg)
54 }
55 }
56}
57
58pub fn convert_to_typescript(root: &IdlRoot) -> String {
66 converter::convert(root)
67}