From 0068450bf15f1b53f72e71ffda05e57ccba85dee Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 23 Aug 2024 09:58:24 -0500 Subject: [PATCH] refactor(varcon): Pull out entry parser --- crates/varcon-core/src/parser.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/varcon-core/src/parser.rs b/crates/varcon-core/src/parser.rs index d576bc0..2ca0814 100644 --- a/crates/varcon-core/src/parser.rs +++ b/crates/varcon-core/src/parser.rs @@ -1001,13 +1001,11 @@ impl Entry { )) .parse_next(input)?; let archaic = - winnow::combinator::opt((winnow::ascii::space1, "(-)")).parse_next(input)?; - let note = winnow::combinator::opt((winnow::ascii::space1, "--")).parse_next(input)?; - let description = winnow::combinator::opt(( - winnow::ascii::space1, - winnow::token::take_till(0.., ('\n', '\r', '#')), - )) - .parse_next(input)?; + winnow::combinator::opt((winnow::ascii::space1, archaic)).parse_next(input)?; + let note = + winnow::combinator::opt((winnow::ascii::space1, NOTE_PREFIX)).parse_next(input)?; + let description = + winnow::combinator::opt((winnow::ascii::space1, description)).parse_next(input)?; let variants = Vec::new(); let pos = pos.map(|(_, p)| p); @@ -1028,6 +1026,17 @@ impl Entry { } } +const NOTE_PREFIX: &str = "--"; + +fn archaic(input: &mut &str) -> PResult<(), ()> { + "(-)".void().parse_next(input) +} + +fn description(input: &mut &str) -> PResult { + let description = winnow::token::take_till(0.., ('\n', '\r', '#')).parse_next(input)?; + Ok(description.to_owned()) +} + #[cfg(test)] mod test_entry { #![allow(clippy::bool_assert_comparison)]