harper_core/patterns/
prepositional_preceder.rs

1use lazy_static::lazy_static;
2
3use super::{SingleTokenPattern, WordSet};
4use crate::Token;
5
6/// Matches adjectives that routinely introduce a `… to …` prepositional phrase, such as
7/// `accustomed`, `prone`, or `used`.
8///
9/// Several `ToTwoToo` branches need this guard so they only flag cases where `to` is meant as
10/// `too`, not when it participates in idioms like `accustomed to precision`.
11#[derive(Debug, Clone)]
12pub struct PrepositionalPrecederPattern {
13    word_set: WordSet,
14}
15
16impl Default for PrepositionalPrecederPattern {
17    fn default() -> Self {
18        Self {
19            word_set: WordSet::new(&[
20                "accustomed",
21                "addicted",
22                "adjacent",
23                "allergic",
24                "attached",
25                "attuned",
26                "committed",
27                "connected",
28                "dedicated",
29                "devoted",
30                "immune",
31                "oblivious",
32                "opposed",
33                "partial",
34                "prone",
35                "receptive",
36                "related",
37                "resistant",
38                "sensitive",
39                "subject",
40                "susceptible",
41                "used",
42            ]),
43        }
44    }
45}
46
47impl SingleTokenPattern for PrepositionalPrecederPattern {
48    fn matches_token(&self, token: &Token, source: &[char]) -> bool {
49        self.word_set.matches_token(token, source)
50    }
51}
52
53lazy_static! {
54    static ref PREPOSITIONAL_PRECEDER_PATTERN: PrepositionalPrecederPattern =
55        PrepositionalPrecederPattern::default();
56}
57
58/// Shared accessor for the lazily-initialized [`PrepositionalPrecederPattern`].
59pub fn prepositional_preceder() -> &'static PrepositionalPrecederPattern {
60    &PREPOSITIONAL_PRECEDER_PATTERN
61}