Skip to content

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

refactor: most `ExprLinter`s don't need to be boxed (#2885)

Andrew Dunbar6932d5aa256a
diff --git a/harper-core/src/linting/a_part.rs b/harper-core/src/linting/a_part.rs
index 0e34638bf..e86f4c769 100644
--- a/harper-core/src/linting/a_part.rs
+++ b/harper-core/src/linting/a_part.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct APart {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for APart {
@@ -20,9 +20,7 @@ impl Default for APart {
Box::new(FixedPhrase::from_phrase("far a part")),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for APart {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/a_while.rs b/harper-core/src/linting/a_while.rs
index 3be6654e8..e2dedf495 100644
--- a/harper-core/src/linting/a_while.rs
+++ b/harper-core/src/linting/a_while.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use harper_brill::UPOS;
use crate::char_string::char_string;
@@ -11,8 +9,7 @@ use super::expr_linter::Chunk;
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct AWhile {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<(CharString, &'static str)>>,
+ expr: ExprMap<(CharString, &'static str)>,
}
impl Default for AWhile {
@@ -45,12 +42,7 @@ impl Default for AWhile {
),
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -58,11 +50,11 @@ impl ExprLinter for AWhile {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let &(ref suggestion, message) = self.map.lookup(0, matched_tokens, source)?;
+ let &(ref suggestion, message) = self.expr.lookup(0, matched_tokens, source)?;
let span = matched_tokens[2..].span()?;
let suggestion =
Suggestion::replace_with_match_case(suggestion.to_vec(), span.get_content(source));
diff --git a/harper-core/src/linting/addicting.rs b/harper-core/src/linting/addicting.rs
index 765ff79e7..9b2d0df9e 100644
--- a/harper-core/src/linting/addicting.rs
+++ b/harper-core/src/linting/addicting.rs
@@ -6,13 +6,13 @@ use crate::{
};
pub struct Addicting {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for Addicting {
fn default() -> Self {
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
// matches `addicting` without anything after
Box::new(SequenceExpr::aco("addicting").then(AnchorEnd)),
// matches `addicting` <ws> [ any word but not a reflexive pronoun or object pronoun ]
@@ -29,7 +29,7 @@ impl Default for Addicting {
]))),
])),
),
- ])),
+ ]),
}
}
}
@@ -38,7 +38,7 @@ impl ExprLinter for Addicting {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/adjective_double_degree.rs b/harper-core/src/linting/adjective_double_degree.rs
index a603141e2..aabcce5d4 100644
--- a/harper-core/src/linting/adjective_double_degree.rs
+++ b/harper-core/src/linting/adjective_double_degree.rs
@@ -6,19 +6,17 @@ use crate::{
};
pub struct AdjectiveDoubleDegree {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AdjectiveDoubleDegree {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["more", "most"])
- .t_ws()
- .then_kind_where(|kind| {
- kind.is_comparative_adjective() || kind.is_superlative_adjective()
- }),
- ),
+ expr: SequenceExpr::word_set(&["more", "most"])
+ .t_ws()
+ .then_kind_where(|kind| {
+ kind.is_comparative_adjective() || kind.is_superlative_adjective()
+ }),
}
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for AdjectiveDoubleDegree {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/after_later.rs b/harper-core/src/linting/after_later.rs
index f6a1ea267..7d0fe7058 100644
--- a/harper-core/src/linting/after_later.rs
+++ b/harper-core/src/linting/after_later.rs
@@ -5,38 +5,36 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::token_string_ext::TokenStringExt;
pub struct AfterLater {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AfterLater {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("after")
- .t_ws()
- .then_optional(
- SequenceExpr::word_set(&[
- "about",
- "almost",
- "approximately",
- "around",
- "circa",
- "exactly",
- "just",
- "maybe",
- "nearly",
- "only",
- "perhaps",
- "precisely",
- "probably",
- "roughly",
- ])
- .t_ws(),
- )
- .then(DurationExpr)
- .t_ws()
- .t_aco("later"),
- ),
+ expr: SequenceExpr::aco("after")
+ .t_ws()
+ .then_optional(
+ SequenceExpr::word_set(&[
+ "about",
+ "almost",
+ "approximately",
+ "around",
+ "circa",
+ "exactly",
+ "just",
+ "maybe",
+ "nearly",
+ "only",
+ "perhaps",
+ "precisely",
+ "probably",
+ "roughly",
+ ])
+ .t_ws(),
+ )
+ .then(DurationExpr)
+ .t_ws()
+ .t_aco("later"),
}
}
}
@@ -45,7 +43,7 @@ impl ExprLinter for AfterLater {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/all_hell_break_loose.rs b/harper-core/src/linting/all_hell_break_loose.rs
index 48ebf391b..9c75f79e8 100644
--- a/harper-core/src/linting/all_hell_break_loose.rs
+++ b/harper-core/src/linting/all_hell_break_loose.rs
@@ -5,21 +5,19 @@ use crate::{
};
pub struct AllHellBreakLoose {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AllHellBreakLoose {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("all")
- .t_ws()
- .t_aco("hell")
- .t_ws()
- .then_word_set(&["break", "breaking", "breaks", "broke", "broken"])
- .t_ws()
- .t_aco("out"),
- ),
+ expr: SequenceExpr::aco("all")
+ .t_ws()
+ .t_aco("hell")
+ .t_ws()
+ .then_word_set(&["break", "breaking", "breaks", "broke", "broken"])
+ .t_ws()
+ .t_aco("out"),
}
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for AllHellBreakLoose {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
}
diff --git a/harper-core/src/linting/all_intents_and_purposes.rs b/harper-core/src/linting/all_intents_and_purposes.rs
index 1db05a3c7..6d33853cf 100644
--- a/harper-core/src/linting/all_intents_and_purposes.rs
+++ b/harper-core/src/linting/all_intents_and_purposes.rs
@@ -6,37 +6,35 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::token_string_ext::TokenStringExt;
pub struct AllIntentsAndPurposes {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AllIntentsAndPurposes {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::default()
- .then_preposition() // Only "for" or "to" are OK
- .t_ws()
- .t_aco("all")
- .t_ws()
- .then_any_of(vec![
- Box::new(
- SequenceExpr::word_set(&[
- "intents", // Correct, as long as it follows "for" or "to"
- "extents", "intense", // Incorrect, no matter the preposition
- ])
- .t_ws()
- .t_aco("and"),
- ),
- Box::new(SequenceExpr::word_set(&[
- "intended",
- "intense",
- "intensive",
- "intrinsic",
- ])),
- ])
- .t_ws()
- .t_aco("purposes"),
- ),
+ expr: SequenceExpr::default()
+ .then_preposition() // Only "for" or "to" are OK
+ .t_ws()
+ .t_aco("all")
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(
+ SequenceExpr::word_set(&[
+ "intents", // Correct, as long as it follows "for" or "to"
+ "extents", "intense", // Incorrect, no matter the preposition
+ ])
+ .t_ws()
+ .t_aco("and"),
+ ),
+ Box::new(SequenceExpr::word_set(&[
+ "intended",
+ "intense",
+ "intensive",
+ "intrinsic",
+ ])),
+ ])
+ .t_ws()
+ .t_aco("purposes"),
}
}
}
@@ -45,7 +43,7 @@ impl ExprLinter for AllIntentsAndPurposes {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/allow_to.rs b/harper-core/src/linting/allow_to.rs
index 034c593c9..0eaed50d2 100644
--- a/harper-core/src/linting/allow_to.rs
+++ b/harper-core/src/linting/allow_to.rs
@@ -5,21 +5,19 @@ use crate::token::Token;
use crate::token_string_ext::TokenStringExt;
pub struct AllowTo {
- exp: Box<dyn Expr>,
+ exp: SequenceExpr,
}
impl Default for AllowTo {
fn default() -> Self {
Self {
// Note: Does not include "allowed to", which is a legitimate usage in its own right.
- exp: Box::new(
- SequenceExpr::word_set(&["allow", "allowing", "allows"])
- .t_ws()
- .t_aco("to")
- .then_optional(SequenceExpr::default().t_ws().then_adverb())
- .t_ws()
- .then_any_word(),
- ),
+ exp: SequenceExpr::word_set(&["allow", "allowing", "allows"])
+ .t_ws()
+ .t_aco("to")
+ .then_optional(SequenceExpr::default().t_ws().then_adverb())
+ .t_ws()
+ .then_any_word(),
}
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for AllowTo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.exp.as_ref()
+ &self.exp
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/am_in_the_morning.rs b/harper-core/src/linting/am_in_the_morning.rs
index 34f2a3b4c..1d76e5860 100644
--- a/harper-core/src/linting/am_in_the_morning.rs
+++ b/harper-core/src/linting/am_in_the_morning.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct AmInTheMorning {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AmInTheMorning {
@@ -36,9 +36,7 @@ impl Default for AmInTheMorning {
let expr = SequenceExpr::any_of(vec![Box::new(maybe_ws_am), Box::new(maybe_ws_pm)])
.then_any_of(vec![Box::new(ws_in_periods), Box::new(ws_at_periods)]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for AmInTheMorning {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/amounts_for.rs b/harper-core/src/linting/amounts_for.rs
index 7723111c5..c0c736cbf 100644
--- a/harper-core/src/linting/amounts_for.rs
+++ b/harper-core/src/linting/amounts_for.rs
@@ -7,7 +7,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct AmountsFor {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for AmountsFor {
@@ -27,10 +27,7 @@ impl Default for AmountsFor {
.then_fixed_phrase("amount for");
Self {
- expr: Box::new(FirstMatchOf::new(vec![
- Box::new(singular_pattern),
- Box::new(plural_pattern),
- ])),
+ expr: FirstMatchOf::new(vec![Box::new(singular_pattern), Box::new(plural_pattern)]),
}
}
}
@@ -39,7 +36,7 @@ impl ExprLinter for AmountsFor {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/and_in.rs b/harper-core/src/linting/and_in.rs
index 09f2ff2a8..cf578610a 100644
--- a/harper-core/src/linting/and_in.rs
+++ b/harper-core/src/linting/and_in.rs
@@ -4,13 +4,13 @@ use crate::linting::expr_linter::Chunk;
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
pub struct AndIn {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AndIn {
fn default() -> Self {
Self {
- expr: Box::new(SequenceExpr::fixed_phrase("an in").then_optional_hyphen()),
+ expr: SequenceExpr::fixed_phrase("an in").then_optional_hyphen(),
}
}
}
@@ -19,7 +19,7 @@ impl ExprLinter for AndIn {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- &*self.expr
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/and_the_like.rs b/harper-core/src/linting/and_the_like.rs
index d33525ec3..7f4457dd5 100644
--- a/harper-core/src/linting/and_the_like.rs
+++ b/harper-core/src/linting/and_the_like.rs
@@ -6,13 +6,13 @@ use crate::token_string_ext::TokenStringExt;
use crate::{Lint, Token};
pub struct AndTheLike {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for AndTheLike {
fn default() -> Self {
Self {
- expr: Box::new(All::new(vec![
+ expr: All::new(vec![
Box::new(
// All known variants seen in the wild, good and bad
SequenceExpr::word_set(&["and", "or", "an"])
@@ -30,7 +30,7 @@ impl Default for AndTheLike {
Box::new(WordSet::new(&["like", "likes"])),
]),
)),
- ])),
+ ]),
}
}
}
@@ -39,7 +39,7 @@ impl ExprLinter for AndTheLike {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/another_thing_coming.rs b/harper-core/src/linting/another_thing_coming.rs
index 13b4d3046..87026e265 100644
--- a/harper-core/src/linting/another_thing_coming.rs
+++ b/harper-core/src/linting/another_thing_coming.rs
@@ -7,16 +7,14 @@ use crate::{
/// Both `another thing coming` and `another think coming` are correct, but `another think coming` is more common.
pub struct AnotherThingComing {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AnotherThingComing {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["had", "has", "have", "got"])
- .then_fixed_phrase(" another think coming"),
- ),
+ expr: SequenceExpr::word_set(&["had", "has", "have", "got"])
+ .then_fixed_phrase(" another think coming"),
}
}
}
@@ -25,7 +23,7 @@ impl ExprLinter for AnotherThingComing {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/another_think_coming.rs b/harper-core/src/linting/another_think_coming.rs
index efa97c055..d395b7660 100644
--- a/harper-core/src/linting/another_think_coming.rs
+++ b/harper-core/src/linting/another_think_coming.rs
@@ -7,16 +7,14 @@ use crate::{
/// Both `another thing coming` and `another think coming` are correct, but `another think coming` is the original.
pub struct AnotherThinkComing {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AnotherThinkComing {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["had", "has", "have", "got"])
- .then_fixed_phrase(" another thing coming"),
- ),
+ expr: SequenceExpr::word_set(&["had", "has", "have", "got"])
+ .then_fixed_phrase(" another thing coming"),
}
}
}
@@ -25,7 +23,7 @@ impl ExprLinter for AnotherThinkComing {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/apart_from.rs b/harper-core/src/linting/apart_from.rs
index ca50c6b78..fc409cd9d 100644
--- a/harper-core/src/linting/apart_from.rs
+++ b/harper-core/src/linting/apart_from.rs
@@ -5,7 +5,7 @@ use crate::linting::expr_linter::Chunk;
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct ApartFrom {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ApartFrom {
@@ -14,9 +14,7 @@ impl Default for ApartFrom {
.t_ws()
.then_any_capitalization_of("form");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -24,7 +22,7 @@ impl ExprLinter for ApartFrom {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/ask_no_preposition.rs b/harper-core/src/linting/ask_no_preposition.rs
index ccd8903a0..9e31bd956 100644
--- a/harper-core/src/linting/ask_no_preposition.rs
+++ b/harper-core/src/linting/ask_no_preposition.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct AskNoPreposition {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AskNoPreposition {
@@ -25,9 +25,7 @@ impl Default for AskNoPreposition {
.then_whitespace()
.then(objs);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -35,7 +33,7 @@ impl ExprLinter for AskNoPreposition {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/avoid_curses.rs b/harper-core/src/linting/avoid_curses.rs
index bbf8db69e..c68315fad 100644
--- a/harper-core/src/linting/avoid_curses.rs
+++ b/harper-core/src/linting/avoid_curses.rs
@@ -6,13 +6,13 @@ use super::{ExprLinter, Lint};
use crate::linting::expr_linter::Chunk;
pub struct AvoidCurses {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for AvoidCurses {
fn default() -> Self {
Self {
- expr: Box::new(SequenceExpr::default().then_swear()),
+ expr: SequenceExpr::default().then_swear(),
}
}
}
@@ -21,7 +21,7 @@ impl ExprLinter for AvoidCurses {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/back_in_the_day.rs b/harper-core/src/linting/back_in_the_day.rs
index f62d601cf..f5dd2e70c 100644
--- a/harper-core/src/linting/back_in_the_day.rs
+++ b/harper-core/src/linting/back_in_the_day.rs
@@ -1,5 +1,6 @@
use crate::expr::Expr;
use crate::expr::FixedPhrase;
+use crate::expr::LongestMatchOf;
use crate::expr::OwnedExprExt;
use crate::expr::SequenceExpr;
use crate::{
@@ -11,7 +12,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct BackInTheDay {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
// The trailing words that should tell us to ignore the rule.
exceptions: Lrc<WordSet>,
}
@@ -27,7 +28,7 @@ impl Default for BackInTheDay {
.or_longest(phrase);
Self {
- expr: Box::new(pattern),
+ expr: pattern,
exceptions,
}
}
@@ -37,7 +38,7 @@ impl ExprLinter for BackInTheDay {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/be_allowed.rs b/harper-core/src/linting/be_allowed.rs
index 9cf379910..f2ffd91ca 100644
--- a/harper-core/src/linting/be_allowed.rs
+++ b/harper-core/src/linting/be_allowed.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::linting::expr_linter::Chunk;
use crate::{
Token,
@@ -8,8 +6,7 @@ use crate::{
};
pub struct BeAllowed {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for BeAllowed {
@@ -42,12 +39,7 @@ impl Default for BeAllowed {
2,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -55,11 +47,11 @@ impl ExprLinter for BeAllowed {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let allowed_index = *self.map.lookup(0, matched_tokens, source)?;
+ let allowed_index = *self.expr.lookup(0, matched_tokens, source)?;
let allowed_token = matched_tokens.get(allowed_index)?;
let span = allowed_token.span;
let template = span.get_content(source);
diff --git a/harper-core/src/linting/behind_the_scenes.rs b/harper-core/src/linting/behind_the_scenes.rs
index c58334c2d..868b9df19 100644
--- a/harper-core/src/linting/behind_the_scenes.rs
+++ b/harper-core/src/linting/behind_the_scenes.rs
@@ -5,19 +5,17 @@ use crate::{
};
pub struct BehindTheScenes {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for BehindTheScenes {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("behind")
- .t_ws_h()
- .t_aco("the")
- .t_ws_h()
- .t_aco("scene"),
- ),
+ expr: SequenceExpr::aco("behind")
+ .t_ws_h()
+ .t_aco("the")
+ .t_ws_h()
+ .t_aco("scene"),
}
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for BehindTheScenes {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/best_of_all_time.rs b/harper-core/src/linting/best_of_all_time.rs
index 47e78c113..4c8873e65 100644
--- a/harper-core/src/linting/best_of_all_time.rs
+++ b/harper-core/src/linting/best_of_all_time.rs
@@ -3,7 +3,7 @@ use crate::expr::{Expr, SequenceExpr};
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Sentence};
pub struct BestOfAllTime {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for BestOfAllTime {
@@ -36,9 +36,7 @@ impl Default for BestOfAllTime {
)
.then_fixed_phrase(" of all times");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for BestOfAllTime {
type Unit = Sentence;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/boring_words.rs b/harper-core/src/linting/boring_words.rs
index 7432f7516..870840581 100644
--- a/harper-core/src/linting/boring_words.rs
+++ b/harper-core/src/linting/boring_words.rs
@@ -1,6 +1,6 @@
use itertools::Itertools;
-use crate::expr::{Expr, WordExprGroup};
+use crate::expr::{Expr, FirstMatchOf, WordExprGroup};
use crate::thesaurus_helper;
use crate::{Token, TokenStringExt};
@@ -8,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct BoringWords {
- expr: Box<dyn Expr>,
+ expr: WordExprGroup<FirstMatchOf>,
}
impl Default for BoringWords {
@@ -21,9 +21,7 @@ impl Default for BoringWords {
expr.add_word("most");
expr.add_word("many");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -31,7 +29,7 @@ impl ExprLinter for BoringWords {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/bought.rs b/harper-core/src/linting/bought.rs
index 9eee3cd39..b1c8d3b7a 100644
--- a/harper-core/src/linting/bought.rs
+++ b/harper-core/src/linting/bought.rs
@@ -5,7 +5,7 @@ use crate::linting::Suggestion;
use crate::linting::expr_linter::Chunk;
pub struct Bought {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Bought {
@@ -17,9 +17,7 @@ impl Default for Bought {
.then_optional(SequenceExpr::default().then_adverb().t_ws())
.then_any_capitalization_of("bough");
- Self {
- expr: Box::new(subject),
- }
+ Self { expr: subject }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for Bought {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/brand_brandish.rs b/harper-core/src/linting/brand_brandish.rs
index 306fdde7a..572fef9b2 100644
--- a/harper-core/src/linting/brand_brandish.rs
+++ b/harper-core/src/linting/brand_brandish.rs
@@ -5,19 +5,17 @@ use crate::{
};
pub struct BrandBrandish {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for BrandBrandish {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["brandish", "brandished", "brandishes", "brandishing"])
- .t_ws()
- // "her" is also a possessive determiner as in "she brandished her sword"
- // "it" and "them" can refer to objects as in "draw your sword(s) and brandish it/them"
- .then_kind_except(TokenKind::is_object_pronoun, &["her", "it", "them"]),
- ),
+ expr: SequenceExpr::word_set(&["brandish", "brandished", "brandishes", "brandishing"])
+ .t_ws()
+ // "her" is also a possessive determiner as in "she brandished her sword"
+ // "it" and "them" can refer to objects as in "draw your sword(s) and brandish it/them"
+ .then_kind_except(TokenKind::is_object_pronoun, &["her", "it", "them"]),
}
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for BrandBrandish {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/by_accident.rs b/harper-core/src/linting/by_accident.rs
index f3de298bc..34ad4e595 100644
--- a/harper-core/src/linting/by_accident.rs
+++ b/harper-core/src/linting/by_accident.rs
@@ -10,23 +10,21 @@ use crate::{
};
pub struct ByAccident {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ByAccident {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("on")
- .t_ws()
- .then_optional(
- SequenceExpr::word_set(&[
- "complete", "happy", "literal", "mere", "pure", "sheer", "total",
- ])
- .t_ws(),
- )
- .t_aco("accident"),
- ),
+ expr: SequenceExpr::aco("on")
+ .t_ws()
+ .then_optional(
+ SequenceExpr::word_set(&[
+ "complete", "happy", "literal", "mere", "pure", "sheer", "total",
+ ])
+ .t_ws(),
+ )
+ .t_aco("accident"),
}
}
}
@@ -39,7 +37,7 @@ impl ExprLinter for ByAccident {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/call_them.rs b/harper-core/src/linting/call_them.rs
index 4b01a847b..edb8ad2d2 100644
--- a/harper-core/src/linting/call_them.rs
+++ b/harper-core/src/linting/call_them.rs
@@ -8,8 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct CallThem {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<Range<usize>>>,
+ expr: ExprMap<Range<usize>>,
}
impl Default for CallThem {
@@ -38,12 +37,7 @@ impl Default for CallThem {
1..3,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -51,11 +45,11 @@ impl ExprLinter for CallThem {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let removal_range = self.map.lookup(0, matched_tokens, source)?.clone();
+ let removal_range = self.expr.lookup(0, matched_tokens, source)?.clone();
let offending_tokens = matched_tokens.get(removal_range)?;
Some(Lint {
diff --git a/harper-core/src/linting/cant.rs b/harper-core/src/linting/cant.rs
index 21e0d5f10..0e38c3094 100644
--- a/harper-core/src/linting/cant.rs
+++ b/harper-core/src/linting/cant.rs
@@ -7,7 +7,7 @@ use crate::linting::expr_linter::find_the_only_token_matching;
use crate::{CharStringExt, Token};
pub struct Cant {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for Cant {
@@ -22,11 +22,11 @@ impl Default for Cant {
.then_kind_is_but_is_not(|kind| kind.is_verb_lemma(), |kind| kind.is_noun());
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
Box::new(nom_cant),
Box::new(cant_pron),
Box::new(cant_verb),
- ])),
+ ]),
}
}
}
@@ -35,7 +35,7 @@ impl ExprLinter for Cant {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/cautionary_tale.rs b/harper-core/src/linting/cautionary_tale.rs
index f4c9a49ff..3aa0bd5fd 100644
--- a/harper-core/src/linting/cautionary_tale.rs
+++ b/harper-core/src/linting/cautionary_tale.rs
@@ -9,7 +9,7 @@ use crate::{
/// Corrects the homophone confusion between "tale" (story) and "tail" (appendage)
/// in common phrases like "cautionary tale" and "inspirational tale".
pub struct CautionaryTale {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for CautionaryTale {
@@ -18,9 +18,7 @@ impl Default for CautionaryTale {
let pattern = SequenceExpr::with(adjectives).t_ws().t_aco("tail");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for CautionaryTale {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/change_tack.rs b/harper-core/src/linting/change_tack.rs
index c89d79f60..dced30d86 100644
--- a/harper-core/src/linting/change_tack.rs
+++ b/harper-core/src/linting/change_tack.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct ChangeTack {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for ChangeTack {
@@ -16,7 +16,7 @@ impl Default for ChangeTack {
let eggcorns = &["tact", "tacks", "tacts"];
Self {
- expr: Box::new(FirstMatchOf::new(vec![
+ expr: FirstMatchOf::new(vec![
Box::new(
SequenceExpr::longest_of(vec![
Box::new(SequenceExpr::word_set(verb_forms).then_optional(
@@ -31,7 +31,7 @@ impl Default for ChangeTack {
.then_word_set(eggcorns),
),
Box::new(SequenceExpr::aco("different").t_ws().t_aco("tact")),
- ])),
+ ]),
}
}
}
@@ -40,7 +40,7 @@ impl ExprLinter for ChangeTack {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/compound_subject_i.rs b/harper-core/src/linting/compound_subject_i.rs
index 924e65124..3c7cf55d9 100644
--- a/harper-core/src/linting/compound_subject_i.rs
+++ b/harper-core/src/linting/compound_subject_i.rs
@@ -8,7 +8,7 @@ use crate::{
const POSSESSIVE_DETERMINERS: &[&str] = &["my", "your", "her", "his", "their", "our"];
pub struct CompoundSubjectI {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for CompoundSubjectI {
@@ -34,9 +34,7 @@ impl Default for CompoundSubjectI {
.t_ws()
.then_kind_either(TokenKind::is_verb, TokenKind::is_auxiliary_verb);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -44,7 +42,7 @@ impl ExprLinter for CompoundSubjectI {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/confident.rs b/harper-core/src/linting/confident.rs
index cf8e66b2f..ce16d835f 100644
--- a/harper-core/src/linting/confident.rs
+++ b/harper-core/src/linting/confident.rs
@@ -7,7 +7,7 @@ use crate::{Token, patterns::Word};
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct Confident {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Confident {
@@ -21,9 +21,7 @@ impl Default for Confident {
.then_whitespace()
.t_aco("confidant");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -31,7 +29,7 @@ impl ExprLinter for Confident {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/criteria_phenomena.rs b/harper-core/src/linting/criteria_phenomena.rs
index 95b5b601a..37424314c 100644
--- a/harper-core/src/linting/criteria_phenomena.rs
+++ b/harper-core/src/linting/criteria_phenomena.rs
@@ -9,7 +9,7 @@ use crate::{Lint, Lrc, Token, TokenStringExt};
/// Linter that checks if 'criteria' or 'phenomena' is used as singular.
pub struct CriteriaPhenomena {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
plural_words: Lrc<WordSet>,
singular_modifiers: Lrc<WordSet>,
}
@@ -21,11 +21,9 @@ impl CriteriaPhenomena {
let singular_modifiers = Lrc::new(WordSet::new(&["this", "that", "a", "one"]));
Self {
- expr: Box::new(
- SequenceExpr::with(singular_modifiers.clone())
- .then_whitespace()
- .then(plural_words.clone()),
- ),
+ expr: SequenceExpr::with(singular_modifiers.clone())
+ .then_whitespace()
+ .then(plural_words.clone()),
plural_words,
singular_modifiers,
}
@@ -36,7 +34,7 @@ impl ExprLinter for CriteriaPhenomena {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/cure_for.rs b/harper-core/src/linting/cure_for.rs
index fa11b9f19..ecf99e01a 100644
--- a/harper-core/src/linting/cure_for.rs
+++ b/harper-core/src/linting/cure_for.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct CureFor {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for CureFor {
@@ -16,9 +16,7 @@ impl Default for CureFor {
.t_ws()
.t_aco("against");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for CureFor {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/damages.rs b/harper-core/src/linting/damages.rs
index db0aa9b67..f164ed064 100644
--- a/harper-core/src/linting/damages.rs
+++ b/harper-core/src/linting/damages.rs
@@ -20,13 +20,13 @@ static KEYWORDS: &[&str] = &[
];
pub struct Damages {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Damages {
fn default() -> Self {
Self {
- expr: Box::new(SequenceExpr::word_set(&["damages", "damage"])),
+ expr: SequenceExpr::word_set(&["damages", "damage"]),
}
}
}
@@ -35,7 +35,7 @@ impl ExprLinter for Damages {
type Unit = Sentence;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/dashes.rs b/harper-core/src/linting/dashes.rs
index baa511e09..1ae6367e3 100644
--- a/harper-core/src/linting/dashes.rs
+++ b/harper-core/src/linting/dashes.rs
@@ -10,7 +10,7 @@ const EN_DASH: char = '–';
const EM_DASH: char = '—';
pub struct Dashes {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for Dashes {
@@ -23,9 +23,7 @@ impl Default for Dashes {
let pattern = LongestMatchOf::new(vec![Box::new(em_dash_or_longer), Box::new(en_dash)]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for Dashes {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/day_and_age.rs b/harper-core/src/linting/day_and_age.rs
index 668ec71ce..2f19183f2 100644
--- a/harper-core/src/linting/day_and_age.rs
+++ b/harper-core/src/linting/day_and_age.rs
@@ -5,21 +5,19 @@ use crate::{
};
pub struct DayAndAge {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for DayAndAge {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["this", "these"])
- .t_ws()
- .then_word_set(&["day", "days"])
- .t_ws()
- .then_word_set(&["and", "in", "an", "on"])
- .t_ws()
- .then_word_set(&["age", "ages"]),
- ),
+ expr: SequenceExpr::word_set(&["this", "these"])
+ .t_ws()
+ .then_word_set(&["day", "days"])
+ .t_ws()
+ .then_word_set(&["and", "in", "an", "on"])
+ .t_ws()
+ .then_word_set(&["age", "ages"]),
}
}
}
@@ -32,7 +30,7 @@ impl ExprLinter for DayAndAge {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/despite_it_is.rs b/harper-core/src/linting/despite_it_is.rs
index d6d90406b..19e599cf4 100644
--- a/harper-core/src/linting/despite_it_is.rs
+++ b/harper-core/src/linting/despite_it_is.rs
@@ -19,7 +19,7 @@ use crate::{
/// - "despite it is" -> "despite it being" or "despite its being"
/// - "despite I am" -> "despite me being" or "despite my being"
pub struct DespiteItIs {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for DespiteItIs {
@@ -33,9 +33,7 @@ impl Default for DespiteItIs {
.t_ws()
.then(be);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -47,7 +45,7 @@ impl ExprLinter for DespiteItIs {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/despite_of.rs b/harper-core/src/linting/despite_of.rs
index 71ce5f116..a8db1dbe0 100644
--- a/harper-core/src/linting/despite_of.rs
+++ b/harper-core/src/linting/despite_of.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct DespiteOf {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for DespiteOf {
@@ -15,9 +15,7 @@ impl Default for DespiteOf {
.then_whitespace()
.then_exact_word("of");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -25,7 +23,7 @@ impl ExprLinter for DespiteOf {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/determiner_without_noun.rs b/harper-core/src/linting/determiner_without_noun.rs
index dcdaa91b6..1d1348d36 100644
--- a/harper-core/src/linting/determiner_without_noun.rs
+++ b/harper-core/src/linting/determiner_without_noun.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct DeterminerWithoutNoun {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for DeterminerWithoutNoun {
@@ -16,9 +16,7 @@ impl Default for DeterminerWithoutNoun {
.t_ws()
.then_conjunction();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for DeterminerWithoutNoun {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/did_past.rs b/harper-core/src/linting/did_past.rs
index 18e3505bd..79973b14c 100644
--- a/harper-core/src/linting/did_past.rs
+++ b/harper-core/src/linting/did_past.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct DidPast<D> {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dict: D,
}
@@ -19,19 +19,17 @@ where
{
pub fn new(dict: D) -> Self {
Self {
- expr: Box::new(
- SequenceExpr::longest_of(vec![
- Box::new(WordSet::new(&["did", "didn't", "didnt"])),
- Box::new(FixedPhrase::from_phrase("did not")),
- ])
- .then_optional(SequenceExpr::default().t_ws().then_subject_pronoun())
- .t_ws()
- // Note that 'simple past forms' may apply only to irregular verbs
- // Note and that 'past forms' applies to regular verbs where preterite and participle share a form
- .then_kind_where(|k| {
- (k.is_verb_simple_past_form() || k.is_verb_past_form()) && !k.is_verb_lemma()
- }),
- ),
+ expr: SequenceExpr::longest_of(vec![
+ Box::new(WordSet::new(&["did", "didn't", "didnt"])),
+ Box::new(FixedPhrase::from_phrase("did not")),
+ ])
+ .then_optional(SequenceExpr::default().t_ws().then_subject_pronoun())
+ .t_ws()
+ // Note that 'simple past forms' may apply only to irregular verbs
+ // Note and that 'past forms' applies to regular verbs where preterite and participle share a form
+ .then_kind_where(|k| {
+ (k.is_verb_simple_past_form() || k.is_verb_past_form()) && !k.is_verb_lemma()
+ }),
dict,
}
}
@@ -58,7 +56,7 @@ where
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/didnt.rs b/harper-core/src/linting/didnt.rs
index c01603502..f34700a37 100644
--- a/harper-core/src/linting/didnt.rs
+++ b/harper-core/src/linting/didnt.rs
@@ -4,7 +4,7 @@ use crate::linting::expr_linter::Chunk;
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
pub struct Didnt {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Didnt {
@@ -14,9 +14,7 @@ impl Default for Didnt {
.t_ws()
.t_aco("dint");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -24,7 +22,7 @@ impl ExprLinter for Didnt {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/disjoint_prefixes.rs b/harper-core/src/linting/disjoint_prefixes.rs
index 12f9ba763..91210a0b6 100644
--- a/harper-core/src/linting/disjoint_prefixes.rs
+++ b/harper-core/src/linting/disjoint_prefixes.rs
@@ -1,12 +1,12 @@
use crate::{
Lint, Token, TokenKind, TokenStringExt,
- expr::{Expr, OwnedExprExt, SequenceExpr},
+ expr::{All, Expr, OwnedExprExt, SequenceExpr},
linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
spell::Dictionary,
};
pub struct DisjointPrefixes<D> {
- expr: Box<dyn Expr>,
+ expr: All,
dict: D,
}
@@ -22,38 +22,36 @@ where
{
pub fn new(dict: D) -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&[
- // These prefixes rarely cause false positives
- "anti", "auto", "bi", "counter", "de", "dis", "extra", "fore", "hyper", "il",
- "im", "inter", "ir", "macro", "mal", "micro", "mid", "mini", "mis", "mono",
- "multi", "non", "omni", "post", "pre", "pro", "re", "semi", "sub", "super",
- "trans", "tri", "ultra", "un", "uni",
- // "co" has one very common false positive: co-op != coop
- "co",
- // These prefixes are all also words in their own right, which leads to more false positives.
- "out", "over", "under",
- "up",
- // These prefixes are commented out due to too many false positives
- // or incorrect transformations:
- // "a": a live -> alive
- // "in": in C -> inc; in action -> inaction
- ])
- .t_ws_h()
- .then_kind_either(TokenKind::is_verb, TokenKind::is_noun)
- .then_optional_hyphen()
- .and_not(SequenceExpr::any_of(vec![
- // No trailing hyphen. Ex: Custom patterns take precedence over built-in patterns -> overbuilt
- Box::new(SequenceExpr::anything().t_any().t_any().then_hyphen()),
- // Don't merge "co op" whether separated by space or hyphen.
- Box::new(SequenceExpr::aco("co").t_any().t_set(&["op", "ops"])),
- // Merge these if they're separated by hyphen, but not space.
- Box::new(SequenceExpr::aco("out").t_ws().t_set(OUT_EXCEPTIONS)),
- Box::new(SequenceExpr::aco("over").t_ws().t_set(OVER_EXCEPTIONS)),
- Box::new(SequenceExpr::aco("under").t_ws().t_set(UNDER_EXCEPTIONS)),
- Box::new(SequenceExpr::aco("up").t_ws().t_set(UP_EXCEPTIONS)),
- ])),
- ),
+ expr: SequenceExpr::word_set(&[
+ // These prefixes rarely cause false positives
+ "anti", "auto", "bi", "counter", "de", "dis", "extra", "fore", "hyper", "il", "im",
+ "inter", "ir", "macro", "mal", "micro", "mid", "mini", "mis", "mono", "multi",
+ "non", "omni", "post", "pre", "pro", "re", "semi", "sub", "super", "trans", "tri",
+ "ultra", "un", "uni",
+ // "co" has one very common false positive: co-op != coop
+ "co",
+ // These prefixes are all also words in their own right, which leads to more false positives.
+ "out", "over", "under",
+ "up",
+ // These prefixes are commented out due to too many false positives
+ // or incorrect transformations:
+ // "a": a live -> alive
+ // "in": in C -> inc; in action -> inaction
+ ])
+ .t_ws_h()
+ .then_kind_either(TokenKind::is_verb, TokenKind::is_noun)
+ .then_optional_hyphen()
+ .and_not(SequenceExpr::any_of(vec![
+ // No trailing hyphen. Ex: Custom patterns take precedence over built-in patterns -> overbuilt
+ Box::new(SequenceExpr::anything().t_any().t_any().then_hyphen()),
+ // Don't merge "co op" whether separated by space or hyphen.
+ Box::new(SequenceExpr::aco("co").t_any().t_set(&["op", "ops"])),
+ // Merge these if they're separated by hyphen, but not space.
+ Box::new(SequenceExpr::aco("out").t_ws().t_set(OUT_EXCEPTIONS)),
+ Box::new(SequenceExpr::aco("over").t_ws().t_set(OVER_EXCEPTIONS)),
+ Box::new(SequenceExpr::aco("under").t_ws().t_set(UNDER_EXCEPTIONS)),
+ Box::new(SequenceExpr::aco("up").t_ws().t_set(UP_EXCEPTIONS)),
+ ])),
dict,
}
}
@@ -66,7 +64,7 @@ where
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/dot_initialisms.rs b/harper-core/src/linting/dot_initialisms.rs
index 99df487cf..b883a3d5b 100644
--- a/harper-core/src/linting/dot_initialisms.rs
+++ b/harper-core/src/linting/dot_initialisms.rs
@@ -1,4 +1,5 @@
use crate::expr::Expr;
+use crate::expr::FirstMatchOf;
use crate::expr::SequenceExpr;
use crate::expr::WordExprGroup;
use hashbrown::HashMap;
@@ -8,7 +9,7 @@ use crate::linting::expr_linter::Chunk;
use crate::{Token, TokenStringExt};
pub struct DotInitialisms {
- expr: Box<dyn Expr>,
+ expr: WordExprGroup<FirstMatchOf>,
corrections: HashMap<&'static str, &'static str>,
}
@@ -29,7 +30,7 @@ impl Default for DotInitialisms {
}
Self {
- expr: Box::new(patterns),
+ expr: patterns,
corrections,
}
}
@@ -39,7 +40,7 @@ impl ExprLinter for DotInitialisms {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/double_click.rs b/harper-core/src/linting/double_click.rs
index 86fb6e389..e02de158c 100644
--- a/harper-core/src/linting/double_click.rs
+++ b/harper-core/src/linting/double_click.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::linting::expr_linter::Chunk;
use crate::{
Token, TokenKind, TokenStringExt,
@@ -8,8 +6,7 @@ use crate::{
};
pub struct DoubleClick {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl DoubleClick {
@@ -48,12 +45,7 @@ impl Default for DoubleClick {
0,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -61,11 +53,11 @@ impl ExprLinter for DoubleClick {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let double_idx = *self.map.lookup(0, matched_tokens, source)?;
+ let double_idx = *self.expr.lookup(0, matched_tokens, source)?;
let click_idx = 2;
let span = matched_tokens.get(double_idx..=click_idx)?.span()?;
let template = span.get_content(source);
diff --git a/harper-core/src/linting/double_modal.rs b/harper-core/src/linting/double_modal.rs
index 9b35c5290..8488640fd 100644
--- a/harper-core/src/linting/double_modal.rs
+++ b/harper-core/src/linting/double_modal.rs
@@ -8,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct DoubleModal {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for DoubleModal {
@@ -17,9 +17,7 @@ impl Default for DoubleModal {
.t_ws()
.then(ModalVerb::default());
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for DoubleModal {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/else_possessive.rs b/harper-core/src/linting/else_possessive.rs
index a417f62ad..1746fed9e 100644
--- a/harper-core/src/linting/else_possessive.rs
+++ b/harper-core/src/linting/else_possessive.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct ElsePossessive {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ElsePossessive {
@@ -29,9 +29,7 @@ impl Default for ElsePossessive {
.then_whitespace()
.t_aco("elses");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -39,7 +37,7 @@ impl ExprLinter for ElsePossessive {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/ever_every.rs b/harper-core/src/linting/ever_every.rs
index 0d0fe7ed9..188656c23 100644
--- a/harper-core/src/linting/ever_every.rs
+++ b/harper-core/src/linting/ever_every.rs
@@ -1,33 +1,31 @@
use crate::{
Lint, Token,
- expr::{Expr, OwnedExprExt, SequenceExpr},
+ expr::{All, Expr, OwnedExprExt, SequenceExpr},
linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
patterns::{ModalVerb, WordSet},
};
pub struct EverEvery {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for EverEvery {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::any_of(vec![
- Box::new(WordSet::new(&[
- "are", "aren't", "arent", "did", "didn't", "didnt", "do", "does",
- "doesn't", "doesnt", "dont", "don't", "had", "hadn't", "hadnt", "has",
- "hasn't", "hasnt", "have", "haven't", "havent", "is", "isn't", "isnt",
- "was", "wasn't", "wasnt", "were", "weren't", "werent",
- ])),
- Box::new(ModalVerb::with_common_errors()),
- ])
- .t_ws()
- .then_subject_pronoun()
- .t_ws()
- .t_aco("every")
- .and_not(SequenceExpr::anything().t_any().t_aco("it")),
- ),
+ expr: SequenceExpr::any_of(vec![
+ Box::new(WordSet::new(&[
+ "are", "aren't", "arent", "did", "didn't", "didnt", "do", "does", "doesn't",
+ "doesnt", "dont", "don't", "had", "hadn't", "hadnt", "has", "hasn't", "hasnt",
+ "have", "haven't", "havent", "is", "isn't", "isnt", "was", "wasn't", "wasnt",
+ "were", "weren't", "werent",
+ ])),
+ Box::new(ModalVerb::with_common_errors()),
+ ])
+ .t_ws()
+ .then_subject_pronoun()
+ .t_ws()
+ .t_aco("every")
+ .and_not(SequenceExpr::anything().t_any().t_aco("it")),
}
}
}
@@ -36,7 +34,7 @@ impl ExprLinter for EverEvery {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/everyday.rs b/harper-core/src/linting/everyday.rs
index 2ec35df7e..c0df3bded 100644
--- a/harper-core/src/linting/everyday.rs
+++ b/harper-core/src/linting/everyday.rs
@@ -7,7 +7,7 @@ use crate::linting::expr_linter::Chunk;
use crate::{Lrc, Punctuation, Token, TokenKind, TokenStringExt, patterns::Word};
pub struct Everyday {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for Everyday {
@@ -109,13 +109,13 @@ impl Default for Everyday {
// verb, past form: "I coded every day" / "I learned everyday phrases"
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
Box::new(everyday_bad_after),
Box::new(bad_before_every_day),
Box::new(everyday_ambiverb_after_then_noun),
Box::new(everyday_punctuation_after),
Box::new(every_day_noun_after_then_punctuation),
- ])),
+ ]),
}
}
}
@@ -124,7 +124,7 @@ impl ExprLinter for Everyday {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/expand_memory_shorthands.rs b/harper-core/src/linting/expand_memory_shorthands.rs
index 3c08609ca..24581e67d 100644
--- a/harper-core/src/linting/expand_memory_shorthands.rs
+++ b/harper-core/src/linting/expand_memory_shorthands.rs
@@ -8,7 +8,7 @@ use crate::linting::expr_linter::Chunk;
use crate::patterns::{ImpliesQuantity, WordSet};
pub struct ExpandMemoryShorthands {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl ExpandMemoryShorthands {
@@ -19,10 +19,10 @@ impl ExpandMemoryShorthands {
]));
Self {
- expr: Box::new(SequenceExpr::with(ImpliesQuantity).then_longest_of(vec![
+ expr: SequenceExpr::with(ImpliesQuantity).then_longest_of(vec![
Box::new(SequenceExpr::with(hotwords.clone())),
Box::new(SequenceExpr::default().t_ws_h().then(hotwords.clone())),
- ])),
+ ]),
}
}
@@ -70,7 +70,7 @@ impl ExprLinter for ExpandMemoryShorthands {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/expand_time_shorthands.rs b/harper-core/src/linting/expand_time_shorthands.rs
index 17d54ed7e..99a98a571 100644
--- a/harper-core/src/linting/expand_time_shorthands.rs
+++ b/harper-core/src/linting/expand_time_shorthands.rs
@@ -9,7 +9,7 @@ use crate::linting::expr_linter::Chunk;
use crate::patterns::{ImpliesQuantity, WordSet};
pub struct ExpandTimeShorthands {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl ExpandTimeShorthands {
@@ -19,10 +19,10 @@ impl ExpandTimeShorthands {
]));
Self {
- expr: Box::new(SequenceExpr::with(ImpliesQuantity).then_longest_of(vec![
+ expr: SequenceExpr::with(ImpliesQuantity).then_longest_of(vec![
Box::new(SequenceExpr::with(hotwords.clone())),
Box::new(SequenceExpr::default().t_ws_h().then(hotwords.clone())),
- ])),
+ ]),
}
}
@@ -52,7 +52,7 @@ impl ExprLinter for ExpandTimeShorthands {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/far_be_it.rs b/harper-core/src/linting/far_be_it.rs
index b7346994f..09c5480dd 100644
--- a/harper-core/src/linting/far_be_it.rs
+++ b/harper-core/src/linting/far_be_it.rs
@@ -5,22 +5,20 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::token::Token;
pub struct FarBeIt {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FarBeIt {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::default()
- .t_aco("far")
- .t_ws()
- .t_aco("be")
- .t_ws()
- .t_aco("it")
- .t_ws()
- .then_word_except(&["from"]),
- ),
+ expr: SequenceExpr::default()
+ .t_aco("far")
+ .t_ws()
+ .t_aco("be")
+ .t_ws()
+ .t_aco("it")
+ .t_ws()
+ .then_word_except(&["from"]),
}
}
}
@@ -29,7 +27,7 @@ impl ExprLinter for FarBeIt {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/fascinated_by.rs b/harper-core/src/linting/fascinated_by.rs
index be626c8f7..68b4d7345 100644
--- a/harper-core/src/linting/fascinated_by.rs
+++ b/harper-core/src/linting/fascinated_by.rs
@@ -5,13 +5,13 @@ use crate::{
};
pub struct FascinatedBy {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FascinatedBy {
fn default() -> Self {
Self {
- expr: Box::new(SequenceExpr::aco("fascinated").t_ws().then_preposition()),
+ expr: SequenceExpr::aco("fascinated").t_ws().then_preposition(),
}
}
}
@@ -20,7 +20,7 @@ impl ExprLinter for FascinatedBy {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/fed_up_with.rs b/harper-core/src/linting/fed_up_with.rs
index e77f317d4..f974ecc05 100644
--- a/harper-core/src/linting/fed_up_with.rs
+++ b/harper-core/src/linting/fed_up_with.rs
@@ -5,7 +5,7 @@ use crate::{
};
pub struct FedUpWith {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dialect: Dialect,
}
@@ -13,10 +13,7 @@ impl FedUpWith {
pub fn new(dialect: Dialect) -> Self {
let expr = SequenceExpr::fixed_phrase("fed up of");
- Self {
- expr: Box::new(expr),
- dialect,
- }
+ Self { expr, dialect }
}
}
@@ -24,7 +21,7 @@ impl ExprLinter for FedUpWith {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/feel_fell.rs b/harper-core/src/linting/feel_fell.rs
index b55fd6593..1d66bd3df 100644
--- a/harper-core/src/linting/feel_fell.rs
+++ b/harper-core/src/linting/feel_fell.rs
@@ -6,7 +6,7 @@ use crate::linting::expr_linter::find_the_only_token_matching;
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
pub struct FeelFell {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FeelFell {
@@ -33,10 +33,7 @@ impl Default for FeelFell {
]);
Self {
- expr: Box::new(SequenceExpr::any_of(vec![
- Box::new(with_word_before),
- Box::new(with_word_after),
- ])),
+ expr: SequenceExpr::any_of(vec![Box::new(with_word_before), Box::new(with_word_after)]),
}
}
}
@@ -45,7 +42,7 @@ impl ExprLinter for FeelFell {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/few_units_of_time_ago.rs b/harper-core/src/linting/few_units_of_time_ago.rs
index 3d324b674..590d02036 100644
--- a/harper-core/src/linting/few_units_of_time_ago.rs
+++ b/harper-core/src/linting/few_units_of_time_ago.rs
@@ -3,12 +3,12 @@ use crate::expr::SequenceExpr;
use crate::expr::TimeUnitExpr;
use crate::linting::expr_linter::Chunk;
use crate::{
- Lrc, Token,
+ Token,
linting::{ExprLinter, Lint, Suggestion},
};
pub struct FewUnitsOfTimeAgo {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FewUnitsOfTimeAgo {
@@ -17,18 +17,14 @@ impl Default for FewUnitsOfTimeAgo {
let start = SequenceExpr::default().then_word_except(&["a"]).t_ws();
- let expr = Lrc::new(
- SequenceExpr::with(start)
- .t_aco("few")
- .then_whitespace()
- .then(units)
- .then_whitespace()
- .t_aco("ago"),
- );
+ let expr = SequenceExpr::with(start)
+ .t_aco("few")
+ .then_whitespace()
+ .then(units)
+ .then_whitespace()
+ .t_aco("ago");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -36,7 +32,7 @@ impl ExprLinter for FewUnitsOfTimeAgo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/filler_words.rs b/harper-core/src/linting/filler_words.rs
index 5a5b6cef3..fe046b5e8 100644
--- a/harper-core/src/linting/filler_words.rs
+++ b/harper-core/src/linting/filler_words.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct FillerWords {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FillerWords {
@@ -20,9 +20,7 @@ impl Default for FillerWords {
Box::new(SequenceExpr::whitespace().then(filler_words)),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for FillerWords {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/find_fine.rs b/harper-core/src/linting/find_fine.rs
index 877ad3207..859cdfc25 100644
--- a/harper-core/src/linting/find_fine.rs
+++ b/harper-core/src/linting/find_fine.rs
@@ -7,7 +7,7 @@ use super::expr_linter::Chunk;
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct FindFine {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FindFine {
@@ -16,9 +16,7 @@ impl Default for FindFine {
.t_ws()
.t_aco("find");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for FindFine {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/first_aid_kit.rs b/harper-core/src/linting/first_aid_kit.rs
index 5e7969471..ee7ba5fe4 100644
--- a/harper-core/src/linting/first_aid_kit.rs
+++ b/harper-core/src/linting/first_aid_kit.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct FirstAidKit {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FirstAidKit {
@@ -17,9 +17,7 @@ impl Default for FirstAidKit {
let pattern = SequenceExpr::with(supply_words)
.then_whitespace()
.then_any_capitalization_of("kid");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for FirstAidKit {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/flesh_out_vs_full_fledged.rs b/harper-core/src/linting/flesh_out_vs_full_fledged.rs
index 49d9f6979..45c71619b 100644
--- a/harper-core/src/linting/flesh_out_vs_full_fledged.rs
+++ b/harper-core/src/linting/flesh_out_vs_full_fledged.rs
@@ -5,21 +5,19 @@ use crate::{
};
pub struct FleshOutVsFullFledged {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FleshOutVsFullFledged {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::optional(SequenceExpr::word_set(&["full", "fully"]).t_ws_h())
- .then_word_set(&[
- "fledge", "fledged", "fledged", "fledges", "fledging", "flesh", "fleshed",
- "fleshed", "fleshes", "fleshing", "pledge", "pledged", "pledged",
- "pledges", "pledging",
- ])
- .then_optional(SequenceExpr::default().t_ws_h().t_aco("out")),
- ),
+ expr: SequenceExpr::optional(SequenceExpr::word_set(&["full", "fully"]).t_ws_h())
+ .then_word_set(&[
+ "fledge", "fledged", "fledged", "fledges", "fledging", "flesh", "fleshed",
+ "fleshed", "fleshes", "fleshing", "pledge", "pledged", "pledged", "pledges",
+ "pledging",
+ ])
+ .then_optional(SequenceExpr::default().t_ws_h().t_aco("out")),
}
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for FleshOutVsFullFledged {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/for_noun.rs b/harper-core/src/linting/for_noun.rs
index fe1248c8c..aecf2ba2e 100644
--- a/harper-core/src/linting/for_noun.rs
+++ b/harper-core/src/linting/for_noun.rs
@@ -10,7 +10,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct ForNoun {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ForNoun {
@@ -19,9 +19,7 @@ impl Default for ForNoun {
.then_whitespace()
.then(NominalPhrase.or(Word::new("sure")));
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -29,7 +27,7 @@ impl ExprLinter for ForNoun {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/free_predicate.rs b/harper-core/src/linting/free_predicate.rs
index 49c8612b0..2d7d0359d 100644
--- a/harper-core/src/linting/free_predicate.rs
+++ b/harper-core/src/linting/free_predicate.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::Token;
use crate::TokenKind;
use crate::char_string::CharStringExt;
@@ -10,8 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct FreePredicate {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for FreePredicate {
@@ -36,12 +33,7 @@ impl Default for FreePredicate {
map.insert(with_adverb, 4);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -49,11 +41,11 @@ impl ExprLinter for FreePredicate {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let offending_idx = *self.map.lookup(0, matched_tokens, source)?;
+ let offending_idx = *self.expr.lookup(0, matched_tokens, source)?;
let offending = matched_tokens.get(offending_idx)?;
Some(Lint {
diff --git a/harper-core/src/linting/friend_of_me.rs b/harper-core/src/linting/friend_of_me.rs
index a446a9654..a9e58c253 100644
--- a/harper-core/src/linting/friend_of_me.rs
+++ b/harper-core/src/linting/friend_of_me.rs
@@ -6,19 +6,17 @@ use crate::{
};
pub struct FriendOfMe {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for FriendOfMe {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["friend", "friends", "enemy", "enemies"])
- .then_whitespace()
- .t_aco("of")
- .t_ws()
- .then_object_pronoun(),
- ),
+ expr: SequenceExpr::word_set(&["friend", "friends", "enemy", "enemies"])
+ .then_whitespace()
+ .t_aco("of")
+ .t_ws()
+ .then_object_pronoun(),
}
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for FriendOfMe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/go_so_far_as_to.rs b/harper-core/src/linting/go_so_far_as_to.rs
index 3cbf8d5b5..b9a29d726 100644
--- a/harper-core/src/linting/go_so_far_as_to.rs
+++ b/harper-core/src/linting/go_so_far_as_to.rs
@@ -6,18 +6,16 @@ use crate::linting::expr_linter::Chunk;
use crate::linting::{ExprLinter, Lint, LintKind};
pub struct GoSoFarAsTo {
- exp: Box<dyn Expr>,
+ exp: SequenceExpr,
}
impl Default for GoSoFarAsTo {
fn default() -> Self {
Self {
- exp: Box::new(
- SequenceExpr::word_set(&["go", "goes", "going", "gone", "went"])
- .then_fixed_phrase(" so far to ")
- .then_optional(SequenceExpr::default().then_adverb().t_ws())
- .then_any_word(),
- ),
+ exp: SequenceExpr::word_set(&["go", "goes", "going", "gone", "went"])
+ .then_fixed_phrase(" so far to ")
+ .then_optional(SequenceExpr::default().then_adverb().t_ws())
+ .then_any_word(),
}
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for GoSoFarAsTo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.exp.as_ref()
+ &self.exp
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/go_to_war.rs b/harper-core/src/linting/go_to_war.rs
index f0eea4856..1df200a92 100644
--- a/harper-core/src/linting/go_to_war.rs
+++ b/harper-core/src/linting/go_to_war.rs
@@ -5,19 +5,17 @@ use crate::{
};
pub struct GoToWar {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for GoToWar {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["go", "goes", "going", "gone", "went"])
- .t_ws()
- .then_preposition()
- .t_ws()
- .then_word_set(&["war"]),
- ),
+ expr: SequenceExpr::word_set(&["go", "goes", "going", "gone", "went"])
+ .t_ws()
+ .then_preposition()
+ .t_ws()
+ .then_word_set(&["war"]),
}
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for GoToWar {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/good_at.rs b/harper-core/src/linting/good_at.rs
index 148384f07..43eff4de6 100644
--- a/harper-core/src/linting/good_at.rs
+++ b/harper-core/src/linting/good_at.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct GoodAt {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for GoodAt {
@@ -65,9 +65,7 @@ impl Default for GoodAt {
Box::new(good_in_skill_or_subject),
]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -75,7 +73,7 @@ impl ExprLinter for GoodAt {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/handful.rs b/harper-core/src/linting/handful.rs
index a9c0e48d4..78389b542 100644
--- a/harper-core/src/linting/handful.rs
+++ b/harper-core/src/linting/handful.rs
@@ -5,7 +5,7 @@ use crate::{Token, TokenStringExt};
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct Handful {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Handful {
@@ -16,9 +16,7 @@ impl Default for Handful {
.then_one_or_more(SpaceOrHyphen)
.then_any_capitalization_of("of");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for Handful {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/have_pronoun.rs b/harper-core/src/linting/have_pronoun.rs
index 4e201f4cc..15ae53e53 100644
--- a/harper-core/src/linting/have_pronoun.rs
+++ b/harper-core/src/linting/have_pronoun.rs
@@ -5,7 +5,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct HavePronoun {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for HavePronoun {
@@ -18,9 +18,7 @@ impl Default for HavePronoun {
TokenKind::is_plural_pronoun,
);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for HavePronoun {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/have_take_a_look.rs b/harper-core/src/linting/have_take_a_look.rs
index 17876e41c..cf697fe16 100644
--- a/harper-core/src/linting/have_take_a_look.rs
+++ b/harper-core/src/linting/have_take_a_look.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct HaveTakeALook {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dialect: Dialect,
}
@@ -22,10 +22,7 @@ impl HaveTakeALook {
.t_ws()
.then_fixed_phrase("a look");
- Self {
- expr: Box::new(expr),
- dialect,
- }
+ Self { expr, dialect }
}
}
@@ -33,7 +30,7 @@ impl ExprLinter for HaveTakeALook {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/hedging.rs b/harper-core/src/linting/hedging.rs
index 6b0c30945..18cb7462f 100644
--- a/harper-core/src/linting/hedging.rs
+++ b/harper-core/src/linting/hedging.rs
@@ -7,7 +7,7 @@ use crate::{Token, TokenStringExt};
/// A linter that detects hedging language.
pub struct Hedging {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for Hedging {
@@ -19,8 +19,9 @@ impl Default for Hedging {
.map(|s| Box::new(FixedPhrase::from_phrase(s)) as Box<dyn Expr>)
.collect();
- let expr = Box::new(FirstMatchOf::new(patterns));
- Self { expr }
+ Self {
+ expr: FirstMatchOf::new(patterns),
+ }
}
}
@@ -28,7 +29,7 @@ impl ExprLinter for Hedging {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/hello_greeting.rs b/harper-core/src/linting/hello_greeting.rs
index a5c65fb58..03f6e7de3 100644
--- a/harper-core/src/linting/hello_greeting.rs
+++ b/harper-core/src/linting/hello_greeting.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct HelloGreeting {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for HelloGreeting {
@@ -20,9 +20,7 @@ impl Default for HelloGreeting {
)
.t_aco("halo");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for HelloGreeting {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/hereby.rs b/harper-core/src/linting/hereby.rs
index 6db78d314..9da7230e7 100644
--- a/harper-core/src/linting/hereby.rs
+++ b/harper-core/src/linting/hereby.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct Hereby {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Hereby {
@@ -17,9 +17,7 @@ impl Default for Hereby {
.then_whitespace()
.then_verb();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for Hereby {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/hope_youre.rs b/harper-core/src/linting/hope_youre.rs
index 6d33031b9..024e9978a 100644
--- a/harper-core/src/linting/hope_youre.rs
+++ b/harper-core/src/linting/hope_youre.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct HopeYoure {
- expr: Box<dyn crate::expr::Expr>,
+ expr: SequenceExpr,
}
impl Default for HopeYoure {
@@ -25,9 +25,7 @@ impl Default for HopeYoure {
.t_ws()
.then(loc);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -35,7 +33,7 @@ impl ExprLinter for HopeYoure {
type Unit = Chunk;
fn expr(&self) -> &dyn crate::expr::Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/how_to.rs b/harper-core/src/linting/how_to.rs
index a37c5480e..73b9cb2bd 100644
--- a/harper-core/src/linting/how_to.rs
+++ b/harper-core/src/linting/how_to.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct HowTo {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for HowTo {
@@ -41,9 +41,7 @@ impl Default for HowTo {
pattern.add(exceptions);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -51,7 +49,7 @@ impl ExprLinter for HowTo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/hyphenate_number_day.rs b/harper-core/src/linting/hyphenate_number_day.rs
index b4cb99d22..8e4013b32 100644
--- a/harper-core/src/linting/hyphenate_number_day.rs
+++ b/harper-core/src/linting/hyphenate_number_day.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct HyphenateNumberDay {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for HyphenateNumberDay {
@@ -26,9 +26,7 @@ impl Default for HyphenateNumberDay {
),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -36,7 +34,7 @@ impl ExprLinter for HyphenateNumberDay {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/i_am_agreement.rs b/harper-core/src/linting/i_am_agreement.rs
index e778a19e1..05b36c34f 100644
--- a/harper-core/src/linting/i_am_agreement.rs
+++ b/harper-core/src/linting/i_am_agreement.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct IAmAgreement {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for IAmAgreement {
@@ -25,9 +25,7 @@ impl Default for IAmAgreement {
Box::new(non_and_word_before_i_are),
]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -35,7 +33,7 @@ impl ExprLinter for IAmAgreement {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/if_wouldve.rs b/harper-core/src/linting/if_wouldve.rs
index 69fdf2a14..a6b64b8e4 100644
--- a/harper-core/src/linting/if_wouldve.rs
+++ b/harper-core/src/linting/if_wouldve.rs
@@ -6,28 +6,26 @@ use crate::token_string_ext::TokenStringExt;
use crate::{CharStringExt, Lint, Token};
pub struct IfWouldve {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for IfWouldve {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("if")
- .t_ws()
- .then(NominalPhrase)
- .t_ws()
- .then_any_of(vec![
- Box::new(
- SequenceExpr::word_set(&["would", "had"])
- .t_ws()
- .then_word_set(&["have", "of"]),
- ),
- Box::new(WordSet::new(&["would've", "wouldve", "had've", "hadve"])),
- ])
- .t_ws()
- .then_verb_past_participle_form(),
- ),
+ expr: SequenceExpr::aco("if")
+ .t_ws()
+ .then(NominalPhrase)
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(
+ SequenceExpr::word_set(&["would", "had"])
+ .t_ws()
+ .then_word_set(&["have", "of"]),
+ ),
+ Box::new(WordSet::new(&["would've", "wouldve", "had've", "hadve"])),
+ ])
+ .t_ws()
+ .then_verb_past_participle_form(),
}
}
}
@@ -36,7 +34,7 @@ impl ExprLinter for IfWouldve {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
/// Identifies and corrects incorrect conditional phrases like "would've", "would have", "would of", etc.
diff --git a/harper-core/src/linting/in_on_the_cards.rs b/harper-core/src/linting/in_on_the_cards.rs
index 3feedb03a..b28d2398d 100644
--- a/harper-core/src/linting/in_on_the_cards.rs
+++ b/harper-core/src/linting/in_on_the_cards.rs
@@ -9,7 +9,7 @@ use super::{ExprLinter, Lint};
use crate::linting::expr_linter::Chunk;
pub struct InOnTheCards {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dialect: Dialect,
}
@@ -33,10 +33,7 @@ impl InOnTheCards {
.t_aco(preposition)
.then_fixed_phrase(" the cards");
- Self {
- expr: Box::new(expr),
- dialect,
- }
+ Self { expr, dialect }
}
}
@@ -44,7 +41,7 @@ impl ExprLinter for InOnTheCards {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/initialism_linter.rs b/harper-core/src/linting/initialism_linter.rs
index 65c961c94..2a10d31c4 100644
--- a/harper-core/src/linting/initialism_linter.rs
+++ b/harper-core/src/linting/initialism_linter.rs
@@ -13,7 +13,7 @@ type InitialismPhrase = Vec<InitialismWord>;
/// A struct that can be composed to expand initialisms, respecting the capitalization of each
/// item.
pub struct InitialismLinter {
- expr: Box<dyn Expr>,
+ expr: Word,
/// The lowercase-normalized expansion of the initialism.
expansions_lower: Vec<InitialismPhrase>,
}
@@ -32,7 +32,7 @@ impl InitialismLinter {
.collect();
Self {
- expr: Box::new(Word::from_char_string(initialism.chars().collect())),
+ expr: Word::from_char_string(initialism.chars().collect()),
expansions_lower,
}
}
@@ -42,7 +42,7 @@ impl ExprLinter for InitialismLinter {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/interested_in.rs b/harper-core/src/linting/interested_in.rs
index b41b3dc94..381467c50 100644
--- a/harper-core/src/linting/interested_in.rs
+++ b/harper-core/src/linting/interested_in.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct InterestedIn {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for InterestedIn {
@@ -19,9 +19,7 @@ impl Default for InterestedIn {
&["around", "for", "through", "to", "within"],
);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -29,7 +27,7 @@ impl ExprLinter for InterestedIn {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/it_is.rs b/harper-core/src/linting/it_is.rs
index 8afa28c88..c21c9854a 100644
--- a/harper-core/src/linting/it_is.rs
+++ b/harper-core/src/linting/it_is.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct ItIs {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ItIs {
@@ -45,9 +45,7 @@ impl Default for ItIs {
)
.then_whitespace()
.then_preposition();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -55,7 +53,7 @@ impl ExprLinter for ItIs {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/it_looks_like_that.rs b/harper-core/src/linting/it_looks_like_that.rs
index 8a4c459be..f71dc4bdf 100644
--- a/harper-core/src/linting/it_looks_like_that.rs
+++ b/harper-core/src/linting/it_looks_like_that.rs
@@ -5,39 +5,37 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::token_string_ext::TokenStringExt;
pub struct ItLooksLikeThat {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ItLooksLikeThat {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::fixed_phrase("it looks like that")
- .then_whitespace()
- .then_kind_where(|kind| {
- // Heuristics on the word after "that" which show "that" was used
- // as a relative pronoun, which is a mistake
- let is_subj = kind.is_subject_pronoun();
- let is_ing = kind.is_verb_progressive_form();
- let is_definitely_rel_pron = is_subj || is_ing;
-
- // Heuristics on the word after "that" which show "that"
- // could possibly be a legitimate demonstrative pronoun or determiner
- // as a demonstrative pronoun or a determiner
- // which would not be a mistake.
- let is_v3psgpres = kind.is_verb_third_person_singular_present_form();
- // NOTE: we don't have .is_modal_verb() but maybe we need it now!
- let is_vmodal_or_aux = kind.is_auxiliary_verb();
- let is_vpret = kind.is_verb_simple_past_form();
- let is_noun = kind.is_noun();
- let is_oov = kind.is_oov();
-
- let maybe_demonstrative_or_determiner =
- is_v3psgpres || is_vmodal_or_aux || is_vpret || is_noun || is_oov;
-
- is_definitely_rel_pron || !maybe_demonstrative_or_determiner
- }),
- ),
+ expr: SequenceExpr::fixed_phrase("it looks like that")
+ .then_whitespace()
+ .then_kind_where(|kind| {
+ // Heuristics on the word after "that" which show "that" was used
+ // as a relative pronoun, which is a mistake
+ let is_subj = kind.is_subject_pronoun();
+ let is_ing = kind.is_verb_progressive_form();
+ let is_definitely_rel_pron = is_subj || is_ing;
+
+ // Heuristics on the word after "that" which show "that"
+ // could possibly be a legitimate demonstrative pronoun or determiner
+ // as a demonstrative pronoun or a determiner
+ // which would not be a mistake.
+ let is_v3psgpres = kind.is_verb_third_person_singular_present_form();
+ // NOTE: we don't have .is_modal_verb() but maybe we need it now!
+ let is_vmodal_or_aux = kind.is_auxiliary_verb();
+ let is_vpret = kind.is_verb_simple_past_form();
+ let is_noun = kind.is_noun();
+ let is_oov = kind.is_oov();
+
+ let maybe_demonstrative_or_determiner =
+ is_v3psgpres || is_vmodal_or_aux || is_vpret || is_noun || is_oov;
+
+ is_definitely_rel_pron || !maybe_demonstrative_or_determiner
+ }),
}
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for ItLooksLikeThat {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/it_would_be.rs b/harper-core/src/linting/it_would_be.rs
index 8c4a5d40e..112f18c48 100644
--- a/harper-core/src/linting/it_would_be.rs
+++ b/harper-core/src/linting/it_would_be.rs
@@ -1,6 +1,4 @@
-use crate::expr::Expr;
-use crate::expr::OwnedExprExt;
-use crate::expr::SequenceExpr;
+use crate::expr::{Expr, FirstMatchOf, OwnedExprExt, SequenceExpr};
use crate::linting::expr_linter::Chunk;
use crate::{
Token,
@@ -9,7 +7,7 @@ use crate::{
};
pub struct ItWouldBe {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for ItWouldBe {
@@ -57,9 +55,7 @@ impl Default for ItWouldBe {
.or(branch(true, false))
.or(branch(true, true));
- Self {
- expr: Box::new(combined),
- }
+ Self { expr: combined }
}
}
@@ -67,7 +63,7 @@ impl ExprLinter for ItWouldBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/its_contraction/proper_noun.rs b/harper-core/src/linting/its_contraction/proper_noun.rs
index e7713c1f5..297a5ad33 100644
--- a/harper-core/src/linting/its_contraction/proper_noun.rs
+++ b/harper-core/src/linting/its_contraction/proper_noun.rs
@@ -1,18 +1,16 @@
use std::ops::Range;
-use std::sync::Arc;
use harper_brill::UPOS;
use crate::{
Document, Token, TokenStringExt,
- expr::{Expr, ExprExt, ExprMap, OwnedExprExt, SequenceExpr},
+ expr::{ExprExt, ExprMap, OwnedExprExt, SequenceExpr},
linting::{Lint, LintKind, Linter, Suggestion},
patterns::{DerivedFrom, UPOSSet},
};
pub struct ProperNoun {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<Range<usize>>>,
+ expr: ExprMap<Range<usize>>,
}
impl Default for ProperNoun {
@@ -49,12 +47,7 @@ impl Default for ProperNoun {
2..3,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -101,7 +94,7 @@ impl ProperNoun {
}
}
- let range = self.map.lookup(0, matched_tokens, source)?.clone();
+ let range = self.expr.lookup(0, matched_tokens, source)?.clone();
let offending = matched_tokens.get(range.start)?;
let offender_text = offending.span.get_content(source);
diff --git a/harper-core/src/linting/its_possessive.rs b/harper-core/src/linting/its_possessive.rs
index 5cf923cf6..e1c88cd6b 100644
--- a/harper-core/src/linting/its_possessive.rs
+++ b/harper-core/src/linting/its_possessive.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use harper_brill::UPOS;
use crate::Token;
@@ -14,8 +12,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct ItsPossessive {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for ItsPossessive {
@@ -121,12 +118,7 @@ impl Default for ItsPossessive {
map.insert(special, 0);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -134,11 +126,11 @@ impl ExprLinter for ItsPossessive {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let offending_idx = self.map.lookup(0, matched_tokens, source).unwrap();
+ let offending_idx = self.expr.lookup(0, matched_tokens, source).unwrap();
let span = matched_tokens[*offending_idx].span;
Some(Lint {
diff --git a/harper-core/src/linting/jealous_of.rs b/harper-core/src/linting/jealous_of.rs
index 4a27f6734..b9b8c6c82 100644
--- a/harper-core/src/linting/jealous_of.rs
+++ b/harper-core/src/linting/jealous_of.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct JealousOf {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for JealousOf {
@@ -25,9 +25,7 @@ impl Default for JealousOf {
.then_optional(SequenceExpr::default().then_determiner().t_ws())
.then(valid_object);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -35,7 +33,7 @@ impl ExprLinter for JealousOf {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/johns_hopkins.rs b/harper-core/src/linting/johns_hopkins.rs
index 0ddf9b0c8..555dd4fc6 100644
--- a/harper-core/src/linting/johns_hopkins.rs
+++ b/harper-core/src/linting/johns_hopkins.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct JohnsHopkins {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for JohnsHopkins {
@@ -23,9 +23,7 @@ impl Default for JohnsHopkins {
.eq_ignore_ascii_case_str("hopkins")
});
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for JohnsHopkins {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/lead_rise_to.rs b/harper-core/src/linting/lead_rise_to.rs
index 689036dcf..d81bec202 100644
--- a/harper-core/src/linting/lead_rise_to.rs
+++ b/harper-core/src/linting/lead_rise_to.rs
@@ -5,19 +5,17 @@ use crate::{
};
pub struct LeadRiseTo {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LeadRiseTo {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["lead", "led", "leads", "leading"])
- .t_ws()
- .t_aco("rise")
- .t_ws()
- .t_aco("to"),
- ),
+ expr: SequenceExpr::word_set(&["lead", "led", "leads", "leading"])
+ .t_ws()
+ .t_aco("rise")
+ .t_ws()
+ .t_aco("to"),
}
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for LeadRiseTo {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/left_right_hand.rs b/harper-core/src/linting/left_right_hand.rs
index 666a6ae79..95d92c8b6 100644
--- a/harper-core/src/linting/left_right_hand.rs
+++ b/harper-core/src/linting/left_right_hand.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct LeftRightHand {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LeftRightHand {
@@ -17,9 +17,7 @@ impl Default for LeftRightHand {
.then_whitespace()
.then_noun();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for LeftRightHand {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/less_worse.rs b/harper-core/src/linting/less_worse.rs
index b2228533f..26f6f51fc 100644
--- a/harper-core/src/linting/less_worse.rs
+++ b/harper-core/src/linting/less_worse.rs
@@ -5,17 +5,15 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct LessWorse {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LessWorse {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["less", "least"])
- .t_ws_h()
- .then_word_set(&["worse", "worst"]),
- ),
+ expr: SequenceExpr::word_set(&["less", "least"])
+ .t_ws_h()
+ .then_word_set(&["worse", "worst"]),
}
}
}
@@ -24,7 +22,7 @@ impl ExprLinter for LessWorse {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/let_to_do.rs b/harper-core/src/linting/let_to_do.rs
index 81d65e9e8..dcbce3ea6 100644
--- a/harper-core/src/linting/let_to_do.rs
+++ b/harper-core/src/linting/let_to_do.rs
@@ -7,41 +7,39 @@ use super::{ExprLinter, Lint};
use crate::linting::expr_linter::Chunk;
pub struct LetToDo {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LetToDo {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["let", "lets", "let's"])
- .t_ws()
- .then_any_of(vec![
- Box::new(SequenceExpr::default().then_object_pronoun()),
- Box::new(SequenceExpr::word_set(&[
- // Elective existential indefinite pronouns
- "anybody",
- "anyone",
- // Universal indefinite pronouns
- "everybody",
- "everyone",
- // Negative indefinite pronouns (correct)
- "nobody",
- // Negative indefinite pronouns (incorrect)
- "noone",
- // Assertive existential indefinite pronouns
- "somebody",
- "someone",
- ])),
- Box::new(
- SequenceExpr::word_set(&["any", "every", "no", "some"])
- .t_ws()
- .then_word_set(&["body", "one"]),
- ),
- ])
- .t_ws()
- .t_aco("to"),
- ),
+ expr: SequenceExpr::word_set(&["let", "lets", "let's"])
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(SequenceExpr::default().then_object_pronoun()),
+ Box::new(SequenceExpr::word_set(&[
+ // Elective existential indefinite pronouns
+ "anybody",
+ "anyone",
+ // Universal indefinite pronouns
+ "everybody",
+ "everyone",
+ // Negative indefinite pronouns (correct)
+ "nobody",
+ // Negative indefinite pronouns (incorrect)
+ "noone",
+ // Assertive existential indefinite pronouns
+ "somebody",
+ "someone",
+ ])),
+ Box::new(
+ SequenceExpr::word_set(&["any", "every", "no", "some"])
+ .t_ws()
+ .then_word_set(&["body", "one"]),
+ ),
+ ])
+ .t_ws()
+ .t_aco("to"),
}
}
}
@@ -50,7 +48,7 @@ impl ExprLinter for LetToDo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/likewise.rs b/harper-core/src/linting/likewise.rs
index fcc8cc579..08c8be093 100644
--- a/harper-core/src/linting/likewise.rs
+++ b/harper-core/src/linting/likewise.rs
@@ -7,7 +7,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct Likewise {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for Likewise {
fn default() -> Self {
@@ -22,16 +22,14 @@ impl Default for Likewise {
.then_noun(),
));
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
impl ExprLinter for Likewise {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let span = matched_tokens.span()?;
diff --git a/harper-core/src/linting/look_down_ones_nose.rs b/harper-core/src/linting/look_down_ones_nose.rs
index 621c9c7f2..e09ad223a 100644
--- a/harper-core/src/linting/look_down_ones_nose.rs
+++ b/harper-core/src/linting/look_down_ones_nose.rs
@@ -5,21 +5,19 @@ use crate::{
};
pub struct LookDownOnesNose {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LookDownOnesNose {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["look", "looked", "looking", "looks"])
- .t_ws()
- .then_possessive_determiner()
- .t_ws()
- .then_word_set(&["nose", "noses"])
- .t_ws()
- .t_aco("down"),
- ),
+ expr: SequenceExpr::word_set(&["look", "looked", "looking", "looks"])
+ .t_ws()
+ .then_possessive_determiner()
+ .t_ws()
+ .then_word_set(&["nose", "noses"])
+ .t_ws()
+ .t_aco("down"),
}
}
}
@@ -55,7 +53,7 @@ impl ExprLinter for LookDownOnesNose {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
}
diff --git a/harper-core/src/linting/looking_forward_to.rs b/harper-core/src/linting/looking_forward_to.rs
index 54938fc8e..606a75c27 100644
--- a/harper-core/src/linting/looking_forward_to.rs
+++ b/harper-core/src/linting/looking_forward_to.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct LookingForwardTo {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for LookingForwardTo {
@@ -20,9 +20,7 @@ impl Default for LookingForwardTo {
// TODO: update the use the verb with progressive tense function later
.then_verb();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for LookingForwardTo {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/map_phrase_set_linter.rs b/harper-core/src/linting/map_phrase_set_linter.rs
index 86fbdcb30..f8a3997cb 100644
--- a/harper-core/src/linting/map_phrase_set_linter.rs
+++ b/harper-core/src/linting/map_phrase_set_linter.rs
@@ -9,7 +9,7 @@ use crate::{Token, TokenStringExt};
pub struct MapPhraseSetLinter<'a> {
description: String,
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
wrong_forms_to_correct_forms: &'a [(&'a str, &'a str)],
multi_wrong_forms_to_multi_correct_forms: &'a [(&'a [&'a str], &'a [&'a str])],
message: String,
@@ -23,7 +23,7 @@ impl<'a> MapPhraseSetLinter<'a> {
description: impl ToString,
lint_kind: Option<LintKind>,
) -> Self {
- let expr = Box::new(LongestMatchOf::new(
+ let expr = LongestMatchOf::new(
wrong_forms_to_correct_forms
.iter()
.map(|(wrong_form, _correct_form)| {
@@ -31,7 +31,7 @@ impl<'a> MapPhraseSetLinter<'a> {
expr
})
.collect(),
- ));
+ );
Self {
description: description.to_string(),
@@ -55,7 +55,7 @@ impl<'a> MapPhraseSetLinter<'a> {
lmo.add(FixedPhrase::from_phrase(wrong_form));
}
}
- let expr = Box::new(lmo);
+ let expr = lmo;
Self {
description: description.to_string(),
@@ -72,7 +72,7 @@ impl<'a> ExprLinter for MapPhraseSetLinter<'a> {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/missing_preposition.rs b/harper-core/src/linting/missing_preposition.rs
index 24835704c..c36f02699 100644
--- a/harper-core/src/linting/missing_preposition.rs
+++ b/harper-core/src/linting/missing_preposition.rs
@@ -12,7 +12,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct MissingPreposition {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for MissingPreposition {
@@ -34,9 +34,7 @@ impl Default for MissingPreposition {
.then_optional(AnyPattern)
.then_optional(AnyPattern);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -44,7 +42,7 @@ impl ExprLinter for MissingPreposition {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/misspell.rs b/harper-core/src/linting/misspell.rs
index 0a09f6402..75187b2d0 100644
--- a/harper-core/src/linting/misspell.rs
+++ b/harper-core/src/linting/misspell.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct Misspell {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Misspell {
@@ -19,9 +19,7 @@ impl Default for Misspell {
"spellings",
]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -29,7 +27,7 @@ impl ExprLinter for Misspell {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/mixed_bag.rs b/harper-core/src/linting/mixed_bag.rs
index 7c0f2eceb..4f260a33e 100644
--- a/harper-core/src/linting/mixed_bag.rs
+++ b/harper-core/src/linting/mixed_bag.rs
@@ -8,23 +8,21 @@ use crate::{
};
pub struct MixedBag {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for MixedBag {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::default()
- .then_kind_any_or_words(
- &[TokenKind::is_adjective, TokenKind::is_adverb] as &[_],
- &["a"],
- )
- .t_ws()
- .t_aco("mixed")
- .t_ws()
- .t_aco("bad"),
- ),
+ expr: SequenceExpr::default()
+ .then_kind_any_or_words(
+ &[TokenKind::is_adjective, TokenKind::is_adverb] as &[_],
+ &["a"],
+ )
+ .t_ws()
+ .t_aco("mixed")
+ .t_ws()
+ .t_aco("bad"),
}
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for MixedBag {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/modal_be_adjective.rs b/harper-core/src/linting/modal_be_adjective.rs
index ad1861bd9..29e4669ff 100644
--- a/harper-core/src/linting/modal_be_adjective.rs
+++ b/harper-core/src/linting/modal_be_adjective.rs
@@ -9,30 +9,28 @@ use crate::{
};
pub struct ModalBeAdjective {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ModalBeAdjective {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::with(ModalVerb::default())
- .t_ws()
- .then_kind_is_but_isnt_any_of_except(
- TokenKind::is_adjective,
- &[
- TokenKind::is_verb_lemma, // set
- TokenKind::is_adverb, // ever
- TokenKind::is_preposition, // on
- TokenKind::is_determiner, // all
- TokenKind::is_pronoun, // all
- ] as &[_],
- &[
- "backup", // adjective commonly misused as a verb
- "likely", // adjective but with special usage
- ] as &[_],
- ),
- ),
+ expr: SequenceExpr::with(ModalVerb::default())
+ .t_ws()
+ .then_kind_is_but_isnt_any_of_except(
+ TokenKind::is_adjective,
+ &[
+ TokenKind::is_verb_lemma, // set
+ TokenKind::is_adverb, // ever
+ TokenKind::is_preposition, // on
+ TokenKind::is_determiner, // all
+ TokenKind::is_pronoun, // all
+ ] as &[_],
+ &[
+ "backup", // adjective commonly misused as a verb
+ "likely", // adjective but with special usage
+ ] as &[_],
+ ),
}
}
}
@@ -41,7 +39,7 @@ impl ExprLinter for ModalBeAdjective {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/modal_of.rs b/harper-core/src/linting/modal_of.rs
index 5726abf8e..d7d8ee511 100644
--- a/harper-core/src/linting/modal_of.rs
+++ b/harper-core/src/linting/modal_of.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct ModalOf {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for ModalOf {
@@ -53,13 +53,13 @@ impl Default for ModalOf {
Lrc::new(SequenceExpr::with(anyword_might_of.clone()).then(ws_course.clone()));
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
Box::new(anyword_might_of_course),
Box::new(modal_of_course),
Box::new(anyword_might_of),
Box::new(noun_will_of_naive),
Box::new(modal_of),
- ])),
+ ]),
}
}
}
@@ -68,7 +68,7 @@ impl ExprLinter for ModalOf {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_toks: &[Token], source_chars: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/modal_seem.rs b/harper-core/src/linting/modal_seem.rs
index 848afbc66..d4aed8103 100644
--- a/harper-core/src/linting/modal_seem.rs
+++ b/harper-core/src/linting/modal_seem.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::linting::expr_linter::Chunk;
use crate::{
CharStringExt, Token,
@@ -14,8 +12,7 @@ struct MatchContext {
}
pub struct ModalSeem {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<MatchContext>>,
+ expr: ExprMap<MatchContext>,
}
impl ModalSeem {
@@ -58,12 +55,7 @@ impl Default for ModalSeem {
MatchContext::default(),
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -71,11 +63,11 @@ impl ExprLinter for ModalSeem {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let context = self.map.lookup(0, matched_tokens, source)?;
+ let context = self.expr.lookup(0, matched_tokens, source)?;
let seen_token = matched_tokens
.iter()
diff --git a/harper-core/src/linting/months.rs b/harper-core/src/linting/months.rs
index e86b88e28..e01cd5de4 100644
--- a/harper-core/src/linting/months.rs
+++ b/harper-core/src/linting/months.rs
@@ -23,7 +23,7 @@ const ALL_MONTHS: &[&str] = &[
];
pub struct Months {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Months {
@@ -79,9 +79,7 @@ impl Default for Months {
),
]));
- Self {
- expr: Box::new(month_expr),
- }
+ Self { expr: month_expr }
}
}
@@ -89,7 +87,7 @@ impl ExprLinter for Months {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/more_adjective.rs b/harper-core/src/linting/more_adjective.rs
index dfbe2fd7b..5297ea08f 100644
--- a/harper-core/src/linting/more_adjective.rs
+++ b/harper-core/src/linting/more_adjective.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct MoreAdjective<D> {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dict: D,
}
@@ -19,11 +19,9 @@ where
{
pub fn new(dict: D) -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["more", "most"])
- .t_ws()
- .then_positive_adjective(),
- ),
+ expr: SequenceExpr::word_set(&["more", "most"])
+ .t_ws()
+ .then_positive_adjective(),
dict,
}
}
@@ -47,7 +45,7 @@ where
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/more_better.rs b/harper-core/src/linting/more_better.rs
index df131b7ab..ef2d4e2b9 100644
--- a/harper-core/src/linting/more_better.rs
+++ b/harper-core/src/linting/more_better.rs
@@ -5,13 +5,13 @@ use crate::token::Token;
use crate::token_string_ext::TokenStringExt;
pub struct MoreBetter {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for MoreBetter {
fn default() -> Self {
Self {
- expr: Box::new(SequenceExpr::any_of(vec![
+ expr: SequenceExpr::any_of(vec![
Box::new(
SequenceExpr::default()
.t_aco("more")
@@ -24,7 +24,7 @@ impl Default for MoreBetter {
.t_ws()
.then_superlative_adjective(),
),
- ])),
+ ]),
}
}
}
@@ -33,7 +33,7 @@ impl ExprLinter for MoreBetter {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/most_number.rs b/harper-core/src/linting/most_number.rs
index 49bdc970e..4c9894ee8 100644
--- a/harper-core/src/linting/most_number.rs
+++ b/harper-core/src/linting/most_number.rs
@@ -7,13 +7,13 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct MostNumber {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for MostNumber {
fn default() -> Self {
Self {
- expr: Box::new(All::new(vec![
+ expr: All::new(vec![
// Main pattern
Box::new(
SequenceExpr::default()
@@ -29,7 +29,7 @@ impl Default for MostNumber {
.then_anything()
.t_aco("of"),
),
- ])),
+ ]),
}
}
}
@@ -38,7 +38,7 @@ impl ExprLinter for MostNumber {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/most_of_the_times.rs b/harper-core/src/linting/most_of_the_times.rs
index dd3b33bc5..a6137553a 100644
--- a/harper-core/src/linting/most_of_the_times.rs
+++ b/harper-core/src/linting/most_of_the_times.rs
@@ -5,20 +5,18 @@ use crate::patterns::Word;
use crate::{Lint, Token};
pub struct MostOfTheTimes {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for MostOfTheTimes {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::any_of(vec![
- Box::new(FixedPhrase::from_phrase("a lot")),
- Box::new(Word::new("most")),
- ])
- .t_ws()
- .then_fixed_phrase("of the times"),
- ),
+ expr: SequenceExpr::any_of(vec![
+ Box::new(FixedPhrase::from_phrase("a lot")),
+ Box::new(Word::new("most")),
+ ])
+ .t_ws()
+ .then_fixed_phrase("of the times"),
}
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for MostOfTheTimes {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/multiple_frequency_adverbs.rs b/harper-core/src/linting/multiple_frequency_adverbs.rs
index ca5ef60c7..20431c2f5 100644
--- a/harper-core/src/linting/multiple_frequency_adverbs.rs
+++ b/harper-core/src/linting/multiple_frequency_adverbs.rs
@@ -5,7 +5,7 @@ use crate::{
};
pub struct MultipleFrequencyAdverbs {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for MultipleFrequencyAdverbs {
@@ -19,13 +19,11 @@ impl Default for MultipleFrequencyAdverbs {
};
Self {
- expr: Box::new(
- SequenceExpr::default()
- .then(adverb_of_frequency)
- .then_optional_comma()
- .t_ws()
- .then(adverb_of_frequency),
- ),
+ expr: SequenceExpr::default()
+ .then(adverb_of_frequency)
+ .then_optional_comma()
+ .t_ws()
+ .then(adverb_of_frequency),
}
}
}
@@ -39,7 +37,7 @@ impl ExprLinter for MultipleFrequencyAdverbs {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/multiple_sequential_pronouns.rs b/harper-core/src/linting/multiple_sequential_pronouns.rs
index 5f7612479..6189cdf45 100644
--- a/harper-core/src/linting/multiple_sequential_pronouns.rs
+++ b/harper-core/src/linting/multiple_sequential_pronouns.rs
@@ -7,7 +7,7 @@ use crate::{
/// Linter that checks if multiple pronouns are being used right after each
/// other. This is a common mistake to make during the revision process.
pub struct MultipleSequentialPronouns {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl MultipleSequentialPronouns {
@@ -20,10 +20,8 @@ impl MultipleSequentialPronouns {
});
Self {
- expr: Box::new(
- SequenceExpr::with(pronouns.clone())
- .then_one_or_more(SequenceExpr::whitespace().then(pronouns.clone())),
- ),
+ expr: SequenceExpr::with(pronouns.clone())
+ .then_one_or_more(SequenceExpr::whitespace().then(pronouns.clone())),
}
}
}
@@ -32,7 +30,7 @@ impl ExprLinter for MultipleSequentialPronouns {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/nail_on_the_head.rs b/harper-core/src/linting/nail_on_the_head.rs
index 80b1d4e82..ca680e0c1 100644
--- a/harper-core/src/linting/nail_on_the_head.rs
+++ b/harper-core/src/linting/nail_on_the_head.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct NailOnTheHead {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for NailOnTheHead {
@@ -22,9 +22,7 @@ impl Default for NailOnTheHead {
.t_aco("the")
.then_whitespace()
.then(mis);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -32,7 +30,7 @@ impl ExprLinter for NailOnTheHead {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/need_to_noun.rs b/harper-core/src/linting/need_to_noun.rs
index abf25b7a5..2dd141efc 100644
--- a/harper-core/src/linting/need_to_noun.rs
+++ b/harper-core/src/linting/need_to_noun.rs
@@ -1,10 +1,6 @@
use crate::Token;
use crate::char_string::char_string;
-use crate::expr::Expr;
-use crate::expr::LongestMatchOf;
-use crate::expr::OwnedExprExt;
-use crate::expr::SequenceExpr;
-use crate::expr::UnlessStep;
+use crate::expr::{All, Expr, LongestMatchOf, OwnedExprExt, SequenceExpr, UnlessStep};
use crate::patterns::DerivedFrom;
use crate::patterns::WordSet;
@@ -12,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct NeedToNoun {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for NeedToNoun {
@@ -52,7 +48,7 @@ impl Default for NeedToNoun {
.then(a.or(b));
Self {
- expr: Box::new(expr.and(UnlessStep::new(exceptions, |_: &Token, _: &[char]| true))),
+ expr: expr.and(UnlessStep::new(exceptions, |_: &Token, _: &[char]| true)),
}
}
}
@@ -61,7 +57,7 @@ impl ExprLinter for NeedToNoun {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/no_longer.rs b/harper-core/src/linting/no_longer.rs
index 8532d534c..a12f0cd44 100644
--- a/harper-core/src/linting/no_longer.rs
+++ b/harper-core/src/linting/no_longer.rs
@@ -1,37 +1,35 @@
use crate::{
Lint, Token, TokenKind,
- expr::{Expr, OwnedExprExt, SequenceExpr},
+ expr::{All, Expr, OwnedExprExt, SequenceExpr},
linting::{Chunk, ExprLinter, LintKind, Suggestion},
};
pub struct NoLonger {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for NoLonger {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("not")
- .t_ws()
- .t_aco("longer")
- .then_optional(SequenceExpr::default().t_ws().then_kind_any(
- &[
- TokenKind::is_verb_lemma,
- TokenKind::is_verb_third_person_singular_present_form,
- TokenKind::is_verb_past_participle_form,
- TokenKind::is_verb_progressive_form,
- TokenKind::is_adjective,
- ][..],
- ))
- .and_not(
- SequenceExpr::anything()
- .t_any()
- .t_any()
- .t_any()
- .t_aco("than"),
- ),
- ),
+ expr: SequenceExpr::aco("not")
+ .t_ws()
+ .t_aco("longer")
+ .then_optional(SequenceExpr::default().t_ws().then_kind_any(
+ &[
+ TokenKind::is_verb_lemma,
+ TokenKind::is_verb_third_person_singular_present_form,
+ TokenKind::is_verb_past_participle_form,
+ TokenKind::is_verb_progressive_form,
+ TokenKind::is_adjective,
+ ][..],
+ ))
+ .and_not(
+ SequenceExpr::anything()
+ .t_any()
+ .t_any()
+ .t_any()
+ .t_aco("than"),
+ ),
}
}
}
@@ -40,7 +38,7 @@ impl ExprLinter for NoLonger {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn description(&self) -> &str {
diff --git a/harper-core/src/linting/no_match_for.rs b/harper-core/src/linting/no_match_for.rs
index ba9726f81..58cac3d6a 100644
--- a/harper-core/src/linting/no_match_for.rs
+++ b/harper-core/src/linting/no_match_for.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct NoMatchFor {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for NoMatchFor {
@@ -28,9 +28,7 @@ impl Default for NoMatchFor {
.then_whitespace()
.then_preposition();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -38,7 +36,7 @@ impl ExprLinter for NoMatchFor {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/nobody.rs b/harper-core/src/linting/nobody.rs
index 4bef53c1e..16cd5b5f8 100644
--- a/harper-core/src/linting/nobody.rs
+++ b/harper-core/src/linting/nobody.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct Nobody {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Nobody {
@@ -16,9 +16,7 @@ impl Default for Nobody {
.t_aco("body")
.then_whitespace()
.then_verb();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for Nobody {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/nominal_wants.rs b/harper-core/src/linting/nominal_wants.rs
index 89b6c3415..136c3b6af 100644
--- a/harper-core/src/linting/nominal_wants.rs
+++ b/harper-core/src/linting/nominal_wants.rs
@@ -12,7 +12,7 @@ use crate::{
};
pub struct NominalWants {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for NominalWants {
@@ -50,9 +50,7 @@ impl Default for NominalWants {
.then_whitespace()
.then(miss);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -60,7 +58,7 @@ impl ExprLinter for NominalWants {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/nor_modal_pronoun.rs b/harper-core/src/linting/nor_modal_pronoun.rs
index 88166ead7..3b05c6a82 100644
--- a/harper-core/src/linting/nor_modal_pronoun.rs
+++ b/harper-core/src/linting/nor_modal_pronoun.rs
@@ -6,19 +6,17 @@ use crate::{
};
pub struct NorModalPronoun {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for NorModalPronoun {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("nor")
- .t_ws()
- .then_subject_pronoun()
- .t_ws()
- .then(ModalVerb::with_common_errors()),
- ),
+ expr: SequenceExpr::aco("nor")
+ .t_ws()
+ .then_subject_pronoun()
+ .t_ws()
+ .then(ModalVerb::with_common_errors()),
}
}
}
@@ -31,7 +29,7 @@ impl ExprLinter for NorModalPronoun {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs b/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
index b96597140..d2851f3d9 100644
--- a/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
+++ b/harper-core/src/linting/noun_verb_confusion/effect_affect/affect_to_effect.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use harper_brill::UPOS;
use crate::linting::expr_linter::Chunk;
@@ -11,8 +9,7 @@ use crate::{
};
pub(super) struct AffectToEffect {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for AffectToEffect {
@@ -72,12 +69,7 @@ impl Default for AffectToEffect {
map.insert(great_affect, 2);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -85,11 +77,11 @@ impl ExprLinter for AffectToEffect {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let offending_index = *self.map.lookup(0, matched_tokens, source)?;
+ let offending_index = *self.expr.lookup(0, matched_tokens, source)?;
let target = &matched_tokens[offending_index];
let preceding = matched_tokens[..offending_index]
diff --git a/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs b/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
index d26bf8431..8891d3b61 100644
--- a/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
+++ b/harper-core/src/linting/noun_verb_confusion/effect_affect/effect_to_affect.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use harper_brill::UPOS;
use crate::linting::expr_linter::Chunk;
@@ -11,8 +9,7 @@ use crate::{
};
pub(super) struct EffectToAffect {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for EffectToAffect {
@@ -30,12 +27,7 @@ impl Default for EffectToAffect {
map.insert(context, 2);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -43,11 +35,11 @@ impl ExprLinter for EffectToAffect {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let offending_idx = *self.map.lookup(0, matched_tokens, source)?;
+ let offending_idx = *self.expr.lookup(0, matched_tokens, source)?;
let target = &matched_tokens[offending_idx];
let preceding = matched_tokens[..offending_idx]
diff --git a/harper-core/src/linting/obsess_preposition.rs b/harper-core/src/linting/obsess_preposition.rs
index edf05d05f..a1766ebcf 100644
--- a/harper-core/src/linting/obsess_preposition.rs
+++ b/harper-core/src/linting/obsess_preposition.rs
@@ -5,17 +5,15 @@ use crate::{
};
pub struct ObsessPreposition {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ObsessPreposition {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["obsess", "obsessed", "obsesses", "obsessing"])
- .t_ws()
- .then_preposition(),
- ),
+ expr: SequenceExpr::word_set(&["obsess", "obsessed", "obsesses", "obsessing"])
+ .t_ws()
+ .then_preposition(),
}
}
}
@@ -24,7 +22,7 @@ impl ExprLinter for ObsessPreposition {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn description(&self) -> &str {
diff --git a/harper-core/src/linting/of_course.rs b/harper-core/src/linting/of_course.rs
index 5743c6e39..c218cd9d0 100644
--- a/harper-core/src/linting/of_course.rs
+++ b/harper-core/src/linting/of_course.rs
@@ -1,7 +1,7 @@
//! Corrects common mistaken forms of "of course" while ignoring valid phrases like
//! "kind of curse".
-use crate::expr::{Expr, OwnedExprExt, SequenceExpr};
+use crate::expr::{Expr, LongestMatchOf, OwnedExprExt, SequenceExpr};
use crate::linting::expr_linter::Chunk;
use crate::{
Token, TokenStringExt,
@@ -10,7 +10,7 @@ use crate::{
};
pub struct OfCourse {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for OfCourse {
@@ -35,9 +35,7 @@ impl Default for OfCourse {
)
.or_longest(WordSet::new(&["ofcourse"]));
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -45,7 +43,7 @@ impl ExprLinter for OfCourse {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/oldest_in_the_book.rs b/harper-core/src/linting/oldest_in_the_book.rs
index 42e01a407..8fafd034e 100644
--- a/harper-core/src/linting/oldest_in_the_book.rs
+++ b/harper-core/src/linting/oldest_in_the_book.rs
@@ -5,7 +5,7 @@ use crate::{
};
pub struct OldestInTheBook {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for OldestInTheBook {
@@ -41,11 +41,9 @@ impl Default for OldestInTheBook {
let noun_phrase = SequenceExpr::optional(adjseq).then(nounseq);
Self {
- expr: Box::new(
- SequenceExpr::fixed_phrase("oldest ")
- .then(noun_phrase)
- .then_fixed_phrase(" in the books"),
- ),
+ expr: SequenceExpr::fixed_phrase("oldest ")
+ .then(noun_phrase)
+ .then_fixed_phrase(" in the books"),
}
}
}
@@ -54,7 +52,7 @@ impl ExprLinter for OldestInTheBook {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/on_floor.rs b/harper-core/src/linting/on_floor.rs
index b73df2078..595fc3ac5 100644
--- a/harper-core/src/linting/on_floor.rs
+++ b/harper-core/src/linting/on_floor.rs
@@ -10,7 +10,7 @@ use crate::{
};
pub struct OnFloor {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for OnFloor {
@@ -48,9 +48,7 @@ impl Default for OnFloor {
),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -58,7 +56,7 @@ impl ExprLinter for OnFloor {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/once_or_twice.rs b/harper-core/src/linting/once_or_twice.rs
index 18c21c2bf..9be0a624d 100644
--- a/harper-core/src/linting/once_or_twice.rs
+++ b/harper-core/src/linting/once_or_twice.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct OnceOrTwice {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for OnceOrTwice {
@@ -17,9 +17,7 @@ impl Default for OnceOrTwice {
.then_whitespace()
.t_aco("twice");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for OnceOrTwice {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/one_and_the_same.rs b/harper-core/src/linting/one_and_the_same.rs
index fb7356938..e3342c9e4 100644
--- a/harper-core/src/linting/one_and_the_same.rs
+++ b/harper-core/src/linting/one_and_the_same.rs
@@ -8,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct OneAndTheSame {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for OneAndTheSame {
@@ -16,7 +16,7 @@ impl Default for OneAndTheSame {
let one_in_the_same = Lrc::new(FixedPhrase::from_phrase("one in the same"));
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
Box::new(
SequenceExpr::word_set(&["are", "were"])
.t_ws()
@@ -27,7 +27,7 @@ impl Default for OneAndTheSame {
.t_ws()
.t_aco("as"),
),
- ])),
+ ]),
}
}
}
@@ -40,7 +40,7 @@ impl ExprLinter for OneAndTheSame {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/one_of_the_singular.rs b/harper-core/src/linting/one_of_the_singular.rs
index 3378bc2fe..59102b625 100644
--- a/harper-core/src/linting/one_of_the_singular.rs
+++ b/harper-core/src/linting/one_of_the_singular.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct OneOfTheSingular<D: Dictionary + 'static> {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dict: D,
}
@@ -41,10 +41,8 @@ impl<D: Dictionary + 'static> OneOfTheSingular<D> {
.then_zero_or_more_spaced(SequenceExpr::default().then_my_noun_or_adjective());
Self {
- expr: Box::new(
- SequenceExpr::fixed_phrase("one of the ")
- .then(SequenceExpr::optional(advs.t_ws()).then(adj_or_nouns)),
- ),
+ expr: SequenceExpr::fixed_phrase("one of the ")
+ .then(SequenceExpr::optional(advs.t_ws()).then(adj_or_nouns)),
dict,
}
}
@@ -144,7 +142,7 @@ impl<D: Dictionary + 'static> ExprLinter for OneOfTheSingular<D> {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
}
diff --git a/harper-core/src/linting/open_compounds.rs b/harper-core/src/linting/open_compounds.rs
index bb37fa638..2d2929575 100644
--- a/harper-core/src/linting/open_compounds.rs
+++ b/harper-core/src/linting/open_compounds.rs
@@ -6,7 +6,7 @@ use crate::linting::expr_linter::Chunk;
use hashbrown::HashMap;
pub struct OpenCompounds {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
compound_to_phrase: HashMap<String, String>,
}
@@ -50,12 +50,12 @@ impl Default for OpenCompounds {
.then_anything();
Self {
- expr: Box::new(LongestMatchOf::new(vec![
+ expr: LongestMatchOf::new(vec![
Box::new(with_prev_and_next),
Box::new(with_prev),
Box::new(with_next),
Box::new(compound),
- ])),
+ ]),
compound_to_phrase,
}
}
@@ -65,7 +65,7 @@ impl ExprLinter for OpenCompounds {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_toks: &[Token], source_chars: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/open_the_light.rs b/harper-core/src/linting/open_the_light.rs
index d22ff8c57..c3bcd5168 100644
--- a/harper-core/src/linting/open_the_light.rs
+++ b/harper-core/src/linting/open_the_light.rs
@@ -10,7 +10,7 @@ use super::{ExprLinter, Lint};
use crate::linting::expr_linter::Chunk;
pub struct OpenTheLight {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for OpenTheLight {
@@ -46,10 +46,10 @@ impl Default for OpenTheLight {
.t_ws()
.then_noun();
- let expr = Box::new(LongestMatchOf::new(vec![
+ let expr = LongestMatchOf::new(vec![
Box::new(open_the_device),
Box::new(open_the_device_then_noun),
- ]));
+ ]);
Self { expr }
}
@@ -59,7 +59,7 @@ impl ExprLinter for OpenTheLight {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/orthographic_consistency.rs b/harper-core/src/linting/orthographic_consistency.rs
index 3034b1c0e..76d45b48d 100644
--- a/harper-core/src/linting/orthographic_consistency.rs
+++ b/harper-core/src/linting/orthographic_consistency.rs
@@ -1,23 +1,22 @@
-use crate::linting::{LintKind, Suggestion};
use std::sync::Arc;
-use crate::expr::Expr;
-use crate::spell::{Dictionary, FstDictionary};
-use crate::{OrthFlags, Token};
-
-use super::{ExprLinter, Lint};
-use crate::linting::expr_linter::Chunk;
+use crate::{
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Chunk},
+ spell::{Dictionary, FstDictionary},
+ {OrthFlags, Token},
+};
pub struct OrthographicConsistency {
dict: Arc<FstDictionary>,
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl OrthographicConsistency {
pub fn new() -> Self {
Self {
dict: FstDictionary::curated(),
- expr: Box::new(|tok: &Token, _: &[char]| tok.kind.is_word()),
+ expr: SequenceExpr::any_word(),
}
}
}
@@ -36,7 +35,7 @@ impl ExprLinter for OrthographicConsistency {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/ought_to_be.rs b/harper-core/src/linting/ought_to_be.rs
index fa961e6b4..f7d7bb17d 100644
--- a/harper-core/src/linting/ought_to_be.rs
+++ b/harper-core/src/linting/ought_to_be.rs
@@ -11,14 +11,11 @@ use crate::{
/// Legitimate phrasal-verb uses like `turn out to be`, `work out to be`, or
/// `make it out to be` are ignored.
pub struct OughtToBe {
- expr: Box<dyn Expr>,
- map: std::sync::Arc<ExprMap<usize>>, // index of the `out` token within the match
+ expr: ExprMap<usize>, // index of the `out` token within the match
}
impl Default for OughtToBe {
fn default() -> Self {
- use std::sync::Arc;
-
// We’ll construct three branches and record where the `out` token sits in each.
// 1) non-verb word + pronoun + "out to be" → index of `out` = 4 tokens after start
// [word(!verb)] [ws] [pronoun] [ws] [out] [ws] [to] [ws] [be]
@@ -50,12 +47,7 @@ impl Default for OughtToBe {
map.insert(branch_anchor_pronoun, 2);
map.insert(branch_punct_pronoun, 4);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -63,12 +55,12 @@ impl ExprLinter for OughtToBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched: &[Token], source: &[char]) -> Option<Lint> {
// Find which branch matched and where the `out` token sits.
- let out_index = *self.map.lookup(0, matched, source)?;
+ let out_index = *self.expr.lookup(0, matched, source)?;
let out_tok = matched.get(out_index)?;
let replace_span = out_tok.span; // only replace the word `out`
let original = replace_span.get_content(source);
diff --git a/harper-core/src/linting/out_of_date.rs b/harper-core/src/linting/out_of_date.rs
index 5ea014e50..966961cc9 100644
--- a/harper-core/src/linting/out_of_date.rs
+++ b/harper-core/src/linting/out_of_date.rs
@@ -7,7 +7,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct OutOfDate {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for OutOfDate {
@@ -18,9 +18,7 @@ impl Default for OutOfDate {
Box::new(FixedPhrase::from_phrase("out of-date")),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for OutOfDate {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/oxford_comma.rs b/harper-core/src/linting/oxford_comma.rs
index 18c5eed1b..a4950127a 100644
--- a/harper-core/src/linting/oxford_comma.rs
+++ b/harper-core/src/linting/oxford_comma.rs
@@ -1,4 +1,3 @@
-use crate::expr::Expr;
use crate::expr::ExprExt;
use crate::expr::OwnedExprExt;
use crate::expr::SequenceExpr;
@@ -7,7 +6,7 @@ use crate::{Lrc, Token, TokenStringExt, linting::Linter};
use super::{super::Lint, LintKind, Suggestion};
pub struct OxfordComma {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for OxfordComma {
@@ -32,9 +31,7 @@ impl Default for OxfordComma {
.then_whitespace()
.then(item.clone());
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
diff --git a/harper-core/src/linting/oxymorons.rs b/harper-core/src/linting/oxymorons.rs
index aeced36bd..1a3172ccc 100644
--- a/harper-core/src/linting/oxymorons.rs
+++ b/harper-core/src/linting/oxymorons.rs
@@ -7,7 +7,7 @@ use crate::{Token, TokenStringExt};
/// A linter that flags oxymoronic phrases.
pub struct Oxymorons {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Oxymorons {
@@ -39,8 +39,9 @@ impl Oxymorons {
.map(|s| Box::new(FixedPhrase::from_phrase(s)) as Box<dyn Expr>)
.collect();
- let expr = Box::new(FirstMatchOf::new(exprs));
- Self { expr }
+ Self {
+ expr: FirstMatchOf::new(exprs),
+ }
}
}
@@ -55,7 +56,7 @@ impl ExprLinter for Oxymorons {
/// Returns the underlying pattern.
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/pique_interest.rs b/harper-core/src/linting/pique_interest.rs
index fff0612a5..fbd9bc3d0 100644
--- a/harper-core/src/linting/pique_interest.rs
+++ b/harper-core/src/linting/pique_interest.rs
@@ -7,7 +7,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct PiqueInterest {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for PiqueInterest {
@@ -22,9 +22,7 @@ impl Default for PiqueInterest {
.then_whitespace()
.t_aco("interest");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for PiqueInterest {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/plural_wrong_word_of_phrase.rs b/harper-core/src/linting/plural_wrong_word_of_phrase.rs
index 20a049f82..232276f9b 100644
--- a/harper-core/src/linting/plural_wrong_word_of_phrase.rs
+++ b/harper-core/src/linting/plural_wrong_word_of_phrase.rs
@@ -5,7 +5,7 @@ use crate::{
};
pub struct PluralWrongWordOfPhrase {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
// If a noun needs other than an -s suffix to be pluralized, include it as the 2nd array element.
@@ -60,7 +60,7 @@ impl Default for PluralWrongWordOfPhrase {
}
Self {
- expr: Box::new(SequenceExpr::any_of(mistakes)),
+ expr: SequenceExpr::any_of(mistakes),
}
}
}
@@ -73,7 +73,7 @@ impl ExprLinter for PluralWrongWordOfPhrase {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/possessive_noun.rs b/harper-core/src/linting/possessive_noun.rs
index b282ac948..522837d85 100644
--- a/harper-core/src/linting/possessive_noun.rs
+++ b/harper-core/src/linting/possessive_noun.rs
@@ -8,7 +8,7 @@ use crate::spell::Dictionary;
use crate::{Token, TokenKind};
pub struct PossessiveNoun<D> {
- expr: Box<dyn Expr>,
+ expr: All,
dict: D,
}
@@ -34,11 +34,11 @@ where
.then_unless(WordSet::new(&["form", "go"]));
Self {
- expr: Box::new(All::new(vec![
+ expr: All::new(vec![
Box::new(expr),
Box::new(additional_req),
Box::new(exceptions),
- ])),
+ ]),
dict,
}
}
@@ -51,7 +51,7 @@ where
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/possessive_your.rs b/harper-core/src/linting/possessive_your.rs
index 2ca0dcd06..713dc2aba 100644
--- a/harper-core/src/linting/possessive_your.rs
+++ b/harper-core/src/linting/possessive_your.rs
@@ -8,7 +8,7 @@ use crate::{
};
pub struct PossessiveYour {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for PossessiveYour {
@@ -21,9 +21,7 @@ impl Default for PossessiveYour {
&["guys", "what's"],
);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -31,7 +29,7 @@ impl ExprLinter for PossessiveYour {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/progressive_needs_be.rs b/harper-core/src/linting/progressive_needs_be.rs
index 313b4b30d..d0e3676af 100644
--- a/harper-core/src/linting/progressive_needs_be.rs
+++ b/harper-core/src/linting/progressive_needs_be.rs
@@ -5,7 +5,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct ProgressiveNeedsBe {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ProgressiveNeedsBe {
@@ -26,9 +26,7 @@ impl Default for ProgressiveNeedsBe {
let expr = SequenceExpr::any_of(vec![Box::new(contracted), Box::new(non_contracted)]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -36,7 +34,7 @@ impl ExprLinter for ProgressiveNeedsBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/pronoun_are.rs b/harper-core/src/linting/pronoun_are.rs
index 758c38178..4324349f9 100644
--- a/harper-core/src/linting/pronoun_are.rs
+++ b/harper-core/src/linting/pronoun_are.rs
@@ -7,7 +7,7 @@ use crate::{
/// Corrects the shorthand `r` after plural first- and second-person pronouns.
pub struct PronounAre {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for PronounAre {
@@ -23,9 +23,7 @@ impl Default for PronounAre {
.t_ws()
.t_aco("r");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for PronounAre {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/pronoun_inflection_be.rs b/harper-core/src/linting/pronoun_inflection_be.rs
index 34eb77210..938510d99 100644
--- a/harper-core/src/linting/pronoun_inflection_be.rs
+++ b/harper-core/src/linting/pronoun_inflection_be.rs
@@ -9,7 +9,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct PronounInflectionBe {
- expr: Box<dyn Expr>,
+ expr: All,
map: Lrc<ExprMap<&'static str>>,
}
@@ -125,10 +125,7 @@ impl PronounInflectionBe {
all.add(map.clone());
all.add(|tok: &Token, _: &[char]| tok.kind.is_upos(UPOS::PRON));
- Self {
- expr: Box::new(all),
- map,
- }
+ Self { expr: all, map }
}
}
@@ -142,7 +139,7 @@ impl ExprLinter for PronounInflectionBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/pronoun_knew.rs b/harper-core/src/linting/pronoun_knew.rs
index e48d56566..55d53af45 100644
--- a/harper-core/src/linting/pronoun_knew.rs
+++ b/harper-core/src/linting/pronoun_knew.rs
@@ -10,7 +10,7 @@ use crate::{
};
pub struct PronounKnew {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
trait PronounKnewExt {
@@ -52,7 +52,7 @@ impl Default for PronounKnew {
]);
Self {
- expr: Box::new(combined_pattern),
+ expr: combined_pattern,
}
}
}
@@ -61,7 +61,7 @@ impl ExprLinter for PronounKnew {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/pronoun_verb_agreement.rs b/harper-core/src/linting/pronoun_verb_agreement.rs
index d57bda90c..ada135a37 100644
--- a/harper-core/src/linting/pronoun_verb_agreement.rs
+++ b/harper-core/src/linting/pronoun_verb_agreement.rs
@@ -31,7 +31,7 @@ static DITRANSITIVE: &[&str] = &[
];
pub struct PronounVerbAgreement<D> {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
dict: D,
}
@@ -81,7 +81,7 @@ where
};
Self {
- expr: Box::new(FirstMatchOf::new(vec![
+ expr: FirstMatchOf::new(vec![
// One Expr for the "I walks" type:
Box::new(non_3p_sing_pres_pron_with_3p_sing_pres_verb),
// Two Expr's for the "he walk" type:
@@ -91,7 +91,7 @@ where
.then(verb_lemma),
),
Box::new(SequenceExpr::aco("it").t_ws().t_aco("don't")),
- ])),
+ ]),
dict,
}
}
@@ -176,7 +176,7 @@ where
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/quantifier_needs_of.rs b/harper-core/src/linting/quantifier_needs_of.rs
index 4cebd9b85..8adddb905 100644
--- a/harper-core/src/linting/quantifier_needs_of.rs
+++ b/harper-core/src/linting/quantifier_needs_of.rs
@@ -6,7 +6,7 @@ use crate::linting::expr_linter::Chunk;
/// Flags phrases like `a couple months` → should be `a couple **of** months`.
pub struct QuantifierNeedsOf {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for QuantifierNeedsOf {
@@ -18,9 +18,7 @@ impl Default for QuantifierNeedsOf {
.t_ws()
.then_plural_nominal();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for QuantifierNeedsOf {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/quantifier_numeral_conflict.rs b/harper-core/src/linting/quantifier_numeral_conflict.rs
index dd48aaa57..3d6ddae51 100644
--- a/harper-core/src/linting/quantifier_numeral_conflict.rs
+++ b/harper-core/src/linting/quantifier_numeral_conflict.rs
@@ -6,13 +6,13 @@ use crate::token_string_ext::TokenStringExt;
use crate::{CharStringExt, Lint, Token};
pub struct QuantifierNumeralConflict {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for QuantifierNumeralConflict {
fn default() -> Self {
Self {
- expr: Box::new(All::new(vec![
+ expr: All::new(vec![
Box::new(
SequenceExpr::default()
.then_quantifier()
@@ -30,7 +30,7 @@ impl Default for QuantifierNumeralConflict {
.t_aco("one"),
),
]))),
- ])),
+ ]),
}
}
}
@@ -39,7 +39,7 @@ impl ExprLinter for QuantifierNumeralConflict {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/quite_quiet.rs b/harper-core/src/linting/quite_quiet.rs
index c46010107..944a6731a 100644
--- a/harper-core/src/linting/quite_quiet.rs
+++ b/harper-core/src/linting/quite_quiet.rs
@@ -4,7 +4,7 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::{CharStringExt, Token, TokenKind, TokenStringExt};
pub struct QuiteQuiet {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for QuiteQuiet {
@@ -42,11 +42,11 @@ impl Default for QuiteQuiet {
.t_aco("quite");
Self {
- expr: Box::new(FirstMatchOf::new(vec![
+ expr: FirstMatchOf::new(vec![
Box::new(quiet_word),
Box::new(negative_contraction_quiet),
Box::new(adverb_quite),
- ])),
+ ]),
}
}
}
@@ -55,7 +55,7 @@ impl ExprLinter for QuiteQuiet {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/redundant_acronyms.rs b/harper-core/src/linting/redundant_acronyms.rs
index c5140115b..9a2b3fa7e 100644
--- a/harper-core/src/linting/redundant_acronyms.rs
+++ b/harper-core/src/linting/redundant_acronyms.rs
@@ -19,7 +19,7 @@ const ACRONYMS: &[(&str, &[&str], &str)] = &[
];
pub struct RedundantAcronyms {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for RedundantAcronyms {
@@ -40,7 +40,7 @@ impl Default for RedundantAcronyms {
.collect();
Self {
- expr: Box::new(FirstMatchOf::new(exprs)),
+ expr: FirstMatchOf::new(exprs),
}
}
}
@@ -49,7 +49,7 @@ impl ExprLinter for RedundantAcronyms {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/redundant_additive_adverbs.rs b/harper-core/src/linting/redundant_additive_adverbs.rs
index 10393a0d8..2137f038d 100644
--- a/harper-core/src/linting/redundant_additive_adverbs.rs
+++ b/harper-core/src/linting/redundant_additive_adverbs.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct RedundantAdditiveAdverbs {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for RedundantAdditiveAdverbs {
@@ -25,7 +25,7 @@ impl Default for RedundantAdditiveAdverbs {
.then_optional(SequenceExpr::whitespace().t_aco("as"));
Self {
- expr: Box::new(multiple_additive_adverbs),
+ expr: multiple_additive_adverbs,
}
}
}
@@ -34,7 +34,7 @@ impl ExprLinter for RedundantAdditiveAdverbs {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/regionalisms.rs b/harper-core/src/linting/regionalisms.rs
index b9bc2e1d4..ca4573217 100644
--- a/harper-core/src/linting/regionalisms.rs
+++ b/harper-core/src/linting/regionalisms.rs
@@ -604,7 +604,7 @@ const REGIONAL_TERMS: &[Term<'_>] = &[
];
pub struct Regionalisms {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
dialect: Dialect,
}
@@ -617,7 +617,7 @@ impl Regionalisms {
.collect();
Self {
- expr: Box::new(FirstMatchOf::new(terms)),
+ expr: FirstMatchOf::new(terms),
dialect,
}
}
@@ -627,7 +627,7 @@ impl ExprLinter for Regionalisms {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/respond.rs b/harper-core/src/linting/respond.rs
index 573e7884b..7f40c43b2 100644
--- a/harper-core/src/linting/respond.rs
+++ b/harper-core/src/linting/respond.rs
@@ -1,13 +1,10 @@
-use std::sync::Arc;
-
use crate::Token;
use crate::expr::{Expr, ExprMap, SequenceExpr};
use crate::linting::expr_linter::Chunk;
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
pub struct Respond {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for Respond {
@@ -52,12 +49,7 @@ impl Default for Respond {
6,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -65,11 +57,11 @@ impl ExprLinter for Respond {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let response_index = *self.map.lookup(0, matched_tokens, source)?;
+ let response_index = *self.expr.lookup(0, matched_tokens, source)?;
let response_token = matched_tokens.get(response_index)?;
Some(Lint {
diff --git a/harper-core/src/linting/right_click.rs b/harper-core/src/linting/right_click.rs
index c5edc0e63..2df17fe1f 100644
--- a/harper-core/src/linting/right_click.rs
+++ b/harper-core/src/linting/right_click.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::{
Token, TokenStringExt,
expr::{Expr, ExprMap, SequenceExpr},
@@ -9,8 +7,7 @@ use crate::{
};
pub struct RightClick {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl Default for RightClick {
@@ -24,12 +21,7 @@ impl Default for RightClick {
0,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -37,11 +29,11 @@ impl ExprLinter for RightClick {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let start_idx = *self.map.lookup(0, matched_tokens, source)?;
+ let start_idx = *self.expr.lookup(0, matched_tokens, source)?;
let click_idx = matched_tokens.len().checked_sub(1)?;
let span = matched_tokens.get(start_idx..=click_idx)?.span()?;
let template = span.get_content(source);
diff --git a/harper-core/src/linting/roller_skated.rs b/harper-core/src/linting/roller_skated.rs
index d7e24c488..3bd18faa0 100644
--- a/harper-core/src/linting/roller_skated.rs
+++ b/harper-core/src/linting/roller_skated.rs
@@ -1,5 +1,3 @@
-use std::sync::Arc;
-
use crate::linting::expr_linter::Chunk;
use crate::{
Token, TokenKind, TokenStringExt,
@@ -9,8 +7,7 @@ use crate::{
/// Suggests hyphenating the past tense of `roller-skate`.
pub struct RollerSkated {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<usize>>,
+ expr: ExprMap<usize>,
}
impl RollerSkated {
@@ -57,12 +54,7 @@ impl Default for RollerSkated {
0,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -70,11 +62,11 @@ impl ExprLinter for RollerSkated {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let roller_idx = *self.map.lookup(0, matched_tokens, source)?;
+ let roller_idx = *self.expr.lookup(0, matched_tokens, source)?;
let skated_idx = roller_idx.checked_add(2)?;
let window = matched_tokens.get(roller_idx..=skated_idx)?;
let span = window.span()?;
diff --git a/harper-core/src/linting/safe_to_save.rs b/harper-core/src/linting/safe_to_save.rs
index fdbcdf39d..089224236 100644
--- a/harper-core/src/linting/safe_to_save.rs
+++ b/harper-core/src/linting/safe_to_save.rs
@@ -1,6 +1,7 @@
use harper_brill::UPOS;
use crate::expr::Expr;
+use crate::expr::LongestMatchOf;
use crate::expr::OwnedExprExt;
use crate::expr::SequenceExpr;
use crate::linting::expr_linter::Chunk;
@@ -11,7 +12,7 @@ use crate::{
};
pub struct SafeToSave {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for SafeToSave {
@@ -32,9 +33,7 @@ impl Default for SafeToSave {
let pattern = with_adv.or_longest(without_adv);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -42,7 +41,7 @@ impl ExprLinter for SafeToSave {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/save_to_safe.rs b/harper-core/src/linting/save_to_safe.rs
index 9ce463024..7b7d1c641 100644
--- a/harper-core/src/linting/save_to_safe.rs
+++ b/harper-core/src/linting/save_to_safe.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct SaveToSafe {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SaveToSafe {
@@ -21,9 +21,7 @@ impl Default for SaveToSafe {
.t_aco("to")
.then_whitespace()
.then_verb();
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -31,7 +29,7 @@ impl ExprLinter for SaveToSafe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/shoot_oneself_in_the_foot.rs b/harper-core/src/linting/shoot_oneself_in_the_foot.rs
index ddd45ec9c..72059563a 100644
--- a/harper-core/src/linting/shoot_oneself_in_the_foot.rs
+++ b/harper-core/src/linting/shoot_oneself_in_the_foot.rs
@@ -9,7 +9,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct ShootOneselfInTheFoot {
- pattern: Box<dyn Expr>,
+ pattern: SequenceExpr,
}
impl Default for ShootOneselfInTheFoot {
@@ -27,9 +27,7 @@ impl Default for ShootOneselfInTheFoot {
.then_determiner()
.t_ws()
.then(body_parts);
- Self {
- pattern: Box::new(pattern),
- }
+ Self { pattern }
}
}
@@ -37,7 +35,7 @@ impl ExprLinter for ShootOneselfInTheFoot {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.pattern.as_ref()
+ &self.pattern
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/simple_past_to_past_participle.rs b/harper-core/src/linting/simple_past_to_past_participle.rs
index 39143cdec..a111e80d9 100644
--- a/harper-core/src/linting/simple_past_to_past_participle.rs
+++ b/harper-core/src/linting/simple_past_to_past_participle.rs
@@ -9,13 +9,13 @@ use crate::{
/// Corrects simple past tense verbs to past participle after auxiliary verbs like "have" or "be".
pub struct SimplePastToPastParticiple {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for SimplePastToPastParticiple {
fn default() -> Self {
Self {
- expr: Box::new(All::new(vec![
+ expr: All::new(vec![
// positive: the general case
Box::new(
SequenceExpr::any_of(vec![
@@ -50,7 +50,7 @@ impl Default for SimplePastToPastParticiple {
.then_word_set(&["came", "did", "went"]),
),
]))),
- ])),
+ ]),
}
}
}
@@ -59,7 +59,7 @@ impl ExprLinter for SimplePastToPastParticiple {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/since_duration.rs b/harper-core/src/linting/since_duration.rs
index d3ebb29db..b9000a286 100644
--- a/harper-core/src/linting/since_duration.rs
+++ b/harper-core/src/linting/since_duration.rs
@@ -20,22 +20,20 @@ fn match_case_string<'a>(template: &[char], variants: [&'a [char]; 3]) -> &'a [c
}
pub struct SinceDuration {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SinceDuration {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::any_capitalization_of("since")
- .then_whitespace()
- .then(DurationExpr)
- .then_optional(
- SequenceExpr::default()
- .t_ws()
- .then_word_set(&["ago", "old"]),
- ),
- ),
+ expr: SequenceExpr::any_capitalization_of("since")
+ .then_whitespace()
+ .then(DurationExpr)
+ .then_optional(
+ SequenceExpr::default()
+ .t_ws()
+ .then_word_set(&["ago", "old"]),
+ ),
}
}
}
@@ -44,7 +42,7 @@ impl ExprLinter for SinceDuration {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/single_be.rs b/harper-core/src/linting/single_be.rs
index fb01bfdba..fa454a7c8 100644
--- a/harper-core/src/linting/single_be.rs
+++ b/harper-core/src/linting/single_be.rs
@@ -57,7 +57,7 @@ fn looks_like_be_contraction(token: &Token, source: &[char]) -> bool {
}
pub struct SingleBe {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SingleBe {
@@ -74,9 +74,7 @@ impl Default for SingleBe {
.t_ws()
.then(be_like_expr());
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -84,7 +82,7 @@ impl ExprLinter for SingleBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/some_without_article.rs b/harper-core/src/linting/some_without_article.rs
index 8abea2eb5..94ee43a4e 100644
--- a/harper-core/src/linting/some_without_article.rs
+++ b/harper-core/src/linting/some_without_article.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct SomeWithoutArticle {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SomeWithoutArticle {
@@ -15,9 +15,7 @@ impl Default for SomeWithoutArticle {
.t_ws()
.then_any_capitalization_of("some");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -25,7 +23,7 @@ impl ExprLinter for SomeWithoutArticle {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/something_is.rs b/harper-core/src/linting/something_is.rs
index 8c43cfd77..39513415a 100644
--- a/harper-core/src/linting/something_is.rs
+++ b/harper-core/src/linting/something_is.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct SomethingIs {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SomethingIs {
@@ -18,9 +18,7 @@ impl Default for SomethingIs {
.then_optional(SequenceExpr::default().then_one_or_more_adverbs().t_ws())
.then_kind_any(&[TokenKind::is_verb_progressive_form]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for SomethingIs {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/somewhat_something.rs b/harper-core/src/linting/somewhat_something.rs
index c6cf79bbe..edba9be5c 100644
--- a/harper-core/src/linting/somewhat_something.rs
+++ b/harper-core/src/linting/somewhat_something.rs
@@ -5,7 +5,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct SomewhatSomething {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SomewhatSomething {
@@ -16,9 +16,7 @@ impl Default for SomewhatSomething {
.then_whitespace()
.t_aco("a");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for SomewhatSomething {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/soon_to_be.rs b/harper-core/src/linting/soon_to_be.rs
index 69509e744..42cfbc753 100644
--- a/harper-core/src/linting/soon_to_be.rs
+++ b/harper-core/src/linting/soon_to_be.rs
@@ -1,4 +1,4 @@
-use std::{ops::Range, sync::Arc};
+use std::ops::Range;
use crate::{
Token, TokenKind, TokenStringExt,
@@ -9,8 +9,7 @@ use crate::{
};
pub struct SoonToBe {
- expr: Box<dyn Expr>,
- map: Arc<ExprMap<Range<usize>>>,
+ expr: ExprMap<Range<usize>>,
}
impl Default for SoonToBe {
@@ -63,7 +62,7 @@ impl Default for SoonToBe {
.then_seq(soon_to_be())
.t_ws()
.then_seq(trailing_phrase()),
- 2..7,
+ 2usize..7usize,
);
map.insert(
@@ -71,15 +70,10 @@ impl Default for SoonToBe {
.then_seq(soon_to_be())
.t_ws()
.then_seq(trailing_phrase()),
- 0..5,
+ 0usize..5usize,
);
- let map = Arc::new(map);
-
- Self {
- expr: Box::new(map.clone()),
- map,
- }
+ Self { expr: map }
}
}
@@ -87,11 +81,11 @@ impl ExprLinter for SoonToBe {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
- let range = self.map.lookup(0, matched_tokens, source)?;
+ let range = self.expr.lookup(0, matched_tokens, source)?;
let span = matched_tokens.get(range.start..range.end)?.span()?;
let template = span.get_content(source);
diff --git a/harper-core/src/linting/sought_after.rs b/harper-core/src/linting/sought_after.rs
index 103bc7b95..29d7b64ae 100644
--- a/harper-core/src/linting/sought_after.rs
+++ b/harper-core/src/linting/sought_after.rs
@@ -5,7 +5,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct SoughtAfter {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SoughtAfter {
@@ -29,9 +29,7 @@ impl Default for SoughtAfter {
.t_ws_h()
.t_aco("after");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -39,7 +37,7 @@ impl ExprLinter for SoughtAfter {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/subject_pronoun.rs b/harper-core/src/linting/subject_pronoun.rs
index 1a4269a61..937cfa208 100644
--- a/harper-core/src/linting/subject_pronoun.rs
+++ b/harper-core/src/linting/subject_pronoun.rs
@@ -5,7 +5,7 @@ use super::expr_linter::Chunk;
use super::{ExprLinter, Lint, LintKind, Suggestion};
pub struct SubjectPronoun {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for SubjectPronoun {
@@ -17,9 +17,7 @@ impl Default for SubjectPronoun {
.t_ws()
.then_proper_noun();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for SubjectPronoun {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/take_a_look_to.rs b/harper-core/src/linting/take_a_look_to.rs
index 439604b27..0c86851ac 100644
--- a/harper-core/src/linting/take_a_look_to.rs
+++ b/harper-core/src/linting/take_a_look_to.rs
@@ -12,24 +12,22 @@ static TAKE_FORMS: &[&str] = &["take", "took", "taken", "takes", "taking"];
static HAVE_FORMS: &[&str] = &["have", "had", "has", "having"];
pub struct TakeALookTo {
- pub expr: Box<dyn Expr>,
+ pub expr: SequenceExpr,
}
impl Default for TakeALookTo {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::any_of(vec![
- Box::new(WordSet::new(TAKE_FORMS)),
- Box::new(WordSet::new(HAVE_FORMS)),
- ])
- .t_ws()
- .t_aco("a")
- .t_ws()
- .t_aco("look")
- .t_ws()
- .t_aco("to"),
- ),
+ expr: SequenceExpr::any_of(vec![
+ Box::new(WordSet::new(TAKE_FORMS)),
+ Box::new(WordSet::new(HAVE_FORMS)),
+ ])
+ .t_ws()
+ .t_aco("a")
+ .t_ws()
+ .t_aco("look")
+ .t_ws()
+ .t_aco("to"),
}
}
}
@@ -42,7 +40,7 @@ impl ExprLinter for TakeALookTo {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/take_medicine.rs b/harper-core/src/linting/take_medicine.rs
index 98faaa48e..4766f7f48 100644
--- a/harper-core/src/linting/take_medicine.rs
+++ b/harper-core/src/linting/take_medicine.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct TakeMedicine {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for TakeMedicine {
@@ -41,9 +41,7 @@ impl Default for TakeMedicine {
.then_optional(adjectives)
.then(medication);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -78,7 +76,7 @@ impl ExprLinter for TakeMedicine {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/take_serious.rs b/harper-core/src/linting/take_serious.rs
index cb35bb8b6..5160edc47 100644
--- a/harper-core/src/linting/take_serious.rs
+++ b/harper-core/src/linting/take_serious.rs
@@ -11,7 +11,7 @@ use crate::{
/// This linter identifies and corrects the common mistake of using the adjective "serious"
/// instead of the adverb "seriously" in phrases like "take it serious".
pub struct TakeSerious {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for TakeSerious {
@@ -28,9 +28,7 @@ impl Default for TakeSerious {
.t_ws()
.t_aco("serious");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -38,7 +36,7 @@ impl ExprLinter for TakeSerious {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/that_than.rs b/harper-core/src/linting/that_than.rs
index 13d0c2288..521d209de 100644
--- a/harper-core/src/linting/that_than.rs
+++ b/harper-core/src/linting/that_than.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct ThatThan {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThatThan {
@@ -22,7 +22,7 @@ impl Default for ThatThan {
.then_word_except(&["way"]);
Self {
- expr: Box::new(adjective_er_that_nextword),
+ expr: adjective_er_that_nextword,
}
}
}
@@ -31,7 +31,7 @@ impl ExprLinter for ThatThan {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/that_which.rs b/harper-core/src/linting/that_which.rs
index 6388472ce..4e657f728 100644
--- a/harper-core/src/linting/that_which.rs
+++ b/harper-core/src/linting/that_which.rs
@@ -1,4 +1,5 @@
use crate::expr::Expr;
+use crate::expr::FirstMatchOf;
use crate::expr::SequenceExpr;
use crate::expr::WordExprGroup;
use itertools::Itertools;
@@ -9,7 +10,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct ThatWhich {
- expr: Box<dyn Expr>,
+ expr: WordExprGroup<FirstMatchOf>,
}
impl Default for ThatWhich {
@@ -25,9 +26,7 @@ impl Default for ThatWhich {
pattern.add("that", matching_pattern.clone());
pattern.add("That", matching_pattern);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -35,7 +34,7 @@ impl ExprLinter for ThatWhich {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/the_my.rs b/harper-core/src/linting/the_my.rs
index adab00095..f3a926c4f 100644
--- a/harper-core/src/linting/the_my.rs
+++ b/harper-core/src/linting/the_my.rs
@@ -9,7 +9,7 @@ use crate::{
};
pub struct TheMy {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl Default for TheMy {
@@ -26,10 +26,7 @@ impl Default for TheMy {
.then(the);
Self {
- expr: Box::new(FirstMatchOf::new(vec![
- Box::new(the_poss),
- Box::new(poss_the),
- ])),
+ expr: FirstMatchOf::new(vec![Box::new(the_poss), Box::new(poss_the)]),
}
}
}
@@ -38,7 +35,7 @@ impl ExprLinter for TheMy {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/the_point_for.rs b/harper-core/src/linting/the_point_for.rs
index a82ec057f..b306b66ac 100644
--- a/harper-core/src/linting/the_point_for.rs
+++ b/harper-core/src/linting/the_point_for.rs
@@ -6,24 +6,22 @@ use crate::{
};
pub struct ThePointFor {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThePointFor {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::any_of(vec![Box::new(WordSet::new(&[
- // "that's" leads to false positives: "that's the point for me"
- "is", "was", "what's", "whats",
- ]))])
- .t_ws()
- .t_aco("the")
- .t_ws()
- .t_aco("point")
- .t_ws()
- .t_aco("for"),
- ),
+ expr: SequenceExpr::any_of(vec![Box::new(WordSet::new(&[
+ // "that's" leads to false positives: "that's the point for me"
+ "is", "was", "what's", "whats",
+ ]))])
+ .t_ws()
+ .t_aco("the")
+ .t_ws()
+ .t_aco("point")
+ .t_ws()
+ .t_aco("for"),
}
}
}
@@ -36,7 +34,7 @@ impl ExprLinter for ThePointFor {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/the_proper_noun_possessive.rs b/harper-core/src/linting/the_proper_noun_possessive.rs
index 62bcddb44..4d2b118ae 100644
--- a/harper-core/src/linting/the_proper_noun_possessive.rs
+++ b/harper-core/src/linting/the_proper_noun_possessive.rs
@@ -5,27 +5,25 @@ use crate::{
};
pub struct TheProperNounPossessive {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for TheProperNounPossessive {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("the")
- .t_ws()
- .then(|t: &Token, s: &[char]| {
- // TODO: should use `k.is_proper_noun()` when #2327 is fixed
- // TODO: should use `k.is_common_noun()` which doesn't exist yet
- t.kind.is_possessive_noun()
- && t.kind.is_titlecase()
- && !t.kind.is_lowercase()
- && !t
- .span
- .get_content(s)
- .eq_any_ignore_ascii_case_str(&["internet's", "internet’s"])
- }),
- ),
+ expr: SequenceExpr::aco("the")
+ .t_ws()
+ .then(|t: &Token, s: &[char]| {
+ // TODO: should use `k.is_proper_noun()` when #2327 is fixed
+ // TODO: should use `k.is_common_noun()` which doesn't exist yet
+ t.kind.is_possessive_noun()
+ && t.kind.is_titlecase()
+ && !t.kind.is_lowercase()
+ && !t
+ .span
+ .get_content(s)
+ .eq_any_ignore_ascii_case_str(&["internet's", "internet’s"])
+ }),
}
}
}
@@ -34,7 +32,7 @@ impl ExprLinter for TheProperNounPossessive {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], _: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/then_than.rs b/harper-core/src/linting/then_than.rs
index a93d9ad67..ee2516c88 100644
--- a/harper-core/src/linting/then_than.rs
+++ b/harper-core/src/linting/then_than.rs
@@ -7,7 +7,7 @@ use crate::{CharStringExt, Token, TokenKind};
/// Corrects the misuse of `then` to `than`.
pub struct ThenThan {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
}
impl ThenThan {
@@ -40,7 +40,7 @@ impl ThenThan {
]);
Self {
- expr: Box::new(FirstMatchOf::new(vec![
+ expr: FirstMatchOf::new(vec![
Box::new(comparison),
Box::new(FixedPhrase::from_phrase("easier said then done")),
Box::new(FixedPhrase::from_phrase("now and than")),
@@ -48,7 +48,7 @@ impl ThenThan {
Box::new(FixedPhrase::from_phrase("rather then")),
Box::new(FixedPhrase::from_phrase("than again")),
Box::new(FixedPhrase::from_phrase("until than")),
- ])),
+ ]),
}
}
}
@@ -71,7 +71,7 @@ impl ExprLinter for ThenThan {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/theres.rs b/harper-core/src/linting/theres.rs
index 15985dc7a..57c6961a3 100644
--- a/harper-core/src/linting/theres.rs
+++ b/harper-core/src/linting/theres.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct Theres {
- expr: Box<dyn crate::expr::Expr>,
+ expr: SequenceExpr,
}
impl Default for Theres {
@@ -16,9 +16,7 @@ impl Default for Theres {
&["no", "enough"],
);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for Theres {
type Unit = Chunk;
fn expr(&self) -> &dyn crate::expr::Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/theses_these.rs b/harper-core/src/linting/theses_these.rs
index a8aea0f94..6a49d664a 100644
--- a/harper-core/src/linting/theses_these.rs
+++ b/harper-core/src/linting/theses_these.rs
@@ -6,7 +6,7 @@ use crate::patterns::UPOSSet;
use harper_brill::UPOS;
pub struct ThesesThese {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThesesThese {
@@ -16,9 +16,7 @@ impl Default for ThesesThese {
.t_ws()
.then(UPOSSet::new(&[UPOS::NOUN, UPOS::PROPN]));
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for ThesesThese {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/thing_think.rs b/harper-core/src/linting/thing_think.rs
index c91341737..0c288a52f 100644
--- a/harper-core/src/linting/thing_think.rs
+++ b/harper-core/src/linting/thing_think.rs
@@ -8,7 +8,7 @@ use crate::{
/// Corrects the typo "thing" for "think".
pub struct ThingThink {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThingThink {
@@ -67,9 +67,7 @@ impl Default for ThingThink {
let pattern = SequenceExpr::with(pre_context).t_ws().t_aco("thing");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -77,7 +75,7 @@ impl ExprLinter for ThingThink {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/this_type_of_thing.rs b/harper-core/src/linting/this_type_of_thing.rs
index 92e6cad5e..9249000ce 100644
--- a/harper-core/src/linting/this_type_of_thing.rs
+++ b/harper-core/src/linting/this_type_of_thing.rs
@@ -6,33 +6,29 @@ use crate::{
};
pub struct ThisTypeOfThing {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThisTypeOfThing {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["this", "these", "that", "those"])
- .t_ws()
- .then(
- SequenceExpr::word_set(&[
- "kind", "kinds", "sort", "sorts", "type", "types",
- ])
+ expr: SequenceExpr::word_set(&["this", "these", "that", "those"])
+ .t_ws()
+ .then(
+ SequenceExpr::word_set(&["kind", "kinds", "sort", "sorts", "type", "types"])
.t_ws(),
- )
- .t_aco("of")
- .t_ws()
- .then_any_of(vec![
- // "thing" is common in this construction and won't be part of a compound noun.
- Box::new(WordSet::new(&["thing", "things"])),
- // Other singular nouns may be part of hard-to-determine compound nouns, but plural nouns won't.
- Box::new(
- SequenceExpr::default()
- .then_kind_where(|k| k.is_plural_noun() && !k.is_singular_noun()),
- ),
- ]),
- ),
+ )
+ .t_aco("of")
+ .t_ws()
+ .then_any_of(vec![
+ // "thing" is common in this construction and won't be part of a compound noun.
+ Box::new(WordSet::new(&["thing", "things"])),
+ // Other singular nouns may be part of hard-to-determine compound nouns, but plural nouns won't.
+ Box::new(
+ SequenceExpr::default()
+ .then_kind_where(|k| k.is_plural_noun() && !k.is_singular_noun()),
+ ),
+ ]),
}
}
}
@@ -41,7 +37,7 @@ impl ExprLinter for ThisTypeOfThing {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn description(&self) -> &str {
diff --git a/harper-core/src/linting/though_thought.rs b/harper-core/src/linting/though_thought.rs
index 9f3265160..85775bcb7 100644
--- a/harper-core/src/linting/though_thought.rs
+++ b/harper-core/src/linting/though_thought.rs
@@ -5,26 +5,24 @@ use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::{CharStringExt, Token, TokenKind};
pub struct ThoughThought {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThoughThought {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::default()
- .then_kind_is_but_is_not(
- TokenKind::is_subject_pronoun,
- TokenKind::is_object_pronoun,
- )
- .t_ws()
- .t_aco("though")
- .t_ws()
- .then_any_of(vec![
- Box::new(SequenceExpr::default().then_subject_pronoun()),
- Box::new(SequenceExpr::aco("that")),
- ]),
- ),
+ expr: SequenceExpr::default()
+ .then_kind_is_but_is_not(
+ TokenKind::is_subject_pronoun,
+ TokenKind::is_object_pronoun,
+ )
+ .t_ws()
+ .t_aco("though")
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(SequenceExpr::default().then_subject_pronoun()),
+ Box::new(SequenceExpr::aco("that")),
+ ]),
}
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for ThoughThought {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/throw_away.rs b/harper-core/src/linting/throw_away.rs
index 88691d87c..496fcb2fa 100644
--- a/harper-core/src/linting/throw_away.rs
+++ b/harper-core/src/linting/throw_away.rs
@@ -6,7 +6,7 @@ use crate::{
};
pub struct ThrowAway {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ThrowAway {
@@ -16,9 +16,7 @@ impl Default for ThrowAway {
.t_ws()
.t_aco("away");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for ThrowAway {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/to_adverb.rs b/harper-core/src/linting/to_adverb.rs
index 77478aa4d..fd5bf1b13 100644
--- a/harper-core/src/linting/to_adverb.rs
+++ b/harper-core/src/linting/to_adverb.rs
@@ -10,7 +10,7 @@ use crate::linting::expr_linter::Chunk;
const AMBIGUOUS_ADVERBS: &[&str] = &["just", "not"];
pub struct ToAdverb {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ToAdverb {
@@ -24,9 +24,7 @@ impl Default for ToAdverb {
.t_ws()
.then_verb();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -34,7 +32,7 @@ impl ExprLinter for ToAdverb {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/touristic.rs b/harper-core/src/linting/touristic.rs
index 584d97e99..b60876116 100644
--- a/harper-core/src/linting/touristic.rs
+++ b/harper-core/src/linting/touristic.rs
@@ -19,7 +19,7 @@ pub enum SuggestionPreference {
use SuggestionPreference::*;
pub struct Touristic {
- expr: Box<dyn crate::expr::Expr>,
+ expr: LongestMatchOf,
}
// "touristy" doesn't sound natural with these words
@@ -79,9 +79,7 @@ impl Default for Touristic {
Box::new(SequenceExpr::default().t_aco("touristic")),
]);
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -89,7 +87,7 @@ impl ExprLinter for Touristic {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/transposed_space.rs b/harper-core/src/linting/transposed_space.rs
index c1c163897..01a0ec9b3 100644
--- a/harper-core/src/linting/transposed_space.rs
+++ b/harper-core/src/linting/transposed_space.rs
@@ -6,27 +6,27 @@ use crate::{
};
pub struct TransposedSpace<D: Dictionary + 'static> {
- expr: Box<dyn Expr>,
+ expr: FirstMatchOf,
dict: D,
}
impl<D: Dictionary + 'static> TransposedSpace<D> {
pub fn new(dict: D) -> Self {
Self {
- expr: Box::new(FirstMatchOf::new(vec![Box::new(
+ expr: FirstMatchOf::new(vec![Box::new(
SequenceExpr::default().then_oov().t_ws().then_oov(),
- )])),
+ )]),
dict,
}
}
pub fn sensitive(dict: D) -> Self {
Self {
- expr: Box::new(FirstMatchOf::new(vec![
+ expr: FirstMatchOf::new(vec![
Box::new(SequenceExpr::default().then_oov().t_ws().then_any_word()),
Box::new(SequenceExpr::any_word().t_ws().then_oov()),
Box::new(SequenceExpr::default().then_oov().t_ws().then_oov()),
- ])),
+ ]),
dict,
}
}
@@ -47,7 +47,7 @@ impl<D: Dictionary + 'static> ExprLinter for TransposedSpace<D> {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/try_ones_hand_at.rs b/harper-core/src/linting/try_ones_hand_at.rs
index e0b838ae4..ef8f2af11 100644
--- a/harper-core/src/linting/try_ones_hand_at.rs
+++ b/harper-core/src/linting/try_ones_hand_at.rs
@@ -5,21 +5,19 @@ use crate::{
};
pub struct TryOnesHandAt {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for TryOnesHandAt {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["try", "tried", "tries", "trying"])
- .t_ws()
- .then_possessive_determiner()
- .t_ws()
- .t_aco("hands")
- .t_ws()
- .t_aco("at"),
- ),
+ expr: SequenceExpr::word_set(&["try", "tried", "tries", "trying"])
+ .t_ws()
+ .then_possessive_determiner()
+ .t_ws()
+ .t_aco("hands")
+ .t_ws()
+ .t_aco("at"),
}
}
}
@@ -28,7 +26,7 @@ impl ExprLinter for TryOnesHandAt {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/update_place_names.rs b/harper-core/src/linting/update_place_names.rs
index 55f448c8a..f9fc132c4 100644
--- a/harper-core/src/linting/update_place_names.rs
+++ b/harper-core/src/linting/update_place_names.rs
@@ -6,7 +6,7 @@ use crate::{Lint, Token, TokenStringExt};
type PlaceNameMappings<'a> = &'a [((i16, &'a str), &'a [&'a str])];
pub struct UpdatePlaceNames<'a> {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
place_name_mappings: PlaceNameMappings<'a>,
}
@@ -83,12 +83,12 @@ impl<'a> Default for UpdatePlaceNames<'a> {
.collect(),
);
- Self::new(Box::new(expr), place_name_mappings)
+ Self::new(expr, place_name_mappings)
}
}
impl<'a> UpdatePlaceNames<'a> {
- pub fn new(expr: Box<dyn Expr>, place_name_mappings: PlaceNameMappings<'a>) -> Self {
+ pub fn new(expr: LongestMatchOf, place_name_mappings: PlaceNameMappings<'a>) -> Self {
Self {
expr,
place_name_mappings,
@@ -100,7 +100,7 @@ impl<'a> ExprLinter for UpdatePlaceNames<'a> {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/verb_to_adjective.rs b/harper-core/src/linting/verb_to_adjective.rs
index 2d4e6807e..558e41bb5 100644
--- a/harper-core/src/linting/verb_to_adjective.rs
+++ b/harper-core/src/linting/verb_to_adjective.rs
@@ -7,7 +7,7 @@ use super::{ExprLinter, Lint, LintKind};
use crate::linting::expr_linter::Chunk;
pub struct VerbToAdjective {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for VerbToAdjective {
@@ -20,9 +20,7 @@ impl Default for VerbToAdjective {
.t_ws()
.then(WordSet::new(&["of"]));
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -30,7 +28,7 @@ impl ExprLinter for VerbToAdjective {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/very_unique.rs b/harper-core/src/linting/very_unique.rs
index 690e246dc..c83362e1e 100644
--- a/harper-core/src/linting/very_unique.rs
+++ b/harper-core/src/linting/very_unique.rs
@@ -6,19 +6,17 @@ use crate::{
};
pub struct VeryUnique {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for VeryUnique {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&[
- "fairly", "pretty", "rather", "quite", "somewhat", "very",
- ])
- .t_ws()
- .t_aco("unique"),
- ),
+ expr: SequenceExpr::word_set(&[
+ "fairly", "pretty", "rather", "quite", "somewhat", "very",
+ ])
+ .t_ws()
+ .t_aco("unique"),
}
}
}
@@ -27,7 +25,7 @@ impl ExprLinter for VeryUnique {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/vice_versa.rs b/harper-core/src/linting/vice_versa.rs
index 7fe9f77d0..37a30b255 100644
--- a/harper-core/src/linting/vice_versa.rs
+++ b/harper-core/src/linting/vice_versa.rs
@@ -70,7 +70,7 @@ fn replacement_for(template: &[char]) -> Vec<char> {
}
pub struct ViceVersa {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for ViceVersa {
@@ -80,9 +80,7 @@ impl Default for ViceVersa {
.then_optional(SequenceExpr::aco("a").then(matches_hyphen))
.t_aco("versa");
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -90,7 +88,7 @@ impl ExprLinter for ViceVersa {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/was_aloud.rs b/harper-core/src/linting/was_aloud.rs
index a62f35c21..960aafbbd 100644
--- a/harper-core/src/linting/was_aloud.rs
+++ b/harper-core/src/linting/was_aloud.rs
@@ -7,7 +7,7 @@ use crate::linting::Suggestion;
use crate::linting::expr_linter::Chunk;
pub struct WasAloud {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for WasAloud {
@@ -16,9 +16,7 @@ impl Default for WasAloud {
.then_whitespace()
.then_exact_word("aloud");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for WasAloud {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/way_too_adjective.rs b/harper-core/src/linting/way_too_adjective.rs
index ccd225fe1..39b65dbee 100644
--- a/harper-core/src/linting/way_too_adjective.rs
+++ b/harper-core/src/linting/way_too_adjective.rs
@@ -8,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct WayTooAdjective {
- expr: Box<dyn Expr>,
+ expr: All,
}
impl Default for WayTooAdjective {
@@ -31,9 +31,7 @@ impl Default for WayTooAdjective {
Box::new(SequenceExpr::unless(exceptions)),
]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -41,7 +39,7 @@ impl ExprLinter for WayTooAdjective {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/well_educated.rs b/harper-core/src/linting/well_educated.rs
index bcb952611..73267b7ee 100644
--- a/harper-core/src/linting/well_educated.rs
+++ b/harper-core/src/linting/well_educated.rs
@@ -8,7 +8,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct WellEducated {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for WellEducated {
@@ -24,9 +24,7 @@ impl Default for WellEducated {
let expr = SequenceExpr::any_of(vec![Box::new(combined), Box::new(separated)]);
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -34,7 +32,7 @@ impl ExprLinter for WellEducated {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/whereas.rs b/harper-core/src/linting/whereas.rs
index d1d0de77f..262b34560 100644
--- a/harper-core/src/linting/whereas.rs
+++ b/harper-core/src/linting/whereas.rs
@@ -6,7 +6,7 @@ use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
pub struct Whereas {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for Whereas {
@@ -16,9 +16,7 @@ impl Default for Whereas {
.then_whitespace()
.t_aco("as");
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -26,7 +24,7 @@ impl ExprLinter for Whereas {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/whom_subject_of_verb.rs b/harper-core/src/linting/whom_subject_of_verb.rs
index 6e7a4c1c3..f52dd9c4e 100644
--- a/harper-core/src/linting/whom_subject_of_verb.rs
+++ b/harper-core/src/linting/whom_subject_of_verb.rs
@@ -6,24 +6,21 @@ use crate::{
};
pub struct WhomSubjectOfVerb {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for WhomSubjectOfVerb {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["whom", "whomever", "whomsoever"])
- .t_ws()
- // .then_verb()
- .then_any_of(vec![
- Box::new(SequenceExpr::default().then_kind_where(|k| {
- k.is_verb_third_person_singular_present_form()
- || k.is_verb_simple_past_form()
- })),
- Box::new(ModalVerb::with_common_errors()),
- ]),
- ),
+ expr: SequenceExpr::word_set(&["whom", "whomever", "whomsoever"])
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(SequenceExpr::default().then_kind_where(|k| {
+ k.is_verb_third_person_singular_present_form()
+ || k.is_verb_simple_past_form()
+ })),
+ Box::new(ModalVerb::with_common_errors()),
+ ]),
}
}
}
@@ -36,7 +33,7 @@ impl ExprLinter for WhomSubjectOfVerb {
}
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint_with_context(
diff --git a/harper-core/src/linting/win_prize.rs b/harper-core/src/linting/win_prize.rs
index 7805fa19b..ef8bd39e4 100644
--- a/harper-core/src/linting/win_prize.rs
+++ b/harper-core/src/linting/win_prize.rs
@@ -1,5 +1,5 @@
-use crate::expr::SequenceExpr;
use crate::expr::{Expr, OwnedExprExt};
+use crate::expr::{LongestMatchOf, SequenceExpr};
use crate::linting::expr_linter::Chunk;
use crate::{
Lrc, Token,
@@ -8,7 +8,7 @@ use crate::{
};
pub struct WinPrize {
- expr: Box<dyn Expr>,
+ expr: LongestMatchOf,
}
impl Default for WinPrize {
@@ -23,9 +23,7 @@ impl Default for WinPrize {
.then(miss.clone())
.or_longest(SequenceExpr::with(verbs).then_whitespace().then(miss));
- Self {
- expr: Box::new(pattern),
- }
+ Self { expr: pattern }
}
}
@@ -33,7 +31,7 @@ impl ExprLinter for WinPrize {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/wish_could.rs b/harper-core/src/linting/wish_could.rs
index c8165d0ab..e7591d6cf 100644
--- a/harper-core/src/linting/wish_could.rs
+++ b/harper-core/src/linting/wish_could.rs
@@ -4,40 +4,38 @@ use crate::expr::{Expr, SequenceExpr};
use crate::linting::{ExprLinter, expr_linter::Chunk};
pub struct WishCould {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for WishCould {
fn default() -> Self {
Self {
- expr: Box::new(
- SequenceExpr::word_set(&["wish", "wished", "wishes", "wishing"])
- .t_ws()
- .then_any_of(vec![
- Box::new(SequenceExpr::default().then_subject_pronoun()),
- Box::new(SequenceExpr::word_set(&[
- // Elective existential indefinite pronouns
- "anybody",
- "anyone",
- // Universal indefinite pronouns
- "everybody",
- "everyone",
- // Negative indefinite pronouns (correct)
- "nobody",
- // Negative indefinite pronouns (incorrect)
- "noone",
- // Assertive existential indefinite pronouns
- "somebody",
- "someone",
- // Demonstrative pronouns
- "these",
- "this",
- "those",
- ])),
- ])
- .t_ws()
- .t_aco("can"),
- ),
+ expr: SequenceExpr::word_set(&["wish", "wished", "wishes", "wishing"])
+ .t_ws()
+ .then_any_of(vec![
+ Box::new(SequenceExpr::default().then_subject_pronoun()),
+ Box::new(SequenceExpr::word_set(&[
+ // Elective existential indefinite pronouns
+ "anybody",
+ "anyone",
+ // Universal indefinite pronouns
+ "everybody",
+ "everyone",
+ // Negative indefinite pronouns (correct)
+ "nobody",
+ // Negative indefinite pronouns (incorrect)
+ "noone",
+ // Assertive existential indefinite pronouns
+ "somebody",
+ "someone",
+ // Demonstrative pronouns
+ "these",
+ "this",
+ "those",
+ ])),
+ ])
+ .t_ws()
+ .t_aco("can"),
}
}
}
@@ -46,7 +44,7 @@ impl ExprLinter for WishCould {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- &*self.expr
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/worth_to_do.rs b/harper-core/src/linting/worth_to_do.rs
index 76a6144a8..dceafd298 100644
--- a/harper-core/src/linting/worth_to_do.rs
+++ b/harper-core/src/linting/worth_to_do.rs
@@ -10,7 +10,7 @@ pub struct WorthToDo<D>
where
D: Dictionary,
{
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
dict: D,
}
@@ -20,13 +20,11 @@ where
{
pub fn new(dict: D) -> Self {
Self {
- expr: Box::new(
- SequenceExpr::aco("worth")
- .t_ws()
- .t_aco("to")
- .t_ws()
- .then_verb_lemma(),
- ),
+ expr: SequenceExpr::aco("worth")
+ .t_ws()
+ .t_aco("to")
+ .t_ws()
+ .then_verb_lemma(),
dict,
}
}
@@ -39,7 +37,7 @@ where
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
diff --git a/harper-core/src/linting/would_never_have.rs b/harper-core/src/linting/would_never_have.rs
index af3880bef..e254e9f9a 100644
--- a/harper-core/src/linting/would_never_have.rs
+++ b/harper-core/src/linting/would_never_have.rs
@@ -7,7 +7,7 @@ use crate::{
};
pub struct WouldNeverHave {
- expr: Box<dyn Expr>,
+ expr: SequenceExpr,
}
impl Default for WouldNeverHave {
@@ -31,9 +31,7 @@ impl Default for WouldNeverHave {
// TODO: verb should be perfect form ("done", "happened", etc.) when verb property changes are merged
let expr = SequenceExpr::any_of(expr).then_whitespace().then_verb();
- Self {
- expr: Box::new(expr),
- }
+ Self { expr }
}
}
@@ -41,7 +39,7 @@ impl ExprLinter for WouldNeverHave {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
- self.expr.as_ref()
+ &self.expr
}
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {