mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-11 06:36:05 +00:00
webidl: add compile
and compile_file
These will be the functions invoked by crates compiling WebIDL into wasm-bindgen Rust sources inside `build.rs`.
This commit is contained in:
parent
a30ccd7c18
commit
c773b29d6d
@ -13,6 +13,7 @@ wasm-bindgen-backend = { version = "=0.2.11", path = "../backend", features = ["
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
proc-macro2 = "0.4"
|
proc-macro2 = "0.4"
|
||||||
|
quote = '0.6'
|
||||||
syn = { version = '0.14', features = ['full'] }
|
syn = { version = '0.14', features = ['full'] }
|
||||||
wasm-bindgen-backend = { version = "=0.2.11", path = "../backend" }
|
wasm-bindgen-backend = { version = "=0.2.11", path = "../backend" }
|
||||||
webidl = "0.6.0"
|
webidl = "0.6.0"
|
||||||
|
@ -10,12 +10,14 @@ emitted for the types and methods described in the WebIDL.
|
|||||||
|
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
|
extern crate quote;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
extern crate wasm_bindgen_backend as backend;
|
extern crate wasm_bindgen_backend as backend;
|
||||||
extern crate webidl;
|
extern crate webidl;
|
||||||
|
|
||||||
use failure::ResultExt;
|
use failure::ResultExt;
|
||||||
use proc_macro2::Ident;
|
use proc_macro2::Ident;
|
||||||
|
use quote::ToTokens;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -43,6 +45,26 @@ pub fn parse(webidl_source: &str) -> Result<backend::ast::Program> {
|
|||||||
Ok(program)
|
Ok(program)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compile the given WebIDL file into Rust source text containing
|
||||||
|
/// `wasm-bindgen` bindings to the things described in the WebIDL.
|
||||||
|
pub fn compile_file(webidl_path: &Path) -> Result<String> {
|
||||||
|
let ast = parse_file(webidl_path)?;
|
||||||
|
Ok(compile_ast(&ast))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compile the given WebIDL source text into Rust source text containing
|
||||||
|
/// `wasm-bindgen` bindings to the things described in the WebIDL.
|
||||||
|
pub fn compile(webidl_source: &str) -> Result<String> {
|
||||||
|
let ast = parse(webidl_source)?;
|
||||||
|
Ok(compile_ast(&ast))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compile_ast(ast: &backend::ast::Program) -> String {
|
||||||
|
let mut tokens = proc_macro2::TokenStream::new();
|
||||||
|
ast.to_tokens(&mut tokens);
|
||||||
|
tokens.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
trait WebidlParse {
|
trait WebidlParse {
|
||||||
fn webidl_parse(&self, program: &mut backend::ast::Program) -> Result<()>;
|
fn webidl_parse(&self, program: &mut backend::ast::Program) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user