Skip to content

Commit 8cb8f74

Browse files
committed
implement translation of starting particle
1 parent d4456b0 commit 8cb8f74

File tree

1 file changed

+53
-7
lines changed

1 file changed

+53
-7
lines changed

src/translator/sentence.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,41 @@ function sentence(
7676
: sentence.punctuation;
7777
switch (sentence.type) {
7878
case "simple": {
79+
let startingAdverb: IterableResult<null | English.Word>;
80+
let startingConjunction: null | English.Word;
7981
if (sentence.startingParticle != null) {
80-
return IterableResult.errors([
81-
new TranslationTodoError(
82-
`"${sentence.startingParticle.word}" starting particle`,
83-
),
84-
]);
82+
const { startingParticle } = sentence;
83+
const emphasis = startingParticle.emphasis != null;
84+
const reduplicationCount = getReduplicationCount(startingParticle);
85+
switch (sentence.startingParticle.word as "taso" | "kin" | "anu") {
86+
case "taso":
87+
startingAdverb = IterableResult.single(null);
88+
startingConjunction = word({
89+
reduplicationCount,
90+
emphasis,
91+
word: "but",
92+
});
93+
break;
94+
case "kin":
95+
startingAdverb = fromSimpleDefinition(
96+
startingParticle,
97+
(definition) =>
98+
definition.type === "adverb" ? definition.adverb : null,
99+
);
100+
startingConjunction = null;
101+
break;
102+
case "anu":
103+
startingAdverb = IterableResult.single(null);
104+
startingConjunction = word({
105+
reduplicationCount,
106+
emphasis,
107+
word: "or",
108+
});
109+
break;
110+
}
111+
} else {
112+
startingAdverb = IterableResult.single(null);
113+
startingConjunction = null;
85114
}
86115
const useAnuSeme = nullableAsArray(sentence.anuSeme)
87116
.map((seme): English.Clause => ({
@@ -113,21 +142,38 @@ function sentence(
113142
}))
114143
: IterableResult.empty();
115144
const clauses = IterableResult.combine(
145+
startingAdverb,
116146
IterableResult.combine(...sentence.contextClauses.map(contextClause))
117147
.map((clause) => clause.flat()),
118148
IterableResult.concat(interjectionClause, clause(sentence.finalClause)),
119149
)
120-
.map(([contextClauses, lastClause]) => [
150+
.map(([adverb, contextClauses, lastClause]) => [
151+
...nullableAsArray(adverb)
152+
.map((adverb): English.Clause => ({ type: "adverb", adverb })),
121153
...contextClauses,
122154
lastClause,
123155
...useAnuSeme,
124156
]);
157+
let withConjunction: IterableResult<ReadonlyArray<English.Clause>>;
158+
if (startingConjunction != null) {
159+
withConjunction = clauses
160+
.map<ReadonlyArray<English.Clause>>(([first, ...rest]) => [
161+
{
162+
type: "dependent",
163+
conjunction: startingConjunction,
164+
clause: first,
165+
},
166+
...rest,
167+
]);
168+
} else {
169+
withConjunction = clauses;
170+
}
125171
const usePunctuation = emphasisAsPunctuation({
126172
emphasis: sentence.emphasis,
127173
interrogative: sentence.interrogative != null,
128174
originalPunctuation: punctuation,
129175
});
130-
return clauses.map((clauses): English.Sentence => ({
176+
return withConjunction.map((clauses): English.Sentence => ({
131177
clauses,
132178
punctuation: usePunctuation,
133179
}));

0 commit comments

Comments
 (0)