@@ -14,7 +14,6 @@ import {
14
14
matchString ,
15
15
nothing ,
16
16
optionalAll ,
17
- Parser ,
18
17
sequence ,
19
18
sourceOnly ,
20
19
UnexpectedError ,
@@ -51,12 +50,13 @@ const latinWord = match(/[a-z][a-zA-Z]*/, "word").skip(spaces);
51
50
const variationSelector = match ( / [ \uFE00 - \uFE0F ] / , "variation selector" ) ;
52
51
const ucsur = match ( UCSUR_CHARACTER_REGEX , "UCSUR glyph" )
53
52
. map ( ( ucsur ) => UCSUR_TO_LATIN . get ( ucsur ) ! ) ;
54
- function specificSpecialUcsur ( specialUcsur : string ) : Parser < string > {
55
- return matchString (
53
+
54
+ const specificSpecialUcsur = memoize ( ( specialUcsur : string ) =>
55
+ matchString (
56
56
specialUcsur ,
57
57
SPECIAL_UCSUR_DESCRIPTIONS . get ( specialUcsur ) ! ,
58
- ) ;
59
- }
58
+ )
59
+ ) ;
60
60
const singleUcsurWord = ucsur . skip ( optionalAll ( variationSelector ) ) . skip ( spaces ) ;
61
61
const joiner = choiceOnlyOne (
62
62
matchString ( "\u200D" , "zero width joiner" ) ,
@@ -71,12 +71,12 @@ const properWords = allAtLeastOnce(
71
71
)
72
72
. map ( ( array ) => array . join ( " " ) )
73
73
. map ( ( words ) => ( { type : "proper word" , words, kind : "latin" } ) as const ) ;
74
- function specificWord ( thatWord : string ) : Parser < string > {
75
- return word . filter ( ( thisWord ) =>
74
+ const specificWord = memoize ( ( thatWord : string ) =>
75
+ word . filter ( ( thisWord ) =>
76
76
thatWord === thisWord ||
77
77
throwError ( new UnexpectedError ( `"${ thisWord } "` , `"${ thatWord } "` ) )
78
- ) ;
79
- }
78
+ )
79
+ ) ;
80
80
const multipleA = specificWord ( "a" )
81
81
. with ( count ( allAtLeastOnce ( specificWord ( "a" ) ) ) )
82
82
. map ( ( count ) => ( { type : "multiple a" , count : count + 1 } ) as const ) ;
@@ -151,20 +151,9 @@ const cartouches = allAtLeastOnce(cartouche)
151
151
kind : "cartouche" ,
152
152
} ) as const
153
153
) ;
154
- function longContainer < T > (
155
- left : string ,
156
- right : string ,
157
- inside : Parser < T > ,
158
- ) : Parser < T > {
159
- return specificSpecialUcsur ( left )
160
- . with ( inside )
161
- . skip ( specificSpecialUcsur ( right ) ) ;
162
- }
163
- const longSpaceContainer = longContainer (
164
- START_OF_LONG_GLYPH ,
165
- END_OF_LONG_GLYPH ,
166
- count ( spacesWithoutNewline ) . filter ( ( length ) => length > 0 ) ,
167
- )
154
+ const longSpaceContainer = specificSpecialUcsur ( START_OF_LONG_GLYPH )
155
+ . with ( count ( spacesWithoutNewline ) . filter ( ( length ) => length > 0 ) )
156
+ . skip ( specificSpecialUcsur ( END_OF_LONG_GLYPH ) )
168
157
. skip ( spaces ) ;
169
158
const longGlyphHead = choiceOnlyOne (
170
159
combinedGlyphs ,
0 commit comments