Skip to content

Commit 283d9d0

Browse files
committed
v0.9, use with_context
1 parent 92dbac8 commit 283d9d0

File tree

10 files changed

+49
-38
lines changed

10 files changed

+49
-38
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.9.0] - 2019-11-17
11+
12+
- [breaking-change] make `ClusterInfo` `description` optional
13+
- [breaking-change] use `anyhow` Error instead of `failure`
14+
1015
## [v0.8.1] - 2019-11-03
1116

1217
- Fix: make `derive_from` module public
@@ -111,7 +116,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
111116
- Initial SVD parser
112117
- A `parse` utility function to parse the contents of a SVD file (XML)
113118

114-
[Unreleased]: https://github.com/rust-embedded/svd/compare/v0.8.1...HEAD
119+
[Unreleased]: https://github.com/rust-embedded/svd/compare/v0.9.0...HEAD
120+
[v0.9.0]: https://github.com/rust-embedded/svd/compare/v0.8.1...v0.9.0
115121
[v0.8.1]: https://github.com/rust-embedded/svd/compare/v0.8.0...v0.8.1
116122
[v0.8.0]: https://github.com/rust-embedded/svd/compare/v0.7.0...v0.8.0
117123
[v0.7.0]: https://github.com/rust-embedded/svd/compare/v0.6.0...v0.7.0

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
1010
name = "svd-parser"
1111
repository = "https://github.com/rust-embedded/svd"
1212
edition = "2018"
13-
version = "0.8.1"
13+
version = "0.9.0"
1414
readme = "README.md"
1515

1616
[features]

src/svd/bitrange.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,30 @@ impl Parse for BitRange {
6363
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax)
6464
})?
6565
.parse::<u32>()
66-
.context(SVDError::InvalidBitRange(
67-
tree.clone(),
68-
InvalidBitRange::ParseError,
69-
))?,
66+
.with_context(|| {
67+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::ParseError)
68+
})?,
7069
parts
7170
.next()
7271
.ok_or_else(|| {
7372
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax)
7473
})?
7574
.parse::<u32>()
76-
.context(SVDError::InvalidBitRange(
77-
tree.clone(),
78-
InvalidBitRange::ParseError,
79-
))?,
75+
.with_context(|| {
76+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::ParseError)
77+
})?,
8078
BitRangeType::BitRange,
8179
)
8280
// TODO: Consider matching instead so we can say which of these tags are missing
8381
} else if let (Some(lsb), Some(msb)) = (tree.get_child("lsb"), tree.get_child("msb")) {
8482
(
8583
// TODO: `u32::parse` should not hide it's errors
86-
u32::parse(msb).context(SVDError::InvalidBitRange(
87-
tree.clone(),
88-
InvalidBitRange::MsbLsb,
89-
))?,
90-
u32::parse(lsb).context(SVDError::InvalidBitRange(
91-
tree.clone(),
92-
InvalidBitRange::MsbLsb,
93-
))?,
84+
u32::parse(msb).with_context(|| {
85+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::MsbLsb)
86+
})?,
87+
u32::parse(lsb).with_context(|| {
88+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::MsbLsb)
89+
})?,
9490
BitRangeType::MsbLsb,
9591
)
9692
} else if let (Some(offset), Some(width)) =
@@ -102,14 +98,12 @@ impl Parse for BitRange {
10298
return Ok(BitRange {
10399
// TODO: capture that error comes from offset/width tag
104100
// TODO: `u32::parse` should not hide it's errors
105-
offset: u32::parse(offset).context(SVDError::InvalidBitRange(
106-
tree.clone(),
107-
InvalidBitRange::ParseError,
108-
))?,
109-
width: u32::parse(width).context(SVDError::InvalidBitRange(
110-
tree.clone(),
111-
InvalidBitRange::ParseError,
112-
))?,
101+
offset: u32::parse(offset).with_context(|| {
102+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::ParseError)
103+
})?,
104+
width: u32::parse(width).with_context(|| {
105+
SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::ParseError)
106+
})?,
113107
range_type: BitRangeType::OffsetWidth,
114108
})
115109
)

