Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: pronoun now its own token kind & word metadata
hippietrail4098c4ad54c1
diff --git a/harper-core/affixes.json b/harper-core/affixes.jsonindex c20bb5296..80ccd4aab 100644--- a/harper-core/affixes.json+++ b/harper-core/affixes.json@@ -589,9 +589,7 @@"replacements": [],"adds_metadata": {},"gifts_metadata": {- "nominal": {- "is_pronoun": true- }+ "pronoun": {}}},"9": {diff --git a/harper-core/src/lib.rs b/harper-core/src/lib.rsindex d357d804c..32d636102 100644--- a/harper-core/src/lib.rs+++ b/harper-core/src/lib.rs@@ -45,7 +45,9 @@ pub use token::Token;pub use token_kind::TokenKind;pub use token_string_ext::TokenStringExt;pub use vec_ext::VecExt;-pub use word_metadata::{AdverbData, ConjunctionData, NominalData, Tense, VerbData, WordMetadata};+pub use word_metadata::{+ AdverbData, ConjunctionData, NominalData, PronounData, Tense, VerbData, WordMetadata,+};/// A utility function that removes overlapping lints in a vector,/// keeping the more important ones.diff --git a/harper-core/src/linting/capitalize_personal_pronouns.rs b/harper-core/src/linting/capitalize_personal_pronouns.rsindex dd7251821..042fbcd8b 100644--- a/harper-core/src/linting/capitalize_personal_pronouns.rs+++ b/harper-core/src/linting/capitalize_personal_pronouns.rs@@ -1,4 +1,4 @@-use crate::{NominalData, TokenKind, TokenStringExt, WordMetadata};+use crate::{TokenKind, TokenStringExt, WordMetadata};use super::{Lint, LintKind, Linter, Suggestion};@@ -12,12 +12,7 @@ impl Linter for CapitalizePersonalPronouns {for tok in document.iter_words() {if let TokenKind::Word(Some(WordMetadata {- nominal:- Some(NominalData {- is_pronoun: Some(true),- ..- }),- ..+ pronoun: Some(_), ..})) = tok.kind{if document.get_span_content(tok.span) == ['i'] {diff --git a/harper-core/src/spell/mutable_dictionary.rs b/harper-core/src/spell/mutable_dictionary.rsindex f96ba607f..82919830f 100644--- a/harper-core/src/spell/mutable_dictionary.rs+++ b/harper-core/src/spell/mutable_dictionary.rs@@ -344,16 +344,8 @@ mod tests {#[test]fn herself_is_pronoun() {let dict = MutableDictionary::curated();- assert!(- dict.get_word_metadata_str("herself")- .unwrap()- .is_pronoun_nominal()- );- assert!(- dict.get_word_metadata_str("Herself")- .unwrap()- .is_pronoun_nominal()- );+ assert!(dict.get_word_metadata_str("herself").unwrap().is_pronoun());+ assert!(dict.get_word_metadata_str("Herself").unwrap().is_pronoun());}#[test]@@ -387,11 +379,6 @@ mod tests {let dict = MutableDictionary::curated();assert!(!dict.get_word_metadata_str("there").unwrap().is_nominal());- assert!(- !dict- .get_word_metadata_str("there")- .unwrap()- .is_pronoun_nominal()- );+ assert!(!dict.get_word_metadata_str("there").unwrap().is_pronoun());}}diff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rsindex 83bfdddfd..8002d94c6 100644--- a/harper-core/src/token_kind.rs+++ b/harper-core/src/token_kind.rs@@ -1,7 +1,7 @@use is_macro::Is;use serde::{Deserialize, Serialize};-use crate::{ConjunctionData, NominalData, Number, Punctuation, Quote, WordMetadata};+use crate::{ConjunctionData, NominalData, Number, PronounData, Punctuation, Quote, WordMetadata};#[derive(Debug, Is, Clone, Copy, Serialize, Deserialize, Default, PartialOrd, Hash, Eq, PartialEq,@@ -64,12 +64,12 @@ impl TokenKind {)}- pub fn is_pronoun(&self) -> bool {+ pub fn is_possessive_pronoun(&self) -> bool {matches!(self,TokenKind::Word(Some(WordMetadata {- nominal: Some(NominalData {- is_pronoun: Some(true),+ pronoun: Some(PronounData {+ is_possessive: Some(true),..}),..@@ -255,20 +255,20 @@ impl TokenKind {metadata.is_linking_verb()}- pub fn is_not_pronoun_nominal(&self) -> bool {+ pub fn is_not_plural_nominal(&self) -> bool {let TokenKind::Word(Some(metadata)) = self else {return true;};- metadata.is_not_pronoun_nominal()+ metadata.is_not_plural_nominal()}- pub fn is_not_plural_nominal(&self) -> bool {+ pub fn is_not_plural_pronoun(&self) -> bool {let TokenKind::Word(Some(metadata)) = self else {return true;};- metadata.is_not_plural_nominal()+ metadata.is_not_plural_pronoun()}pub fn is_common_word(&self) -> bool {@@ -287,6 +287,14 @@ impl TokenKind {metadata.is_plural_nominal()}+ pub fn is_plural_pronoun(&self) -> bool {+ let TokenKind::Word(Some(metadata)) = self else {+ return false;+ };++ metadata.is_plural_pronoun()+ }+pub fn is_nominal(&self) -> bool {let TokenKind::Word(Some(metadata)) = self else {return false;@@ -295,6 +303,14 @@ impl TokenKind {metadata.is_nominal()}+ pub fn is_pronoun(&self) -> bool {+ let TokenKind::Word(Some(metadata)) = self else {+ return false;+ };++ metadata.is_pronoun()+ }+pub fn is_likely_homograph(&self) -> bool {let TokenKind::Word(Some(metadata)) = self else {return false;diff --git a/harper-core/src/word_metadata.rs b/harper-core/src/word_metadata.rsindex f1330780c..02bde6a8d 100644--- a/harper-core/src/word_metadata.rs+++ b/harper-core/src/word_metadata.rs@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Hash)]pub struct WordMetadata {pub nominal: Option<NominalData>,+ pub pronoun: Option<PronounData>,pub verb: Option<VerbData>,pub adjective: Option<AdjectiveData>,pub adverb: Option<AdverbData>,@@ -90,6 +91,7 @@ impl WordMetadata {Self {nominal: merge!(self.nominal, other.nominal),+ pronoun: merge!(self.pronoun, other.pronoun),verb: merge!(self.verb, other.verb),adjective: merge!(self.adjective, other.adjective),adverb: merge!(self.adverb, other.adverb),@@ -102,7 +104,8 @@ impl WordMetadata {}generate_metadata_queries!(- nominal has proper, plural, possessive, pronoun.+ nominal has proper, plural, possessive.+ pronoun has plural, possessive.verb has linking.conjunction has.adjective has.@@ -149,7 +152,6 @@ pub struct NominalData {pub is_proper: Option<bool>,pub is_plural: Option<bool>,pub is_possessive: Option<bool>,- pub is_pronoun: Option<bool>,}impl NominalData {@@ -159,7 +161,22 @@ impl NominalData {is_proper: self.is_proper.or(other.is_proper),is_plural: self.is_plural.or(other.is_plural),is_possessive: self.is_possessive.or(other.is_possessive),- is_pronoun: self.is_pronoun.or(other.is_pronoun),+ }+ }+}++#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]+pub struct PronounData {+ pub is_plural: Option<bool>,+ pub is_possessive: Option<bool>,+}++impl PronounData {+ /// Produce a copy of `self` with the known properties of `other` set.+ pub fn or(&self, other: &Self) -> Self {+ Self {+ is_plural: self.is_plural.or(other.is_plural),+ is_possessive: self.is_possessive.or(other.is_possessive),}}}