Skip to content

Commit 567b24b

Browse files
committed
move filtering of "of"
1 parent 73a348f commit 567b24b

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/translator/fixer.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function fixNounPhrase(noun: English.NounPhrase): English.NounPhrase {
2929
determiners: fixMultipleDeterminers(noun.determiners),
3030
adjectives: fixMultipleAdjectives(noun.adjectives),
3131
postCompound: mapNullable(noun.postCompound, fixNounPhrase),
32-
prepositions: noun.prepositions.map(fixPreposition),
32+
prepositions: fixMultiplePrepositions(noun.prepositions),
3333
};
3434
case "compound":
3535
return {
@@ -212,15 +212,15 @@ function fixVerbPhrase(verb: English.VerbPhrase): English.VerbPhrase {
212212
contentClause: mapNullable(verb.contentClause, fixClause),
213213
object: mapNullable(verb.object, fixNounPhrase),
214214
objectComplement: mapNullable(verb.objectComplement, fixComplement),
215-
prepositions: verb.prepositions.map(fixPreposition),
215+
prepositions: fixMultiplePrepositions(verb.prepositions),
216216
};
217217
case "compound":
218218
return {
219219
...verb,
220220
verbs: verb.verbs.map(fixVerbPhrase),
221221
object: mapNullable(verb.object, fixNounPhrase),
222222
objectComplement: mapNullable(verb.objectComplement, fixComplement),
223-
prepositions: verb.prepositions.map(fixPreposition),
223+
prepositions: fixMultiplePrepositions(verb.prepositions),
224224
};
225225
}
226226
}
@@ -245,6 +245,18 @@ function fixPreposition(
245245
object: fixNounPhrase(preposition.object),
246246
};
247247
}
248+
function fixMultiplePrepositions(
249+
prepositions: ReadonlyArray<English.Preposition>,
250+
): ReadonlyArray<English.Preposition> {
251+
if (
252+
prepositions.filter((preposition) => preposition.preposition.word === "of")
253+
.length > 1
254+
) {
255+
throw new FilteredError('multiple "of"');
256+
} else {
257+
return prepositions.map(fixPreposition);
258+
}
259+
}
248260
function fixClause(clause: English.Clause): English.Clause {
249261
switch (clause.type) {
250262
case "simple":

src/translator/modifier.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type AdjectivalModifier = Readonly<{
3232
determiners: ReadonlyArray<English.Determiner>;
3333
adjectives: ReadonlyArray<English.AdjectivePhrase>;
3434
name: null | string;
35-
ofPhrase: null | English.NounPhrase;
35+
ofPhrase: ReadonlyArray<English.NounPhrase>;
3636
}>;
3737
export type AdverbialModifier = Readonly<{
3838
adverbs: ReadonlyArray<English.Adverb>;
@@ -208,7 +208,6 @@ export function multipleModifiers(
208208

209209
let adjectival: IterableResult<MultipleModifierTranslation>;
210210
if (
211-
nouns.length <= 1 &&
212211
nounPrepositions.length <= 1 &&
213212
adverbs.length === 0 &&
214213
names.length <= 1
@@ -219,7 +218,7 @@ export function multipleModifiers(
219218
determiners,
220219
adjectives,
221220
name: names[0] ?? null,
222-
ofPhrase: nouns[0] ?? null,
221+
ofPhrase: nouns,
223222
});
224223
} else {
225224
adjectival = IterableResult.empty();

src/translator/phrase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function nounPhrase(
6969
modifier.name,
7070
(name): English.AdjectiveName => ({ adjective: "named", name }),
7171
);
72-
const prepositions = nullableAsArray(modifier.ofPhrase)
72+
const prepositions = modifier.ofPhrase
7373
.map((object) => nounAsPreposition(object, "of"));
7474
const { nounPreposition } = modifier;
7575
const headNoun = fromNounForms(noun, quantity)

0 commit comments

Comments
 (0)