mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 22:22:12 +00:00
* remove BindgenAttrs from other backend::ast structs This is primarily a tool for use with the macro crate. Most of these attributes were ignored in the actual codegen, but a few were still being used. This is confusing when trying to add other sources for codegen (such as webidl and typescript). * move parsing logic to macro crate This makes the backend crate solely concerned with having an ast for which we can generate code.
35 lines
929 B
Rust
Executable File
35 lines
929 B
Rust
Executable File
#![feature(proc_macro)]
|
|
|
|
extern crate proc_macro;
|
|
extern crate proc_macro2;
|
|
extern crate quote;
|
|
extern crate wasm_bindgen_shared as shared;
|
|
#[macro_use]
|
|
extern crate syn;
|
|
extern crate wasm_bindgen_backend as backend;
|
|
|
|
use proc_macro::TokenStream;
|
|
use quote::ToTokens;
|
|
|
|
mod parser;
|
|
|
|
use parser::MacroParse;
|
|
|
|
#[proc_macro_attribute]
|
|
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
|
|
let item = syn::parse::<syn::Item>(input.clone()).expect("expected a valid Rust item");
|
|
let opts =
|
|
syn::parse::<parser::BindgenAttrs>(attr).expect("invalid arguments to #[wasm_bindgen]");
|
|
|
|
let mut ret = proc_macro2::TokenStream::new();
|
|
let mut program = backend::ast::Program::default();
|
|
item.macro_parse(&mut program, (Some(opts), &mut ret));
|
|
program.to_tokens(&mut ret);
|
|
|
|
if cfg!(feature = "xxx_debug_only_print_generated_code") {
|
|
println!("{}", ret);
|
|
}
|
|
|
|
ret.into()
|
|
}
|