1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![allow(clippy::never_loop)]
extern crate proc_macro;
mod util;
mod ast;
mod generator;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn node_bindgen(args: TokenStream, item: TokenStream) -> TokenStream {
use syn::AttributeArgs;
use ast::FunctionAttributes;
use ast::NodeItem;
use generator::generate_function;
use generator::generate_class;
let attribute_args = syn::parse_macro_input!(args as AttributeArgs);
let attribute: FunctionAttributes = match FunctionAttributes::from_ast(attribute_args) {
Ok(attr) => attr,
Err(err) => return err.to_compile_error().into(),
};
let parsed_item = syn::parse_macro_input!(item as NodeItem);
let out_express = match parsed_item {
NodeItem::Function(fn_item) => generate_function(fn_item, attribute),
NodeItem::Impl(impl_item) => generate_class(impl_item),
};
out_express.into()
}