Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
refactor: problem found. all tests now pass
hippietrailea0da02c3a10
diff --git a/harper-core/affixes.json b/harper-core/affixes.jsonindex 66fb6a7e3..f0daaf115 100644--- a/harper-core/affixes.json+++ b/harper-core/affixes.json@@ -2,7 +2,7 @@"affixes": {"K": {"#": "'pro-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -16,7 +16,7 @@},"L": {"#": "'-ment' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -30,7 +30,7 @@},"E": {"#": "'dis-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -44,7 +44,7 @@},"Y": {"#": "'-ly' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -58,7 +58,7 @@},"U": {"#": "'un-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -72,7 +72,7 @@},"H": {"#": "'-ieth' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": false,"replacements": [{@@ -91,7 +91,7 @@},"T": {"#": "'-(i)est' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": false,"replacements": [{@@ -120,7 +120,7 @@},"R": {"#": "'-(i)er' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -151,7 +151,7 @@},"C": {"#": "'de-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -165,7 +165,7 @@},"V": {"#": "'-ive' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": false,"replacements": [{@@ -184,7 +184,7 @@},"N": {"#": "nominalization suffixes: -ion, -ication, -en",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -208,7 +208,7 @@},"A": {"#": "'re-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -222,7 +222,7 @@},"Z": {"#": "'-(i)(e)rs' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -251,7 +251,7 @@},"P": {"#": "'-(i)ness' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -275,7 +275,7 @@},"M": {"#": "-'s possessive suffix; contraction of 'has' and 'is",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -295,7 +295,7 @@},"F": {"#": "'con-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -309,7 +309,7 @@},"B": {"#": "'-able' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -333,7 +333,7 @@},"S": {"#": "'-(i)(e)s' plural suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -366,7 +366,7 @@},"D": {"#": "'-(e)d' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -399,7 +399,7 @@},"G": {"#": "'-ing' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -422,7 +422,7 @@},"Q": {"#": "'-ally' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -436,7 +436,7 @@},"O": {"#": "'-ful' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -450,7 +450,7 @@},"I": {"#": "'in-' prefix",- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -464,7 +464,7 @@},"X": {"#": "'-ions', '-ications', '-ens' suffixes",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -488,7 +488,7 @@},"J": {"#": "'-ings' suffix",- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -507,7 +507,7 @@},"1": {"#": "singular noun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -519,7 +519,7 @@},"2": {"#": "proper noun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -531,7 +531,7 @@},"3": {"#": "linking verb property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -543,7 +543,7 @@},"4": {"#": "verb property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -553,7 +553,7 @@},"5": {"#": "adjective property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -563,7 +563,7 @@},"6": {"#": "swear word property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {@@ -575,7 +575,7 @@},"7": {"#": "conjunction property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -585,7 +585,7 @@},"8": {"#": "pronoun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -595,7 +595,7 @@},"9": {"#": "plural noun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -607,7 +607,7 @@},"~": {"#": "common word property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -617,7 +617,7 @@},"+": {"#": "preposition property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -627,7 +627,7 @@},"-": {"#": "determiner property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -637,7 +637,7 @@},"j": {"#": "adverb property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -647,7 +647,7 @@},"s": {"#": "subject case property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -657,7 +657,7 @@},"o": {"#": "object case property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -667,7 +667,7 @@},"f": {"#": "first-person property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -679,7 +679,7 @@},"n": {"#": "second-person property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -689,7 +689,7 @@},"t": {"#": "third-person property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -699,7 +699,7 @@},"c": {"#": "comparative property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -709,7 +709,7 @@},"u": {"#": "superlative property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -719,7 +719,7 @@},"*": {"#": "singular third-person pronoun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -732,7 +732,7 @@},":": {"#": "plural pronoun property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -744,7 +744,7 @@},"m": {"#": "auxiliary verb property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -756,7 +756,7 @@},"<": {"#": "American property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -766,7 +766,7 @@},"!": {"#": "GB property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},@@ -776,7 +776,7 @@},"@": {"#": "CA property",- "entry_kind": "property",+ "kind": "property","cross_product": true,"replacements": [],"target_metadata": {},diff --git a/harper-core/src/spell/rune/attribute_list.rs b/harper-core/src/spell/rune/attribute_list.rsindex b54ce2643..4e5686408 100644--- a/harper-core/src/spell/rune/attribute_list.rs+++ b/harper-core/src/spell/rune/attribute_list.rs@@ -5,7 +5,11 @@ use smallvec::ToSmallVec;use super::super::word_map::{WordMap, WordMapEntry};use super::Error;use super::affix_replacement::AffixReplacement;-use super::expansion::{AffixEntryKind, Expansion, HumanReadableExpansion};+use super::expansion::{+ AffixEntryKind,+ AffixEntryKind::{Prefix, Suffix},+ Expansion, HumanReadableExpansion,+};use super::word_list::MarkedWord;use crate::{CharString, Span, WordId, WordMetadata};@@ -52,7 +56,7 @@ impl AttributeList {for replacement in &expansion.replacements {if let Some(replaced) =- Self::apply_replacement(replacement, &word.letters, expansion.entry_kind)+ Self::apply_replacement(replacement, &word.letters, expansion.kind){if let Some(val) = new_words.get_mut(&replaced) {val.append(&expansion.target_metadata);@@ -69,7 +73,8 @@ impl AttributeList {let Some(attr_def) = self.affixes.get(attr) else {continue;};- if attr_def.entry_kind != expansion.entry_kind {+ // This looks wrong but matches the old logic: if attr_def.suffix != expansion.suffix+ if (attr_def.kind != Prefix) != (expansion.kind != Prefix) {opp_attr.push(*attr);}}@@ -131,13 +136,13 @@ impl AttributeList {fn apply_replacement(replacement: &AffixReplacement,letters: &[char],- entry_kind: AffixEntryKind,+ kind: AffixEntryKind,) -> Option<CharString> {if replacement.condition.len() > letters.len() {return None;}- let target_span = if entry_kind == AffixEntryKind::Suffix {+ let target_span = if kind == Suffix {Span::new(letters.len() - replacement.condition.len(), letters.len())} else {Span::new(0, replacement.condition.len())@@ -149,7 +154,7 @@ impl AttributeList {let mut replaced_segment = letters.to_smallvec();let mut remove: CharString = replacement.remove.to_smallvec();- if entry_kind != AffixEntryKind::Suffix {+ if kind != Suffix {replaced_segment.reverse();} else {remove.reverse();@@ -167,13 +172,13 @@ impl AttributeList {let mut to_add = replacement.add.to_vec();- if entry_kind != AffixEntryKind::Suffix {+ if kind != Suffix {to_add.reverse()}replaced_segment.extend(to_add);- if entry_kind != AffixEntryKind::Suffix {+ if kind != Suffix {replaced_segment.reverse();}diff --git a/harper-core/src/spell/rune/expansion.rs b/harper-core/src/spell/rune/expansion.rsindex a7b9560f3..987900988 100644--- a/harper-core/src/spell/rune/expansion.rs+++ b/harper-core/src/spell/rune/expansion.rs@@ -16,7 +16,7 @@ pub enum AffixEntryKind {pub struct Expansion {/// If `!true`, this is a prefix/// But if `true` it may be a prefix but may be a property only- pub entry_kind: AffixEntryKind,+ pub kind: AffixEntryKind,pub cross_product: bool,pub replacements: Vec<AffixReplacement>,/// When the expansion is applied, the resulting word will have this@@ -30,7 +30,7 @@ pub struct Expansion {impl Expansion {pub fn into_human_readable(self) -> HumanReadableExpansion {HumanReadableExpansion {- entry_kind: self.entry_kind,+ kind: self.kind,cross_product: self.cross_product,replacements: self.replacements@@ -45,7 +45,7 @@ impl Expansion {#[derive(Debug, Clone, Serialize, Deserialize)]pub struct HumanReadableExpansion {- pub entry_kind: AffixEntryKind,+ pub kind: AffixEntryKind,pub cross_product: bool,pub replacements: Vec<HumanReadableAffixReplacement>,pub target_metadata: WordMetadata,@@ -61,7 +61,7 @@ impl HumanReadableExpansion {}Ok(Expansion {- entry_kind: self.entry_kind,+ kind: self.kind,cross_product: self.cross_product,replacements,target_metadata: self.target_metadata,diff --git a/harper-core/src/spell/rune/mod.rs b/harper-core/src/spell/rune/mod.rsindex 02f58751f..347e763bf 100644--- a/harper-core/src/spell/rune/mod.rs+++ b/harper-core/src/spell/rune/mod.rs@@ -34,7 +34,7 @@ mod tests {json!({"affixes": {"A": {- "entry_kind": "prefix",+ "kind": "prefix","cross_product": true,"replacements": [{@@ -50,7 +50,7 @@ mod tests {"base_metadata": {}},"B": {- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -151,7 +151,7 @@ mod tests {&json!({"affixes": {"S": {- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{@@ -180,7 +180,7 @@ mod tests {}},"M": {- "entry_kind": "suffix",+ "kind": "suffix","cross_product": true,"replacements": [{diff --git a/packages/web/src/routes/docs/contributors/dictionary/+page.md b/packages/web/src/routes/docs/contributors/dictionary/+page.mdindex f32386bd9..7fd87f092 100644--- a/packages/web/src/routes/docs/contributors/dictionary/+page.md+++ b/packages/web/src/routes/docs/contributors/dictionary/+page.md@@ -19,7 +19,7 @@ In `affixes.json`, this expansion rule looks like this:{"L": {// Denotes that the area of interest is at the _end_ of the base word.- "entry_kind": "suffix",+ "kind": "suffix",// Declare that it is OK to use the result of the expansion with other expansions."cross_product": true,// The actual replacement rules that result in an expansion.