1use crate::EnglishCore;
2use crate::grammar::*;
3impl EnglishCore {
4 pub fn verb(
5 word: &str,
6 person: &Person,
7 number: &Number,
8 tense: &Tense,
9 form: &Form,
10 ) -> String {
11 match word {
12 "be" => {
13 return EnglishCore::to_be(person, number, tense, form).to_string();
14 }
15 _ => (),
16 }
17 match (person, number, tense, form) {
18 (_, _, _, Form::Infinitive) => {
19 return word.to_string();
20 }
21
22 (Person::Third, Number::Singular, Tense::Present, Form::Finite) => {
23 if let Some(irr) = EnglishCore::iter_replace_last(word, IRREGULAR_THIRD) {
24 return irr;
25 }
26 format!("{}{}", word, "s")
27 }
28 (_, _, Tense::Present, Form::Finite) => {
29 return word.to_string();
30 }
31 (_, _, Tense::Present, Form::Participle) => {
32 if let Some(irr) = EnglishCore::iter_replace_last(word, IRREGULAR_PRES_PART) {
33 return irr;
34 }
35 format!("{}{}", word, "ing")
36 }
37
38 (_, _, Tense::Past, _) => {
39 if let Some(irr) = EnglishCore::iter_replace_last(word, IRREGULAR_PAST) {
40 return irr;
41 }
42 format!("{}{}", word, "ed")
43 }
44 }
45 }
46 pub fn to_be(person: &Person, number: &Number, tense: &Tense, form: &Form) -> &'static str {
47 match (tense, form) {
48 (_, Form::Infinitive) => "be",
49 (Tense::Present, Form::Finite) => match number {
50 Number::Singular => match person {
51 Person::First => "am",
52 Person::Second => "are",
53 Person::Third => "is",
54 },
55 Number::Plural => "are",
56 },
57 (Tense::Past, Form::Finite) => match number {
58 Number::Singular => match person {
59 Person::First => "was",
60 Person::Second => "were",
61 Person::Third => "was",
62 },
63 Number::Plural => "were",
64 },
65 (Tense::Past, Form::Participle) => "been",
66 (Tense::Present, Form::Participle) => "being",
67 }
68 }
69}
70
71static IRREGULAR_PRES_PART: &[(&str, &str)] = &[
72 ("e", "ing"),
73 ("p", "pping"),
74 ("ng", "nging"),
75 ("g", "gging"),
76 ];
80
81static IRREGULAR_PAST: &[(&str, &str)] = &[
82 ("fight", "fought"),
83 ("buy", "bought"),
84 ("e", "ed"),
85 ("p", "pped"),
86 ("y", "ied"),
87 ("ng", "nged"),
88 ("g", "gged"),
89 ];
93
94static IRREGULAR_THIRD: &[(&str, &str)] = &[
95 ("sh", "shes"),
96 ("ch", "ches"),
97 ("s", "ses"),
98 ("z", "zes"),
99 ("x", "xes"),
100 ("buy", "buys"),
101 ("y", "ies"),
102];