Skip to content

Commit 756107b

Browse files
committed
strict ucsur description mapping
1 parent beca6de commit 756107b

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/parser/lexer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
END_OF_REVERSE_LONG_GLYPH,
3434
SCALING_JOINER,
3535
SPECIAL_UCSUR_DESCRIPTIONS,
36+
SpecialUcsur,
3637
STACKING_JOINER,
3738
START_OF_CARTOUCHE,
3839
START_OF_LONG_GLYPH,
@@ -49,11 +50,8 @@ const variationSelector = match(/[\uFE00-\uFE0F]/, "variation selector");
4950
const ucsur = match(UCSUR_CHARACTER_REGEX, "UCSUR glyph")
5051
.map((ucsur) => UCSUR_TO_LATIN.get(ucsur)!);
5152

52-
const specificSpecialUcsur = memoize((specialUcsur: string) =>
53-
matchString(
54-
specialUcsur,
55-
SPECIAL_UCSUR_DESCRIPTIONS.get(specialUcsur)!,
56-
)
53+
const specificSpecialUcsur = memoize((specialUcsur: SpecialUcsur) =>
54+
matchString(specialUcsur, SPECIAL_UCSUR_DESCRIPTIONS[specialUcsur])
5755
);
5856
const singleUcsurWord = ucsur.skip(optionalAll(variationSelector)).skip(spaces);
5957
const joiner = choiceOnlyOne(

src/parser/ucsur.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@ export const END_OF_REVERSE_LONG_GLYPH = "\u{F199B}";
1515
export const UCSUR_MIDDLE_DOT = "\u{F199C}";
1616
export const UCSUR_COLON = "\u{F199D}";
1717

18-
export const SPECIAL_UCSUR_DESCRIPTIONS = new Map(
19-
Object.entries({
20-
[START_OF_CARTOUCHE]: "start of cartouche",
21-
[END_OF_CARTOUCHE]: "end of cartouche",
22-
[COMBINING_CARTOUCHE_EXTENSION]: "combining cartouche extension",
23-
[START_OF_LONG_PI]: "start of long pi",
24-
[COMBINING_LONG_PI_EXTENSION]: "combining long pi extension",
25-
[STACKING_JOINER]: "stacking joiner",
26-
[SCALING_JOINER]: "scaling joiner",
27-
[START_OF_LONG_GLYPH]: "start of long glyph",
28-
[END_OF_LONG_GLYPH]: "end of long glyph",
29-
[COMBINING_LONG_GLYPH_EXTENSION]: "combining long glyph extension",
30-
[START_OF_REVERSE_LONG_GLYPH]: "start of reverse long glyph",
31-
[END_OF_REVERSE_LONG_GLYPH]: "end of reverse long glyph",
32-
[UCSUR_MIDDLE_DOT]: "middle dot",
33-
[UCSUR_COLON]: "colon",
34-
}),
35-
);
18+
export const SPECIAL_UCSUR_DESCRIPTIONS = {
19+
[START_OF_CARTOUCHE]: "start of cartouche",
20+
[END_OF_CARTOUCHE]: "end of cartouche",
21+
[COMBINING_CARTOUCHE_EXTENSION]: "combining cartouche extension",
22+
[START_OF_LONG_PI]: "start of long pi",
23+
[COMBINING_LONG_PI_EXTENSION]: "combining long pi extension",
24+
[STACKING_JOINER]: "stacking joiner",
25+
[SCALING_JOINER]: "scaling joiner",
26+
[START_OF_LONG_GLYPH]: "start of long glyph",
27+
[END_OF_LONG_GLYPH]: "end of long glyph",
28+
[COMBINING_LONG_GLYPH_EXTENSION]: "combining long glyph extension",
29+
[START_OF_REVERSE_LONG_GLYPH]: "start of reverse long glyph",
30+
[END_OF_REVERSE_LONG_GLYPH]: "end of reverse long glyph",
31+
[UCSUR_MIDDLE_DOT]: "middle dot",
32+
[UCSUR_COLON]: "colon",
33+
} as const;
34+
35+
export type SpecialUcsur = keyof typeof SPECIAL_UCSUR_DESCRIPTIONS;
36+
3637
export const PU = [
3738
"a",
3839
"akesi",

0 commit comments

Comments
 (0)