Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: added lexers for more punctuation, as well as many shorthand replacements.

Elijah Potter578a5656af2d
diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dict
index d00170173..81c842f2c 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -11313,6 +11313,7 @@ adversary/SM
adverse/PRYT
adverseness/M
adversity/SM
+adversive
advert/SMDG
advertise/LZGDRS
advertised/U
@@ -28801,7 +28802,7 @@ invalid/GMDYS
invalidism/M
invaluable
invaluably
-invariant
+invariant/S
invasion/MS
invasive
invective/M
@@ -49593,9 +49594,14 @@ backend
frontend
automata
Grammarly/M
+Raytheon/M
LanguageTool/M
WebAssembly/M
Neovim/M
quartile/S
autocomplete/MS
GPU/S
+codebase/S
+LIDAR
+LiDAR
+LADAR
diff --git a/harper-core/src/lexing/mod.rs b/harper-core/src/lexing/mod.rs
index 48337a3d7..4e743daf1 100644
--- a/harper-core/src/lexing/mod.rs
+++ b/harper-core/src/lexing/mod.rs
@@ -140,6 +140,10 @@ fn lex_punctuation(source: &[char]) -> Option<FoundToken> {
')' => CloseRound,
'#' => Hash,
'*' => Star,
+ '&' => Ampersand,
+ '–' => EnDash,
+ '—' => EmDash,
+ '…' => Ellipsis,
_ => return None,
};
diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rs
index 03b1b87bb..f734ffc77 100644
--- a/harper-core/src/linting/matcher.rs
+++ b/harper-core/src/linting/matcher.rs
@@ -32,12 +32,19 @@ macro_rules! vecword {
}
macro_rules! pt {
+
($str:literal) => {
PatternToken {
kind: TokenKind::Word,
content: Some($str.chars().collect()),
}
};
+ (Word) => {
+ PatternToken {
+ kind: TokenKind::Word,
+ content: None,
+ }
+ };
(Period) => {
PatternToken {
kind: TokenKind::Punctuation(Punctuation::Period),
@@ -92,7 +99,18 @@ pub struct Matcher {
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 = pt! {
+ "united nations" => "United Nations",
+ "mins" => "minutes",
+ "min" => "minute",
+ "secs" => "seconds",
+ "sec" => "second",
+ "hrs" => "hours",
+ "hr" => "hour",
+ "w/o" => "without",
+ "w/" => "with",
"wordlist" => "word list",
"the","challenged" => "that challenged",
"stdin" => "standard input",
@@ -111,6 +129,7 @@ impl Matcher {
"north","america" => "North America",
"fatal","outcome" => "death",
"geiger","counter" => "Geiger counter",
+ "Geiger","Counter" => "Geiger counter",
"veterans","day" => "Veterans Day",
"presidents","day" => "Presidents' Day",
"president's","day" => "Presidents' Day",
@@ -164,6 +183,25 @@ impl Matcher {
"Al","though" => "although"
};
+ // TODO: Improve the description for this lint specifically.
+ // We need to be more explicit that we are replacing with an Em dash
+ triggers.push(Rule {
+ pattern: vec![pt!(Hyphen), pt!(Hyphen), pt!(Hyphen)],
+ replace_with: vecword!("—"),
+ });
+
+ // Same goes for this En dash
+ triggers.push(Rule {
+ pattern: vec![pt!(Hyphen), pt!(Hyphen), pt!(Hyphen)],
+ replace_with: vecword!("–"),
+ });
+
+ // An this ellipsis
+ triggers.push(Rule {
+ pattern: vec![pt!(Period), pt!(Period), pt!(Period)],
+ replace_with: vecword!("…"),
+ });
+
triggers.push(Rule {
pattern: vec![pt!("break"), pt!(Hyphen), pt!("up")],
replace_with: vecword!("break-up"),
diff --git a/harper-core/src/linting/repeated_words.rs b/harper-core/src/linting/repeated_words.rs
index 4079b9211..f5e8b693f 100644
--- a/harper-core/src/linting/repeated_words.rs
+++ b/harper-core/src/linting/repeated_words.rs
@@ -38,7 +38,7 @@ impl RepeatedWords {
"people", "into", "year", "your", "good", "some", "could", "them", "see", "other",
"than", "then", "now", "look", "only", "come", "its", "over", "think", "also", "back",
"after", "use", "two", "how", "our", "work", "first", "well", "way", "even", "new",
- "want", "because", "any", "these", "give", "day", "most", "us"
+ "want", "because", "any", "these", "give", "day", "most", "us", "are"
);
Self { set }
diff --git a/harper-core/src/token.rs b/harper-core/src/token.rs
index eb98a2b7f..a25f35f14 100644
--- a/harper-core/src/token.rs
+++ b/harper-core/src/token.rs
@@ -71,6 +71,14 @@ impl TokenKind {
#[derive(Debug, Is, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
#[serde(tag = "kind")]
pub enum Punctuation {
+ /// `…`
+ Ellipsis,
+ /// `–`
+ EnDash,
+ /// `—`
+ EmDash,
+ /// `&`
+ Ampersand,
/// `.`
Period,
/// `!`