Patch accidental panic
This commit is contained in:
parent
9db45daafa
commit
6f2a96e182
1 changed files with 16 additions and 28 deletions
44
src/main.rs
44
src/main.rs
|
@ -47,11 +47,15 @@ fn main() {
|
|||
fn new_parse(doc:&roxmltree::Document) -> Result<oop::Family,core::fmt::Error>{
|
||||
let mut wrapped_family:Option<oop::Family> = None;
|
||||
let mut messages: oop::Messages = oop::Messages::new(Vec::new(), Vec::new(), Vec::new(), Vec::new(), Vec::new());
|
||||
let root = doc.root_element();
|
||||
|
||||
if let Some(root) = doc.root_element().first_child(){
|
||||
println!("{:?}",doc.root_element());
|
||||
println!("{:?}",doc.root_element().first_element_child());
|
||||
if let Some(_) = doc.root_element().first_element_child(){
|
||||
match root.tag_name().name() {
|
||||
"FAMILY" => {
|
||||
if let Some(attribute) = root.attributes().filter(|attribute| attribute.name() == "name" ).next(){
|
||||
for attribute in root.attributes().filter(|attribute| { println!("{:?}",attribute.name()); attribute.name() == "name" }){
|
||||
println!("successful match");
|
||||
wrapped_family = Some(oop::Family::new(attribute.value().to_string(), Vec::new(), Vec::new()));
|
||||
}
|
||||
},
|
||||
|
@ -77,6 +81,8 @@ fn new_parse(doc:&roxmltree::Document) -> Result<oop::Family,core::fmt::Error>{
|
|||
}
|
||||
|
||||
fn nested_parse(input_family:&mut oop::Family, node: roxmltree::Node) {
|
||||
if node.is_text() || node.is_comment() { return; }
|
||||
println!("{:?}",node);
|
||||
match node.tag_name().name() {
|
||||
"SPECIES_KEY" => {
|
||||
node.children().for_each(|child| nested_parse(input_family, child));
|
||||
|
@ -129,19 +135,9 @@ fn nested_parse(input_family:&mut oop::Family, node: roxmltree::Node) {
|
|||
node.children().for_each(|child| nested_parse(input_family, child));
|
||||
},
|
||||
"MEMBER" => {
|
||||
let Some(attr_family) = node.attribute("family")
|
||||
else { todo!() };
|
||||
let Some(attr_genus) = node.attribute("genus")
|
||||
else { todo!() };
|
||||
let Some(attr_species) = node.attribute("species")
|
||||
else { todo!() };
|
||||
if attr_family != input_family.get_name() {
|
||||
println!("Inconsistent family naming scheme. Check XML file.");
|
||||
panic!();
|
||||
}
|
||||
input_family.get_genera().as_mut_slice().iter_mut().filter(|genus| genus.get_name().as_str() == attr_genus)
|
||||
input_family.get_genera().as_mut_slice().iter_mut()
|
||||
.for_each(|genus| {
|
||||
genus.get_species().as_mut_slice().iter_mut().filter(|species| species.get_name().as_str() == attr_species)
|
||||
genus.get_species().as_mut_slice().iter_mut()
|
||||
.for_each(|species|{
|
||||
species.get_objects().as_mut_slice().iter_mut()
|
||||
.for_each(|object| {
|
||||
|
@ -162,24 +158,13 @@ fn nested_parse(input_family:&mut oop::Family, node: roxmltree::Node) {
|
|||
node.children().for_each(|child| nested_parse(input_family, child));
|
||||
},
|
||||
"ENUM" => {
|
||||
let Some(attr_family) = node.attribute("family")
|
||||
else { todo!() };
|
||||
let Some(attr_genus) = node.attribute("genus")
|
||||
else { todo!() };
|
||||
let Some(attr_species) = node.attribute("species")
|
||||
else { todo!() };
|
||||
let Some(attr_name) = node.attribute("name")
|
||||
else { todo!() };
|
||||
if attr_family != input_family.get_name() {
|
||||
println!("Inconsistent family naming scheme. Check XML file.");
|
||||
}
|
||||
input_family.get_genera().as_mut_slice().iter_mut().filter(|genus| genus.get_name().as_str() == attr_genus)
|
||||
input_family.get_genera().as_mut_slice().iter_mut()
|
||||
.for_each(|genus| {
|
||||
genus.get_species().as_mut_slice().iter_mut().filter(|species| species.get_name().as_str() == attr_species)
|
||||
genus.get_species().as_mut_slice().iter_mut()
|
||||
.for_each(|species|{
|
||||
species.get_objects().as_mut_slice().iter_mut()
|
||||
.for_each(|object| {
|
||||
object.get_members().as_mut_slice().iter_mut().filter(|member| member.get_name().as_str() == attr_name)
|
||||
object.get_members().as_mut_slice().iter_mut()
|
||||
.for_each(|member| {
|
||||
member.get_enumerations().push(
|
||||
oop::MemberEnumeration::new(
|
||||
|
@ -193,8 +178,11 @@ fn nested_parse(input_family:&mut oop::Family, node: roxmltree::Node) {
|
|||
}
|
||||
);
|
||||
},
|
||||
//These two are handled elsewhere
|
||||
"MESSAGES" => {},
|
||||
"MSG" => {},
|
||||
|
||||
//catch-all
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue