A Web IDL parser for rust, powered by nom. It supports converting parsed Web IDL back to a string.
[dependencies]
webidl_rs = { git = "https://github.com/l4yton/webidl_rs" }
use webidl_rs::{Constructor, Definition, Member};
fn main() {
let mut definitions =
webidl_rs::parse("[Exposed=Window] interface Foo { };").unwrap();
// Add a constructor to the first definition.
if let Some(Definition::Interface(interface)) = definitions.first_mut() {
interface.members.push(Member::Constructor(Constructor {
ext_attrs: vec![],
arguments: vec![],
}))
}
// Print the Web IDL with the added constructor.
print!("{}", webidl_rs::to_string(&definitions));
}
- Better documentation
- Add more tests
- Replace asserts with custom errors in parser
- Validate Web IDL semantically (more)