Skip to content

Commit a9731e8

Browse files
committed
simplify nanpa handling
1 parent c369943 commit a9731e8

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

src/translator/modifier.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export type ModifierTranslation =
2424
| Readonly<{ type: "adjective"; adjective: English.AdjectivePhrase }>
2525
| Readonly<{ type: "determiner"; determiner: English.Determiner }>
2626
| Readonly<{ type: "adverb"; adverb: English.Adverb }>
27-
| Readonly<{ type: "name"; name: string }>
28-
| Readonly<{ type: "position phrase"; noun: English.NounPhrase }>;
27+
| Readonly<{ type: "name"; name: string }>;
2928
export type AdjectivalModifier = Readonly<{
3029
nounPreposition:
3130
| null
@@ -34,7 +33,6 @@ export type AdjectivalModifier = Readonly<{
3433
adjectives: ReadonlyArray<English.AdjectivePhrase>;
3534
name: null | string;
3635
ofPhrase: null | English.NounPhrase;
37-
inPositionPhrase: null | English.NounPhrase;
3836
}>;
3937
export type AdverbialModifier = Readonly<{
4038
adverbs: ReadonlyArray<English.Adverb>;
@@ -180,7 +178,7 @@ function modifier(modifier: TokiPona.Modifier) {
180178
case "nanpa":
181179
return nanpa(modifier)
182180
.map((noun): ModifierTranslation => ({
183-
type: "position phrase",
181+
type: "noun",
184182
noun,
185183
}));
186184
}
@@ -213,18 +211,12 @@ export function multipleModifiers(
213211
const names = modifiers
214212
.flatMap((modifier) => modifier.type === "name" ? [modifier.name] : []);
215213

216-
const inPositionPhrases = modifiers.flatMap((modifier) =>
217-
modifier.type === "position phrase" ? [modifier.noun] : []
218-
);
219-
220214
let adjectival: IterableResult<MultipleModifierTranslation>;
221215
if (
222216
nouns.length <= 1 &&
223217
nounPrepositions.length <= 1 &&
224218
adverbs.length === 0 &&
225-
names.length <= 1 &&
226-
inPositionPhrases.length <= 1 &&
227-
(nouns.length === 0 || inPositionPhrases.length === 0)
219+
names.length <= 1
228220
) {
229221
adjectival = IterableResult.single<MultipleModifierTranslation>({
230222
type: "adjectival",
@@ -233,7 +225,6 @@ export function multipleModifiers(
233225
adjectives,
234226
name: names[0] ?? null,
235227
ofPhrase: nouns[0] ?? null,
236-
inPositionPhrase: inPositionPhrases[0] ?? null,
237228
});
238229
} else {
239230
adjectival = IterableResult.empty();
@@ -244,8 +235,7 @@ export function multipleModifiers(
244235
nounPrepositions.length === 0 &&
245236
determiners.length === 0 &&
246237
adjectives.length <= 1 &&
247-
names.length === 0 &&
248-
inPositionPhrases.length === 0
238+
names.length === 0
249239
) {
250240
const inWayPhrase: null | English.NounPhrase = adjectives.length > 0
251241
? {

src/translator/nanpa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FilteredError } from "./error.ts";
66
import { phrase } from "./phrase.ts";
77

88
export function nanpa(
9-
nanpa: TokiPona.Modifier & { type: "nanpa" },
9+
nanpa: TokiPona.Nanpa,
1010
): IterableResult<English.NounPhrase> {
1111
return phrase({
1212
phrase: nanpa.phrase,

src/translator/phrase.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,8 @@ function nounPhrase(
6363
modifier.name,
6464
(name): English.PostAdjective => ({ adjective: "named", name }),
6565
);
66-
const prepositions = [
67-
...nullableAsArray(modifier.inPositionPhrase)
68-
.map((object) => nounAsPreposition(object, "in")),
69-
...nullableAsArray(modifier.ofPhrase)
70-
.map((object) => nounAsPreposition(object, "of")),
71-
];
72-
if (prepositions.length > 1) {
73-
throw new FilteredError("multiple preposition within noun phrase");
74-
}
66+
const prepositions = nullableAsArray(modifier.ofPhrase)
67+
.map((object) => nounAsPreposition(object, "of"));
7568
// TODO: do this on `fixer.ts` instead
7669
if (prepositions.length > 0 && postAdjective != null) {
7770
throw new FilteredError("named noun with preposition");
@@ -96,9 +89,7 @@ function nounPhrase(
9689
}));
9790
if (modifier.nounPreposition == null) {
9891
return headNoun;
99-
} else if (
100-
modifier.ofPhrase == null && modifier.inPositionPhrase == null
101-
) {
92+
} else if (modifier.ofPhrase == null) {
10293
return headNoun.map((noun): English.NounPhrase => ({
10394
...modifier.nounPreposition!.noun as English.NounPhrase & {
10495
type: "simple";

0 commit comments

Comments
 (0)