@@ -20,14 +20,7 @@ import {
20
20
UnexpectedError ,
21
21
withSource ,
22
22
} from "../src/parser/parser_lib.ts" ;
23
- import {
24
- Definition ,
25
- Determiner ,
26
- Dictionary ,
27
- Noun ,
28
- NounForms ,
29
- VerbForms ,
30
- } from "./type.ts" ;
23
+ import { Definition , Dictionary , VerbForms } from "./type.ts" ;
31
24
32
25
const RESERVED_SYMBOLS = "#()*+/:;<=>@[\\]^`{|}~" ;
33
26
const WORDS = new RegExp ( `[^${ escapeRegex ( RESERVED_SYMBOLS ) } ]` ) ;
@@ -117,66 +110,62 @@ const nounOnly = choiceOnlyOne(
117
110
. with ( optionalAll ( keyword ( "gerund" ) ) ) ,
118
111
) ,
119
112
)
120
- . map < NounForms & { gerund : boolean } > (
121
- ( [ noun , gerund ] ) => {
122
- const sentence = nlp ( noun ) ;
123
- sentence . tag ( "Noun" ) ;
124
- const singular = sentence
125
- . nouns ( )
126
- . toSingular ( )
127
- . text ( ) ;
128
- const plural = sentence
129
- . nouns ( )
130
- . toPlural ( )
131
- . text ( ) ;
132
- if ( singular === "" || plural === "" ) {
133
- throw new ArrayResultError (
134
- `no singular or plural form found for "${ noun } ". consider ` +
135
- "providing both singular and plural forms instead" ,
136
- ) ;
137
- }
138
- if ( noun !== singular ) {
139
- throw new ArrayResultError (
140
- `conjugation error: "${ noun } " is not "${ singular } ". ` +
141
- "consider providing both singular and plural forms instead" ,
142
- ) ;
143
- }
144
- return {
145
- singular : escapeHtml ( singular ) ,
146
- plural : escapeHtml ( plural ) ,
147
- gerund : gerund != null ,
148
- } ;
149
- } ,
150
- ) ,
113
+ . map ( ( [ noun , gerund ] ) => {
114
+ const sentence = nlp ( noun ) ;
115
+ sentence . tag ( "Noun" ) ;
116
+ const singular = sentence
117
+ . nouns ( )
118
+ . toSingular ( )
119
+ . text ( ) ;
120
+ const plural = sentence
121
+ . nouns ( )
122
+ . toPlural ( )
123
+ . text ( ) ;
124
+ if ( singular === "" || plural === "" ) {
125
+ throw new ArrayResultError (
126
+ `no singular or plural form found for "${ noun } ". consider ` +
127
+ "providing both singular and plural forms instead" ,
128
+ ) ;
129
+ }
130
+ if ( noun !== singular ) {
131
+ throw new ArrayResultError (
132
+ `conjugation error: "${ noun } " is not "${ singular } ". ` +
133
+ "consider providing both singular and plural forms instead" ,
134
+ ) ;
135
+ }
136
+ return {
137
+ singular : escapeHtml ( singular ) ,
138
+ plural : escapeHtml ( plural ) ,
139
+ gerund : gerund != null ,
140
+ } ;
141
+ } ) ,
151
142
sequence (
152
143
word ,
153
144
tag (
154
145
keyword ( "n" )
155
146
. with ( sequence ( optionalAll ( keyword ( "gerund" ) ) , number ) ) ,
156
147
) ,
157
148
)
158
- . map < NounForms & { gerund : boolean } > (
159
- ( [ noun , [ gerund , number ] ] ) => {
160
- let singular : null | string ;
161
- let plural : null | string ;
162
- switch ( number ) {
163
- case "singular" :
164
- case "plural" :
165
- switch ( number ) {
166
- case "singular" :
167
- singular = noun ;
168
- plural = null ;
169
- break ;
170
- case "plural" :
171
- singular = null ;
172
- plural = noun ;
173
- break ;
174
- }
175
- break ;
176
- }
177
- return { singular, plural, gerund : gerund != null } ;
178
- } ,
179
- ) ,
149
+ . map ( ( [ noun , [ gerund , number ] ] ) => {
150
+ let singular : null | string ;
151
+ let plural : null | string ;
152
+ switch ( number ) {
153
+ case "singular" :
154
+ case "plural" :
155
+ switch ( number ) {
156
+ case "singular" :
157
+ singular = noun ;
158
+ plural = null ;
159
+ break ;
160
+ case "plural" :
161
+ singular = null ;
162
+ plural = noun ;
163
+ break ;
164
+ }
165
+ break ;
166
+ }
167
+ return { singular, plural, gerund : gerund != null } ;
168
+ } ) ,
180
169
sequence (
181
170
word ,
182
171
optionalAll ( slash . with ( word ) ) ,
@@ -185,13 +174,11 @@ const nounOnly = choiceOnlyOne(
185
174
. with ( optionalAll ( keyword ( "gerund" ) ) ) ,
186
175
) ,
187
176
)
188
- . map < NounForms & { gerund : boolean } > (
189
- ( [ singular , plural , gerund ] ) => ( {
190
- singular,
191
- plural,
192
- gerund : gerund != null ,
193
- } ) ,
194
- ) ,
177
+ . map ( ( [ singular , plural , gerund ] ) => ( {
178
+ singular,
179
+ plural,
180
+ gerund : gerund != null ,
181
+ } ) ) ,
195
182
) ;
196
183
const determinerType = choiceOnlyOne (
197
184
keyword ( "article" ) ,
@@ -208,17 +195,19 @@ const determiner = sequence(
208
195
optionalAll ( slash . with ( word ) ) ,
209
196
tag ( keyword ( "d" ) . with ( sequence ( determinerType , optionalNumber ) ) ) ,
210
197
)
211
- . map < Determiner > ( ( [ determiner , plural , [ kind , quantity ] ] ) => ( {
212
- determiner,
213
- plural,
214
- kind,
215
- quantity : quantity ?? "both" ,
216
- } ) ) ;
198
+ . map ( ( [ determiner , plural , [ kind , quantity ] ] ) =>
199
+ ( {
200
+ determiner,
201
+ plural,
202
+ kind,
203
+ quantity : quantity ?? "both" ,
204
+ } ) as const
205
+ ) ;
217
206
const adjectiveKind = choiceOnlyOne (
218
207
keyword ( "opinion" ) ,
219
208
keyword ( "size" ) ,
220
209
sequence ( keyword ( "physical" ) , keyword ( "quality" ) )
221
- . map < "physical quality" > ( ( ) => "physical quality" ) ,
210
+ . map ( ( ) => "physical quality" as const ) ,
222
211
keyword ( "age" ) ,
223
212
keyword ( "color" ) ,
224
213
keyword ( "origin" ) ,
@@ -249,17 +238,17 @@ const noun = sequence(
249
238
. skip ( tag ( sequence ( keyword ( "n" ) , keyword ( "proper" ) ) ) ) ,
250
239
) ,
251
240
)
252
- . map < Noun > ( ( [ determiner , adjective , noun , post ] ) => {
253
- return {
241
+ . map ( ( [ determiner , adjective , noun , post ] ) =>
242
+ ( {
254
243
...noun ,
255
244
determiner,
256
245
adjective,
257
246
postAdjective : mapNullable (
258
247
post ,
259
248
( [ adjective , name ] ) => ( { adjective, name } ) ,
260
249
) ,
261
- } ;
262
- } ) ;
250
+ } ) as const
251
+ ) ;
263
252
function verbOnly ( tagInside : Parser < unknown > ) : Parser < VerbForms > {
264
253
return choiceOnlyOne (
265
254
sequence (
@@ -437,15 +426,13 @@ const definition = choiceOnlyOne<Definition>(
437
426
) ,
438
427
)
439
428
. skip ( semicolon )
440
- . map ( (
441
- [
442
- singularSubject ,
443
- singularObject ,
444
- pluralSubject ,
445
- pluralObject ,
446
- perspective ,
447
- ] ,
448
- ) => ( {
429
+ . map ( ( [
430
+ singularSubject ,
431
+ singularObject ,
432
+ pluralSubject ,
433
+ pluralObject ,
434
+ perspective ,
435
+ ] ) => ( {
449
436
type : "personal pronoun" ,
450
437
singular : { subject : singularSubject , object : singularObject } ,
451
438
plural : { subject : pluralSubject , object : pluralObject } ,
0 commit comments