Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(varcon)!: Parse verified/level #1085

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading