Add meta support to macros.

This commit is contained in:
Emmanuel Gil Peyrot 2017-10-31 18:37:32 +00:00
parent 929bd577f3
commit 61badccf8b

View file

@ -174,11 +174,8 @@ macro_rules! check_no_unknown_attributes {
} }
macro_rules! generate_empty_element { macro_rules! generate_empty_element {
($elem:ident, $name:tt, $ns:expr) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr) => (
// TODO: Find a better way to concatenate doc. $(#[$meta])*
#[doc="Structure representing a "]
#[doc=$name]
#[doc=" element."]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct $elem; pub struct $elem;
@ -204,13 +201,15 @@ macro_rules! generate_empty_element {
} }
macro_rules! generate_element_with_only_attributes { macro_rules! generate_element_with_only_attributes {
($elem:ident, $name:tt, $ns:expr, [$($attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
generate_element_with_only_attributes!($elem, $name, $ns, [$($attr: $attr_type = $attr_name => $attr_action),*]); generate_element_with_only_attributes!($(#[$meta])* $elem, $name, $ns, [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*]);
); );
($elem:ident, $name:tt, $ns:expr, [$($attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
$(#[$meta])*
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct $elem { pub struct $elem {
$( $(
$(#[$attr_meta])*
pub $attr: $attr_type pub $attr: $attr_type
),* ),*
} }