Skip to content

Commit 2c6676a

Browse files
committed
more type annotation
1 parent 917741e commit 2c6676a

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

src/parser/parser_lib.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function error(error: ResultError): Parser<never> {
125125
}
126126
export const empty: Parser<never> = new Parser(() => ArrayResult.empty());
127127
export const nothing: Parser<null> = new Parser(() =>
128-
new ArrayResult([{ value: null, length: 0 }])
128+
new ArrayResult<ValueLength<null>>([{ value: null, length: 0 }])
129129
);
130130
export const emptyArray: Parser<ReadonlyArray<never>> = nothing.map(() => []);
131131
export function lookAhead<T>(parser: Parser<T>): Parser<T> {
@@ -263,7 +263,10 @@ export function matchCapture(
263263
return new Parser((position) => {
264264
const match = currentSource.slice(position).match(newRegex);
265265
if (match != null) {
266-
return new ArrayResult([{ value: match, length: match[0].length }]);
266+
return new ArrayResult<ValueLength<RegExpMatchArray>>([{
267+
value: match,
268+
length: match[0].length,
269+
}]);
267270
} else {
268271
return generateError(position, description);
269272
}
@@ -281,7 +284,7 @@ export function matchString(
281284
currentSource.length - position >= match.length &&
282285
currentSource.slice(position, position + match.length) === match
283286
) {
284-
return new ArrayResult([{
287+
return new ArrayResult<ValueLength<string>>([{
285288
value: match,
286289
length: match.length,
287290
}]);
@@ -291,19 +294,19 @@ export function matchString(
291294
});
292295
}
293296
export const allRest: Parser<string> = new Parser((position) =>
294-
new ArrayResult([{
297+
new ArrayResult<ValueLength<string>>([{
295298
value: currentSource.slice(position),
296299
length: currentSource.length - position,
297300
}])
298301
);
299302
export const end: Parser<null> = new Parser((position) =>
300303
position === currentSource.length
301-
? new ArrayResult([{ value: null, length: 0 }])
304+
? new ArrayResult<ValueLength<null>>([{ value: null, length: 0 }])
302305
: generateError(position, "end of text")
303306
);
304307
export const notEnd: Parser<null> = new Parser((position) =>
305308
position < currentSource.length
306-
? new ArrayResult([{ value: null, length: 0 }])
309+
? new ArrayResult<ValueLength<null>>([{ value: null, length: 0 }])
307310
: ArrayResult.errors([
308311
new UnexpectedError(
309312
"end of text",

src/translator/modifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function multipleModifiers(
226226
inPositionPhrases.length <= 1 &&
227227
(nouns.length === 0 || inPositionPhrases.length === 0)
228228
) {
229-
adjectival = IterableResult.single({
229+
adjectival = IterableResult.single<MultipleModifierTranslation>({
230230
type: "adjectival",
231231
nounPreposition: nounPrepositions[0] ?? null,
232232
determiners,
@@ -261,7 +261,7 @@ export function multipleModifiers(
261261
emphasis: false,
262262
}
263263
: null;
264-
adverbial = IterableResult.single({
264+
adverbial = IterableResult.single<MultipleModifierTranslation>({
265265
type: "adverbial",
266266
adverbs,
267267
inWayPhrase,

src/translator/noun.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,23 @@ export function fromNounForms(
8282
]);
8383
case "condensed":
8484
if (singular != null && plural != null) {
85-
return IterableResult.single({
85+
return IterableResult.single<NounQuantity>({
8686
noun: condense(singular, plural),
8787
quantity: "condensed",
8888
});
8989
}
9090
// fallthrough
9191
case "default only":
9292
if (singular != null) {
93-
return IterableResult.single({
93+
return IterableResult.single<NounQuantity>({
9494
noun: singular,
9595
quantity: "singular",
9696
});
9797
} else {
98-
return IterableResult.single({ noun: plural!, quantity: "plural" });
98+
return IterableResult.single<NounQuantity>({
99+
noun: plural!,
100+
quantity: "plural",
101+
});
99102
}
100103
}
101104
}

src/translator/verb.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ function fromVerbForms(
213213
case "condensed":
214214
if (negated) {
215215
if (is) {
216-
result = IterableResult.single({
216+
result = IterableResult.single<Result>({
217217
modal: null,
218218
doesNot: null,
219219
verb: `${present} not/${past} not/will not be`,
220220
postAdverb: null,
221221
});
222222
} else {
223-
result = IterableResult.single({
223+
result = IterableResult.single<Result>({
224224
modal: null,
225225
doesNot: {
226226
preAdverbs: [],
@@ -233,14 +233,14 @@ function fromVerbForms(
233233
}
234234
} else {
235235
if (is) {
236-
result = IterableResult.single({
236+
result = IterableResult.single<Result>({
237237
modal: null,
238238
doesNot: null,
239239
verb: `${present}/${past}/will be`,
240240
postAdverb: null,
241241
});
242242
} else {
243-
result = IterableResult.single({
243+
result = IterableResult.single<Result>({
244244
modal: noAdverbs(noEmphasis("(will)")),
245245
doesNot: null,
246246
verb: condenseVerb(present, past),
@@ -316,14 +316,14 @@ function fromVerbForms(
316316
case "default only":
317317
if (negated) {
318318
if (is) {
319-
result = IterableResult.single({
319+
result = IterableResult.single<Result>({
320320
modal: null,
321321
doesNot: null,
322322
verb: present,
323323
postAdverb: NOT,
324324
});
325325
} else {
326-
result = IterableResult.single({
326+
result = IterableResult.single<Result>({
327327
modal: null,
328328
doesNot: {
329329
preAdverbs: [],
@@ -335,7 +335,7 @@ function fromVerbForms(
335335
});
336336
}
337337
} else {
338-
result = IterableResult.single({
338+
result = IterableResult.single<Result>({
339339
modal: null,
340340
doesNot: null,
341341
verb: present,
@@ -378,7 +378,7 @@ export function verb(
378378
const { first } = verb;
379379
switch (first.type) {
380380
case "modal":
381-
return IterableResult.single({
381+
return IterableResult.single<English.VerbPhrase>({
382382
...verb,
383383
type: "simple",
384384
verb: { modal: first, verbs: verb.rest },

0 commit comments

Comments
 (0)