add vereinsgesetz; add optional 'beachte' text for paragraphs
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
2024-02-15 13:12:00 +01:00
parent a32b3a66c7
commit eb8af55554
7 changed files with 92 additions and 4 deletions

View File

@ -128,6 +128,8 @@ pub struct LawBuilder {
/// Stores the header of the next paragraph
next_para_header: Option<String>,
next_para_note: Option<String>,
#[cfg(test)]
pub history: Vec<String>,
}
@ -154,6 +156,7 @@ impl LawBuilder {
header: Vec::new(),
next_para_header: None,
last_instance: None,
next_para_note: None,
#[cfg(test)]
history: Vec::new(),
}
@ -261,6 +264,9 @@ impl LawBuilder {
let par_header = self.next_para_header.clone();
self.next_para_header = None;
let par_note = self.next_para_note.clone();
self.next_para_note = None;
self.last_instance
.clone()
.expect("Expect at least one classifier")
@ -268,6 +274,7 @@ impl LawBuilder {
.add_section(Section {
symb: par,
par_header,
par_note,
content,
});
}
@ -284,12 +291,20 @@ impl LawBuilder {
debug!("new_next_para_header={header}");
self.next_para_header = Some(header.trim().into());
}
pub fn add_next_para_note(&mut self, content: String) {
#[cfg(test)]
self.history.push(format!("New_para_note: {content}"));
self.next_para_note = Some(content);
}
}
#[derive(Clone, PartialEq, Serialize, Deserialize)]
pub struct Section {
pub symb: String, // §"1", §"2", ...
pub par_header: Option<String>,
pub par_note: Option<String>,
pub content: Content,
}
@ -302,11 +317,16 @@ impl fmt::Debug for Section {
impl fmt::Display for Section {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(header) = &self.par_header {
f.write_str(&format!("{} ({})\n{}", self.symb, header, self.content))
let mut to_write = if let Some(header) = &self.par_header {
format!("{} ({})\n{}", self.symb, header, self.content)
} else {
f.write_str(&format!("{}\n{}", self.symb, self.content))
format!("{}\n{}", self.symb, self.content)
};
if let Some(note) = &self.par_note {
to_write.push_str(&format!("\nBeachte: {}", note));
}
f.write_str(&to_write)
}
}

View File

@ -76,7 +76,24 @@ impl Abschnitt {
Fzinhalt::parse(c.next().unwrap());
// Skip all UeberschriftTitle and Absatz
while let Some(child) = c.peek() {
while let Some(child) = &c.peek() {
if Ueberschrift::test_with_typ_and_content(child, "titel", "Beachte") {
c.next();
//<absatz typ="erltext" ct="beachte" halign="j">Zu Abs. 2: zum Bezugszeitraum vgl. § 33 Abs. 13</absatz>
let absatz = Absatz::parse(
c.next()
.expect("After a 'Beachte' title, we need an Absatz"),
);
println!("{}", absatz.typ);
if absatz.typ != "erltext".to_string() {
panic!("Expected erltext absatz after 'Beachte'");
}
builder.add_next_para_note(absatz.content);
continue;
}
if Ueberschrift::test(child, "titel") {
c.next();
continue;
@ -508,6 +525,7 @@ impl Leaf {
#[derive(Debug, PartialEq)]
pub(crate) struct Absatz {
content: String,
typ: String,
}
impl Absatz {
pub(crate) fn test(n: &Node) -> bool {
@ -523,10 +541,12 @@ impl Absatz {
if let Some(text) = n.text() {
Self {
content: text.into(),
typ: n.attribute("typ").unwrap().into(),
}
} else {
Self {
content: String::new(),
typ: n.attribute("typ").unwrap().into(),
}
}
}
@ -541,6 +561,9 @@ 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");