Skip to content

Commit 3ec0906

Browse files
Merge #134
134: Implement strict flag r=Emilgardis a=brainstorm Fixes #127 among others Co-authored-by: Roman Valls Guimera <brainstorm@nopcode.org>
2 parents f8e2d9e + f25b857 commit 3ec0906

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ readme = "README.md"
1515

1616
[features]
1717
derive-from = []
18+
strict = []
1819

1920
[dependencies]
2021
xmltree = "0.8"

src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ pub(crate) fn check_name(name: &str, tag: &str) -> Result<()> {
9191
static PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new("^[_A-Za-z0-9]*$").unwrap());
9292
if PATTERN.is_match(name) {
9393
Ok(())
94-
} else {
94+
} else if cfg!(feature = "strict") {
9595
Err(NameError::Invalid(name.to_string(), tag.to_string()).into())
96+
} else {
97+
Ok(())
9698
}
9799
}
98100

src/svd/clusterinfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl ClusterInfo {
111111
if let Some(name) = self.derived_from.as_ref() {
112112
check_derived_name(name, "derivedFrom")?;
113113
} else if self.children.is_empty() {
114+
#[cfg(feature = "strict")]
114115
return Err(SVDError::EmptyCluster)?;
115116
}
116117
Ok(self)

src/svd/peripheral.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl Peripheral {
162162
check_dimable_name(name, "derivedFrom")?;
163163
} else if let Some(registers) = self.registers.as_ref() {
164164
if registers.is_empty() {
165+
#[cfg(feature = "strict")]
165166
return Err(SVDError::EmptyRegisters)?;
166167
}
167168
}

src/svd/registerinfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl RegisterInfo {
191191
check_derived_name(name, "derivedFrom")?;
192192
} else if let Some(fields) = self.fields.as_ref() {
193193
if fields.is_empty() {
194+
#[cfg(feature = "strict")]
194195
return Err(SVDError::EmptyFields)?;
195196
}
196197
}

0 commit comments

Comments
 (0)