push
Some checks failed
CI/CD Pipeline / test (push) Failing after 1m49s

This commit is contained in:
philipp 2024-02-27 07:17:50 +01:00
parent b6002526c1
commit c87f037b1e
2 changed files with 4 additions and 95 deletions

View File

@ -100,7 +100,7 @@ impl Abschnitt {
// data. // data.
fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut LawBuilder) { fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut LawBuilder) {
while c.peek().is_some() { while c.peek().is_some() {
let key = Ueberschrift::parse(c, "titel").0.content; //TODO: fix .0. let key = Ueberschrift::parse(c.next().unwrap(), "titel").content;
// We are done with meta-data parsing // We are done with meta-data parsing
if key == "Text" { if key == "Text" {
@ -187,8 +187,8 @@ impl Abschnitt {
// while (not if) because we can have two subsequent paraheaders (e.g. § 405 abgb) // while (not if) because we can have two subsequent paraheaders (e.g. § 405 abgb)
while let Some(child) = c.peek() { while let Some(child) = c.peek() {
if Ueberschrift::test(child, "para") { if Ueberschrift::test(child, "para") {
builder.new_next_para_header(&Ueberschrift::parse(c, "para").0.content); // TODO: builder
// fix .0. .new_next_para_header(&Ueberschrift::parse(c.next().unwrap(), "para").content);
continue; continue;
} }
break; break;

View File

@ -360,103 +360,12 @@ impl Ueberschrift {
assert_eq!(n.attribute("typ").unwrap(), typ); assert_eq!(n.attribute("typ").unwrap(), typ);
let mut ret = Self { Self {
content: n.text().unwrap().into(), content: n.text().unwrap().into(),
typ: typ.into(), typ: typ.into(),
};
let mut next_para_header = None;
if ret.content != "Text" {
if let Some(child) = c.peek() {
if Ueberschrift::test(child, "art") {
let (next_para, sub) = Ueberschrift::parse(c, "art");
if sub.is_some() {
panic!("That should not happen");
}
next_para_header = Some(next_para);
} else if typ == "g1" && ret.content.starts_with("Artikel ") {
// wrongly tagged
// artikel
// TODO: remove code duplication from further down
let mut clone = c.clone();
if let Some(first_child) = clone.next() {
if let Some(second_child) = clone.next() {
if Ueberschrift::test(&first_child, "para")
&& Ueberschrift::test(&second_child, "para")
{
let (first_para, empty) = Ueberschrift::parse(c, "para");
if empty.is_some() {
panic!("That should not happen");
}
let (second_para, empty) = Ueberschrift::parse(c, "para");
if empty.is_some() {
panic!("That should not happen");
}
next_para_header = Some(Ueberschrift {
typ: first_para.typ,
content: format!(
"{} - {}",
first_para.content, second_para.content
),
});
}
}
}
} else if typ == "art" && !ret.content.starts_with("Artikel") {
ret.content = format!("Artikel {}", ret.content);
}
}
} }
debug!("Parsed Ueberschrift {ret:#?}");
(ret, next_para_header)
} }
fn parse_art(n: &mut Peekable<Children>) -> (Self, Option<Self>) {
let (mut art, empty) = Self::parse(n, "art");
if empty.is_some() {
panic!("That should not happen");
}
let mut next_para_header = None;
let mut clone = n.clone();
if let Some(first_child) = clone.next() {
if let Some(second_child) = clone.next() {
if Ueberschrift::test(&first_child, "para")
&& Ueberschrift::test(&second_child, "para")
{
let (first_para, empty) = Ueberschrift::parse(n, "para");
if empty.is_some() {
panic!("That should not happen");
}
let (second_para, empty) = Ueberschrift::parse(n, "para");
if empty.is_some() {
panic!("That should not happen");
}
next_para_header = Some(Ueberschrift {
typ: first_para.typ,
content: format!("{} - {}", first_para.content, second_para.content),
});
} else if Ueberschrift::test(&first_child, "para") {
let (first_para, empty) = Ueberschrift::parse(n, "para");
if empty.is_some() {
panic!("That should not happen");
}
next_para_header = Some(Ueberschrift {
typ: first_para.typ,
content: format!("{}", first_para.content),
});
}
}
}
(art, next_para_header)
}
pub(crate) fn parse_full(c: &mut Peekable<Children>, typ: &str) -> (Self, Option<Self>) { pub(crate) fn parse_full(c: &mut Peekable<Children>, typ: &str) -> (Self, Option<Self>) {
let n = c.next().unwrap(); let n = c.next().unwrap();
Expect::from(&n).tag("ueberschrift"); Expect::from(&n).tag("ueberschrift");