Merge branch 'large' of ssh://git.hofer.link:2222/philipp/risp into large
Some checks failed
CI/CD Pipeline / test (push) Failing after 1m38s
Some checks failed
CI/CD Pipeline / test (push) Failing after 1m38s
This commit is contained in:
commit
eff5c546c8
@ -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.next().unwrap(), "titel").content;
|
let key = Ueberschrift::parse(c, "titel").0.content; //TODO: fix .0.
|
||||||
|
|
||||||
// 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
|
builder.new_next_para_header(&Ueberschrift::parse(c, "para").0.content); // TODO:
|
||||||
.new_next_para_header(&Ueberschrift::parse(c.next().unwrap(), "para").content);
|
// fix .0.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -360,10 +360,102 @@ impl Ueberschrift {
|
|||||||
|
|
||||||
assert_eq!(n.attribute("typ").unwrap(), typ);
|
assert_eq!(n.attribute("typ").unwrap(), typ);
|
||||||
|
|
||||||
Self {
|
let mut ret = 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();
|
||||||
|
Loading…
Reference in New Issue
Block a user