Skip to content

Commit f9fa3a1

Browse files
committed
separate out quantity detection
1 parent d0dd91b commit f9fa3a1

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src/translator/ast.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export type NounPhrase =
2424
type: "compound";
2525
conjunction: string;
2626
nouns: ReadonlyArray<NounPhrase>;
27-
quantity: Quantity;
2827
}>;
2928
export type Determiner = Readonly<{
3029
kind: Dictionary.DeterminerType;

src/translator/clause.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as TokiPona from "../parser/ast.ts";
44
import * as English from "./ast.ts";
55
import { FilteredError, TranslationTodoError } from "./error.ts";
66
import { nanpa } from "./nanpa.ts";
7-
import { perspective } from "./noun.ts";
7+
import { perspective, quantity } from "./noun.ts";
88
import { multiplePhrases, multiplePhrasesAsNoun } from "./phrase.ts";
99
import { predicate } from "./predicate.ts";
1010
import { nounAsPreposition, preposition } from "./preposition.ts";
@@ -81,7 +81,7 @@ function liClause(clause: TokiPona.Clause & { type: "li clause" }) {
8181
predicate(clause.predicates, "li"),
8282
)
8383
.flatMap(([subject, predicate]) =>
84-
verb(predicate, perspective(subject), subject.quantity)
84+
verb(predicate, perspective(subject), quantity(subject))
8585
.map((verb) => ({
8686
type: "simple",
8787
subject,
@@ -149,15 +149,16 @@ function oClause(clause: TokiPona.Clause & { type: "o clause" }) {
149149
return IterableResult.combine(subject, predicate(clause.predicates, "o"))
150150
.flatMap(([subject, predicate]) => {
151151
const subjectPerspective = perspective(subject);
152+
const subjectQuantity = quantity(subject);
152153
return IterableResult.concat(
153-
verb(predicate, subjectPerspective, subject.quantity)
154+
verb(predicate, subjectPerspective, subjectQuantity)
154155
.map((verb) => iWish(subject, verb)),
155156
IterableResult.from(() => {
156157
const takeNegative = true;
157158
return verb(
158159
addModalToAll("should", predicate, takeNegative),
159160
subjectPerspective,
160-
subject.quantity,
161+
subjectQuantity,
161162
);
162163
})
163164
.map((verb) => ({

src/translator/noun.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ export function perspective(noun: English.NounPhrase): Dictionary.Perspective {
134134
return "third";
135135
}
136136
}
137+
export function quantity(noun: English.NounPhrase): English.Quantity {
138+
switch (noun.type) {
139+
case "simple":
140+
return noun.quantity;
141+
case "compound":
142+
switch (noun.conjunction as "and" | "or") {
143+
case "and":
144+
return "plural";
145+
case "or":
146+
return quantity(noun.nouns[noun.nouns.length - 1]);
147+
}
148+
}
149+
}
137150
export function extractNegativeFromNoun(
138151
noun: English.NounPhrase,
139152
): null | English.NounPhrase {

src/translator/phrase.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,10 @@ function compoundNoun(
307307
return [noun];
308308
}
309309
});
310-
let quantity: English.Quantity;
311-
switch (conjunction) {
312-
case "and":
313-
quantity = "plural";
314-
break;
315-
case "or":
316-
quantity = nouns[nouns.length - 1].quantity;
317-
break;
318-
}
319310
return {
320311
type: "compound",
321312
conjunction,
322313
nouns,
323-
quantity,
324314
} as const;
325315
}
326316
function compoundAdjective(

0 commit comments

Comments
 (0)