From 06651dc878e128e18564eb2030e7ef19686c4047 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 15 Feb 2024 18:44:21 +0100 Subject: [PATCH] code clean --- src/paragraph/parser/abschnitt.rs | 61 ++++++++++++------------------- src/paragraph/parser/mod.rs | 3 -- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/paragraph/parser/abschnitt.rs b/src/paragraph/parser/abschnitt.rs index 6691797..6b881b9 100644 --- a/src/paragraph/parser/abschnitt.rs +++ b/src/paragraph/parser/abschnitt.rs @@ -32,12 +32,10 @@ impl Abschnitt { Self::skip_static_fields(&mut c); - if !ret.handle_headers(&mut c, builder) { - return ret; - } + ret.handle_headers(&mut c, builder); while let Some(child) = c.peek() { - // Shciffahrtsgesetz: stop @ anlagen (for now) + // Schiffahrtsgesetz: stop @ anlagen (for now) if Ueberschrift::test(child, "anlage") { return ret; } @@ -202,44 +200,31 @@ impl Abschnitt { // There are paragraph-specific meta-data at the top of each xml file. We parse those. When we // encounter the title "Text" the real content starts, we stop parsing meta data. - // - // # Returns - // `false` if the parsing should be stopped - fn handle_headers(&mut self, c: &mut Peekable, builder: &mut LawBuilder) -> bool { - while let Some(child) = &c.peek() { - if Ueberschrift::test(child, "titel") { - let key = Ueberschrift::parse(c.next().unwrap(), "titel").content; + fn handle_headers(&mut self, c: &mut Peekable, builder: &mut LawBuilder) { + loop { + let key = Ueberschrift::parse(c.next().unwrap(), "titel").content; - // We are done with meta-data parsing - if key == "Text" { - break; - } - - let absatz = Absatz::parse( - c.next() - .expect("Expected absatz after title in par headers"), - ); - if &absatz.typ != "erltext" { - panic!( - "Expected erlext absatz after title in par headers, got '{}'", - absatz.typ - ); - } - let value = absatz.content; - - // We want ot use this information in our markdown output. - // TODO: Use all metadata, instead of this specific call - if key == "Beachte" { - builder.add_next_para_note(value.clone()); - } - - self.metadata.insert(key, value); - continue; + // We are done with meta-data parsing + if key == "Text" { + break; } - panic!("Something unforeseen happened") + let absatz = Absatz::parse( + c.next() + .expect("Expected absatz after title in par headers"), + ); + + let value = absatz.content; + + // We want ot use this information in our markdown output. + // TODO: Use all metadata, instead of this specific call + if key == "Beachte" { + builder.add_next_para_note(value.clone()); + } + + self.metadata.insert(key, value); + continue; } - true } // At the beginning of each 'Abschnitt' there are 4 static fields. Since they don't provide any diff --git a/src/paragraph/parser/mod.rs b/src/paragraph/parser/mod.rs index 01b27de..6e76d89 100644 --- a/src/paragraph/parser/mod.rs +++ b/src/paragraph/parser/mod.rs @@ -406,9 +406,6 @@ impl Ueberschrift { fn test(n: &Node, typ: &str) -> bool { n.tag_name().name() == "ueberschrift" && n.attribute("typ").unwrap() == typ } - fn test_with_typ_and_content(n: &Node, typ: &str, content: &str) -> bool { - Self::test(n, typ) && n.text().unwrap() == content - } pub(crate) fn parse(n: Node, typ: &str) -> Self { assert!(n.tag_name().name() == "ueberschrift");