mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-21 16:41:01 -05:00
refactor(varcon): Pull out core types
This commit is contained in:
parent
4ae8f91436
commit
f4400c2280
10 changed files with 122 additions and 98 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -1095,7 +1095,7 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
|||
name = "varcon"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"enumflags2",
|
||||
"varcon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1104,13 +1104,14 @@ version = "1.0.2"
|
|||
dependencies = [
|
||||
"codegenrs",
|
||||
"structopt",
|
||||
"varcon-parser",
|
||||
"varcon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "varcon-parser"
|
||||
name = "varcon-core"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"enumflags2",
|
||||
"nom",
|
||||
]
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ members = [
|
|||
"crates/codespell-dict", "crates/codespell-dict/codegen",
|
||||
"crates/misspell-dict", "crates/misspell-dict/codegen",
|
||||
"crates/wikipedia-dict", "crates/wikipedia-dict/codegen",
|
||||
"crates/varcon", "crates/varcon/codegen", "crates/varcon-parser",
|
||||
"crates/varcon", "crates/varcon/codegen", "crates/varcon-core",
|
||||
]
|
||||
|
||||
[package]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "varcon-parser"
|
||||
name = "varcon-core"
|
||||
version = "1.0.0"
|
||||
authors = ["Ed Page <eopage@gmail.com>"]
|
||||
description = "Parse varcon.txt file"
|
||||
description = "Varcon-relevant data structures"
|
||||
repository = "https://github.com/crate-ci/typos"
|
||||
readme = "../../../README.md"
|
||||
categories = ["text-processing"]
|
||||
|
@ -13,5 +13,14 @@ edition = "2018"
|
|||
azure-devops = { project = "crate-ci", pipeline = "typos" }
|
||||
codecov = { repository = "crate-ci/typos" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
parser = ["nom"]
|
||||
flags = ["enumflags2"]
|
||||
|
||||
[dependencies]
|
||||
nom = "5.1.1"
|
||||
nom = { version = "5.1.1", optional = true }
|
||||
enumflags2 = { version = "0.6", optional = true }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [ "parser", "flags" ]
|
54
crates/varcon-core/src/borrowed.rs
Normal file
54
crates/varcon-core/src/borrowed.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Cluster {
|
||||
pub header: Option<&'static str>,
|
||||
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()),
|
||||
entries: self.entries.iter().map(|s| s.into_owned()).collect(),
|
||||
notes: self.notes.iter().map(|s| (*s).to_owned()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Entry {
|
||||
pub variants: &'static [Variant],
|
||||
pub pos: Option<crate::Pos>,
|
||||
pub archaic: bool,
|
||||
pub note: bool,
|
||||
pub description: Option<&'static str>,
|
||||
pub comment: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
pub fn into_owned(self) -> crate::Entry {
|
||||
crate::Entry {
|
||||
variants: self.variants.iter().map(|v| v.into_owned()).collect(),
|
||||
pos: self.pos,
|
||||
archaic: self.archaic,
|
||||
note: self.note,
|
||||
description: self.description.map(|s| s.to_owned()),
|
||||
comment: self.comment.map(|s| s.to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Variant {
|
||||
pub types: &'static [crate::Type],
|
||||
pub word: &'static str,
|
||||
}
|
||||
|
||||
impl Variant {
|
||||
pub fn into_owned(self) -> crate::Variant {
|
||||
crate::Variant {
|
||||
types: self.types.iter().copied().collect(),
|
||||
word: self.word.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
pub mod borrowed;
|
||||
|
||||
#[cfg(feature = "parser")]
|
||||
mod parser;
|
||||
|
||||
pub use parser::ClusterIter;
|
||||
#[cfg(feature = "parser")]
|
||||
pub use crate::parser::ClusterIter;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Cluster {
|
||||
|
@ -72,7 +76,7 @@ pub struct Variant {
|
|||
pub word: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Type {
|
||||
pub category: Category,
|
||||
pub tag: Option<Tag>,
|
||||
|
@ -80,28 +84,43 @@ pub struct Type {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Category {
|
||||
American,
|
||||
BritishIse,
|
||||
BritishIze,
|
||||
Canadian,
|
||||
Australian,
|
||||
Other,
|
||||
American = 0x01,
|
||||
BritishIse = 0x02,
|
||||
BritishIze = 0x04,
|
||||
Canadian = 0x08,
|
||||
Australian = 0x10,
|
||||
Other = 0x20,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
#[cfg(feature = "flags")]
|
||||
pub type CategorySet = enumflags2::BitFlags<Category>;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Tag {
|
||||
Eq,
|
||||
Variant,
|
||||
Seldom,
|
||||
Possible,
|
||||
Improper,
|
||||
Eq = 0x01,
|
||||
Variant = 0x02,
|
||||
Seldom = 0x04,
|
||||
Possible = 0x08,
|
||||
Improper = 0x10,
|
||||
}
|
||||
|
||||
#[cfg(feature = "flags")]
|
||||
pub type TagSet = enumflags2::BitFlags<Tag>;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Pos {
|
||||
Noun,
|
||||
Verb,
|
||||
Adjective,
|
||||
Adverb,
|
||||
Noun = 0x01,
|
||||
Verb = 0x02,
|
||||
Adjective = 0x04,
|
||||
Adverb = 0x08,
|
||||
}
|
||||
|
||||
#[cfg(feature = "flags")]
|
||||
pub type PosSet = enumflags2::BitFlags<Pos>;
|
|
@ -17,7 +17,7 @@ codecov = { repository = "crate-ci/typos" }
|
|||
[features]
|
||||
default = ["all"]
|
||||
all = ["flags"]
|
||||
flags = ["enumflags2"]
|
||||
flags = ["varcon-core/flags"]
|
||||
|
||||
[dependencies]
|
||||
enumflags2 = { version = "0.6", optional = true }
|
||||
varcon-core = { version = "1.0", path = "../varcon-core" }
|
||||
|
|
|
@ -17,4 +17,4 @@ codecov = { repository = "crate-ci/typos" }
|
|||
[dependencies]
|
||||
codegenrs = "0.1"
|
||||
structopt = "0.3"
|
||||
varcon-parser = { version = "1.0", path = "../../varcon-parser" }
|
||||
varcon-core = { version = "1.0", path = "../../varcon-core", features = ["parser"] }
|
||||
|
|
|
@ -4,7 +4,7 @@ const DICT: &[u8] = include_bytes!("../../assets/varcon.txt");
|
|||
|
||||
fn generate<W: std::io::Write>(file: &mut W) {
|
||||
let dict = String::from_utf8_lossy(DICT);
|
||||
let clusters = varcon_parser::ClusterIter::new(&dict);
|
||||
let clusters = varcon_core::ClusterIter::new(&dict);
|
||||
|
||||
writeln!(
|
||||
file,
|
||||
|
|
|
@ -1,75 +1,16 @@
|
|||
mod codegen;
|
||||
|
||||
pub use codegen::*;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Cluster {
|
||||
pub header: Option<&'static str>,
|
||||
pub entries: &'static [Entry],
|
||||
pub notes: &'static [&'static str],
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Entry {
|
||||
pub variants: &'static [Variant],
|
||||
pub pos: Option<Pos>,
|
||||
pub archaic: bool,
|
||||
pub note: bool,
|
||||
pub description: Option<&'static str>,
|
||||
pub comment: Option<&'static str>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Variant {
|
||||
pub types: &'static [Type],
|
||||
pub word: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Type {
|
||||
pub category: Category,
|
||||
pub tag: Option<Tag>,
|
||||
pub num: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Category {
|
||||
American = 0x01,
|
||||
BritishIse = 0x02,
|
||||
BritishIze = 0x04,
|
||||
Canadian = 0x08,
|
||||
Australian = 0x10,
|
||||
Other = 0x20,
|
||||
}
|
||||
|
||||
pub use varcon_core::borrowed::Cluster;
|
||||
pub use varcon_core::borrowed::Entry;
|
||||
pub use varcon_core::borrowed::Variant;
|
||||
pub use varcon_core::Category;
|
||||
#[cfg(feature = "flags")]
|
||||
pub type CategorySet = enumflags2::BitFlags<Category>;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Tag {
|
||||
Eq = 0x01,
|
||||
Variant = 0x02,
|
||||
Seldom = 0x04,
|
||||
Possible = 0x08,
|
||||
Improper = 0x10,
|
||||
}
|
||||
|
||||
pub use varcon_core::CategorySet;
|
||||
pub use varcon_core::Pos;
|
||||
#[cfg(feature = "flags")]
|
||||
pub type TagSet = enumflags2::BitFlags<Tag>;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||
#[repr(u8)]
|
||||
pub enum Pos {
|
||||
Noun = 0x01,
|
||||
Verb = 0x02,
|
||||
Adjective = 0x04,
|
||||
Adverb = 0x08,
|
||||
}
|
||||
|
||||
pub use varcon_core::PosSet;
|
||||
pub use varcon_core::Tag;
|
||||
#[cfg(feature = "flags")]
|
||||
pub type PosSet = enumflags2::BitFlags<Pos>;
|
||||
pub use varcon_core::TagSet;
|
||||
pub use varcon_core::Type;
|
||||
|
|
Loading…
Reference in a new issue