Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 1021 Bytes

README.md

File metadata and controls

37 lines (30 loc) · 1021 Bytes

webidl_rs

A Web IDL parser for rust, powered by nom. It supports converting parsed Web IDL back to a string.

Usage

Cargo.toml

[dependencies]
webidl_rs = { git = "https://github.com/l4yton/webidl_rs" }

src/main.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));
}

TODO

  • Better documentation
  • Add more tests
  • Replace asserts with custom errors in parser
  • Validate Web IDL semantically (more)