1use super::*;
2use crate::svd::{Cluster, ClusterInfo, RegisterCluster, RegisterProperties};
3
4impl Parse for Cluster {
5 type Object = Self;
6 type Error = SVDErrorAt;
7 type Config = Config;
8
9 fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
10 parse_array("cluster", tree, config)
11 }
12}
13
14impl Parse for ClusterInfo {
15 type Object = Self;
16 type Error = SVDErrorAt;
17 type Config = Config;
18
19 fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
20 ClusterInfo::builder()
21 .name(tree.get_child_text("name")?)
22 .description(tree.get_child_text_opt("description")?)
23 .alternate_cluster(tree.get_child_text_opt("alternateCluster")?)
24 .header_struct_name(tree.get_child_text_opt("headerStructName")?)
25 .address_offset(tree.get_child_u32("addressOffset")?)
26 .default_register_properties(RegisterProperties::parse(tree, config)?)
27 .children({
28 let children: Result<Vec<_>, _> = tree
29 .children()
30 .filter(|t| {
31 t.is_element() && (t.has_tag_name("register") || t.has_tag_name("cluster"))
32 })
33 .map(|t| RegisterCluster::parse(&t, config))
34 .collect();
35 children?
36 })
37 .derived_from(tree.attribute("derivedFrom").map(|s| s.to_owned()))
38 .build(config.validate_level)
39 .map_err(|e| SVDError::from(e).at(tree.id()))
40 }
41}