disco: Use a macro for <identity/>.

This commit is contained in:
Emmanuel Gil Peyrot 2019-02-28 02:26:10 +01:00
commit b56582c8b5
2 changed files with 40 additions and 61 deletions

View file

@ -33,6 +33,25 @@ macro_rules! get_attr {
}
}
};
($elem:ident, $attr:tt, RequiredNonEmpty, $value:ident, $func:expr) => {
match $elem.attr($attr) {
Some("") => {
return Err(crate::util::error::Error::ParseError(concat!(
"Required attribute '",
$attr,
"' must not be empty."
)));
},
Some($value) => $func,
None => {
return Err(crate::util::error::Error::ParseError(concat!(
"Required attribute '",
$attr,
"' missing."
)));
}
}
};
($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => {
match $elem.attr($attr) {
Some($value) => $func,
@ -408,6 +427,9 @@ macro_rules! decl_attr {
(Required, $type:ty) => (
$type
);
(RequiredNonEmpty, $type:ty) => (
$type
);
(Default, $type:ty) => (
$type
);