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"
|
name = "varcon"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"enumflags2",
|
"varcon-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1104,13 +1104,14 @@ version = "1.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"codegenrs",
|
"codegenrs",
|
||||||
"structopt",
|
"structopt",
|
||||||
"varcon-parser",
|
"varcon-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "varcon-parser"
|
name = "varcon-core"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"enumflags2",
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ members = [
|
||||||
"crates/codespell-dict", "crates/codespell-dict/codegen",
|
"crates/codespell-dict", "crates/codespell-dict/codegen",
|
||||||
"crates/misspell-dict", "crates/misspell-dict/codegen",
|
"crates/misspell-dict", "crates/misspell-dict/codegen",
|
||||||
"crates/wikipedia-dict", "crates/wikipedia-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]
|
[package]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "varcon-parser"
|
name = "varcon-core"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
authors = ["Ed Page <eopage@gmail.com>"]
|
authors = ["Ed Page <eopage@gmail.com>"]
|
||||||
description = "Parse varcon.txt file"
|
description = "Varcon-relevant data structures"
|
||||||
repository = "https://github.com/crate-ci/typos"
|
repository = "https://github.com/crate-ci/typos"
|
||||||
readme = "../../../README.md"
|
readme = "../../../README.md"
|
||||||
categories = ["text-processing"]
|
categories = ["text-processing"]
|
||||||
|
@ -13,5 +13,14 @@ edition = "2018"
|
||||||
azure-devops = { project = "crate-ci", pipeline = "typos" }
|
azure-devops = { project = "crate-ci", pipeline = "typos" }
|
||||||
codecov = { repository = "crate-ci/typos" }
|
codecov = { repository = "crate-ci/typos" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
parser = ["nom"]
|
||||||
|
flags = ["enumflags2"]
|
||||||
|
|
||||||
[dependencies]
|
[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;
|
mod parser;
|
||||||
|
|
||||||
pub use parser::ClusterIter;
|
#[cfg(feature = "parser")]
|
||||||
|
pub use crate::parser::ClusterIter;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct Cluster {
|
pub struct Cluster {
|
||||||
|
@ -72,7 +76,7 @@ pub struct Variant {
|
||||||
pub word: String,
|
pub word: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct Type {
|
pub struct Type {
|
||||||
pub category: Category,
|
pub category: Category,
|
||||||
pub tag: Option<Tag>,
|
pub tag: Option<Tag>,
|
||||||
|
@ -80,28 +84,43 @@ pub struct Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
|
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum Category {
|
pub enum Category {
|
||||||
American,
|
American = 0x01,
|
||||||
BritishIse,
|
BritishIse = 0x02,
|
||||||
BritishIze,
|
BritishIze = 0x04,
|
||||||
Canadian,
|
Canadian = 0x08,
|
||||||
Australian,
|
Australian = 0x10,
|
||||||
Other,
|
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 {
|
pub enum Tag {
|
||||||
Eq,
|
Eq = 0x01,
|
||||||
Variant,
|
Variant = 0x02,
|
||||||
Seldom,
|
Seldom = 0x04,
|
||||||
Possible,
|
Possible = 0x08,
|
||||||
Improper,
|
Improper = 0x10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flags")]
|
||||||
|
pub type TagSet = enumflags2::BitFlags<Tag>;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
|
#[cfg_attr(feature = "flags", derive(enumflags2::BitFlags))]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum Pos {
|
pub enum Pos {
|
||||||
Noun,
|
Noun = 0x01,
|
||||||
Verb,
|
Verb = 0x02,
|
||||||
Adjective,
|
Adjective = 0x04,
|
||||||
Adverb,
|
Adverb = 0x08,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flags")]
|
||||||
|
pub type PosSet = enumflags2::BitFlags<Pos>;
|
|
@ -17,7 +17,7 @@ codecov = { repository = "crate-ci/typos" }
|
||||||
[features]
|
[features]
|
||||||
default = ["all"]
|
default = ["all"]
|
||||||
all = ["flags"]
|
all = ["flags"]
|
||||||
flags = ["enumflags2"]
|
flags = ["varcon-core/flags"]
|
||||||
|
|
||||||
[dependencies]
|
[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]
|
[dependencies]
|
||||||
codegenrs = "0.1"
|
codegenrs = "0.1"
|
||||||
structopt = "0.3"
|
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) {
|
fn generate<W: std::io::Write>(file: &mut W) {
|
||||||
let dict = String::from_utf8_lossy(DICT);
|
let dict = String::from_utf8_lossy(DICT);
|
||||||
let clusters = varcon_parser::ClusterIter::new(&dict);
|
let clusters = varcon_core::ClusterIter::new(&dict);
|
||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
file,
|
file,
|
||||||
|
|
|
@ -1,75 +1,16 @@
|
||||||
mod codegen;
|
mod codegen;
|
||||||
|
|
||||||
pub use codegen::*;
|
pub use codegen::*;
|
||||||
|
pub use varcon_core::borrowed::Cluster;
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
pub use varcon_core::borrowed::Entry;
|
||||||
pub struct Cluster {
|
pub use varcon_core::borrowed::Variant;
|
||||||
pub header: Option<&'static str>,
|
pub use varcon_core::Category;
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "flags")]
|
#[cfg(feature = "flags")]
|
||||||
pub type CategorySet = enumflags2::BitFlags<Category>;
|
pub use varcon_core::CategorySet;
|
||||||
|
pub use varcon_core::Pos;
|
||||||
#[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,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "flags")]
|
#[cfg(feature = "flags")]
|
||||||
pub type TagSet = enumflags2::BitFlags<Tag>;
|
pub use varcon_core::PosSet;
|
||||||
|
pub use varcon_core::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,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "flags")]
|
#[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