src/svd/clusterinfo.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::svd::{registercluster::RegisterCluster, registerproperties::RegisterP
1616
pub struct ClusterInfo {
1717
pub name: String,
1818
pub derived_from: Option<String>,
19-
pub description: String,
19+
pub description: Option<String>,
2020
pub header_struct_name: Option<String>,
2121
pub address_offset: u32,
2222
pub default_register_properties: RegisterProperties,
@@ -30,10 +30,17 @@ impl Parse for ClusterInfo {
3030
type Error = anyhow::Error;
3131

3232
fn parse(tree: &Element) -> Result<ClusterInfo> {
33+
let name = tree.get_child_text("name")?;
34+
ClusterInfo::_parse(tree, name.clone()).with_context(|| format!("In cluster `{}`", name))
35+
}
36+
}
37+
38+
impl ClusterInfo {
39+
fn _parse(tree: &Element, name: String) -> Result<ClusterInfo> {
3340
Ok(ClusterInfo {
34-
name: tree.get_child_text("name")?, // TODO: Handle naming of cluster
41+
name, // TODO: Handle naming of cluster
3542
derived_from: tree.attributes.get("derivedFrom").map(|s| s.to_owned()),
36-
description: tree.get_child_text("description")?,
43+
description: tree.get_child_text_opt("description")?,
3744
header_struct_name: tree.get_child_text_opt("headerStructName")?,
3845
address_offset: tree.get_child_u32("addressOffset")?,
3946
default_register_properties: RegisterProperties::parse(tree)?,
@@ -64,7 +71,7 @@ impl Encode for ClusterInfo {
6471
}
6572

6673
e.children
67-
.push(new_element("description", Some(self.description.clone())));
74+
.push(new_element("description", self.description.clone()));
6875

6976
if let Some(v) = &self.header_struct_name {
7077
e.children

src/svd/enumeratedvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Parse for EnumeratedValue {
4747
}
4848
let name = tree.get_child_text("name")?;
4949
EnumeratedValue::_parse(tree, name.clone())
50-
.context(format!("In enumerated value `{}`", name))
50+
.with_context(|| format!("In enumerated value `{}`", name))
5151
}
5252
}
5353

src/svd/enumeratedvalues.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Parse for EnumeratedValues {
5050
.map(|(e, t)| {
5151
if t.name == "enumeratedValue" {
5252
EnumeratedValue::parse(t)
53-
.context(format!("Parsing enumerated value #{}", e))
53+
.with_context(|| format!("Parsing enumerated value #{}", e))
5454
} else {
5555
Err(
5656
SVDError::NotExpectedTag(t.clone(), "enumeratedValue".to_string())

src/svd/fieldinfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Parse for FieldInfo {
4141
return Err(SVDError::NotExpectedTag(tree.clone(), "field".to_string()).into());
4242
}
4343
let name = tree.get_child_text("name")?;
44-
FieldInfo::_parse(tree, name.clone()).context(format!("In field `{}`", name))
44+
FieldInfo::_parse(tree, name.clone()).with_context(|| format!("In field `{}`", name))
4545
}
4646
}
4747

src/svd/interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Parse for Interrupt {
3939
return Err(SVDError::NotExpectedTag(tree.clone(), "interrupt".to_string()).into());
4040
}
4141
let name = tree.get_child_text("name")?;
42-
Interrupt::_parse(tree, name.clone()).context(format!("In interrupt `{}`", name))
42+
Interrupt::_parse(tree, name.clone()).with_context(|| format!("In interrupt `{}`", name))
4343
}
4444
}
4545

src/svd/peripheral.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Parse for Peripheral {
4646
return Err(SVDError::NotExpectedTag(tree.clone(), "peripheral".to_string()).into());
4747
}
4848
let name = tree.get_child_text("name")?;
49-
Peripheral::_parse(tree, name.clone()).context(format!("In peripheral `{}`", name))
49+
Peripheral::_parse(tree, name.clone()).with_context(|| format!("In peripheral `{}`", name))
5050
}
5151
}
5252

@@ -66,7 +66,9 @@ impl Peripheral {
6666
.iter()
6767
.filter(|t| t.name == "interrupt")
6868
.enumerate()
69-
.map(|(e, i)| Interrupt::parse(i).context(format!("Parsing interrupt #{}", e)))
69+
.map(|(e, i)| {
70+
Interrupt::parse(i).with_context(|| format!("Parsing interrupt #{}", e))
71+
})
7072
.collect();
7173
interrupt?
7274
},

src/svd/registerinfo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Parse for RegisterInfo {
4444

4545
fn parse(tree: &Element) -> Result<RegisterInfo> {
4646
let name = tree.get_child_text("name")?;
47-
RegisterInfo::_parse(tree, name.clone()).context(format!("In register `{}`", name))
47+
RegisterInfo::_parse(tree, name.clone()).with_context(|| format!("In register `{}`", name))
4848
}
4949
}
5050

@@ -68,7 +68,9 @@ impl RegisterInfo {
6868
.children
6969
.iter()
7070
.enumerate()
71-
.map(|(e, t)| Field::parse(t).context(format!("Parsing field #{}", e)))
71+
.map(|(e, t)| {
72+
Field::parse(t).with_context(|| format!("Parsing field #{}", e))
73+
})
7274
.collect();
7375
Some(fs?)
7476
} else {

0 commit comments

Comments
 (0)