Skip to content

Commit e917b56

Browse files
committed
small refactor
1 parent 2f05228 commit e917b56

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

dictionary/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ArrayResultError } from "../src/array_result.ts";
88
import {
99
all,
1010
allAtLeastOnce,
11-
character,
1211
choiceOnlyOne,
1312
end,
1413
match,
@@ -32,6 +31,7 @@ const comment = match(/#[^\n]*\n?/, "comment");
3231
const spaces = sourceOnly(all(choiceOnlyOne(match(/\s/, "space"), comment)));
3332
const backtick = matchString("`", "backtick");
3433
const colon = matchString(":", "colon");
34+
const character = match(/./u, "character");
3535

3636
const tokiPonaWord = lex(match(/[a-z][a-zA-Z]*/, "word"));
3737
const openParenthesis = lex(matchString("(", "open parenthesis"));

src/parser/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
count,
5050
empty,
5151
end,
52-
everything,
52+
allRest,
5353
lazy,
5454
lookAhead,
5555
many,
@@ -715,7 +715,7 @@ const sentence = choice<Sentence>(
715715
.filter(filter(SENTENCE_RULE));
716716
export const parser = spaces
717717
.with(
718-
lookAhead(everything.filter((source) =>
718+
lookAhead(allRest.filter((source) =>
719719
source.trimEnd().length <= 500 ||
720720
throwError(new UnrecognizedError("long text"))
721721
)),

src/parser/parser_lib.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export function allAtLeastOnce<T>(parser: Parser<T>): Parser<ReadonlyArray<T>> {
178178
return sequence(parser, all(parser))
179179
.map(([first, rest]) => [first, ...rest]);
180180
}
181-
export function count(parser: Parser<{ length: number }>): Parser<number> {
181+
export function count(
182+
parser: Parser<Readonly<{ length: number }>>,
183+
): Parser<number> {
182184
return parser.map(({ length }) => length);
183185
}
184186
function describeSource(source: string): string {
@@ -240,13 +242,12 @@ export function matchString(
240242
}
241243
});
242244
}
243-
export const everything = new Parser((position) =>
245+
export const allRest = new Parser((position) =>
244246
new ArrayResult([{
245247
value: currentSource.slice(position),
246248
length: currentSource.length - position,
247249
}])
248250
);
249-
export const character = match(/./us, "character");
250251
export const end = new Parser((position) =>
251252
position === currentSource.length
252253
? new ArrayResult([{ value: null, length: 0 }])

0 commit comments

Comments
 (0)