svd_parser/
addressblock.rs1use super::*;
2use crate::svd::{AddressBlock, AddressBlockUsage, Protection};
3
4impl Parse for AddressBlock {
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        Self::builder()
11            .offset(tree.get_child_u32("offset")?)
12            .size(tree.get_child_u32("size")?)
13            .usage(AddressBlockUsage::parse(
14                &tree.get_child_elem("usage")?,
15                config,
16            )?)
17            .protection(optional::<Protection>("protection", tree, config)?)
18            .build(config.validate_level)
19            .map_err(|e| SVDError::from(e).at(tree.id()))
20    }
21}
22
23impl Parse for AddressBlockUsage {
24    type Object = Self;
25    type Error = SVDErrorAt;
26    type Config = Config;
27
28    fn parse(tree: &Node, _config: &Self::Config) -> Result<Self, Self::Error> {
29        let text = tree.get_text()?;
30
31        Self::parse_str(text).ok_or_else(|| SVDError::UnknownAddressBlockUsageVariant.at(tree.id()))
32    }
33}