2024-04-26 22:14:01 -04:00
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
|
|
#![warn(clippy::print_stderr)]
|
|
|
|
#![warn(clippy::print_stdout)]
|
|
|
|
|
2020-05-27 21:51:04 -04:00
|
|
|
pub mod borrowed;
|
|
|
|
|
|
|
|
#[cfg(feature = "parser")]
|
2020-04-07 20:50:06 -04:00
|
|
|
mod parser;
|
|
|
|
|
2020-05-27 21:51:04 -04:00
|
|
|
#[cfg(feature = "parser")]
|
|
|
|
pub use crate::parser::ClusterIter;
|
2020-04-07 20:50:06 -04:00
|
|
|
|
2020-05-27 21:47:49 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub struct Cluster {
|
|
|
|
pub header: Option<String>,
|
|
|
|
pub entries: Vec<Entry>,
|
|
|
|
pub notes: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Cluster {
|
|
|
|
pub fn infer(&mut self) {
|
|
|
|
for entry in self.entries.iter_mut() {
|
|
|
|
entry.infer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:47:49 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub struct Entry {
|
|
|
|
pub variants: Vec<Variant>,
|
|
|
|
pub pos: Option<Pos>,
|
|
|
|
pub archaic: bool,
|
|
|
|
pub description: Option<String>,
|
2024-08-23 11:46:32 -04:00
|
|
|
pub note: bool,
|
2020-04-07 20:50:06 -04:00
|
|
|
pub comment: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Entry {
|
|
|
|
pub fn infer(&mut self) {
|
|
|
|
imply(
|
|
|
|
&mut self.variants,
|
|
|
|
Category::BritishIse,
|
|
|
|
Category::BritishIze,
|
|
|
|
);
|
|
|
|
imply(&mut self.variants, Category::BritishIze, Category::Canadian);
|
|
|
|
imply(
|
|
|
|
&mut self.variants,
|
|
|
|
Category::BritishIse,
|
|
|
|
Category::Australian,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:09:17 -04:00
|
|
|
fn imply(variants: &mut [Variant], required: Category, missing: Category) {
|
2020-04-07 20:50:06 -04:00
|
|
|
let missing_exists = variants
|
|
|
|
.iter()
|
|
|
|
.any(|v| v.types.iter().any(|t| t.category == missing));
|
|
|
|
if missing_exists {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for variant in variants.iter_mut() {
|
|
|
|
let types: Vec<_> = variant
|
|
|
|
.types
|
|
|
|
.iter()
|
|
|
|
.filter(|t| t.category == required)
|
|
|
|
.cloned()
|
|
|
|
.map(|mut t| {
|
|
|
|
t.category = missing;
|
|
|
|
t
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
variant.types.extend(types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:47:49 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub struct Variant {
|
|
|
|
pub types: Vec<Type>,
|
|
|
|
pub word: String,
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:51:04 -04:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub struct Type {
|
|
|
|
pub category: Category,
|
|
|
|
pub tag: Option<Tag>,
|
|
|
|
pub num: Option<usize>,
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:20:15 -04:00
|
|
|
#[cfg_attr(feature = "flags", enumflags2::bitflags)]
|
2020-04-07 20:50:06 -04:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
2020-05-27 21:51:04 -04:00
|
|
|
#[repr(u8)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub enum Category {
|
2020-05-27 21:51:04 -04:00
|
|
|
American = 0x01,
|
|
|
|
BritishIse = 0x02,
|
|
|
|
BritishIze = 0x04,
|
|
|
|
Canadian = 0x08,
|
|
|
|
Australian = 0x10,
|
|
|
|
Other = 0x20,
|
2020-04-07 20:50:06 -04:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:51:04 -04:00
|
|
|
#[cfg(feature = "flags")]
|
|
|
|
pub type CategorySet = enumflags2::BitFlags<Category>;
|
|
|
|
|
2021-05-13 11:20:15 -04:00
|
|
|
#[cfg_attr(feature = "flags", enumflags2::bitflags)]
|
2020-05-27 21:51:04 -04:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
#[repr(u8)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub enum Tag {
|
2020-05-27 21:51:04 -04:00
|
|
|
Eq = 0x01,
|
|
|
|
Variant = 0x02,
|
|
|
|
Seldom = 0x04,
|
|
|
|
Possible = 0x08,
|
|
|
|
Improper = 0x10,
|
2020-04-07 20:50:06 -04:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:51:04 -04:00
|
|
|
#[cfg(feature = "flags")]
|
|
|
|
pub type TagSet = enumflags2::BitFlags<Tag>;
|
|
|
|
|
2021-05-13 11:20:15 -04:00
|
|
|
#[cfg_attr(feature = "flags", enumflags2::bitflags)]
|
2020-04-07 20:50:06 -04:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
2020-05-27 21:51:04 -04:00
|
|
|
#[repr(u8)]
|
2020-04-07 20:50:06 -04:00
|
|
|
pub enum Pos {
|
2020-05-27 21:51:04 -04:00
|
|
|
Noun = 0x01,
|
|
|
|
Verb = 0x02,
|
|
|
|
Adjective = 0x04,
|
|
|
|
Adverb = 0x08,
|
2024-08-23 12:30:42 -04:00
|
|
|
Interjection = 0x10,
|
2024-08-23 12:33:22 -04:00
|
|
|
Preposition = 0x20,
|
2020-04-07 20:50:06 -04:00
|
|
|
}
|
2020-05-27 21:51:04 -04:00
|
|
|
|
|
|
|
#[cfg(feature = "flags")]
|
|
|
|
pub type PosSet = enumflags2::BitFlags<Pos>;
|