Skip to content

Commit 24ff940

Browse files
committed
refactor anu seme translation
1 parent de68fb0 commit 24ff940

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/translator/sentence.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { nullableAsArray, repeatWithSpace } from "../../misc/misc.ts";
1+
import { nullableAsArray } from "../../misc/misc.ts";
22
import { ArrayResult } from "../array_result.ts";
33
import { dictionary } from "../dictionary.ts";
44
import * as TokiPona from "../parser/ast.ts";
55
import { definitionAsPlainString } from "./as_string.ts";
66
import * as English from "./ast.ts";
77
import { clause, contextClause, unwrapSingleWord } from "./clause.ts";
8-
import { FilteredError, TranslationTodoError } from "./error.ts";
9-
import { noEmphasis } from "./word.ts";
10-
import { fromSimpleDefinition } from "./word_unit.ts";
8+
import { TranslationTodoError } from "./error.ts";
9+
import { noEmphasis, word } from "./word.ts";
10+
import { fromSimpleDefinition, getReduplicationCount } from "./word_unit.ts";
1111

1212
function filler(filler: TokiPona.Filler): ArrayResult<string> {
1313
switch (filler.type) {
@@ -64,26 +64,6 @@ function emphasisAsPunctuation(
6464
return `${questionMark}${exclamationMark}`;
6565
}
6666
}
67-
function anuSeme(seme: TokiPona.HeadedWordUnit): English.Clause {
68-
let interjection: string;
69-
switch (seme.type) {
70-
case "default":
71-
interjection = "right";
72-
break;
73-
case "reduplication":
74-
interjection = repeatWithSpace("right", seme.count);
75-
break;
76-
case "x ala x":
77-
throw new FilteredError('"seme ala seme"');
78-
}
79-
return {
80-
type: "interjection",
81-
interjection: {
82-
word: interjection,
83-
emphasis: seme.emphasis != null,
84-
},
85-
};
86-
}
8767
function sentence(
8868
sentence: TokiPona.Sentence,
8969
isFinal: boolean,
@@ -103,7 +83,17 @@ function sentence(
10383
),
10484
);
10585
}
106-
const useAnuSeme = nullableAsArray(sentence.anuSeme).map(anuSeme);
86+
const useAnuSeme = nullableAsArray(sentence.anuSeme)
87+
.map((seme) =>
88+
({
89+
type: "interjection",
90+
interjection: word({
91+
word: "right",
92+
reduplicationCount: getReduplicationCount(seme),
93+
emphasis: seme.emphasis != null,
94+
}),
95+
}) as const
96+
);
10797
const interjectionClause: ArrayResult<English.Clause> =
10898
sentence.contextClauses.length === 0 &&
10999
sentence.startingParticle == null

0 commit comments

Comments
 (0)