Skip to content

Commit 490c943

Browse files
committed
various high-priority grammar fixing
1 parent 22cff3b commit 490c943

4 files changed

Lines changed: 55 additions & 15 deletions

File tree

src/translator/adjective.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function compoundAdjective(
6666
emphasis: null | TokiPona.Emphasis;
6767
}>,
6868
): IterableResult<English.AdjectivePhrase> {
69-
// TODO: flattening of adjectives in AST fixer
7069
const { adjectives, reduplicationCount, emphasis } = options;
7170
if (reduplicationCount === 1) {
7271
return IterableResult.combine(

src/translator/fixer.ts

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ function fixNounPhrase(noun: English.NounPhrase): English.NounPhrase {
2626
case "compound":
2727
return {
2828
...noun,
29-
nouns: noun.nouns.map(fixNounPhrase),
29+
nouns: noun.nouns.flatMap((item) =>
30+
item.type === "compound" && item.conjunction === noun.conjunction
31+
? item.nouns
32+
: [item]
33+
)
34+
.map(fixNounPhrase),
3035
};
3136
}
3237
}
@@ -120,7 +125,14 @@ function fixAdjectivePhrase(
120125
case "compound":
121126
return {
122127
...adjective,
123-
adjectives: adjective.adjectives.map(fixAdjectivePhrase),
128+
adjectives: adjective.adjectives
129+
.flatMap((item) =>
130+
item.type === "compound" &&
131+
item.conjunction === adjective.conjunction
132+
? item.adjectives
133+
: [item]
134+
)
135+
.map(fixAdjectivePhrase),
124136
};
125137
}
126138
}
@@ -169,15 +181,42 @@ function fixMultipleAdverbs(adverbs: ReadonlyArray<English.Adverb>) {
169181
return adverbs;
170182
}
171183
}
184+
function filterGerundNoun(noun: English.NounPhrase): void {
185+
switch (noun.type) {
186+
case "simple":
187+
if (noun.gerund) {
188+
throw new FilteredError("continuous tense");
189+
}
190+
break;
191+
case "compound":
192+
noun.nouns.forEach(filterGerundNoun);
193+
break;
194+
}
195+
}
196+
function filterGerundLikeAdjective(adjective: English.AdjectivePhrase): void {
197+
switch (adjective.type) {
198+
case "simple":
199+
if (adjective.gerundLike) {
200+
throw new FilteredError("continuous tense");
201+
}
202+
break;
203+
case "compound":
204+
adjective.adjectives.forEach(filterGerundLikeAdjective);
205+
break;
206+
}
207+
}
172208
function fixComplement(complement: English.Complement): English.Complement {
173209
switch (complement.type) {
174-
case "noun":
175-
return { type: "noun", noun: fixNounPhrase(complement.noun) };
176-
case "adjective":
177-
return {
178-
type: "adjective",
179-
adjective: fixAdjectivePhrase(complement.adjective),
180-
};
210+
case "noun": {
211+
const noun = fixNounPhrase(complement.noun);
212+
filterGerundNoun(noun);
213+
return { type: "noun", noun };
214+
}
215+
case "adjective": {
216+
const adjective = fixAdjectivePhrase(complement.adjective);
217+
filterGerundLikeAdjective(adjective);
218+
return { type: "adjective", adjective };
219+
}
181220
}
182221
}
183222
function fixAdverbVerb(adverbVerb: English.AdverbVerb): English.AdverbVerb {
@@ -189,7 +228,13 @@ function fixAdverbVerb(adverbVerb: English.AdverbVerb): English.AdverbVerb {
189228
function fixMultipleVerb(
190229
verb: ReadonlyArray<English.AdverbVerb>,
191230
): ReadonlyArray<English.AdverbVerb> {
192-
return verb.map(fixAdverbVerb);
231+
const newVerb = verb.map(fixAdverbVerb);
232+
for (const verb of newVerb.slice(1)) {
233+
if (verb.verb.type === "modal") {
234+
throw new FilteredError("modal verb after another verb");
235+
}
236+
}
237+
return newVerb;
193238
}
194239
function fixVerbPhrase(verb: English.VerbPhrase): English.VerbPhrase {
195240
switch (verb.type) {

src/translator/phrase.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ function preverb(
268268
const predicateAsVerb = phraseAsVerb(predicate);
269269
if (predicateAsVerb != null && predicateAsVerb.type === "simple") {
270270
const first = predicateAsVerb.verb[0];
271-
// TODO: filter out modal verb when found in the middle
272271
const verbForPreverb: English.AdverbVerb = {
273272
preAdverbs: first.preAdverbs,
274273
verb: first.verb,
@@ -411,7 +410,6 @@ export function multiplePhrases(
411410
) {
412411
return {
413412
type: "noun",
414-
// TODO: flatten compound nouns on the grammar fixer
415413
noun: {
416414
type: "compound",
417415
conjunction,
@@ -426,7 +424,6 @@ export function multiplePhrases(
426424
// TODO: filter out "<adjective> and <adjective>" when used as a sole phrase
427425
return {
428426
type: "adjective",
429-
// TODO: flatten compound adjective on the grammar fixer
430427
adjective: {
431428
type: "compound",
432429
conjunction,

src/translator/word_unit.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type WordUnitTranslation =
1616
| Readonly<{ type: "adjective"; adjective: English.AdjectivePhrase }>
1717
| (Readonly<{ type: "verb" }> & English.SimpleVerbPhrase);
1818

19-
// TODO: filter out gerund and gerund-like on fixer
2019
function defaultWordUnit(
2120
options: Readonly<{
2221
word: string;

0 commit comments

Comments
 (0)