Skip to content

Commit

Permalink
Merge pull request #1085 from epage/header
Browse files Browse the repository at this point in the history
fix(varcon)!: Parse verified/level
  • Loading branch information
epage authored Aug 23, 2024
2 parents 19ed24a + 17b003e commit e872ab8
Show file tree
Hide file tree
Showing 5 changed files with 21,532 additions and 7,186 deletions.
8 changes: 6 additions & 2 deletions crates/varcon-core/src/borrowed.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Cluster {
pub header: Option<&'static str>,
pub header: &'static str,
pub verified: bool,
pub level: usize,
pub entries: &'static [Entry],
pub notes: &'static [&'static str],
}

impl Cluster {
pub fn into_owned(self) -> crate::Cluster {
crate::Cluster {
header: self.header.map(|s| s.to_owned()),
header: self.header.to_owned(),
verified: self.verified,
level: self.level,
entries: self.entries.iter().map(|s| s.into_owned()).collect(),
notes: self.notes.iter().map(|s| (*s).to_owned()).collect(),
}
Expand Down
4 changes: 3 additions & 1 deletion crates/varcon-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub use crate::parser::ClusterIter;

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct Cluster {
pub header: Option<String>,
pub header: String,
pub verified: bool,
pub level: usize,
pub entries: Vec<Entry>,
pub notes: Vec<String>,
}
Expand Down
44 changes: 26 additions & 18 deletions crates/varcon-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ A Cv: acknowledgment's / Av B C: acknowledgement's
str![[r#"
[
Cluster {
header: Some(
"acknowledgment <verified> (level 35)",
),
header: "acknowledgment ",
verified: true,
level: 35,
entries: [
Entry {
variants: [
Expand Down Expand Up @@ -231,9 +231,9 @@ A Cv: acknowledgment's / Av B C: acknowledgement's
str![[r#"
[
Cluster {
header: Some(
"acknowledgment <verified> (level 35)",
),
header: "acknowledgment ",
verified: true,
level: 35,
entries: [
Entry {
variants: [
Expand Down Expand Up @@ -383,9 +383,9 @@ A Cv: acknowledgment's / Av B C: acknowledgement's
notes: [],
},
Cluster {
header: Some(
"acknowledgment <verified> (level 35)",
),
header: "acknowledgment ",
verified: true,
level: 35,
entries: [
Entry {
variants: [
Expand Down Expand Up @@ -551,15 +551,19 @@ impl Cluster {
let header = (
"#",
winnow::ascii::space0,
winnow::ascii::till_line_ending,
winnow::token::take_till(1.., ('\r', '\n', '<', '(')),
winnow::ascii::space0,
opt(("<verified>", winnow::ascii::space0)),
delimited("(level ", winnow::ascii::digit1, ')').parse_to::<usize>(),
winnow::ascii::space0,
winnow::ascii::line_ending,
);
let note = preceded(
("##", winnow::ascii::space0),
terminated(winnow::ascii::till_line_ending, winnow::ascii::line_ending),
);
let mut cluster = (
opt(header),
header,
winnow::combinator::repeat(
1..,
terminated(Entry::parse_, winnow::ascii::line_ending),
Expand All @@ -568,10 +572,14 @@ impl Cluster {
);
let (header, entries, notes): (_, _, Vec<_>) = cluster.parse_next(input)?;

let header = header.map(|s| s.2.to_owned());
let verified = header.4.is_some();
let level = header.5;
let header = header.2.to_owned();
let notes = notes.into_iter().map(|s| s.to_owned()).collect();
let c = Self {
header,
verified,
level,
entries,
notes,
};
Expand Down Expand Up @@ -612,9 +620,9 @@ A Cv: acknowledgment's / Av B C: acknowledgement's
actual.to_debug(),
str![[r#"
Cluster {
header: Some(
"acknowledgment <verified> (level 35)",
),
header: "acknowledgment ",
verified: true,
level: 35,
entries: [
Entry {
variants: [
Expand Down Expand Up @@ -793,9 +801,9 @@ A B C: coloration's / B. Cv: colouration's
actual.to_debug(),
str![[r#"
Cluster {
header: Some(
"coloration <verified> (level 50)",
),
header: "coloration ",
verified: true,
level: 50,
entries: [
Entry {
variants: [
Expand Down
Loading

0 comments on commit e872ab8

Please sign in to comment.