Skip to content

Commit 2c97296

Browse files
committed
add type annotation
1 parent 411c0d3 commit 2c97296

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

dictionary/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
withPosition,
2525
withSource,
2626
} from "../src/parser/parser_lib.ts";
27-
import { Definition, Noun, PartialVerb } from "./type.ts";
27+
import { Definition, Dictionary, Noun, PartialVerb } from "./type.ts";
2828

2929
const RESERVED_SYMBOLS = "#()*+/:;<=>@[\\]^`{|}~";
3030

@@ -594,7 +594,7 @@ const entry = withSource(
594594
),
595595
)
596596
.map(([definitions, source]) => ({ definitions, source: source.trimEnd() }));
597-
export const dictionaryParser = ignore
597+
export const dictionaryParser: Parser<Dictionary> = ignore
598598
.with(
599599
allWithCheck(new CheckedParser(notEnd, sequence(positionedHead, entry))),
600600
)

src/parser/lexer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
matchString,
1515
nothing,
1616
optionalAll,
17+
Parser,
1718
sequence,
1819
UnexpectedError,
1920
UnrecognizedError,
@@ -192,7 +193,7 @@ const combinedGlyphsToken = combinedGlyphs
192193
.map((words) => ({ type: "combined glyphs", words }) as const);
193194
const wordToken = word.map((word) => ({ type: "word", word }) as const);
194195

195-
export const token = choiceOnlyOne<Token>(
196+
export const token: Parser<Token> = choiceOnlyOne<Token>(
196197
xAlaX,
197198
multipleA,
198199
choice<Token>(longWord, wordToken),

src/parser/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ const sentence = choice<Sentence>(
696696
})),
697697
)
698698
.filter(filter(SENTENCE_RULE));
699-
export const parser = spaces
699+
export const parser: Parser<MultipleSentences> = spaces
700700
.with(
701701
lookAhead(allRest.filter((source) =>
702702
source.trimEnd().length <= 500 ||

src/parser/parser_lib.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ export class UnrecognizedError extends PositionedError {
119119
export function error(error: ArrayResultError): Parser<never> {
120120
return new Parser(() => ArrayResult.errors([error]));
121121
}
122-
export const empty = new Parser<never>(() => ArrayResult.empty());
123-
export const nothing = new Parser(() =>
122+
export const empty: Parser<never> = new Parser(() => ArrayResult.empty());
123+
export const nothing: Parser<null> = new Parser(() =>
124124
new ArrayResult([{ value: null, length: 0 }])
125125
);
126-
export const emptyArray = nothing.map(() => []);
126+
export const emptyArray: Parser<ReadonlyArray<never>> = nothing.map(() => []);
127127
export function lookAhead<T>(parser: Parser<T>): Parser<T> {
128128
return new Parser((input) =>
129129
parser.rawParser(input)
@@ -188,7 +188,7 @@ export function sequence<T extends ReadonlyArray<unknown>>(
188188
) as Parser<any>;
189189
}
190190
export const many = memoize(<T>(parser: Parser<T>): Parser<ReadonlyArray<T>> =>
191-
choice(
191+
choice<ReadonlyArray<T>>(
192192
sequence(parser, lazy(lazyEval(() => many(parser))))
193193
.map(([first, rest]) => [first, ...rest]),
194194
emptyArray,
@@ -201,7 +201,7 @@ export function manyAtLeastOnce<T>(
201201
.map(([first, rest]) => [first, ...rest]);
202202
}
203203
export const all = memoize(<T>(parser: Parser<T>): Parser<ReadonlyArray<T>> =>
204-
choiceOnlyOne(
204+
choiceOnlyOne<ReadonlyArray<T>>(
205205
sequence(parser, lazy(lazyEval(() => all(parser))))
206206
.map(([first, rest]) => [first, ...rest]),
207207
emptyArray,
@@ -278,18 +278,18 @@ export function matchString(
278278
}
279279
});
280280
}
281-
export const allRest = new Parser((position) =>
281+
export const allRest: Parser<string> = new Parser((position) =>
282282
new ArrayResult([{
283283
value: currentSource.slice(position),
284284
length: currentSource.length - position,
285285
}])
286286
);
287-
export const end = new Parser((position) =>
287+
export const end: Parser<null> = new Parser((position) =>
288288
position === currentSource.length
289289
? new ArrayResult([{ value: null, length: 0 }])
290290
: generateError(position, "end of text")
291291
);
292-
export const notEnd = new Parser((position) =>
292+
export const notEnd: Parser<null> = new Parser((position) =>
293293
position < currentSource.length
294294
? new ArrayResult([{ value: null, length: 0 }])
295295
: ArrayResult.errors([
@@ -377,7 +377,7 @@ export function optionalWithCheck<T>(
377377
export const allWithCheck = memoize(<T>(
378378
parser: CheckedParser<T>,
379379
): Parser<ReadonlyArray<T>> =>
380-
choiceWithCheck(
380+
choiceWithCheck<ReadonlyArray<T>>(
381381
new CheckedParser(
382382
parser.check,
383383
sequence(parser.parser, lazy(lazyEval(() => allWithCheck(parser))))

0 commit comments

Comments
 (0)