Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
chore(core): remove `matcher.rs`
Elijah Potterf373ef6b4926
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 96c7cc52b..40072336b 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -37,7 +37,6 @@ use super::lets_confusion::LetsConfusion;use super::likewise::Likewise;use super::linking_verbs::LinkingVerbs;use super::long_sentences::LongSentences;-use super::matcher::Matcher;use super::merge_words::MergeWords;use super::modal_of::ModalOf;use super::multiple_sequential_pronouns::MultipleSequentialPronouns;@@ -320,7 +319,6 @@ impl LintGroup {insert_struct_rule!(LongSentences, true);insert_struct_rule!(RepeatedWords, true);insert_struct_rule!(Spaces, true);- insert_struct_rule!(Matcher, true);insert_struct_rule!(CorrectNumberSuffix, true);insert_struct_rule!(NumberSuffixCapitalization, true);insert_pattern_rule!(MultipleSequentialPronouns, true);diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rsdeleted file mode 100644index 95fa6d512..000000000--- a/harper-core/src/linting/matcher.rs+++ /dev/null@@ -1,241 +0,0 @@-use crate::linting::{Lint, LintKind, Linter, Suggestion};-use crate::{CharString, Document, Punctuation, Span, Token, TokenKind};--#[derive(Debug, PartialEq, PartialOrd, Clone)]-struct PatternToken {- /// The general variant of the token.- /// The inner data of the [`TokenKind`] should be replaced with the default- /// value.- kind: TokenKind,- content: Option<CharString>,-}--impl PatternToken {- fn from_token(token: Token, document: &Document) -> Self {- if token.kind.is_word() {- Self {- kind: token.kind.with_default_data(),- content: Some(document.get_span_content(&token.span).into()),- }- } else {- Self {- kind: token.kind,- content: None,- }- }- }-}--macro_rules! vecword {- ($lit:literal) => {- $lit.chars().collect()- };-}--macro_rules! pt {- ($str:literal) => {- PatternToken {- kind: TokenKind::Word(None),- content: Some($str.chars().collect()),- }- };- (Word) => {- PatternToken {- kind: TokenKind::Word,- content: None,- }- };- (Period) => {- PatternToken {- kind: TokenKind::Punctuation(Punctuation::Period),- content: None,- }- };- (Hyphen) => {- PatternToken {- kind: TokenKind::Punctuation(Punctuation::Hyphen),- content: None,- }- };- (Space) => {- PatternToken {- kind: TokenKind::Space(1),- content: None,- }- };- ( $($($str:literal),* => $repl:literal),*) => {- vec![- $(- {- let mut rule = Rule {- pattern: vec![$(- pt!($str),- pt!(Space),- )*],- replace_with: $repl.chars().collect()- };-- if rule.pattern.len() > 0{- rule.pattern.pop();- }-- rule- },- )*- ]- };-}--struct Rule {- pattern: Vec<PatternToken>,- replace_with: Vec<char>,-}--/// A linter that uses a variety of curated pattern matches to find and fix-/// common grammatical issues.-pub struct Matcher {- triggers: Vec<Rule>,-}--impl Matcher {- pub fn new() -> Self {- // This match list needs to be automatically expanded instead of explicitly- // defined like it is now.- let mut triggers = Vec::new();-- // expand abbreviations- triggers.extend(pt! {- "dep" => "dependency",- "deps" => "dependencies",- "min" => "minimum",- "stdin" => "standard input",- "stdout" => "standard output",- "w/" => "with",- "w/o" => "without"- });-- // expand compound words- triggers.extend(pt! {- "hashmap" => "hash map",- "hashtable" => "hash table",- "wordlist" => "word list"- });-- // not a perfect fit for any of the other categories- triggers.extend(pt! {- "performing","this" => "perform this",- "simply","grammatical" => "simple grammatical",- "the","challenged" => "that challenged"- });-- // countries and capitals with special casing or punctuation- triggers.extend(pt! {- // Note: When the case is already correct,- // Note: hyphenation is handled by phrase_corrections.rs- // Note: which cannot correct wrong case- "guinea","bissau" => "Guinea-Bissau",- "Guinea","bissau" => "Guinea-Bissau",- "port","au","prince" => "Port-au-Prince",- "Port","au","prince" => "Port-au-Prince",- "porto","novo" => "Porto-Novo",- "Porto","novo" => "Porto-Novo",- // Note: Period/full stop cannot be handled in- // Note: inputs as it's always treated as punctuation- // Note: But we can add periods and apostrophes- "st","georges" => "St. George's",- "st","george's" => "St. George's",- "St","georges" => "St. George's",- "St","george's" => "St. George's",- "St","Georges" => "St. George's",- "St","George's" => "St. George's"- });-- // multi-word countries and capitals with accents and diacritics- triggers.extend(pt! {- "san","jose" => "San José",- "San","jose" => "San José",- "sao","tome" => "São Tomé",- "Sao","Tome" => "São Tomé",- "sao","tome","and","principe" => "São Tomé and Príncipe",- "Sao","Tome","and","Principe" => "São Tomé and Príncipe",- "Sao","Tome","And","Principe" => "São Tomé and Príncipe"- });-- triggers.push(Rule {- pattern: vec![pt!("L"), pt!(Period), pt!("L"), pt!(Period), pt!("M")],- replace_with: vecword!("large language model"),- });-- triggers.push(Rule {- pattern: vec![- pt!("L"),- pt!(Period),- pt!("L"),- pt!(Period),- pt!("M"),- pt!(Period),- ],- replace_with: vecword!("large language model"),- });-- Self { triggers }- }-}--impl Default for Matcher {- fn default() -> Self {- Self::new()- }-}--impl Linter for Matcher {- fn lint(&mut self, document: &Document) -> Vec<Lint> {- let mut lints = Vec::new();-- let mut match_tokens = Vec::new();-- for (index, _) in document.tokens().enumerate() {- for trigger in &self.triggers {- match_tokens.clear();-- for (p_index, pattern) in trigger.pattern.iter().enumerate() {- let Some(token) = document.get_token(index + p_index) else {- break;- };-- let t_pattern = PatternToken::from_token(token.clone(), document);-- if t_pattern != *pattern {- break;- }-- match_tokens.push(token);- }-- if match_tokens.len() == trigger.pattern.len() && !match_tokens.is_empty() {- let span = Span::new(- match_tokens.first().unwrap().span.start,- match_tokens.last().unwrap().span.end,- );-- lints.push(Lint {- span,- lint_kind: LintKind::Miscellaneous,- suggestions: vec![Suggestion::ReplaceWith(trigger.replace_with.to_owned())],- message: format!(- "Did you mean “{}”?",- trigger.replace_with.iter().collect::<String>()- ),- priority: 15,- })- }- }- }-- lints- }-- fn description(&self) -> &'static str {- "A collection of curated rules. A catch-all that will be removed in the future."- }-}diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 46d8661e4..a434dbd94 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -35,7 +35,6 @@ mod lint_group;mod lint_kind;mod long_sentences;mod map_phrase_linter;-mod matcher;mod merge_linters;mod merge_words;mod modal_of;@@ -100,7 +99,6 @@ pub use lint_group::{LintGroup, LintGroupConfig};pub use lint_kind::LintKind;pub use long_sentences::LongSentences;pub use map_phrase_linter::MapPhraseLinter;-pub use matcher::Matcher;pub use merge_words::MergeWords;pub use modal_of::ModalOf;pub use multiple_sequential_pronouns::MultipleSequentialPronouns;diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rsindex 4380a589f..79782dfc3 100644--- a/harper-core/src/linting/phrase_corrections.rs+++ b/harper-core/src/linting/phrase_corrections.rs@@ -881,6 +881,48 @@ pub fn lint_group() -> LintGroup {"Use `the other` or `another`, not both.","Corrects `the another`."),+ "ExpandDependency" => (+ ["dep"],+ ["dependency"],+ "Use `dependency` instead of `dep`",+ "Expands the abbreviation `dep` to the full word `dependency` for clarity."+ ),+ "ExpandDependencies" => (+ ["deps"],+ ["dependencies"],+ "Use `dependencies` instead of `deps`",+ "Expands the abbreviation `deps` to the full word `dependencies` for clarity."+ ),+ "ExpandMinimum" => (+ ["min"],+ ["minimum"],+ "Use `minimum` instead of `min`",+ "Expands the abbreviation `min` to the full word `minimum` for clarity."+ ),+ "ExpandStandardInput" => (+ ["stdin"],+ ["standard input"],+ "Use `standard input` instead of `stdin`",+ "Expands the abbreviation `stdin` to `standard input` for clarity."+ ),+ "ExpandStandardOutput" => (+ ["stdout"],+ ["standard output"],+ "Use `standard output` instead of `stdout`",+ "Expands the abbreviation `stdout` to `standard output` for clarity."+ ),+ "ExpandWith" => (+ ["w/"],+ ["with"],+ "Use `with` instead of `w/`",+ "Expands the abbreviation `w/` to the full word `with` for clarity."+ ),+ "ExpandWithout" => (+ ["w/o"],+ ["without"],+ "Use `without` instead of `w/o`",+ "Expands the abbreviation `w/o` to the full word `without` for clarity."+ ),});group.set_all_rules_to(Some(true));@@ -928,7 +970,7 @@ mod tests {assert_suggestion_result("For now we got rid off circular deps in model tree structure and it's API.",lint_group(),- "For now we got rid of circular deps in model tree structure and it's API.",+ "For now we got rid of circular dependencies in model tree structure and it's API.",);}