refactor(varcon): Consolidate description start with description

This commit is contained in:
Ed Page 2024-08-23 10:34:22 -05:00
parent c1644d8876
commit ffcca9ff99

View file

@ -964,24 +964,12 @@ impl Entry {
let variants = let variants =
winnow::combinator::separated(1.., Variant::parse_, var_sep).parse_next(input)?; winnow::combinator::separated(1.., Variant::parse_, var_sep).parse_next(input)?;
let desc_sep = (winnow::ascii::space0, '|'); let mut e = Self::parse_description.parse_next(input)?;
let description = opt((desc_sep, Self::parse_description)).parse_next(input)?;
let comment_sep = (winnow::ascii::space0, '#'); let comment_sep = (winnow::ascii::space0, '#');
let comment = let comment =
opt((comment_sep, space1, winnow::ascii::till_line_ending)).parse_next(input)?; opt((comment_sep, space1, winnow::ascii::till_line_ending)).parse_next(input)?;
let mut e = match description {
Some((_, description)) => description,
None => Self {
variants: Vec::new(),
pos: None,
archaic: false,
note: false,
description: None,
comment: None,
},
};
e.variants = variants; e.variants = variants;
e.comment = comment.map(|c| c.2.to_owned()); e.comment = comment.map(|c| c.2.to_owned());
Ok(e) Ok(e)
@ -1000,6 +988,10 @@ impl Entry {
comment: None, comment: None,
}; };
if opt((winnow::ascii::space0, '|'))
.parse_next(input)?
.is_some()
{
let _ = opt((space1, "<abbr>")).parse_next(input)?; let _ = opt((space1, "<abbr>")).parse_next(input)?;
let _ = opt((space1, "<pl>")).parse_next(input)?; let _ = opt((space1, "<pl>")).parse_next(input)?;
let pos = opt((space1, delimited('<', cut_err(Pos::parse_), cut_err('>')))) let pos = opt((space1, delimited('<', cut_err(Pos::parse_), cut_err('>'))))
@ -1012,6 +1004,7 @@ impl Entry {
entry.archaic = archaic.is_some(); entry.archaic = archaic.is_some();
entry.note = note.is_some(); entry.note = note.is_some();
entry.description = description.map(|(_, d)| d.to_owned()); entry.description = description.map(|(_, d)| d.to_owned());
}
Ok(entry) Ok(entry)
}) })
.parse_next(input) .parse_next(input)