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,18 +988,23 @@ impl Entry {
comment: None, comment: None,
}; };
let _ = opt((space1, "<abbr>")).parse_next(input)?; if opt((winnow::ascii::space0, '|'))
let _ = opt((space1, "<pl>")).parse_next(input)?; .parse_next(input)?
let pos = opt((space1, delimited('<', cut_err(Pos::parse_), cut_err('>')))) .is_some()
.parse_next(input)?; {
let archaic = opt((space1, archaic)).parse_next(input)?; let _ = opt((space1, "<abbr>")).parse_next(input)?;
let note = opt((space1, NOTE_PREFIX)).parse_next(input)?; let _ = opt((space1, "<pl>")).parse_next(input)?;
let description = opt((space1, description)).parse_next(input)?; let pos = opt((space1, delimited('<', cut_err(Pos::parse_), cut_err('>'))))
.parse_next(input)?;
let archaic = opt((space1, archaic)).parse_next(input)?;
let note = opt((space1, NOTE_PREFIX)).parse_next(input)?;
let description = opt((space1, description)).parse_next(input)?;
entry.pos = pos.map(|(_, p)| p); entry.pos = pos.map(|(_, p)| p);
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)