aboutsummaryrefslogtreecommitdiffstats
path: root/components/dom_struct/lib.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-02-21 11:27:05 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2017-02-24 01:50:51 +0100
commit31e9d81c0f8fdfa4bb8ab27fda804b8d424e5378 (patch)
tree2a60d1308916da48c5c3958572865f48f03c60e3 /components/dom_struct/lib.rs
parent64885c4213c97c818f37026c7071975f299466fb (diff)
downloadservo-31e9d81c0f8fdfa4bb8ab27fda804b8d424e5378.tar.gz
servo-31e9d81c0f8fdfa4bb8ab27fda804b8d424e5378.zip
Make #[dom_struct] a proc_macro attribute
Diffstat (limited to 'components/dom_struct/lib.rs')
-rw-r--r--components/dom_struct/lib.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/components/dom_struct/lib.rs b/components/dom_struct/lib.rs
new file mode 100644
index 00000000000..f74427789db
--- /dev/null
+++ b/components/dom_struct/lib.rs
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#![feature(proc_macro)]
+
+extern crate proc_macro;
+#[macro_use] extern crate quote;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
+ if !args.to_string().is_empty() {
+ panic!("#[dom_struct] takes no arguments");
+ }
+ expand_string(&input.to_string()).parse().unwrap()
+}
+
+fn expand_string(input: &str) -> String {
+ let mut tokens = quote! {
+ #[derive(DenyPublicFields, DomObject, HeapSizeOf, JSTraceable)]
+ #[must_root]
+ #[repr(C)]
+ };
+ tokens.append(input);
+ tokens.to_string()
+}