1use super::*;
2use crate::svd::{
3 Access, BitRange, EnumeratedValues, Field, FieldInfo, ModifiedWriteValues, ReadAction,
4 WriteConstraint,
5};
6
7impl Parse for Field {
8 type Object = Self;
9 type Error = SVDErrorAt;
10 type Config = Config;
11
12 fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
13 parse_array("field", tree, config)
14 }
15}
16
17impl Parse for FieldInfo {
18 type Object = Self;
19 type Error = SVDErrorAt;
20 type Config = Config;
21
22 fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
23 if !tree.has_tag_name("field") {
24 return Err(SVDError::NotExpectedTag("field".to_string()).at(tree.id()));
25 }
26
27 let bit_range = BitRange::parse(tree, config)?;
28 FieldInfo::builder()
29 .name(tree.get_child_text("name")?)
30 .description(tree.get_child_text_opt("description")?)
31 .bit_range(bit_range)
32 .access(optional::<Access>("access", tree, config)?)
33 .modified_write_values(optional::<ModifiedWriteValues>(
34 "modifiedWriteValues",
35 tree,
36 config,
37 )?)
38 .write_constraint(if !config.ignore_enums {
39 optional::<WriteConstraint>("writeConstraint", tree, config)?
40 } else {
41 None
42 })
43 .read_action(optional::<ReadAction>("readAction", tree, config)?)
44 .enumerated_values(if !config.ignore_enums {
45 let values: Result<Vec<_>, _> = tree
46 .children()
47 .filter(|t| t.is_element() && t.has_tag_name("enumeratedValues"))
48 .map(|t| EnumeratedValues::parse(&t, config))
49 .collect();
50 values?
51 } else {
52 Vec::new()
53 })
54 .derived_from(tree.attribute("derivedFrom").map(|s| s.to_owned()))
55 .build(config.validate_level)
56 .map_err(|e| SVDError::from(e).at(tree.id()))
57 }
58}