Skip to content

Commit d4e4177

Browse files
committed
recognize anu as sentence starting particle
1 parent 0724177 commit d4e4177

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

src/parser/ast.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ export type Clause =
8080
>;
8181
export type ContextClause =
8282
| Clause
83-
| (Readonly<{ type: "nanpa" }> & Nanpa);
83+
| (Readonly<{ type: "nanpa" }> & Nanpa)
84+
| (Readonly<{ type: "anu"; anu: HeadedWordUnit }>);
8485
export type Sentence =
8586
| Readonly<{
8687
type: "default";
87-
kinOrTaso: null | HeadedWordUnit;
88+
startingParticle: null | HeadedWordUnit;
8889
laClauses: ReadonlyArray<ContextClause>;
8990
finalClause: Clause;
9091
anuSeme: null | HeadedWordUnit;

src/parser/composer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export function contextClause(contextClause: ContextClause): string {
176176
switch (contextClause.type) {
177177
case "nanpa":
178178
return nanpa(contextClause);
179+
case "anu":
180+
return wordUnit(contextClause.anu);
179181
default:
180182
return clause(contextClause);
181183
}
@@ -185,7 +187,7 @@ export function sentence(sentence: Sentence): string {
185187
switch (sentence.type) {
186188
case "default":
187189
text = [
188-
...nullableAsArray(sentence.kinOrTaso).map(wordUnit),
190+
...nullableAsArray(sentence.startingParticle).map(wordUnit),
189191
...sentence.laClauses
190192
.map(contextClause)
191193
.map((clause) => `${clause} la`),

src/parser/extract.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export function everyWordUnitInContextClause(
104104
switch (contextClause.type) {
105105
case "nanpa":
106106
return everyWordUnitInNanpa(contextClause);
107+
case "anu":
108+
return [contextClause.anu];
107109
default:
108110
return everyWordUnitInClause(contextClause);
109111
}
@@ -114,7 +116,7 @@ export function everyWordUnitInSentence(
114116
switch (sentence.type) {
115117
case "default":
116118
return [
117-
...nullableAsArray(sentence.kinOrTaso),
119+
...nullableAsArray(sentence.startingParticle),
118120
...sentence.laClauses.flatMap(everyWordUnitInContextClause),
119121
...everyWordUnitInClause(sentence.finalClause),
120122
...nullableAsArray(sentence.anuSeme),

src/parser/filter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,21 @@ export const SENTENCE_RULE: ReadonlyArray<(sentence: Sentence) => boolean> = [
301301
(sentence) => {
302302
if (sentence.type === "default") {
303303
if (
304-
sentence.kinOrTaso != null && sentence.kinOrTaso.type === "x ala x"
304+
sentence.startingParticle != null &&
305+
sentence.startingParticle.type === "x ala x"
305306
) {
306-
const { kinOrTaso: { word } } = sentence;
307+
const { startingParticle: { word } } = sentence;
307308
throw new UnrecognizedError(`"${word} ala ${word}"`);
308309
}
309310
}
310311
return true;
311312
},
312-
// If there is "la", there can't be "taso" or "kin"
313+
// If there is "la", there can't be starting particle e.g. taso
313314
(sentence) =>
314315
sentence.type !== "default" || sentence.laClauses.length === 0 ||
315-
sentence.kinOrTaso == null || throwError(
316+
sentence.startingParticle == null || throwError(
316317
new UnrecognizedError(
317-
`${sentence.kinOrTaso.word} particle with "la"`,
318+
`${sentence.startingParticle.word} particle with "la"`,
318319
),
319320
),
320321

src/parser/parser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ const clause = choice<Clause>(
605605
.filter(filter(CLAUSE_RULE));
606606
const contextClause = choice<ContextClause>(
607607
nanpa.map((nanpa) => ({ ...nanpa, type: "nanpa" })),
608+
wordUnit(new Set(["anu"]), '"anu"').map((anu) => ({ type: "anu", anu })),
608609
clause,
609610
);
610611
const la = choice(
@@ -652,7 +653,8 @@ const anuSeme = choice(
652653
const sentence = choice<Sentence>(
653654
sequence(
654655
optional(
655-
wordUnit(new Set(["kin", "taso"]), "taso/kin").skip(optionalComma),
656+
wordUnit(new Set(["taso", "kin", "anu"]), "taso/kin/anu")
657+
.skip(optionalComma),
656658
),
657659
many(contextClause.skip(la)),
658660
clause,
@@ -668,7 +670,7 @@ const sentence = choice<Sentence>(
668670
.map<Sentence & { type: "default" }>(
669671
(
670672
[
671-
kinOrTaso,
673+
startingParticle,
672674
laClauses,
673675
finalClause,
674676
anuSeme,
@@ -678,7 +680,7 @@ const sentence = choice<Sentence>(
678680
) => {
679681
const sentence: Sentence & { type: "default" } = {
680682
type: "default",
681-
kinOrTaso,
683+
startingParticle,
682684
laClauses,
683685
finalClause,
684686
anuSeme,

src/translator/clause.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ export function contextClause(
209209
): ArrayResult<English.Clause> {
210210
switch (contextClause.type) {
211211
case "nanpa":
212-
return new ArrayResult(new TranslationTodoError("nanpa context clause"));
212+
case "anu":
213+
return new ArrayResult(
214+
new TranslationTodoError(`${contextClause.type} context clause`),
215+
);
213216
default:
214217
return clause(contextClause);
215218
}

src/translator/sentence.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,18 @@ function sentence(
144144
clause,
145145
}))
146146
);
147-
if (sentence.kinOrTaso != null) {
147+
if (sentence.startingParticle != null) {
148148
return new ArrayResult(
149149
new TranslationTodoError(
150-
`"${sentence.kinOrTaso.word}" starting particle`,
150+
`"${sentence.startingParticle.word}" starting particle`,
151151
),
152152
);
153153
}
154154
const lastEngClause = clause(sentence.finalClause);
155155
const right = nullableAsArray(sentence.anuSeme).map(anuSeme);
156156
const interjectionClause =
157-
sentence.laClauses.length === 0 && sentence.kinOrTaso == null &&
158-
sentence.kinOrTaso == null
157+
sentence.laClauses.length === 0 && sentence.startingParticle == null &&
158+
sentence.startingParticle == null
159159
? interjection(sentence.finalClause)
160160
: new ArrayResult<English.Clause>();
161161
const engClauses = ArrayResult.combine(

0 commit comments

Comments
 (0)