Skip to content

Commit 14dac5a

Browse files
authoredNov 30, 2023
Merge pull request #781 from rust-embedded/validate
post-serde validation
2 parents 99e68c7 + 6f8e955 commit 14dac5a

File tree

4 files changed

+118
-40
lines changed

4 files changed

+118
-40
lines changed
 

‎CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Add `svd::Device` validation after parsing by `serde`
11+
- Add `skip-crate-attributes` config flag
12+
- Better display parsing errors
13+
1014
## [v0.31.2] - 2023-11-29
1115

12-
- Add `skip-crate-attributes` config flag
1316
- Add iterators for register/cluster/field arrays
1417
- Use parentheses instead of square brackets in docs for field arrays
15-
- Better display parsing errors
1618

1719
## [v0.31.1] - 2023-11-27
1820

‎Cargo.lock

+93-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ html-escape = "0.2"
6060

6161
[dependencies.svd-parser]
6262
features = ["expand"]
63-
version = "0.14.3"
63+
version = "0.14.4"
6464

6565
[dependencies.svd-rs]
6666
features = ["serde"]
67-
version = "0.14.5"
67+
version = "0.14.6"
6868

6969
[dependencies.syn]
7070
version = "2.0"

‎src/lib.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -620,24 +620,34 @@ pub fn load_from(input: &str, config: &Config) -> Result<svd::Device> {
620620
use config::SourceType;
621621
use svd_parser::ValidateLevel;
622622

623+
let validate_level = if config.strict {
624+
ValidateLevel::Strict
625+
} else {
626+
ValidateLevel::Weak
627+
};
628+
623629
let mut device = match config.source_type {
624630
SourceType::Xml => {
625631
let mut parser_config = svd_parser::Config::default();
626-
parser_config.validate_level = if config.strict {
627-
ValidateLevel::Strict
628-
} else {
629-
ValidateLevel::Weak
630-
};
632+
parser_config.validate_level = validate_level;
631633

632634
svd_parser::parse_with_config(input, &parser_config)
633635
.with_context(|| "Error parsing SVD XML file".to_string())?
634636
}
635637
#[cfg(feature = "yaml")]
636-
SourceType::Yaml => serde_yaml::from_str(input)
637-
.with_context(|| "Error parsing SVD YAML file".to_string())?,
638+
SourceType::Yaml => {
639+
let device: svd::Device = serde_yaml::from_str(input)
640+
.with_context(|| "Error parsing SVD YAML file".to_string())?;
641+
device.validate_all(validate_level)?;
642+
device
643+
}
638644
#[cfg(feature = "json")]
639-
SourceType::Json => serde_json::from_str(input)
640-
.with_context(|| "Error parsing SVD JSON file".to_string())?,
645+
SourceType::Json => {
646+
let device: svd::Device = serde_json::from_str(input)
647+
.with_context(|| "Error parsing SVD JSON file".to_string())?;
648+
device.validate_all(validate_level)?;
649+
device
650+
}
641651
};
642652
svd_parser::expand_properties(&mut device);
643653
Ok(device)

0 commit comments

Comments
 (0)
Please sign in to comment.