helpers, disco: Parse children based on their name and namespace.
This commit is contained in:
parent
d78a0e6dae
commit
0ead24a041
2 changed files with 8 additions and 4 deletions
|
@ -214,7 +214,7 @@ generate_element_with_children!(
|
||||||
],
|
],
|
||||||
children: [
|
children: [
|
||||||
/// List of items pointed by this entity.
|
/// List of items pointed by this entity.
|
||||||
items: Vec<Item> = "item" => Item
|
items: Vec<Item> = ("item", ns::DISCO_ITEMS) => Item
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ macro_rules! generate_element_with_text {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! generate_element_with_children {
|
macro_rules! generate_element_with_children {
|
||||||
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = $child_name:tt => $child_constructor:ident),+]) => (
|
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:expr) => $child_constructor:ident),+]) => (
|
||||||
$(#[$meta])*
|
$(#[$meta])*
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct $elem {
|
pub struct $elem {
|
||||||
|
@ -318,9 +318,13 @@ macro_rules! generate_element_with_children {
|
||||||
let mut parsed_children = vec!();
|
let mut parsed_children = vec!();
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
$(
|
$(
|
||||||
let parsed_child = $child_constructor::try_from(child.clone())?;
|
if child.is($child_name, $child_ns) {
|
||||||
parsed_children.push(parsed_child);
|
let parsed_child = $child_constructor::try_from(child.clone())?;
|
||||||
|
parsed_children.push(parsed_child);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
)*
|
)*
|
||||||
|
return Err(Error::ParseError(concat!("Unknown child in ", $name, " element.")));
|
||||||
}
|
}
|
||||||
Ok($elem {
|
Ok($elem {
|
||||||
$(
|
$(
|
||||||
|
|
Loading…
Reference in a new issue